Master Core  v0.0.9 - 49a5c0d97abf09ef2911ddfe8d9551df59f9efd3-dirty
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
mastercore_values.h
Go to the documentation of this file.
1 #ifndef MASTERCORE_VALUES_H
2 #define MASTERCORE_VALUES_H
3 
4 #include <stdlib.h>
5 #include <stdint.h>
6 #include <string>
7 #include <boost/utility/enable_if.hpp>
8 #include <boost/type_traits/is_arithmetic.hpp>
9 
10 namespace mastercore
11 {
12 const uint8_t ECOSYSTEM_MAIN = 1;
13 const uint8_t ECOSYSTEM_TEST = 2;
14 
15 const uint8_t BLOCK_INTERVAL_MIN = 1;
16 const uint8_t BLOCK_INTERVAL_MAX = 255;
17 
18 const uint8_t DEX_ACTION_NEW = 1;
19 const uint8_t DEX_ACTION_UPDATE = 2;
20 const uint8_t DEX_ACTION_CANCEL = 3;
21 
22 const uint8_t MDEX_ACTION_ADD = 1;
23 const uint8_t MDEX_ACTION_CANCEL_AT_PRICE = 2;
26 
27 const uint16_t PROPERTY_TYPE_INDIVISIBLE = 1;
28 const uint16_t PROPERTY_TYPE_DIVISIBLE = 2;
30 const uint16_t PROPERTY_TYPE_DIVISIBLE_REPLACING = 66;
32 const uint16_t PROPERTY_TYPE_DIVISIBLE_APPENDING = 130;
33 
34 const uint32_t PROPERTY_ID_MIN = 1;
35 const uint32_t PROPERTY_ID_MAX = 4294967295;
36 
37 const uint64_t AMOUNT_INDIVISIBLE_MIN = 1;
38 const uint64_t AMOUNT_INDIVISIBLE_MAX = 9223372036854775807;
39 
40 const long double AMOUNT_DIVISIBLE_MIN = 0.00000001L;
41 const long double AMOUNT_DIVISIBLE_MAX = 92233720368.54775807L;
42 
47 template<class T>
48 inline bool IsEcosystem(T value, typename boost::enable_if<boost::is_arithmetic<T> >::type* dummy = 0)
49 {
50  uint8_t n = static_cast<uint8_t>(value);
51  return (ECOSYSTEM_MAIN == n ||
52  ECOSYSTEM_TEST == n);
53 }
54 inline bool IsEcosystem(const char* pzn) { return IsEcosystem(atoi(pzn)); }
55 inline bool IsEcosystem(const std::string& str) { return IsEcosystem(str.c_str()); }
57 
62 template<class T>
63 inline bool IsBlockInterval(T value, typename boost::enable_if<boost::is_arithmetic<T> >::type* dummy = 0)
64 {
65  uint8_t n = static_cast<uint8_t>(value);
66  return (BLOCK_INTERVAL_MIN <= n &&
67  BLOCK_INTERVAL_MAX >= n);
68 }
69 inline bool IsBlockInterval(const char* pzn) { return IsBlockInterval(atoi(pzn)); }
70 inline bool IsBlockInterval(const std::string& str) { return IsBlockInterval(str.c_str()); }
72 
77 template<class T>
78 inline bool IsDexAction(T value, typename boost::enable_if<boost::is_arithmetic<T> >::type* dummy = 0)
79 {
80  switch (static_cast<uint8_t>(value)) {
81  case DEX_ACTION_NEW:
82  case DEX_ACTION_UPDATE:
83  case DEX_ACTION_CANCEL:
84  return true;
85  }
86  return false;
87 }
88 inline bool IsDexAction(const char* pzn) { return IsDexAction(atoi(pzn)); }
89 inline bool IsDexAction(const std::string& str) { return IsDexAction(str.c_str()); }
91 
96 template<class T>
97 inline bool IsMetaDexAction(T value, typename boost::enable_if<boost::is_arithmetic<T> >::type* dummy = 0)
98 {
99  switch (static_cast<uint8_t>(value)) {
100  case MDEX_ACTION_ADD:
101  case MDEX_ACTION_CANCEL_AT_PRICE:
102  case MDEX_ACTION_CANCEL_ALL_FOR_PAIR:
103  case MDEX_ACTION_CANCEL_CANCEL_EVERYTHING:
104  return true;
105  }
106  return false;
107 }
108 inline bool IsMetaDexAction(const char* pzn) { return IsMetaDexAction(atoi(pzn)); }
109 inline bool IsMetaDexAction(const std::string& str) { return IsMetaDexAction(str.c_str()); }
111 
116 template<class T>
117 inline bool IsSubAction(T value, typename boost::enable_if<boost::is_arithmetic<T> >::type* dummy = 0)
118 {
119  return (IsDexAction(value) ||
120  IsMetaDexAction(value));
121 }
122 inline bool IsSubAction(const char* pzn) { return IsSubAction(atoi(pzn)); }
123 inline bool IsSubAction(const std::string& str) { return IsSubAction(str.c_str()); }
125 
130 template<class T>
131 inline bool IsPropertyType(T value, typename boost::enable_if<boost::is_arithmetic<T> >::type* dummy = 0)
132 {
133  switch (static_cast<uint8_t>(value)) {
134  case PROPERTY_TYPE_INDIVISIBLE:
135  case PROPERTY_TYPE_DIVISIBLE:
136  case PROPERTY_TYPE_INDIVISIBLE_REPLACING:
137  case PROPERTY_TYPE_DIVISIBLE_REPLACING:
138  case PROPERTY_TYPE_INDIVISIBLE_APPENDING:
139  case PROPERTY_TYPE_DIVISIBLE_APPENDING:
140  return true;
141  }
142  return false;
143 }
144 inline bool IsPropertyType(const char* pzn) { return IsPropertyType(atoi(pzn)); }
145 inline bool IsPropertyType(const std::string& str) { return IsPropertyType(str.c_str()); }
147 
152 template<class T>
153 inline bool IsPropertyId(T value, typename boost::enable_if<boost::is_arithmetic<T> >::type* dummy = 0)
154 {
155  uint32_t n = static_cast<uint32_t>(value);
156  return (PROPERTY_ID_MIN <= n &&
157  PROPERTY_ID_MAX >= n);
158 }
159 inline bool IsPropertyId(const char* pzn) { return IsPropertyId(atoi(pzn)); }
160 inline bool IsPropertyId(const std::string& str) { return IsPropertyId(str.c_str()); }
162 
167 template<class T>
168 inline bool IsDivisibleAmount(T value, typename boost::enable_if<boost::is_arithmetic<T> >::type* dummy = 0)
169 {
170  long double n = static_cast<long double>(value);
171  return (AMOUNT_DIVISIBLE_MIN <= n &&
172  AMOUNT_DIVISIBLE_MAX >= n);
173 }
174 inline bool IsDivisibleAmount(const char* pzn) { return IsDivisibleAmount(strtold(pzn, NULL)); }
175 inline bool IsDivisibleAmount(const std::string& str) { return IsDivisibleAmount(str.c_str()); }
177 
182 template<class T>
183 inline bool IsIndivisibleAmount(T value, typename boost::enable_if<boost::is_arithmetic<T> >::type* dummy = 0)
184 {
185  uint64_t n = static_cast<uint64_t>(value);
186  return (AMOUNT_INDIVISIBLE_MIN <= n &&
187  AMOUNT_INDIVISIBLE_MAX >= n);
188 }
189 inline bool IsIndivisibleAmount(const char* pzn) { return IsIndivisibleAmount(strtoull(pzn, NULL, 10)); }
190 inline bool IsIndivisibleAmount(const std::string& str) { return IsIndivisibleAmount(str.c_str()); }
192 
197 template<class T>
198 inline bool IsTokenAmount(T value, typename boost::enable_if<boost::is_arithmetic<T> >::type* dummy = 0)
199 {
200  return (IsDivisibleAmount(value) ||
201  IsIndivisibleAmount(value));
202 }
203 inline bool IsTokenAmount(const char* pzn) { return IsTokenAmount(strtold(pzn, NULL)); }
204 inline bool IsTokenAmount(const std::string& str) { return IsTokenAmount(str.c_str()); }
206 }
207 
208 #endif // MASTERCORE_VALUES_H
209 
const uint8_t BLOCK_INTERVAL_MAX
Maximum interval measured in blocks.
const uint64_t AMOUNT_INDIVISIBLE_MIN
Minimum indivisible amount.
bool IsMetaDexAction(T value, typename boost::enable_if< boost::is_arithmetic< T > >::type *dummy=0)
Checks whether the value describes an action of the distributed token exchange.
const uint16_t PROPERTY_TYPE_DIVISIBLE
Divisible property type.
const uint32_t PROPERTY_ID_MIN
Minimum property identifier value.
const uint16_t PROPERTY_TYPE_DIVISIBLE_APPENDING
Indivisible property type when appending a property.
const uint8_t DEX_ACTION_NEW
New offer action value.
const uint8_t MDEX_ACTION_ADD
Add offer action value.
const uint8_t DEX_ACTION_CANCEL
Cancel offer action value.
bool IsDexAction(T value, typename boost::enable_if< boost::is_arithmetic< T > >::type *dummy=0)
Checks whether the value describes an action of the distributed exchange.
const uint8_t ECOSYSTEM_TEST
Test ecosystem value.
const uint8_t ECOSYSTEM_MAIN
Main ecosystem value.
bool IsBlockInterval(T value, typename boost::enable_if< boost::is_arithmetic< T > >::type *dummy=0)
Checks whether the value describes an interval measured in blocks.
const uint16_t PROPERTY_TYPE_INDIVISIBLE_REPLACING
Indivisible property type when replacing a property.
const uint8_t MDEX_ACTION_CANCEL_CANCEL_EVERYTHING
Cancel every offer action value.
bool IsTokenAmount(T value, typename boost::enable_if< boost::is_arithmetic< T > >::type *dummy=0)
Checks whether the value describes either a divisible or indivisible amount.
bool IsEcosystem(T value, typename boost::enable_if< boost::is_arithmetic< T > >::type *dummy=0)
Checks whether the value describes an ecosystem.
bool IsPropertyId(T value, typename boost::enable_if< boost::is_arithmetic< T > >::type *dummy=0)
Checks whether the value describes a property identifier.
const uint8_t BLOCK_INTERVAL_MIN
Minimum interval measured in blocks.
const uint8_t MDEX_ACTION_CANCEL_AT_PRICE
Cancel offers at price action value.
bool IsPropertyType(T value, typename boost::enable_if< boost::is_arithmetic< T > >::type *dummy=0)
Checks whether the value describes a property type.
const uint16_t PROPERTY_TYPE_INDIVISIBLE_APPENDING
Indivisible property type when appending a property.
const uint8_t DEX_ACTION_UPDATE
Update offer action value.
const uint16_t PROPERTY_TYPE_INDIVISIBLE
Indivisible property type.
const long double AMOUNT_DIVISIBLE_MAX
Maximum divisible amount.
bool IsSubAction(T value, typename boost::enable_if< boost::is_arithmetic< T > >::type *dummy=0)
Checks whether the value describes a subaction.
const uint16_t PROPERTY_TYPE_DIVISIBLE_REPLACING
Divisible property type when replacing a property.
bool IsDivisibleAmount(T value, typename boost::enable_if< boost::is_arithmetic< T > >::type *dummy=0)
Checks whether the value describes a divisible amount.
const uint32_t PROPERTY_ID_MAX
Maximum property identifier value.
const uint8_t MDEX_ACTION_CANCEL_ALL_FOR_PAIR
Cancel all offers of property pair action value.
bool IsIndivisibleAmount(T value, typename boost::enable_if< boost::is_arithmetic< T > >::type *dummy=0)
Checks whether the value describes an indivisible amount.
const long double AMOUNT_DIVISIBLE_MIN
Minimum divisible amount.
const uint64_t AMOUNT_INDIVISIBLE_MAX
Maximum indivisible amount.
int atoi(const std::string &str)
Definition: util.h:242