Primitive.hpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842
  1. /***************************************************************************
  2. *
  3. * Project _____ __ ____ _ _
  4. * ( _ ) /__\ (_ _)_| |_ _| |_
  5. * )(_)( /(__)\ )( (_ _)(_ _)
  6. * (_____)(__)(__)(__) |_| |_|
  7. *
  8. *
  9. * Copyright 2018-present, Leonid Stryzhevskyi <lganzzzo@gmail.com>
  10. *
  11. * Licensed under the Apache License, Version 2.0 (the "License");
  12. * you may not use this file except in compliance with the License.
  13. * You may obtain a copy of the License at
  14. *
  15. * http://www.apache.org/licenses/LICENSE-2.0
  16. *
  17. * Unless required by applicable law or agreed to in writing, software
  18. * distributed under the License is distributed on an "AS IS" BASIS,
  19. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  20. * See the License for the specific language governing permissions and
  21. * limitations under the License.
  22. *
  23. ***************************************************************************/
  24. #ifndef oatpp_data_type_Primitive_hpp
  25. #define oatpp_data_type_Primitive_hpp
  26. #include "./Type.hpp"
  27. #include "oatpp/core/base/memory/ObjectPool.hpp"
  28. #include "oatpp/core/base/Countable.hpp"
  29. #include <algorithm>
  30. #include <cctype>
  31. #include <iterator>
  32. namespace oatpp { namespace data { namespace mapping { namespace type {
  33. namespace __class {
  34. class String; // FWD
  35. class Int8; // FWD
  36. class UInt8; // FWD
  37. class Int16; // FWD
  38. class UInt16; // FWD
  39. class Int32; // FWD
  40. class UInt32; // FWD
  41. class Int64; // FWD
  42. class UInt64; // FWD
  43. class Float32; // FWD
  44. class Float64; // FWD
  45. class Boolean; // FWD
  46. }
  47. /**
  48. * Mapping-enables String is &id:type::ObjectWrapper; over `std::string`;
  49. */
  50. class String : public type::ObjectWrapper<std::string, __class::String> {
  51. public:
  52. String(const std::shared_ptr<std::string>& ptr, const type::Type* const valueType);
  53. public:
  54. String() {}
  55. explicit String(v_buff_size size)
  56. : type::ObjectWrapper<std::string, __class::String>(std::make_shared<std::string>(size, 0))
  57. {}
  58. String(const char* data, v_buff_size size)
  59. : type::ObjectWrapper<std::string, __class::String>(std::make_shared<std::string>(data, size))
  60. {}
  61. template<typename T,
  62. typename enabled = typename std::enable_if<std::is_same<T, std::nullptr_t>::value, void>::type
  63. >
  64. String(T) {}
  65. template<typename T,
  66. typename enabled = typename std::enable_if<std::is_same<T, char>::value, void>::type
  67. >
  68. String(const T* data)
  69. : type::ObjectWrapper<std::string, __class::String>(
  70. data == nullptr ? nullptr : std::make_shared<std::string>(data)
  71. )
  72. {}
  73. template<typename T,
  74. typename enabled = typename std::enable_if<std::is_same<T, std::string>::value, void>::type
  75. >
  76. String(const T& str)
  77. : type::ObjectWrapper<std::string, __class::String>(std::make_shared<std::string>(str))
  78. {}
  79. template<typename T,
  80. typename enabled = typename std::enable_if<std::is_same<T, std::string>::value, void>::type
  81. >
  82. String(T&& str)
  83. : type::ObjectWrapper<std::string, __class::String>(
  84. std::make_shared<std::string>(std::forward<std::string>(str))
  85. )
  86. {}
  87. String(const std::shared_ptr<std::string>& ptr)
  88. : type::ObjectWrapper<std::string, __class::String>(ptr)
  89. {}
  90. String(std::shared_ptr<std::string>&& ptr)
  91. : type::ObjectWrapper<std::string, __class::String>(std::forward<std::shared_ptr<std::string>>(ptr))
  92. {}
  93. String(const String& other)
  94. : type::ObjectWrapper<std::string, __class::String>(other)
  95. {}
  96. String(String&& other)
  97. : type::ObjectWrapper<std::string, __class::String>(std::forward<String>(other))
  98. {}
  99. /**
  100. * Load data from file and store in &id:oatpp::String;.
  101. * @param filename - name of the file.
  102. * @return - &id:oatpp::String;.
  103. */
  104. static String loadFromFile(const char* filename);
  105. /**
  106. * Save content of the buffer to file.
  107. * @param filename - name of the file.
  108. */
  109. void saveToFile(const char* filename) const;
  110. const std::string& operator*() const;
  111. operator std::string() const {
  112. if (this->m_ptr == nullptr) {
  113. throw std::runtime_error("[oatpp::data::mapping::type::String::operator std::string() const]: "
  114. "Error. Null pointer.");
  115. }
  116. return this->m_ptr.operator*();
  117. }
  118. template<typename T,
  119. typename enabled = typename std::enable_if<std::is_same<T, std::nullptr_t>::value, void>::type
  120. >
  121. inline String& operator = (std::nullptr_t) {
  122. m_ptr.reset();
  123. return *this;
  124. }
  125. template<typename T,
  126. typename enabled = typename std::enable_if<std::is_same<T, char>::value, void>::type
  127. >
  128. inline String& operator = (const T* str) {
  129. if (str) {
  130. m_ptr = std::make_shared<std::string>(str);
  131. } else {
  132. m_ptr.reset();
  133. }
  134. return *this;
  135. }
  136. template<typename T,
  137. typename enabled = typename std::enable_if<std::is_same<T, std::string>::value, void>::type
  138. >
  139. inline String& operator = (const T& str) {
  140. m_ptr = std::make_shared<std::string>(str);
  141. return *this;
  142. }
  143. template<typename T,
  144. typename enabled = typename std::enable_if<std::is_same<T, std::string>::value, void>::type
  145. >
  146. inline String& operator = (T&& str) {
  147. m_ptr = std::make_shared<std::string>(std::forward<std::string>(str));
  148. return *this;
  149. }
  150. inline String& operator = (const String& other){
  151. m_ptr = other.m_ptr;
  152. return *this;
  153. }
  154. inline String& operator = (String&& other) noexcept {
  155. m_ptr = std::move(other.m_ptr);
  156. return *this;
  157. }
  158. /**
  159. * Case insensitive compare (ASCII only).
  160. * @param other
  161. * @return
  162. */
  163. bool equalsCI_ASCII(const std::string& other);
  164. /**
  165. * Case insensitive compare (ASCII only).
  166. * @param other
  167. * @return
  168. */
  169. bool equalsCI_ASCII(const String& other);
  170. /**
  171. * Case insensitive compare (ASCII only).
  172. * @param other
  173. * @return
  174. */
  175. bool equalsCI_ASCII(const char* str);
  176. /**
  177. * Get underlying value.
  178. * @param defaultValue - value to return in case stored value is `nullptr`.
  179. * @return - value or `defaultValue` if stored value is `nullptr`.
  180. */
  181. std::string getValue(const std::string& defaultValue) const;
  182. template<typename T,
  183. typename enabled = typename std::enable_if<std::is_same<T, std::nullptr_t>::value, void>::type
  184. >
  185. inline bool operator == (T) const {
  186. return m_ptr.get() == nullptr;
  187. }
  188. template<typename T,
  189. typename enabled = typename std::enable_if<std::is_same<T, std::nullptr_t>::value, void>::type
  190. >
  191. inline bool operator != (T) const {
  192. return m_ptr.get() != nullptr;
  193. }
  194. template<typename T,
  195. typename enabled = typename std::enable_if<std::is_same<T, char>::value, void>::type
  196. >
  197. inline bool operator == (const T* str) const {
  198. if(!m_ptr) return str == nullptr;
  199. if(str == nullptr) return false;
  200. return *m_ptr == str;
  201. }
  202. template<typename T,
  203. typename enabled = typename std::enable_if<std::is_same<T, char>::value, void>::type
  204. >
  205. inline bool operator != (const T* str) const {
  206. return !operator == (str);
  207. }
  208. template<typename T,
  209. typename enabled = typename std::enable_if<std::is_same<T, std::string>::value, void>::type
  210. >
  211. inline bool operator == (const T& str) const {
  212. if(!m_ptr) return false;
  213. return *m_ptr == str;
  214. }
  215. template<typename T,
  216. typename enabled = typename std::enable_if<std::is_same<T, std::string>::value, void>::type
  217. >
  218. inline bool operator != (const T& str) const {
  219. return !operator == (str);
  220. }
  221. inline bool operator == (const String &other) const {
  222. if(!m_ptr) return !other.m_ptr;
  223. if(!other.m_ptr) return false;
  224. return *m_ptr == *other.m_ptr;
  225. }
  226. inline bool operator != (const String &other) const {
  227. return !operator == (other);
  228. }
  229. };
  230. String operator + (const char* a, const String& b);
  231. String operator + (const String& a, const char* b);
  232. String operator + (const String& a, const String& b);
  233. /**
  234. * Template for primitive mapping-enabled types.
  235. * @tparam TValueType - type of the value ex.: v_int64.
  236. * @tparam Clazz - Class holding static class information.
  237. */
  238. template<typename TValueType, class Clazz>
  239. class Primitive : public type::ObjectWrapper<TValueType, Clazz> {
  240. public:
  241. typedef TValueType UnderlyingType;
  242. public:
  243. OATPP_DEFINE_OBJECT_WRAPPER_DEFAULTS(Primitive, TValueType, Clazz)
  244. Primitive(TValueType value)
  245. : type::ObjectWrapper<TValueType, Clazz>(std::make_shared<TValueType>(value))
  246. {}
  247. Primitive& operator = (TValueType value) {
  248. this->m_ptr = std::make_shared<TValueType>(value);
  249. return *this;
  250. }
  251. TValueType operator*() const {
  252. return this->m_ptr.operator*();
  253. }
  254. template<typename T,
  255. typename enabled = typename std::enable_if<std::is_same<T, std::nullptr_t>::value, void>::type
  256. >
  257. inline bool operator == (T){
  258. return this->m_ptr.get() == nullptr;
  259. }
  260. template<typename T,
  261. typename enabled = typename std::enable_if<std::is_same<T, std::nullptr_t>::value, void>::type
  262. >
  263. inline bool operator != (T){
  264. return this->m_ptr.get() != nullptr;
  265. }
  266. template<typename T,
  267. typename enabled = typename std::enable_if<std::is_same<T, TValueType>::value, void>::type
  268. >
  269. inline bool operator == (T value) const {
  270. if(!this->m_ptr) return false;
  271. return *this->m_ptr == value;
  272. }
  273. template<typename T,
  274. typename enabled = typename std::enable_if<std::is_same<T, TValueType>::value, void>::type
  275. >
  276. inline bool operator != (T value) const {
  277. if(!this->m_ptr) return true;
  278. return *this->m_ptr != value;
  279. }
  280. template<typename T,
  281. typename enabled = typename std::enable_if<std::is_same<T, Primitive>::value, void>::type
  282. >
  283. inline bool operator == (const T &other) const {
  284. if(this->m_ptr.get() == other.m_ptr.get()) return true;
  285. if(!this->m_ptr || !other.m_ptr) return false;
  286. return *this->m_ptr == *other.m_ptr;
  287. }
  288. template<typename T,
  289. typename enabled = typename std::enable_if<std::is_same<T, Primitive>::value, void>::type
  290. >
  291. inline bool operator != (const T &other) const {
  292. return !operator == (other);
  293. }
  294. inline operator TValueType() const {
  295. return *this->m_ptr;
  296. }
  297. TValueType getValue(const TValueType& defaultValue) const {
  298. if(this->m_ptr) {
  299. return *this->m_ptr;
  300. }
  301. return defaultValue;
  302. }
  303. };
  304. /**
  305. * ObjectWrapper for Boolean.
  306. */
  307. class Boolean : public type::ObjectWrapper<bool, __class::Boolean> {
  308. public:
  309. typedef bool UnderlyingType;
  310. public:
  311. OATPP_DEFINE_OBJECT_WRAPPER_DEFAULTS(Boolean, bool, __class::Boolean)
  312. Boolean(bool value)
  313. : type::ObjectWrapper<bool, __class::Boolean>(std::make_shared<bool>(value))
  314. {}
  315. Boolean& operator = (bool value) {
  316. this->m_ptr = std::make_shared<bool>(value);
  317. return *this;
  318. }
  319. inline bool operator*() const {
  320. return this->m_ptr.operator*();
  321. }
  322. template<typename T,
  323. typename enabled = typename std::enable_if<std::is_same<T, std::nullptr_t>::value, void>::type
  324. >
  325. inline bool operator == (T){
  326. return m_ptr.get() == nullptr;
  327. }
  328. template<typename T,
  329. typename enabled = typename std::enable_if<std::is_same<T, std::nullptr_t>::value, void>::type
  330. >
  331. inline bool operator != (T){
  332. return m_ptr.get() != nullptr;
  333. }
  334. template<typename T,
  335. typename enabled = typename std::enable_if<std::is_same<T, bool>::value, void>::type
  336. >
  337. inline bool operator == (T value) const {
  338. if(!this->m_ptr) return false;
  339. return *this->m_ptr == value;
  340. }
  341. template<typename T,
  342. typename enabled = typename std::enable_if<std::is_same<T, bool>::value, void>::type
  343. >
  344. inline bool operator != (T value) const {
  345. if(!this->m_ptr) return true;
  346. return *this->m_ptr != value;
  347. }
  348. inline bool operator == (const Boolean &other) const {
  349. if(this->m_ptr.get() == other.m_ptr.get()) return true;
  350. if(!this->m_ptr || !other.m_ptr) return false;
  351. return *this->m_ptr == *other.m_ptr;
  352. }
  353. inline bool operator != (const Boolean &other) const {
  354. return !operator == (other);
  355. }
  356. inline operator bool() const {
  357. if(this->m_ptr) {
  358. return *(this->m_ptr);
  359. }
  360. return false;
  361. }
  362. bool getValue(bool defaultValue) const {
  363. if(this->m_ptr) {
  364. return *this->m_ptr;
  365. }
  366. return defaultValue;
  367. }
  368. };
  369. /**
  370. * Int8 is an ObjectWrapper over `v_int8` and __class::Int8.
  371. */
  372. typedef Primitive<v_int8, __class::Int8> Int8;
  373. /**
  374. * UInt8 is an ObjectWrapper over `v_uint8` and __class::UInt8.
  375. */
  376. typedef Primitive<v_uint8, __class::UInt8> UInt8;
  377. /**
  378. * Int16 is an ObjectWrapper over `v_int16` and __class::Int16.
  379. */
  380. typedef Primitive<v_int16, __class::Int16> Int16;
  381. /**
  382. * UInt16 is an ObjectWrapper over `v_uint16` and __class::UInt16.
  383. */
  384. typedef Primitive<v_uint16, __class::UInt16> UInt16;
  385. /**
  386. * Int32 is an ObjectWrapper over `v_int32` and __class::Int32.
  387. */
  388. typedef Primitive<v_int32, __class::Int32> Int32;
  389. /**
  390. * UInt32 is an ObjectWrapper over `v_uint32` and __class::UInt32.
  391. */
  392. typedef Primitive<v_uint32, __class::UInt32> UInt32;
  393. /**
  394. * Int64 is an ObjectWrapper over `v_int64` and __class::Int64.
  395. */
  396. typedef Primitive<v_int64, __class::Int64> Int64;
  397. /**
  398. * UInt64 is an ObjectWrapper over `v_uint64` and __class::UInt64.
  399. */
  400. typedef Primitive<v_uint64, __class::UInt64> UInt64;
  401. /**
  402. * Float32 is an ObjectWrapper over `v_float32` and __class::Float32.
  403. */
  404. typedef Primitive<v_float32, __class::Float32> Float32;
  405. /**
  406. * Float64 is an ObjectWrapper over `v_float64` and __class::Float64.
  407. */
  408. typedef Primitive<v_float64, __class::Float64> Float64;
  409. template<>
  410. struct ObjectWrapperByUnderlyingType <v_int8> {
  411. typedef Int8 ObjectWrapper;
  412. };
  413. template<>
  414. struct ObjectWrapperByUnderlyingType <v_uint8> {
  415. typedef UInt8 ObjectWrapper;
  416. };
  417. template<>
  418. struct ObjectWrapperByUnderlyingType <v_int16> {
  419. typedef Int16 ObjectWrapper;
  420. };
  421. template<>
  422. struct ObjectWrapperByUnderlyingType <v_uint16> {
  423. typedef UInt16 ObjectWrapper;
  424. };
  425. template<>
  426. struct ObjectWrapperByUnderlyingType <v_int32> {
  427. typedef Int32 ObjectWrapper;
  428. };
  429. template<>
  430. struct ObjectWrapperByUnderlyingType <v_uint32> {
  431. typedef UInt32 ObjectWrapper;
  432. };
  433. template<>
  434. struct ObjectWrapperByUnderlyingType <v_int64> {
  435. typedef Int64 ObjectWrapper;
  436. };
  437. template<>
  438. struct ObjectWrapperByUnderlyingType <v_uint64> {
  439. typedef UInt64 ObjectWrapper;
  440. };
  441. template<>
  442. struct ObjectWrapperByUnderlyingType <bool> {
  443. typedef Boolean ObjectWrapper;
  444. };
  445. namespace __class {
  446. class String {
  447. public:
  448. static const ClassId CLASS_ID;
  449. static Type* getType(){
  450. static Type type(CLASS_ID);
  451. return &type;
  452. }
  453. };
  454. class Int8 {
  455. public:
  456. static const ClassId CLASS_ID;
  457. static Type* getType(){
  458. static Type type(CLASS_ID);
  459. return &type;
  460. }
  461. };
  462. class UInt8 {
  463. public:
  464. static const ClassId CLASS_ID;
  465. static Type* getType(){
  466. static Type type(CLASS_ID);
  467. return &type;
  468. }
  469. };
  470. class Int16 {
  471. public:
  472. static const ClassId CLASS_ID;
  473. static Type* getType(){
  474. static Type type(CLASS_ID);
  475. return &type;
  476. }
  477. };
  478. class UInt16 {
  479. public:
  480. static const ClassId CLASS_ID;
  481. static Type* getType(){
  482. static Type type(CLASS_ID);
  483. return &type;
  484. }
  485. };
  486. class Int32 {
  487. public:
  488. static const ClassId CLASS_ID;
  489. static Type* getType(){
  490. static Type type(CLASS_ID);
  491. return &type;
  492. }
  493. };
  494. class UInt32 {
  495. public:
  496. static const ClassId CLASS_ID;
  497. static Type* getType(){
  498. static Type type(CLASS_ID);
  499. return &type;
  500. }
  501. };
  502. class Int64 {
  503. public:
  504. static const ClassId CLASS_ID;
  505. static Type* getType(){
  506. static Type type(CLASS_ID);
  507. return &type;
  508. }
  509. };
  510. class UInt64 {
  511. public:
  512. static const ClassId CLASS_ID;
  513. static Type* getType(){
  514. static Type type(CLASS_ID);
  515. return &type;
  516. }
  517. };
  518. class Float32 {
  519. public:
  520. static const ClassId CLASS_ID;
  521. static Type* getType(){
  522. static Type type(CLASS_ID);
  523. return &type;
  524. }
  525. };
  526. class Float64 {
  527. public:
  528. static const ClassId CLASS_ID;
  529. static Type* getType(){
  530. static Type type(CLASS_ID);
  531. return &type;
  532. }
  533. };
  534. class Boolean {
  535. public:
  536. static const ClassId CLASS_ID;
  537. static Type* getType(){
  538. static Type type(CLASS_ID);
  539. return &type;
  540. }
  541. };
  542. }
  543. }}}}
  544. namespace std {
  545. template<>
  546. struct hash<oatpp::data::mapping::type::String> {
  547. typedef oatpp::data::mapping::type::String argument_type;
  548. typedef v_uint64 result_type;
  549. result_type operator()(argument_type const& s) const noexcept {
  550. if(s.get() == nullptr) return 0;
  551. return hash<std::string> {} (*s);
  552. }
  553. };
  554. template<>
  555. struct hash<oatpp::data::mapping::type::Boolean> {
  556. typedef oatpp::data::mapping::type::Boolean argument_type;
  557. typedef v_uint64 result_type;
  558. result_type operator()(argument_type const& v) const noexcept {
  559. if(v.get() == nullptr) return 2;
  560. return result_type(*v);
  561. }
  562. };
  563. template<>
  564. struct hash<oatpp::data::mapping::type::Int8> {
  565. typedef oatpp::data::mapping::type::Int8 argument_type;
  566. typedef v_uint64 result_type;
  567. result_type operator()(argument_type const& v) const noexcept {
  568. if(v.get() == nullptr) return 0;
  569. return (result_type) *v;
  570. }
  571. };
  572. template<>
  573. struct hash<oatpp::data::mapping::type::UInt8> {
  574. typedef oatpp::data::mapping::type::UInt8 argument_type;
  575. typedef v_uint64 result_type;
  576. result_type operator()(argument_type const& v) const noexcept {
  577. if(v.get() == nullptr) return 0;
  578. return (result_type) *v;
  579. }
  580. };
  581. template<>
  582. struct hash<oatpp::data::mapping::type::Int16> {
  583. typedef oatpp::data::mapping::type::Int16 argument_type;
  584. typedef v_uint64 result_type;
  585. result_type operator()(argument_type const& v) const noexcept {
  586. if(v.get() == nullptr) return 0;
  587. return (result_type) *v;
  588. }
  589. };
  590. template<>
  591. struct hash<oatpp::data::mapping::type::UInt16> {
  592. typedef oatpp::data::mapping::type::UInt16 argument_type;
  593. typedef v_uint64 result_type;
  594. result_type operator()(argument_type const& v) const noexcept {
  595. if(v.get() == nullptr) return 0;
  596. return (result_type) *v;
  597. }
  598. };
  599. template<>
  600. struct hash<oatpp::data::mapping::type::Int32> {
  601. typedef oatpp::data::mapping::type::Int32 argument_type;
  602. typedef v_uint64 result_type;
  603. result_type operator()(argument_type const& v) const noexcept {
  604. if(v.get() == nullptr) return 0;
  605. return (result_type) *v;
  606. }
  607. };
  608. template<>
  609. struct hash<oatpp::data::mapping::type::UInt32> {
  610. typedef oatpp::data::mapping::type::UInt32 argument_type;
  611. typedef v_uint64 result_type;
  612. result_type operator()(argument_type const& v) const noexcept {
  613. if(v.get() == nullptr) return 0;
  614. return (result_type) *v;
  615. }
  616. };
  617. template<>
  618. struct hash<oatpp::data::mapping::type::Int64> {
  619. typedef oatpp::data::mapping::type::Int64 argument_type;
  620. typedef v_uint64 result_type;
  621. result_type operator()(argument_type const& v) const noexcept {
  622. if(v.get() == nullptr) return 0;
  623. return (result_type) *v;
  624. }
  625. };
  626. template<>
  627. struct hash<oatpp::data::mapping::type::UInt64> {
  628. typedef oatpp::data::mapping::type::UInt64 argument_type;
  629. typedef v_uint64 result_type;
  630. result_type operator()(argument_type const& v) const noexcept {
  631. if(v.get() == nullptr) return 0;
  632. return (result_type) *v;
  633. }
  634. };
  635. template<>
  636. struct hash<oatpp::data::mapping::type::Float32> {
  637. typedef oatpp::data::mapping::type::Float32 argument_type;
  638. typedef v_uint64 result_type;
  639. result_type operator()(argument_type const& v) const noexcept {
  640. if(v.get() == nullptr) return 0;
  641. return *((v_uint32*) v.get());
  642. }
  643. };
  644. template<>
  645. struct hash<oatpp::data::mapping::type::Float64> {
  646. typedef oatpp::data::mapping::type::Float64 argument_type;
  647. typedef v_uint64 result_type;
  648. result_type operator()(argument_type const& v) const noexcept {
  649. if(v.get() == nullptr) return 0;
  650. return *((result_type*) v.get());
  651. }
  652. };
  653. }
  654. #endif /* oatpp_base_Countable_PrimitiveDataTypes_hpp */