24 #pragma message "C++ support is required for extras module" 28 #ifndef MCR_EXTRAS_CONTRACT_H_ 29 #define MCR_EXTRAS_CONTRACT_H_ 31 #include "mcr/extras/base_cpp.h" 32 #include "mcr/extras/util/string_less_ci.h" 44 std::map<T, std::string> map;
45 std::map<std::string, T, string_less_ci> rmap;
49 Contract(
const T ¬Found) : notFound(notFound)
57 T value(
const std::string &name)
const 59 auto it = rmap.find(name);
60 return it == rmap.end() ? notFound : it->second;
62 T value(
const char *name)
const 64 auto it = rmap.find(name);
65 return it == rmap.end() ? notFound : it->second;
75 return map.rbegin()->first;
77 const char *name(T value)
const 79 auto it = map.find(value);
80 return it == map.end() ?
nullptr : it->second.c_str();
82 void set(T value,
const std::string &name)
87 void add(T value,
const std::string &addName)
89 rmap[addName] = value;
91 void add(T value,
const char *
const*addNames,
size_t count)
93 for (
size_t i = 0; i < count; i++) {
94 add(value, addNames[i]);
97 void setMap(T value,
const std::string &name,
const char *
const*addNames,
101 add(value, addNames, count);
Raise a compiler error. Usage: #include "mcr/err.h"
Libmacro, by Jonathan Pelletier, New Paradigm Software. Alpha version.
Contract(const T ¬Found)