Dripline-Cpp  v2.4.2
Dripline Implementation in C++
version_store.hh
Go to the documentation of this file.
1 /*
2  * version_store.hh
3  *
4  * Created on: Sep 20, 2019
5  * Author: N.S. Oblath
6  */
7 
8 #ifndef DRIPLINE_VERSIONSTORE_HH_
9 #define DRIPLINE_VERSIONSTORE_HH_
10 
11 #include "singleton.hh"
12 
13 #include "dripline_api.hh"
14 
15 #include "member_variables.hh"
16 #include "version_semantic.hh"
17 
18 #include <map>
19 #include <memory>
20 
21 
22 namespace dripline
23 {
24 
36  class DRIPLINE_API version_store : public scarab::singleton< version_store >
37  {
38  protected:
39  friend class scarab::singleton< version_store >;
40  friend class scarab::destroyer< version_store >;
41  version_store();
42  virtual ~version_store();
43 
44  public:
45  template< typename x_version >
46  void add_version( const std::string& a_name );
47  void add_version( const std::string& a_name, scarab::version_semantic_ptr_t a_version_ptr );
48  void remove_version( const std::string& a_name );
49 
50  typedef std::map< std::string, scarab::version_semantic_ptr_t > version_map_t;
51  mv_referrable_const( version_map_t, versions );
52  };
53 
54 
65  template< typename x_version >
67  {
68  version_store_adder( const std::string& a_name )
69  {
70  version_store::get_instance()->add_version< x_version >( a_name );
71  }
72  };
73 
85  template< typename x_version >
86  DRIPLINE_API std::shared_ptr< version_store_adder< x_version > > add_version( const std::string& a_name )
87  {
88  return std::make_shared< version_store_adder<x_version> >( a_name );
89  }
90 
91  // function to use to add a version via a base-class pointer to a derived object
102  DRIPLINE_API void add_version( const std::string& a_name, scarab::version_semantic_ptr_t a_version_ptr );
103 
110  #define ADD_VERSION( version_name, version_type ) \
111  static ::dripline::version_store_adder< version_type > s_version_adder_##version_name( TOSTRING(version_name) );
112 
113 
114  template< typename x_version >
115  inline void version_store::add_version( const std::string& a_name )
116  {
117  f_versions.insert( std::make_pair( a_name, scarab::version_semantic_ptr_t( new x_version() ) ) );
118  return;
119  }
120 
121  inline void version_store::add_version( const std::string& a_name, scarab::version_semantic_ptr_t a_version_ptr )
122  {
123  f_versions.insert( std::make_pair( a_name, a_version_ptr ) );
124  return;
125  }
126 
127  inline void version_store::remove_version( const std::string& a_name )
128  {
129  f_versions.erase( a_name );
130  return;
131  }
132 
133 } /* namespace dripline */
134 
135 #endif /*DRIPLINE_VERSIONSTORE_HH_ */
std::map< std::string, scarab::version_semantic_ptr_t > version_map_t
Singleton class to store all version information relevant in any particular application context...
#define DRIPLINE_API
Definition: dripline_api.hh:34
void remove_version(const std::string &a_name)
Version adder struct to enable adding version classes at static initialization. See ADD_VERSION...
version_store_adder(const std::string &a_name)
void add_version(const std::string &a_name)
void add_version(const std::string &a_name, scarab::version_semantic_ptr_t a_version_ptr)