Changeset 700


Ignore:
Timestamp:
09/22/15 10:09:53 (9 years ago)
Author:
rlacroix
Message:

Registry: Fix the getter/setter methods.

  • Fix a typo in void setKey(const std::string& key, const CBaseType& value).
  • Fix the templated methods by taking advantage of SFINAE concept.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • XIOS/trunk/src/registry.hpp

    r696 r700  
    77#include "message.hpp" 
    88 
     9// Those two headers can be replaced by the C++11 equivalent in the future 
     10#include <boost/utility/enable_if.hpp> 
     11#include <boost/type_traits.hpp> 
     12 
    913namespace xios 
    1014{ 
    1115/*! 
    1216  \class CRegistry 
    13  This class is a registry database which store key with an associated value. Internaly the value is stored as a memory bloc 
    14  and the key is a string. The registry can be gathered and merge between mpi process, broadcasted and read or wrote from a file 
     17 This class is a registry database which store key with an associated value. Internally the value is stored as a memory bloc 
     18 and the key is a string. The registry can be gathered and merge between MPI process, broadcast and read or wrote from a file 
    1519*/ 
    1620  class CRegistry : virtual public CBaseType 
     
    2024/** Constructor, the communicator is used for bcast or gather operation between MPI processes */ 
    2125      CRegistry(const MPI_Comm& comm=MPI_COMM_WORLD) : communicator(comm) {} 
    22        
     26 
    2327/** Copy constructor */ 
    2428      CRegistry(const CRegistry& reg) ; 
    25        
     29 
    2630 
    2731/** insert a value associated to a key*/ 
    28       void setKey(const std::string& key, const CBaseType& value) {this->setKey(key,value); } 
     32      void setKey(const std::string& key, const CBaseType& value) { this->setKey_(key,value); } 
    2933 
    3034/** insert a value associated to a key*/ 
    31       template<typename T> void setKey(const std::string& key, const CType<T>& value) {this->setKey_(key,value); } 
     35      template<typename T> typename boost::enable_if_c<!boost::is_convertible<T&, CBaseType&>::value>::type 
     36      setKey(const std::string& key, const T& value) { this->setKey_(key,CType<T>(value)); } 
    3237 
    3338 
    34 /** retreive a value from a key */ 
    35       void getKey(const std::string& key, CBaseType& value ) {this->getKey_(key,value); } 
     39/** retrieve a value from a key */ 
     40      void getKey(const std::string& key, CBaseType& value) { this->getKey_(key,value); } 
    3641 
    37 /** retreive a value from a key */ 
    38       template<typename T> void getKey(const std::string& key, CType<T>&  value ) {this->getKey_(key,value); } 
     42/** retrieve a value from a key */ 
     43      template<typename T> typename boost::enable_if_c<!boost::is_convertible<T&, CBaseType&>::value>::type 
     44      getKey(const std::string& key, T& value) { CType_ref<T> valRef(value); this->getKey_(key,valRef); } 
    3945 
    4046 
    4147/** query for an already inserted key */ 
    4248      bool foundKey(const std::string& key) const ; 
    43        
     49 
    4450/** The registry is wrote into a memory buffer */ 
    4551      bool toBuffer(CBufferOut& buffer) const ; 
     
    5157      void toFile(const string& filename) ; 
    5258 
    53 /** The registry is read from the file given by "filename". If no file exist, the registry remain empty */      
     59/** The registry is read from the file given by "filename". If no file exist, the registry remain empty */ 
    5460      void fromFile(const string& filename) ; 
    5561 
    56 /** Merge the registry with an other. Existing keys in the current registry are not overwritten */          
     62/** Merge the registry with an other. Existing keys in the current registry are not overwritten */ 
    5763      void mergeRegistry(const CRegistry& inRegistry) ; 
    5864 
    59 /** Broadcast registry from the root process (rank 0) to the other processes of the communicator */     
     65/** Broadcast registry from the root process (rank 0) to the other processes of the communicator */ 
    6066      void bcastRegistry(void) ; 
    6167 
    62 /** Gather registry to the root process (rank 0) from the other processes of the communicator */           
     68/** Gather registry to the root process (rank 0) from the other processes of the communicator */ 
    6369      void gatherRegistry(void) ; 
    6470 
    65 /** Gather registry with a hierachical algorithm which avoid root process to get registries from whole processes of the communicator. 
    66    Registry are merged two by two hirarchicaly. */ 
     71/** Gather registry with a hierarchical algorithm which avoid root process to get registries from whole processes of the communicator. 
     72   Registry are merged two by two hierarchically. */ 
    6773      void hierarchicalGatherRegistry(void) ; 
    6874 
     
    7379      void fromString(const string& str) ; 
    7480 
    75 /** Dump registry to a string (need for CBaseType pure virtual class)*/       
     81/** Dump registry to a string (need for CBaseType pure virtual class)*/ 
    7682      string toString(void) const ; 
    7783 
    78 /** Clone the registry (need for CBaseType pure virtual class)*/       
     84/** Clone the registry (need for CBaseType pure virtual class)*/ 
    7985      CRegistry* clone(void) const { return new CRegistry(*this); } 
    8086 
    81 /** return the size needed to bufferized the registry (need for CBaseType pure virtual class)*/         
     87/** return the size needed to bufferize the registry (need for CBaseType pure virtual class)*/ 
    8288      size_t size(void) const ; 
    8389 
    84 /** return true if the registry is empty (need for CBaseType pure virtual class)*/  
     90/** return true if the registry is empty (need for CBaseType pure virtual class)*/ 
    8591      bool isEmpty(void) const { return registry.empty(); } 
    8692 
    87 /** Clean the registry and delete associated memory (need for CBaseType pure virtual class)*/  
     93/** Clean the registry and delete associated memory (need for CBaseType pure virtual class)*/ 
    8894      void reset(void) ; 
    8995 
    90 /** Set the prefix added systematicaly to the keys, with "::" as separator*/        
     96/** Set the prefix added systematically to the keys, with "::" as separator*/ 
    9197      void setPath(const string& str) { path=str+"::" ; } 
    92         
     98 
    9399    private: 
    94100 
     
    96102      void setKey_(const std::string& key, const CBaseType& value) ; 
    97103 
    98 /** retreive a value from a key (internal use)*/ 
    99       void getKey_(const std::string& key, CBaseType& value ) ; 
    100        
     104/** retrieve a value from a key (internal use)*/ 
     105      void getKey_(const std::string& key, CBaseType& value) ; 
     106 
    101107/** use internally for recursivity */ 
    102108      void gatherRegistry(const MPI_Comm& comm) ; 
     
    106112 
    107113 
    108 /** Prefix added systematicaly to the keys, with "::" as separator*/ 
     114/** Prefix added systematically to the keys, with "::" as separator*/ 
    109115      std::string path ; 
    110116 
    111117/** Map containing registry, the key is a string type and the value is stored in a pair with the size 
    112  *  of the memory bloc and the associated pointer*/       
     118 *  of the memory bloc and the associated pointer*/ 
    113119      std::map<std::string,std::pair<size_t,char*> > registry ; 
    114120 
Note: See TracChangeset for help on using the changeset viewer.