Apama  10.1.0.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
map_helper.hpp
Go to the documentation of this file.
1 /*
2  * Title: bits/map_helper.hpp
3  * Description: C++ header-only wrapper for C-ABI data_t type
4  * $Copyright (c) 2015-2016 Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors.$
5  * Use, reproduction, transfer, publication or disclosure is prohibited except as specifically provided for in your License Agreement with Software AG
6  * @Version: $Id: map_helper.hpp 294926 2016-11-09 18:33:24Z matj $
7  */
8 
15 #ifndef _DATAT_BITS_INCLUDE_TAG
16 #error Must only be included from sag_connectivity_cpp.hpp, use that instead
17 #endif
18 
24 class MapHelper
25 {
26 public:
27  // String
29  static std::string getString(const map_t &map, const char *key) { return getAs<std::string>(map, key); }
31  static std::string getString(const map_t &map, const char *key, const char *defaultValue) { return getAs<std::string>(map, key, defaultValue); }
33  static std::string getString(const map_t &map, const std::string &key) { return getAs<std::string>(map, key.c_str()); }
35  static std::string getString(const map_t &map, const std::string &key, const std::string &defaultValue) { return getAs<std::string>(map, key.c_str(), defaultValue); }
36  // Integer
38  static int64_t getInteger(const map_t &map, const char *key) { return getAs<int64_t>(map, key); }
40  static int64_t getInteger(const map_t &map, const char *key, int64_t defaultValue) { return getAs<int64_t>(map, key, defaultValue); }
42  static int64_t getInteger(const map_t &map, const std::string &key) { return getAs<int64_t>(map, key.c_str()); }
44  static int64_t getInteger(const map_t &map, const std::string &key, int64_t defaultValue) { return getAs<int64_t>(map, key.c_str(), defaultValue); }
45  // Double
47  static double getDouble(const map_t &map, const char *key) { return getAs<double>(map, key); }
49  static double getDouble(const map_t &map, const char *key, double defaultValue) { return getAs<double>(map, key, defaultValue); }
51  static double getDouble(const map_t &map, const std::string &key) { return getAs<double>(map, key.c_str()); }
53  static double getDouble(const map_t &map, const std::string &key, double defaultValue) { return getAs<double>(map, key.c_str(), defaultValue); }
54  // Boolean
56  static bool getBoolean(const map_t &map, const char *key) { return getAs<bool>(map, key); }
58  static bool getBoolean(const map_t &map, const char *key, bool defaultValue) { return getAs<bool>(map, key, defaultValue); }
60  static bool getBoolean(const map_t &map, const std::string &key) { return getAs<bool>(map, key.c_str()); }
62  static bool getBoolean(const map_t &map, const std::string &key, bool defaultValue) { return getAs<bool>(map, key.c_str(), defaultValue); }
63  // Map
65  static const map_t &getMap(const map_t &map, const char *key) { return getAs<const map_t&>(map, key); }
67  static const map_t &getMap(const map_t &map, const char *key, const map_t &defaultValue) { return getAs<const map_t&>(map, key, defaultValue); }
69  static const map_t &getMap(const map_t &map, const std::string &key) { return getAs<const map_t&>(map, key.c_str()); }
71  static const map_t &getMap(const map_t &map, const std::string &key, const map_t &defaultValue) { return getAs<const map_t&>(map, key.c_str(), defaultValue); }
72  // List
74  static const list_t &getList(const map_t &map, const char *key) { return getAs<const list_t&>(map, key); }
76  static const list_t &getList(const map_t &map, const char *key, const list_t &defaultValue) { return getAs<const list_t&>(map, key, defaultValue); }
78  static const list_t &getList(const map_t &map, const std::string &key) { return getAs<const list_t&>(map, key.c_str()); }
80  static const list_t &getList(const map_t &map, const std::string &key, const list_t &defaultValue) { return getAs<const list_t&>(map, key.c_str(), defaultValue); }
81 
82 private:
84  template<typename T>
85  static T getAs(const map_t &map, const char *key);
87  template<typename T>
88  static T getAs(const map_t &map, const char *key, const T &def);
89 };
90 
91 
static const list_t & getList(const map_t &map, const char *key, const list_t &defaultValue)
Get a list value from the map, returning the given default if the key is not present.
Definition: map_helper.hpp:76
static const map_t & getMap(const map_t &map, const std::string &key)
Get a map value from the map, throwing if the key is not present.
Definition: map_helper.hpp:69
static int64_t getInteger(const map_t &map, const std::string &key)
Get an integer value from the map, throwing if the key is not present.
Definition: map_helper.hpp:42
static std::string getString(const map_t &map, const char *key, const char *defaultValue)
Get a string value from the map, returning the given default if the key is not present.
Definition: map_helper.hpp:31
A list class which implements many of the functions on std::vector.
Definition: list_t.hpp:34
A map class which implements many of the functions on std::map.
Definition: map_t.hpp:36
static std::string getString(const map_t &map, const char *key)
Get a string value from the map, throwing if the key is not present.
Definition: map_helper.hpp:29
static int64_t getInteger(const map_t &map, const char *key, int64_t defaultValue)
Get an integer value from the map, returning the given default if the key is not present.
Definition: map_helper.hpp:40
static const map_t & getMap(const map_t &map, const char *key)
Get a map value from the map, throwing if the key is not present.
Definition: map_helper.hpp:65
Helper class for extracting values from a string->data_t map_t in a type-safe way with error checking...
Definition: map_helper.hpp:24
static const list_t & getList(const map_t &map, const std::string &key, const list_t &defaultValue)
Get a list value from the map, returning the given default if the key is not present.
Definition: map_helper.hpp:80
static const list_t & getList(const map_t &map, const std::string &key)
Get a list value from the map, throwing if the key is not present.
Definition: map_helper.hpp:78
static double getDouble(const map_t &map, const std::string &key)
Get a double value from the map, throwing if the key is not present.
Definition: map_helper.hpp:51
static std::string getString(const map_t &map, const std::string &key, const std::string &defaultValue)
Get a string value from the map, returning the given default if the key is not present.
Definition: map_helper.hpp:35
static int64_t getInteger(const map_t &map, const char *key)
Get an integer value from the map, throwing if the key is not present.
Definition: map_helper.hpp:38
static std::string getString(const map_t &map, const std::string &key)
Get a string value from the map, throwing if the key is not present.
Definition: map_helper.hpp:33
static bool getBoolean(const map_t &map, const std::string &key, bool defaultValue)
Get a boolean value from the map, returning the given default if the key is not present.
Definition: map_helper.hpp:62
static bool getBoolean(const map_t &map, const char *key, bool defaultValue)
Get a boolean value from the map, returning the given default if the key is not present.
Definition: map_helper.hpp:58
static const map_t & getMap(const map_t &map, const char *key, const map_t &defaultValue)
Get a map value from the map, returning the given default if the key is not present.
Definition: map_helper.hpp:67
static const list_t & getList(const map_t &map, const char *key)
Get a list value from the map, throwing if the key is not present.
Definition: map_helper.hpp:74
static double getDouble(const map_t &map, const char *key, double defaultValue)
Get a double value from the map, returning the given default if the key is not present.
Definition: map_helper.hpp:49
static double getDouble(const map_t &map, const char *key)
Get a double value from the map, throwing if the key is not present.
Definition: map_helper.hpp:47
static int64_t getInteger(const map_t &map, const std::string &key, int64_t defaultValue)
Get an integer value from the map, returning the given default if the key is not present.
Definition: map_helper.hpp:44
static const map_t & getMap(const map_t &map, const std::string &key, const map_t &defaultValue)
Get a map value from the map, returning the given default if the key is not present.
Definition: map_helper.hpp:71
static double getDouble(const map_t &map, const std::string &key, double defaultValue)
Get a double value from the map, returning the given default if the key is not present.
Definition: map_helper.hpp:53
static bool getBoolean(const map_t &map, const std::string &key)
Get a boolean value from the map, throwing if the key is not present.
Definition: map_helper.hpp:60
static bool getBoolean(const map_t &map, const char *key)
Get a boolean value from the map, throwing if the key is not present.
Definition: map_helper.hpp:56