14 #include "../acl_cpp_define.hpp" 15 #include "../stdlib/string.hpp" 16 #include "../stdlib/json.hpp" 17 #include "../stdlib/string.hpp" 31 static const bool value =
false;
161 struct _Is_number<ssize_t> : true_type
261 !is_string<T>::value &&
262 !is_double<T>::value &&
263 !is_number<T>::value &&
264 !is_bool<T>::value &&
265 !is_char_ptr<T>::value>
270 static inline bool check_nullptr(T&)
276 static inline bool check_nullptr(T *t)
285 typename enable_if<is_string<T>::value,
const char *>::type
286 static inline get_value(
const T &value)
288 return value.c_str();
292 typename enable_if<is_string<T>::value,
const char *>::type
293 static inline get_value(
const T *value)
295 return value->c_str();
299 static inline const char *get_value(
const char *value)
305 static inline bool get_value(
const bool value)
310 static inline bool get_value(
const bool* value)
317 typename enable_if<is_number<T>::value, T>::type
318 static inline get_value(
const T t)
326 typename enable_if<is_number<T>::value, T>::type
327 static inline get_value(
const T *t)
333 typename enable_if<is_double<T>::value, T>::type
334 static inline get_value(
const T &t)
340 typename enable_if<is_double<T>::value, T>::type
341 static inline get_value(
const T *t)
348 typename enable_if<is_object<T>::value,
void>::type
351 if(check_nullptr(obj))
359 typename enable_if<is_number<T>::value,
void>::type
366 typename enable_if<is_number<T>::value,
void>::type
369 if (check_nullptr(value))
376 typename enable_if<is_double<T>::value,
void>::type
383 typename enable_if<is_double<T>::value,
void>::type
386 if(check_nullptr(value))
394 typename enable_if<is_bool<T>::value,
void>::type
397 if (check_nullptr(value))
404 typename enable_if<is_bool<T>::value,
void>::type
411 typename enable_if<is_string<T>::value,
void>::type
418 typename enable_if<is_string<T>::value,
void>::type
421 if (check_nullptr(value))
429 if (check_nullptr(value))
437 const std::list<T> &objects)
440 for (
typename std::list<T>::const_iterator
441 itr = objects.begin(); itr != objects.end(); ++itr)
443 add_item(json, node, *itr);
450 const std::list<T> *objects)
452 return gson(json, *objects);
458 const std::vector<T> &objects)
461 for (
typename std::vector<T>::const_iterator
462 itr = objects.begin(); itr != objects.end(); ++itr)
464 add_item(json, node, *itr);
472 const std::vector<T> *objects)
474 return gson(json, *objects);
480 return gson(json, *objects);
485 const std::set<T> &objects)
488 for (
typename std::set<T>::const_iterator
489 itr = objects.begin(); itr != objects.end(); ++itr)
491 add_item(json, node, *itr);
498 template<
class K,
class V>
500 static inline gson(
acl::json &json,
const std::map<K, V> &objects)
503 for (
typename std::map<K, V>::const_iterator
504 itr = objects.begin(); itr != objects.end(); ++itr)
506 const char *tag = get_value(itr->first);
507 if (check_nullptr(itr->second))
518 template<
class K,
class V>
520 static inline gson(
acl::json &json,
const std::map<K, V> *objects)
523 for (
typename std::map<K, V>::const_iterator
524 itr = objects->begin(); itr != objects->end(); ++itr)
526 const char *tag = get_value(itr->first);
527 if (check_nullptr(itr->second))
538 template<
class K,
class V>
540 static inline gson(
acl::json &json,
const std::map<K, V> &objects)
543 for (
typename std::map<K, V>::const_iterator
544 itr = objects.begin(); itr != objects.end(); ++itr)
546 const char *tag = get_value(itr->first);
547 if (check_nullptr(itr->second))
557 template<
class K,
class V>
559 static inline gson(
acl::json &json,
const std::map<K, V> *objects)
562 for (
typename std::map<K, V>::const_iterator
563 itr = objects->begin(); itr != objects->end(); ++itr)
565 const char *tag = get_value(itr->first);
566 if (check_nullptr(itr->second))
577 template<
class K,
class V>
579 static inline gson(
acl::json &json,
const std::map<K, V> &objects)
582 for (
typename std::map<K, V>::const_iterator itr = objects.begin();
583 itr != objects.end(); ++itr)
585 const char *tag = get_value(itr->first);
586 if (check_nullptr(itr->second))
596 template<
class K,
class V>
597 typename enable_if<is_string<V>::value
599 static inline gson(
acl::json &json,
const std::map<K, V> & objects)
602 for (
typename std::map<K, V>::const_iterator
603 itr = objects.begin(); itr != objects.end(); ++itr)
605 const char *tag = get_value(itr->first);
606 if (check_nullptr(itr->second))
610 .
add_text(tag, get_value(itr->second)));
616 template<
class K,
class V>
617 typename enable_if<is_string<V>::value
619 static inline gson(
acl::json &json,
const std::map<K, V*> & objects)
622 for (
typename std::map<K, V*>::const_iterator
623 itr = objects.begin(); itr != objects.end(); ++itr)
625 const char *tag = get_value(itr->first);
626 if (check_nullptr(itr->second))
630 .
add_text(tag, get_value(itr->second)));
636 template<
class T,
class V>
638 static inline gson(
acl::json &json,
const std::map<T, V> &objects)
641 for (
typename std::map<T, V>::const_iterator
642 itr = objects.begin(); itr != objects.end(); ++itr)
644 const char *tag = get_value(itr->first);
645 if (check_nullptr(itr->second))
658 template<
class T,
class V>
660 static inline gson(
acl::json &json,
const std::map<T, V> *objects)
662 return gson(json, *objects);
665 template<
class T,
class V>
667 static inline gson(
acl::json &json,
const std::map<T, V*> &objects)
670 for (
typename std::map<T, V*>::const_iterator
671 itr = objects.begin(); itr != objects.end(); ++itr)
673 const char *tag = get_value(itr->first);
674 if (check_nullptr(itr->second))
687 template<
class T,
class V>
689 static inline gson(
acl::json &json,
const std::map<T, V*> *objects)
691 return gson(json, *objects);
698 typename enable_if<is_object<T>::value,
699 std::pair<bool, std::string> >::type
704 static inline void del(T **obj)
711 static inline void del(T *obj)
717 static inline std::pair<bool, std::string>
721 return std::make_pair(
false,
"get bool failed");
724 return std::make_pair(
true,
"");
727 static inline std::pair<bool, std::string>
732 return std::make_pair(
false,
"get bool failed");
737 return std::make_pair(
true,
"");
742 typename enable_if<is_double<T>::value,
743 std::pair<bool, std::string> >::type
747 return std::make_pair(
false,
"get double failed");
750 return std::make_pair(
true,
"");
754 typename enable_if<is_double<T>::value,
755 std::pair<bool, std::string> >::type
760 return std::make_pair(
false,
"get double failed");;
765 return std::make_pair(
true,
"");
770 typename enable_if<is_number<T>::value,
771 std::pair<bool, std::string> >::type
775 return std::make_pair(
false,
"get number failed");
777 *obj = static_cast<T>(*node.
get_int64());
778 return std::make_pair(
true,
"");
782 typename enable_if<is_number<T>::value,
783 std::pair<bool, std::string> >::type
788 return std::make_pair(
false,
"get number failed");;
791 **obj = static_cast<T>(*node.
get_int64());
793 return std::make_pair(
true,
"");
797 static inline std::pair<bool, std::string>
802 return std::make_pair(
false,
"get char * string failed");
805 *obj =
new char[len + 1];
809 return std::make_pair(
true,
"");
812 static inline std::pair<bool, std::string>
816 return std::make_pair(
false,
"get string failed");
820 return std::make_pair(
true,
"");
823 static inline std::pair<bool, std::string>
827 return std::make_pair(
false,
"get string failed");
830 return std::make_pair(
true,
"");
833 static inline std::pair<bool, std::string>
838 return std::make_pair(
false,
"get string failed");
843 return std::make_pair(
true,
"");
846 static inline std::pair<bool, std::string>
850 return std::make_pair(
false,
"get string failed");
853 return std::make_pair(
true,
"");
856 static inline std::pair<bool, std::string>
860 return std::make_pair(
false,
"get string failed");
863 return std::make_pair(
true,
"");
866 static inline std::pair<bool, std::string>
871 return std::make_pair(
false,
"get string failed");
873 *obj =
new std::string;
876 return std::make_pair(
true,
"");
881 static inline std::pair<bool, std::string>
884 std::pair<bool, std::string> result;
891 return std::make_pair(
true,
"");
900 objs->push_back(T());
901 typename std::list<T>::iterator it = objs->end();
903 result = gson(*itr, &*it);
919 static inline std::pair<bool, std::string>
922 std::pair<bool, std::string> result;
929 return std::make_pair(
true,
"");
935 objs->push_back(obj);
936 result = gson(*itr, obj);
945 delete *objs->begin();
953 std::pair<bool, std::string>
956 std::pair<bool, std::string> result;
963 return std::make_pair(
true,
"");
971 objs->push_back(T());
972 typename std::vector<T>::iterator it = objs->end();
974 result = gson(*itr, &*it);
987 std::pair<bool, std::string>
990 std::pair<bool, std::string> result;
997 return std::make_pair(
true,
"");
1003 objs->push_back(obj);
1004 typename std::vector<T*>::iterator it = objs->end();
1006 result = gson(*itr, *it);
1018 T *obj = (*objs)[0];
1027 std::pair<bool, std::string>
1030 std::pair<bool, std::string> result;
1037 return std::make_pair(
true,
"");
1043 result = gson(*itr, obj);
1058 T* obj = *objs->begin();
1059 objs->erase(objs->begin());
1066 std::pair<bool, std::string>
1069 std::pair<bool, std::string> result;
1076 return std::make_pair(
true,
"");
1082 result = gson(*itr, &obj);
1099 typename enable_if<is_object<T>::value,
1100 std::pair<bool, std::string> >::type
1104 std::pair<bool, std::string> result = gson(node, *obj);
1105 if (result.first ==
false)
1117 template<
class K,
class T>
1124 std::pair<bool, std::string> >::type
1127 std::pair<bool, std::string> result;
1132 result = gson(*itr, &obj);
1136 objs->insert(std::make_pair(K(itr->
tag_name()), obj));
1141 return std::make_pair(
true,
"");
1143 for (
typename std::map<K, T>::iterator it = objs->begin();
1144 it != objs->end(); ++it)
1153 template<
class K,
class T>
1154 typename enable_if <is_object<T>::value ,
1155 std::pair<bool, std::string > > ::type
1158 std::pair<bool, std::string> result;
1164 result = gson(*(itr->
get_obj()), &obj);
1168 objs->insert(std::make_pair(K(itr->
tag_name()), obj));
1173 return std::make_pair(
true,
"");
1175 for (
typename std::map<K, T>::iterator itr2 = objs->begin();
1176 itr2 != objs->end(); ++itr2)
1186 template<
class K,
class V>
1187 std::pair<bool, std::string>
1190 std::pair<bool, std::string> result;
1192 std::string error_string;
1196 result = expand(*itr, objs);
1197 if (result.first ==
false)
1198 error_string.append(result.second);
1202 return std::make_pair(!!!objs->empty(), error_string);
1205 template<
class K,
class T>
1212 std::pair<bool, std::string> >::type
1213 static inline expand(
acl::json_node &node, std::map<K, T*> *objs)
1215 std::pair<bool, std::string> result;
1220 result = gson(*itr, obj);
1224 objs->insert(std::make_pair(K(itr->
tag_name()), obj));
1229 return std::make_pair(
true,
"");
1231 for (
typename std::map<K, T*>::iterator it = objs->begin();
1232 it != objs->end(); ++it)
1241 template<
class K,
class T>
1242 typename enable_if <is_object<T>::value ,
1243 std::pair<bool, std::string > > ::type
1244 static inline expand(
acl::json_node &node, std::map<K, T*> *objs)
1246 std::pair<bool, std::string> result;
1252 result = gson(*(itr->
get_obj()), obj);
1256 objs->insert(std::make_pair(K(itr->
tag_name()), obj));
1261 return std::make_pair(
true,
"");
1263 for (
typename std::map<K, T*>::iterator itr2 = objs->begin();
1264 itr2 != objs->end(); ++itr2)
1274 template<
class K,
class V>
1275 std::pair<bool, std::string>
1278 std::pair<bool, std::string> result;
1280 std::string error_string;
1284 result = expand(*itr, objs);
1285 if (result.first ==
false)
1286 error_string.append(result.second);
1290 return std::make_pair(!!!objs->empty(), error_string);
string & append(const string &s)
const char * get_string(void) const
json_node & add_double(const char *tag, double value, bool return_child=false)
json_node & add_number(const char *tag, long long int value, bool return_child=false)
json_node * first_child(void)
const double * get_double(void) const
json_node & add_text(const char *tag, const char *value, bool return_child=false)
json_node * get_obj(void) const
const long long int * get_int64(void) const
json_node & add_array_number(long long int value, bool return_child=false)
json_node & add_child(json_node *child, bool return_child=false)
remove_const< typename remove_volatile< T >::type >::type type
json_node & add_null(const char *tag, bool return_child=false)
json_node & create_node(const char *tag, const char *value)
bool is_double(void) const
json_node & add_array_double(double value, bool return_child=false)
json_node & create_array(void)
json_node & add_array_null(bool return_child=false)
bool is_number(void) const
json_node * next_child(void)
json_node & add_array_bool(bool value, bool return_child=false)
const bool * get_bool(void) const
json_node & add_array_text(const char *text, bool return_child=false)
bool is_string(void) const
json_node & add_bool(const char *tag, bool value, bool return_child=false)
const char * tag_name(void) const