| TerraLib 4.1

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Examples

- File List
- File Members

E:/Projetos_Primeiro_Semestre_2012/TerraView/terralib/src/terralib/drivers/spl/PluginsParametersContainer.h
Go to the documentation of this file.

    00001 /************************************************************************************
    00002 TerraView - visualization and exploration of geographical databases
    00003 using TerraLib.
    00004 Copyright � 2001-2007 INPE and Tecgraf/PUC-Rio.
    00005 This file is part of TerraView. TerraView is free software; you can redistribute it
    00006 and/or modify it under the terms of the GNU General Public License as published by
    00007 the Free Software Foundation; either version 2 of the License, or
    00008 (at your option) any later version.
    00009
    00010 You should have received a copy of the GNU General Public License
    00011 along with TerraView.
    00012 The authors reassure the license terms regarding the warranties.
    00013 They specifically disclaim any warranties, including, but not limited to,
    00014 the implied warranties of merchantability and fitness for a particular purpose.
    00015 The software provided hereunder is on an "as is" basis, and the authors have no
    00016 obligation to provide maintenance, support, updates, enhancements, or modifications.
    00017 In no event shall INPE and Tecgraf / PUC-Rio be held liable to any party for direct,
    00018 indirect, special, incidental, or consequential damages arising out of the use of
    00019 this program and its documentation.
    00020 *************************************************************************************/
    00021
    00027 #ifndef PLUGINPARAMETERSCONTAINER_H
    00028   #define PLUGINPARAMETERSCONTAINER_H
    00029
    00030   #include "../../kernel/TeSharedPtr.h"
    00031   #include "../../kernel/TeMutex.h"
    00032
    00033 #include "TeSPLDefines.h"
    00034
    00035   #include <time.h>
    00036   #include <vector>
    00037
    00042   class TLSPL_DLL PPCNodeInterface {
    00043     public :
    00044
    00048       PPCNodeInterface() {};
    00049
    00053       virtual ~PPCNodeInterface() {};
    00054
    00060       virtual TeSharedPtr< PPCNodeInterface > clone() const = 0;
    00061
    00062     private :
    00063
    00070       const PPCNodeInterface& operator=(
    00071         const PPCNodeInterface& ext_instance );
    00072   };
    00073
    00074
    00079   template< typename ObjectT >
    00080   class PPCNode : public PPCNodeInterface {
    00081     public :
    00082
    00086       PPCNode() {};
    00087
    00091       ~PPCNode() {};
    00092
    00098       TeSharedPtr< PPCNodeInterface > clone() const
    00099       {
    00100         PPCNode< ObjectT >* new_node_ptr =
    00101           new PPCNode< ObjectT >;
    00102
    00103         TeSharedPtr< ObjectT > new_obj_ptr( new ObjectT );
    00104         ( *new_obj_ptr )= ( *obj_ptr_ );
    00105
    00106         new_node_ptr->setObjPtr( new_obj_ptr );
    00107
    00108         TeSharedPtr< PPCNodeInterface > new_nodei_ptr(
    00109           new_node_ptr );
    00110
    00111         return new_nodei_ptr;
    00112       };
    00113
    00118       void setObjPtr( const TeSharedPtr< ObjectT >& ptr )
    00119       {
    00120         obj_ptr_ = ptr;
    00121       };
    00122
    00127       TeSharedPtr< ObjectT > getObjPtr() const
    00128       {
    00129         return obj_ptr_;
    00130       };
    00131
    00132     protected :
    00133
    00137       TeSharedPtr< ObjectT > obj_ptr_;
    00138
    00139   };
    00140
    00146   template< typename PluginsParametersContainerKeyT >
    00147   class PluginsParametersContainer {
    00148
    00149     public :
    00150
    00153       typedef TeSharedPtr< PluginsParametersContainer< PluginsParametersContainerKeyT > > pointer;
    00154
    00157       typedef const TeSharedPtr< PluginsParametersContainer< PluginsParametersContainerKeyT > > const_pointer;
    00158
    00162       PluginsParametersContainer();
    00163
    00168       PluginsParametersContainer(
    00169         const PluginsParametersContainer< PluginsParametersContainerKeyT >& external );
    00170
    00174       ~PluginsParametersContainer();
    00175
    00183       bool operator==(
    00184         const PluginsParametersContainer< PluginsParametersContainerKeyT >& ext_instance ) const;
    00185
    00193       bool operator!=(
    00194         const PluginsParametersContainer< PluginsParametersContainerKeyT >& ext_instance ) const;
    00195
    00202       const PluginsParametersContainer< PluginsParametersContainerKeyT >& operator=(
    00203         const PluginsParametersContainer< PluginsParametersContainerKeyT >& ext_instance );
    00204
    00209       void clear();
    00210
    00217       template< typename ObjectT >
    00218       void store( const PluginsParametersContainerKeyT& obj_key,
    00219                          const ObjectT& obj_reference );
    00220
    00228       template< typename ObjectT >
    00229       bool retrive( const PluginsParametersContainerKeyT& obj_key,
    00230         ObjectT& obj_reference ) const;
    00231
    00232     protected :
    00233
    00236       typedef typename std::pair< PluginsParametersContainerKeyT,
    00237         TeSharedPtr< PPCNodeInterface > > VectorKeyT;
    00238
    00241       typedef typename std::vector< VectorKeyT > VectorT;
    00242
    00244       VectorT objects_vector_;
    00245
    00249       time_t last_up_time_;
    00250
    00254       mutable TeMutex this_lock_instance_;
    00255
    00261       void update_time();
    00262
    00263 };
    00264
    00265
    00266 template< typename PluginsParametersContainerKeyT >
    00267 PluginsParametersContainer< PluginsParametersContainerKeyT >::PluginsParametersContainer()
    00268 {
    00269   last_up_time_ = 0;
    00270 }
    00271
    00272
    00273 template< typename PluginsParametersContainerKeyT >
    00274 PluginsParametersContainer< PluginsParametersContainerKeyT >::PluginsParametersContainer(
    00275   const PluginsParametersContainer< PluginsParametersContainerKeyT >& external )
    00276 {
    00277   last_up_time_ = 0;
    00278
    00279   operator=( external );
    00280 }
    00281
    00282
    00283 template< typename PluginsParametersContainerKeyT >
    00284 PluginsParametersContainer< PluginsParametersContainerKeyT >::~PluginsParametersContainer()
    00285 {
    00286   clear();
    00287 }
    00288
    00289
    00290 template< typename PluginsParametersContainerKeyT >
    00291 void PluginsParametersContainer< PluginsParametersContainerKeyT >::clear()
    00292 {
    00293   this_lock_instance_.lock();
    00294
    00295   objects_vector_.clear();
    00296
    00297   this_lock_instance_.unLock();
    00298 }
    00299
    00300
    00301 template< typename PluginsParametersContainerKeyT >
    00302 bool PluginsParametersContainer< PluginsParametersContainerKeyT >::operator==(
    00303   const PluginsParametersContainer< PluginsParametersContainerKeyT >& ext_instance ) const
    00304 {
    00305   if( last_up_time_ == ext_instance.last_up_time_ ) {
    00306     return true;
    00307   } else {
    00308     return false;
    00309   }
    00310 }
    00311
    00312
    00313 template< typename PluginsParametersContainerKeyT >
    00314 bool PluginsParametersContainer< PluginsParametersContainerKeyT >::operator!=(
    00315   const PluginsParametersContainer< PluginsParametersContainerKeyT >& ext_instance ) const
    00316 {
    00317   if( last_up_time_ == ext_instance.last_up_time_ ) {
    00318     return false;
    00319   } else {
    00320     return true;
    00321   }
    00322 }
    00323
    00324
    00325 template< typename PluginsParametersContainerKeyT >
    00326 const PluginsParametersContainer< PluginsParametersContainerKeyT >&
    00327 PluginsParametersContainer< PluginsParametersContainerKeyT >::operator=(
    00328   const PluginsParametersContainer< PluginsParametersContainerKeyT >& ext_instance )
    00329 {
    00330   if( ( &ext_instance ) != this ) {
    00331     this_lock_instance_.lock();
    00332
    00333     objects_vector_.clear();
    00334
    00335     ext_instance.this_lock_instance_.lock();
    00336
    00337     typename VectorT::const_iterator objects_vector_it =
    00338       ext_instance.objects_vector_.begin();
    00339     typename VectorT::const_iterator objects_vector_it_end =
    00340       ext_instance.objects_vector_.end();
    00341
    00342     VectorKeyT auxkey;
    00343
    00344     while( objects_vector_it != objects_vector_it_end ) {
    00345       auxkey.first = objects_vector_it->first;
    00346       auxkey.second = objects_vector_it->second->clone();
    00347
    00348       objects_vector_.push_back( auxkey );
    00349
    00350       ++objects_vector_it;
    00351     }
    00352
    00353     last_up_time_ = ext_instance.last_up_time_;
    00354
    00355     ext_instance.this_lock_instance_.unLock();
    00356
    00357     this_lock_instance_.unLock();
    00358   }
    00359
    00360   return *this;
    00361 }
    00362
    00363
    00364 template< typename PluginsParametersContainerKeyT >
    00365 void PluginsParametersContainer< PluginsParametersContainerKeyT >::update_time()
    00366 {
    00367   last_up_time_ = time( 0 );
    00368 }
    00369
    00370
    00371 template< typename PluginsParametersContainerKeyT >
    00372 template< typename ObjectT >
    00373 void PluginsParametersContainer< PluginsParametersContainerKeyT >::store(
    00374   const PluginsParametersContainerKeyT& obj_key, const ObjectT& obj_reference )
    00375 {
    00376   this_lock_instance_.lock();
    00377
    00378   typename VectorT::iterator objects_vector_it =
    00379     objects_vector_.begin();
    00380   typename VectorT::iterator objects_vector_it_end =
    00381     objects_vector_.end();
    00382
    00383   PPCNode< ObjectT >* node_ptr = 0;
    00384
    00385   while( objects_vector_it != objects_vector_it_end ) {
    00386     if( objects_vector_it->first == obj_key ) {
    00387       node_ptr = (PPCNode< ObjectT >*)
    00388         objects_vector_it->second.nakedPointer();
    00389
    00390       break;
    00391     }
    00392
    00393     ++objects_vector_it;
    00394   }
    00395
    00396   if( node_ptr == 0 ) {
    00397     TeSharedPtr< ObjectT > new_obj_ptr( new ObjectT );
    00398     (*new_obj_ptr) = obj_reference;
    00399
    00400     node_ptr = new PPCNode< ObjectT >;
    00401     node_ptr->setObjPtr( new_obj_ptr );
    00402
    00403     VectorKeyT auxkey;
    00404     auxkey.first = obj_key;
    00405     auxkey.second =
    00406       TeSharedPtr< PPCNodeInterface >(
    00407         (PPCNodeInterface*)node_ptr );
    00408
    00409     objects_vector_.push_back( auxkey );
    00410   } else {
    00411     (*( node_ptr->getObjPtr() ) ) = obj_reference;
    00412   }
    00413
    00414   update_time();
    00415
    00416   this_lock_instance_.unLock();
    00417 }
    00418
    00419
    00420 template< typename PluginsParametersContainerKeyT >
    00421 template< typename ObjectT >
    00422 bool PluginsParametersContainer< PluginsParametersContainerKeyT >::retrive(
    00423   const PluginsParametersContainerKeyT& obj_key, ObjectT& obj_reference ) const
    00424 {
    00425   this_lock_instance_.lock();
    00426
    00427   typename VectorT::const_iterator objects_vector_it =
    00428     objects_vector_.begin();
    00429   typename VectorT::const_iterator objects_vector_it_end =
    00430     objects_vector_.end();
    00431
    00432   PPCNode< ObjectT >* node_ptr = 0;
    00433
    00434   while( objects_vector_it != objects_vector_it_end ) {
    00435     if( objects_vector_it->first == obj_key ) {
    00436       node_ptr = (PPCNode< ObjectT >*)
    00437         objects_vector_it->second.nakedPointer();
    00438
    00439       break;
    00440     }
    00441
    00442     ++objects_vector_it;
    00443   }
    00444
    00445   if( node_ptr == 0 ) {
    00446     TEAGN_LOGWARN( "Trying to retrive an object not stored" );
    00447
    00448     this_lock_instance_.unLock();
    00449
    00450     return false;
    00451   } else {
    00452     obj_reference = ( *( node_ptr->getObjPtr() ) );
    00453
    00454     this_lock_instance_.unLock();
    00455
    00456     return true;
    00457   }
    00458 }
    00459
    00460
    00461 #endif
    00462

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines