CARMA C++
PhysicalDeviceIDAuthority.h
Go to the documentation of this file.
1 #ifndef CARMA_DBMS_PHYSICALDEVICEIDAUTHORITY_H
2 #define CARMA_DBMS_PHYSICALDEVICEIDAUTHORITY_H
3 
4 
17 #include <string>
18 #include <map>
19 
20 namespace carma {
21 
22 namespace dbms {
23 
24 class DBConfigurator;
25 
26 
40 public:
41 
50  static const PhysicalDeviceIDAuthority &
51  getAuthority( bool production = false,
52  const dbms::DBConfigurator * dbconf = 0 );
53 
58  static int getLocationCount( );
59 
64  static int getDeviceCount( );
65 
72  static void closeAuthority( );
73 
79  int getLocationID( const ::std::string & location ) const;
80 
81  static int getLocationID( const ::std::string & location,
82  bool production,
83  const dbms::DBConfigurator * dbconf );
84 
85 
91  int getDeviceID( const ::std::string & device ) const;
92 
93  static int getDeviceID( const ::std::string & device,
94  bool production,
95  const dbms::DBConfigurator * dbconf );
96 
97 
103  ::std::string getLocation( const int & locationID ) const;
104 
105  static ::std::string getLocation( const int & locationID,
106  bool production,
107  const dbms::DBConfigurator * dbconf );
108 
109 
115  ::std::string getDevice( const int & deviceID ) const;
116 
117  static ::std::string getDevice( const int & deviceID,
118  bool production,
119  const dbms::DBConfigurator * dbconf );
120 
121 
122 private:
123  typedef ::std::map< ::std::string, int > Name2IdMap;
124  typedef ::std::map< int, ::std::string > Id2NameMap;
125 
140  PhysicalDeviceIDAuthority( bool production,
141  const dbms::DBConfigurator * dbconf );
142 
150  void registerLocationNameID( const ::std::string & location,
151  const int & locationID );
152 
160  void registerDeviceNameID( const ::std::string & device,
161  const int & deviceID );
162 
163  static const char * const locationNames_[];
164  static const char * const deviceNames_[];
165 
166  static const int locationCount_;
167  static const int deviceCount_;
168 
169  const bool usingDB_;
170  Name2IdMap deviceName2ID_;
171  Name2IdMap locationName2ID_;
172  Id2NameMap deviceID2Name_;
173  Id2NameMap locationID2Name_;
174 };
175 
176 
177 }
178 }
179 
180 
181 inline int
183 {
184  return locationCount_;
185 }
186 
187 
188 inline int
190 {
191  return deviceCount_;
192 }
193 
194 
195 #endif // CARMA_DBMS_PHYSICALDEVICEIDAUTHORITY_H
int getDeviceID(const ::std::string &device) const
return the ID for a given hardware device name
Class used for configuring a DBConnection.
int getLocationID(const ::std::string &location) const
return the ID for a given hardware location name
static int getLocationCount()
return the number of locations
static int getDeviceCount()
return the number of devices
A lookup class for mapping names and IDs of locations and devices.
::std::string getLocation(const int &locationID) const
return the location name for for an ID
static const PhysicalDeviceIDAuthority & getAuthority(bool production=false, const dbms::DBConfigurator *dbconf=0)
get the singleton instance of the PhysicalDeviceIDAuthority.
::std::string getDevice(const int &deviceID) const
return the device name for for an ID
static void closeAuthority()
indicate that one&#39;s use of the authority is complete.