XIOS  1.0
Xml I/O Server
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Définitions de type Énumérations Valeurs énumérées Amis Macros
registry.hpp
Aller à la documentation de ce fichier.
1 #ifndef __XIOS_REGISTRY_HPP__
2 #define __XIOS_REGISTRY_HPP__
3 
4 #include "base_type.hpp"
5 #include "type.hpp"
6 #include "mpi.hpp"
7 #include "message.hpp"
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 
13 namespace xios
14 {
20  class CRegistry : virtual public CBaseType
21  {
22  public:
23 
25  CRegistry(const MPI_Comm& comm=MPI_COMM_WORLD) : communicator(comm) {}
26 
28  CRegistry(const CRegistry& reg) ;
29 
30 
32  void setKey(const std::string& key, const CBaseType& value) { this->setKey_(key,value); }
33 
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)); }
37 
38 
40  void getKey(const std::string& key, CBaseType& value) { this->getKey_(key,value); }
41 
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); }
45 
46 
48  bool foundKey(const std::string& key) const ;
49 
51  bool toBuffer(CBufferOut& buffer) const ;
52 
54  bool fromBuffer(CBufferIn& buffer) ;
55 
57  void toFile(const string& filename) ;
58 
60  void fromFile(const string& filename) ;
61 
63  void mergeRegistry(const CRegistry& inRegistry) ;
64 
66  void bcastRegistry(void) ;
67 
69  void gatherRegistry(void) ;
70 
73  void hierarchicalGatherRegistry(void) ;
74 
76  ~CRegistry() { reset() ; }
77 
79  void fromString(const string& str) ;
80 
82  string toString(void) const ;
83 
85  CRegistry* clone(void) const { return new CRegistry(*this); }
86 
88  size_t size(void) const ;
89 
91  bool isEmpty(void) const { return registry.empty(); }
92 
94  void reset(void) ;
95 
97  void setPath(const string& str) { path=str+"::" ; }
98 
99  private:
100 
102  void setKey_(const std::string& key, const CBaseType& value) ;
103 
105  void getKey_(const std::string& key, CBaseType& value) ;
106 
108  void gatherRegistry(const MPI_Comm& comm) ;
109 
111  void hierarchicalGatherRegistry(const MPI_Comm& comm) ;
112 
113 
115  std::string path ;
116 
119  std::map<std::string,std::pair<size_t,char*> > registry ;
120 
122  MPI_Comm communicator ;
123  } ;
124 
125  inline CMessage& operator<<(CMessage& msg, CRegistry& registry)
126  {
127  msg.push(registry) ;
128  return msg ;
129  }
130 
131  inline CMessage& operator<<(CMessage& msg, const CRegistry& registry)
132  {
133  msg.push(registry) ;
134  return msg ;
135  }
136 
137 }
138 
139 #endif
bool toBuffer(CBufferOut &buffer) const
Definition: registry.cpp:76
void bcastRegistry(void)
Definition: registry.cpp:190
void gatherRegistry(void)
Definition: registry.cpp:211
boost::enable_if_c<!boost::is_convertible< T &, CBaseType & >::value >::type getKey(const std::string &key, T &value)
Definition: registry.hpp:44
void setPath(const string &str)
Definition: registry.hpp:97
void getKey(const std::string &key, CBaseType &value)
Definition: registry.hpp:40
void fromFile(const string &filename)
Definition: registry.cpp:156
size_t size(void) const
Definition: registry.cpp:88
string toString(void) const
Definition: registry.cpp:103
CRegistry * clone(void) const
Definition: registry.hpp:85
void setKey(const std::string &key, const CBaseType &value)
Definition: registry.hpp:32
bool isEmpty(void) const
Definition: registry.hpp:91
#define xios(arg)
void mergeRegistry(const CRegistry &inRegistry)
Definition: registry.cpp:170
void getKey_(const std::string &key, CBaseType &value)
Definition: registry.cpp:53
CBufferOut & operator<<(CBufferOut &buffer, const CArray< T_numtype, N_rank > &array)
Definition: array_new.hpp:657
void toFile(const string &filename)
Definition: registry.cpp:143
std::map< std::string, std::pair< size_t, char * > > registry
Definition: registry.hpp:119
This class is a registry database which store key with an associated value.
Definition: registry.hpp:20
void setKey_(const std::string &key, const CBaseType &value)
Definition: registry.cpp:31
CMessage & push(const CBaseType &type)
Definition: message.cpp:12
MPI_Comm communicator
Definition: registry.hpp:122
CRegistry(const MPI_Comm &comm=MPI_COMM_WORLD)
Definition: registry.hpp:25
void fromString(const string &str)
Definition: registry.cpp:98
std::string path
Definition: registry.hpp:115
void reset(void)
Definition: registry.cpp:22
bool foundKey(const std::string &key) const
Definition: registry.cpp:68
bool fromBuffer(CBufferIn &buffer)
Definition: registry.cpp:116
void hierarchicalGatherRegistry(void)
Definition: registry.cpp:258
boost::enable_if_c<!boost::is_convertible< T &, CBaseType & >::value >::type setKey(const std::string &key, const T &value)
Definition: registry.hpp:36