key.hpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #ifndef BL_KEY_HPP
  2. #define BL_KEY_HPP
  3. /*!
  4. *\file
  5. *
  6. */
  7. // Config Class
  8. // Author: Charles Gruenwald III
  9. #include "fixed_types.h"
  10. namespace config
  11. {
  12. //! Enumeration for the types a given key may be
  13. enum KeyType
  14. {
  15. TYPE_INT_VALID = 0x01,
  16. TYPE_FLOAT_VALID = 0x02,
  17. TYPE_STRING_VALID = 0x04,
  18. TYPE_BOOL_VALID = 0x08
  19. };
  20. /*! \brief Key: A configuration setting entry
  21. * This class is used to hold a given setting from a configuration.
  22. * It contains the actual data, as well as functions to get the type
  23. */
  24. class Key
  25. {
  26. public:
  27. //! \brief Constructor to create a key
  28. template <class V>
  29. Key(const String & parentPath, const String & name, const V & value);
  30. const String getString() const;
  31. //Note: The following may throw boost::bad_lexial_cast
  32. bool getBool() const;
  33. SInt64 getInt() const;
  34. double getFloat() const;
  35. void getValue(bool &bool_val) const;
  36. void getValue(SInt64 &int_val) const;
  37. void getValue(String &string_val) const;
  38. void getValue(double &double_val) const;
  39. bool getFloatValid(){ return (bool)(m_type & TYPE_FLOAT_VALID); }
  40. bool getIntValid(){ return (bool)(m_type & TYPE_INT_VALID); }
  41. bool getBoolValid(){ return (bool)(m_type & TYPE_BOOL_VALID); }
  42. bool getStringValid(){ return true; }
  43. const String getName() const { return m_name; }
  44. private:
  45. unsigned short DetermineType(String);
  46. void throwInvalid(String) const;
  47. String m_name;
  48. String m_value;
  49. double m_value_f;
  50. SInt64 m_value_i;
  51. bool m_value_b;
  52. String m_parentPath;
  53. const unsigned short m_type;
  54. };
  55. }//end of namespace config
  56. #endif //KEY_HPP