Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
json-util.h
Go to the documentation of this file.
1 // Copyright 2012 Cloudera Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef IMPALA_UTIL_JSON_UTIL_H
16 #define IMPALA_UTIL_JSON_UTIL_H
17 
18 #include <rapidjson/rapidjson.h>
19 #include <rapidjson/document.h>
20 
21 #include "util/template-util.h"
22 #include "util/pretty-printer.h"
23 
24 namespace impala {
25 
31 template <typename T>
33 ToJsonValue(const T& value, const TUnit::type unit, rapidjson::Document* document,
34  rapidjson::Value* out_val) {
35  *out_val = value;
36 }
37 
40 template <>
41 void ToJsonValue<std::string>(const std::string& value, const TUnit::type unit,
42  rapidjson::Document* document, rapidjson::Value* out_val);
43 
46 template <typename T>
47 ENABLE_IF_ARITHMETIC(T, void)
48 ToJsonValue(const T& value, const TUnit::type unit, rapidjson::Document* document,
49  rapidjson::Value* out_val) {
50  if (unit != TUnit::NONE) {
51  const std::string& s = PrettyPrinter::Print(value, unit);
52  ToJsonValue(s, unit, document, out_val);
53  } else {
54  *out_val = value;
55  }
56 }
57 
58 }
59 
60 #endif
#define ENABLE_IF_NOT_ARITHMETIC(type_param, return_type)
Definition: template-util.h:37
static std::string Print(bool value, TUnit::type ignored, bool verbose=false)
#define ENABLE_IF_ARITHMETIC(type_param, return_type)
Definition: template-util.h:32
ToJsonValue(const T &value, const TUnit::type unit, rapidjson::Document *document, rapidjson::Value *out_val)
Definition: json-util.h:33