![]() |
RTBKit
0.9
Open-source framework to create real-time ad bidding systems.
|
00001 /* value_description.cc -*- C++ -*- 00002 Jeremy Barnes, 29 March 2013 00003 Copyright (c) 2013 Datacratic Inc. All rights reserved. 00004 00005 Code for description and introspection of values and structures. Used 00006 to allow for automated formatters and parsers to be built. 00007 */ 00008 00009 00010 #include "value_description.h" 00011 #include "jml/arch/demangle.h" 00012 00013 00014 using namespace std; 00015 using namespace ML; 00016 00017 00018 namespace Datacratic { 00019 00020 std::ostream & operator << (std::ostream & stream, ValueKind kind) 00021 { 00022 switch (kind) { 00023 case ValueKind::ATOM: return stream << "ATOM"; 00024 case ValueKind::INTEGER: return stream << "INTEGER"; 00025 case ValueKind::FLOAT: return stream << "FLOAT"; 00026 case ValueKind::BOOLEAN: return stream << "BOOLEAN"; 00027 case ValueKind::STRING: return stream << "STRING"; 00028 case ValueKind::ENUM: return stream << "ENUM"; 00029 case ValueKind::OPTIONAL: return stream << "OPTIONAL"; 00030 case ValueKind::ARRAY: return stream << "ARRAY"; 00031 case ValueKind::STRUCTURE: return stream << "STRUCTURE"; 00032 case ValueKind::TUPLE: return stream << "TUPLE"; 00033 case ValueKind::VARIANT: return stream << "VARIANT"; 00034 case ValueKind::MAP: return stream << "MAP"; 00035 case ValueKind::ANY: return stream << "ANY"; 00036 default: 00037 return stream << "ValueKind(" << to_string((int)kind) << ")"; 00038 } 00039 } 00040 00041 void registerValueDescription(const std::type_info & type, 00042 std::function<ValueDescription * ()> fn, 00043 bool isDefault) 00044 { 00045 #if 0 00046 auto desc = fn(); 00047 00048 cerr << "got " << ML::demangle(type.name()) 00049 << " with description " 00050 << ML::type_name(*desc) << endl; 00051 00052 delete desc; 00053 #endif 00054 } 00055 00056 void 00057 ValueDescription:: 00058 convertAndCopy(const void * from, 00059 const ValueDescription & fromDesc, 00060 void * to) const 00061 { 00062 StructuredJsonPrintingContext context; 00063 fromDesc.printJson(from, context); 00064 00065 StructuredJsonParsingContext context2(context.output); 00066 parseJson(to, context2); 00067 } 00068 00069 } // namespace Datacratic