Dictionary.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /* -*- C++ -*- */
  2. /****************************************************************************
  3. ** Copyright (c) 2001-2014
  4. **
  5. ** This file is part of the QuickFIX FIX Engine
  6. **
  7. ** This file may be distributed under the terms of the quickfixengine.org
  8. ** license as defined by quickfixengine.org and appearing in the file
  9. ** LICENSE included in the packaging of this file.
  10. **
  11. ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
  12. ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  13. **
  14. ** See http://www.quickfixengine.org/LICENSE for licensing information.
  15. **
  16. ** Contact ask@quickfixengine.org if any conditions of this licensing are
  17. ** not clear to you.
  18. **
  19. ****************************************************************************/
  20. #ifndef FIX_DICTIONARY_H
  21. #define FIX_DICTIONARY_H
  22. #ifdef _MSC_VER
  23. #pragma warning( disable : 4503 4355 4786 4290 )
  24. #endif
  25. #include <map>
  26. #include <string>
  27. #include "Exceptions.h"
  28. namespace FIX
  29. {
  30. /// For storage and retrieval of key/value pairs.
  31. class Dictionary
  32. {
  33. public:
  34. Dictionary( const std::string& name ) : m_name( name ) {}
  35. Dictionary() {}
  36. virtual ~Dictionary() {}
  37. typedef std::map < std::string, std::string > Data;
  38. typedef Data::const_iterator iterator;
  39. typedef iterator const_iterator;
  40. /// Get the name of the dictionary.
  41. std::string getName() const { return m_name; }
  42. /// Return the number of key/value pairs.
  43. int size() const { return m_data.size(); }
  44. /// Get a value as a string.
  45. std::string getString( const std::string&, bool capitalize = false ) const
  46. throw( ConfigError, FieldConvertError );
  47. /// Get a value as a int.
  48. int getInt( const std::string& ) const
  49. throw( ConfigError, FieldConvertError );
  50. /// Get a value as a double.
  51. double getDouble( const std::string& ) const
  52. throw( ConfigError, FieldConvertError );
  53. /// Get a value as a bool
  54. bool getBool( const std::string& ) const
  55. throw( ConfigError, FieldConvertError );
  56. /// Get a value as a day of week
  57. int getDay( const std::string& ) const
  58. throw( ConfigError, FieldConvertError );
  59. /// Set a value from a string.
  60. void setString( const std::string&, const std::string& );
  61. /// Set a value from a int.
  62. void setInt( const std::string&, int );
  63. /// Set a value from a double.
  64. void setDouble( const std::string&, double );
  65. /// Set a value from a bool
  66. void setBool( const std::string&, bool );
  67. /// Set a value from a day
  68. void setDay( const std::string&, int );
  69. /// Check if the dictionary contains a value for key.
  70. bool has( const std::string& ) const;
  71. /// Merge two dictionaries.
  72. void merge( const Dictionary& );
  73. iterator begin() const { return m_data.begin(); }
  74. iterator end() const { return m_data.end(); }
  75. private:
  76. Data m_data;
  77. std::string m_name;
  78. };
  79. /*! @} */
  80. }
  81. #endif //FIX_DICTIONARY_H