Changeset 700
- Timestamp:
- 09/22/15 10:09:53 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/trunk/src/registry.hpp
r696 r700 7 7 #include "message.hpp" 8 8 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 9 13 namespace xios 10 14 { 11 15 /*! 12 16 \class CRegistry 13 This class is a registry database which store key with an associated value. Internal y the value is stored as a memory bloc14 and the key is a string. The registry can be gathered and merge between mpi process, broadcastedand read or wrote from a file17 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 15 19 */ 16 20 class CRegistry : virtual public CBaseType … … 20 24 /** Constructor, the communicator is used for bcast or gather operation between MPI processes */ 21 25 CRegistry(const MPI_Comm& comm=MPI_COMM_WORLD) : communicator(comm) {} 22 26 23 27 /** Copy constructor */ 24 28 CRegistry(const CRegistry& reg) ; 25 29 26 30 27 31 /** 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); } 29 33 30 34 /** 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)); } 32 37 33 38 34 /** retr eive 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); } 36 41 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); } 39 45 40 46 41 47 /** query for an already inserted key */ 42 48 bool foundKey(const std::string& key) const ; 43 49 44 50 /** The registry is wrote into a memory buffer */ 45 51 bool toBuffer(CBufferOut& buffer) const ; … … 51 57 void toFile(const string& filename) ; 52 58 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 */ 54 60 void fromFile(const string& filename) ; 55 61 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 */ 57 63 void mergeRegistry(const CRegistry& inRegistry) ; 58 64 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 */ 60 66 void bcastRegistry(void) ; 61 67 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 */ 63 69 void gatherRegistry(void) ; 64 70 65 /** Gather registry with a hiera chical algorithm which avoid root process to get registries from whole processes of the communicator.66 Registry are merged two by two hi rarchicaly. */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. */ 67 73 void hierarchicalGatherRegistry(void) ; 68 74 … … 73 79 void fromString(const string& str) ; 74 80 75 /** Dump registry to a string (need for CBaseType pure virtual class)*/ 81 /** Dump registry to a string (need for CBaseType pure virtual class)*/ 76 82 string toString(void) const ; 77 83 78 /** Clone the registry (need for CBaseType pure virtual class)*/ 84 /** Clone the registry (need for CBaseType pure virtual class)*/ 79 85 CRegistry* clone(void) const { return new CRegistry(*this); } 80 86 81 /** return the size needed to bufferize d the registry (need for CBaseType pure virtual class)*/87 /** return the size needed to bufferize the registry (need for CBaseType pure virtual class)*/ 82 88 size_t size(void) const ; 83 89 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)*/ 85 91 bool isEmpty(void) const { return registry.empty(); } 86 92 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)*/ 88 94 void reset(void) ; 89 95 90 /** Set the prefix added systematical y to the keys, with "::" as separator*/96 /** Set the prefix added systematically to the keys, with "::" as separator*/ 91 97 void setPath(const string& str) { path=str+"::" ; } 92 98 93 99 private: 94 100 … … 96 102 void setKey_(const std::string& key, const CBaseType& value) ; 97 103 98 /** retr eive 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 101 107 /** use internally for recursivity */ 102 108 void gatherRegistry(const MPI_Comm& comm) ; … … 106 112 107 113 108 /** Prefix added systematical y to the keys, with "::" as separator*/114 /** Prefix added systematically to the keys, with "::" as separator*/ 109 115 std::string path ; 110 116 111 117 /** 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*/ 113 119 std::map<std::string,std::pair<size_t,char*> > registry ; 114 120
Note: See TracChangeset
for help on using the changeset viewer.