1 /* 2 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License, version 2.0, 6 * as published by the Free Software Foundation. 7 * 8 * This program is also distributed with certain software (including 9 * but not limited to OpenSSL) that is licensed under separate terms, 10 * as designated in a particular file or component or in included license 11 * documentation. The authors of MySQL hereby grant you an additional 12 * permission to link the program and your derivative works with the 13 * separately licensed software that they have included with MySQL. 14 * 15 * This program is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU General Public License, version 2.0, for more details. 19 * 20 * You should have received a copy of the GNU General Public License 21 * along with this program; if not, write to the Free Software 22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 23 * 02110-1301 USA 24 */ 25 26 #ifndef _NGS_SETTER_ANY_H_ 27 #define _NGS_SETTER_ANY_H_ 28 29 #include <string> 30 #include <vector> 31 #include "ngs_common/protocol_protobuf.h" 32 33 34 namespace ngs 35 { 36 37 38 class Setter_any 39 { 40 public: set_scalar(::Mysqlx::Datatypes::Scalar & scalar,const bool value)41 static void set_scalar(::Mysqlx::Datatypes::Scalar &scalar, const bool value) 42 { 43 scalar.set_type(::Mysqlx::Datatypes::Scalar::V_BOOL); 44 scalar.set_v_bool(value); 45 } 46 47 set_scalar(::Mysqlx::Datatypes::Scalar & scalar,const int64_t value)48 static void set_scalar(::Mysqlx::Datatypes::Scalar &scalar, const int64_t value) 49 { 50 scalar.set_type(::Mysqlx::Datatypes::Scalar::V_SINT); 51 scalar.set_v_signed_int(value); 52 } 53 54 set_scalar(::Mysqlx::Datatypes::Scalar & scalar,const uint64_t value)55 static void set_scalar(::Mysqlx::Datatypes::Scalar &scalar, const uint64_t value) 56 { 57 scalar.set_type(::Mysqlx::Datatypes::Scalar::V_UINT); 58 scalar.set_v_unsigned_int(value); 59 } 60 61 set_scalar(::Mysqlx::Datatypes::Scalar & scalar,const float value)62 static void set_scalar(::Mysqlx::Datatypes::Scalar &scalar, const float value) 63 { 64 scalar.set_type(::Mysqlx::Datatypes::Scalar::V_FLOAT); 65 scalar.set_v_float(value); 66 } 67 68 set_scalar(::Mysqlx::Datatypes::Scalar & scalar,const double value)69 static void set_scalar(::Mysqlx::Datatypes::Scalar &scalar, const double value) 70 { 71 scalar.set_type(::Mysqlx::Datatypes::Scalar::V_DOUBLE); 72 scalar.set_v_double(value); 73 } 74 75 set_scalar(::Mysqlx::Datatypes::Scalar & scalar,const char * value)76 static void set_scalar(::Mysqlx::Datatypes::Scalar &scalar, const char *value) 77 { 78 scalar.set_type(::Mysqlx::Datatypes::Scalar::V_STRING); 79 80 scalar.set_allocated_v_string(new ::Mysqlx::Datatypes::Scalar_String()); 81 82 scalar.mutable_v_string()->set_value(value); 83 } 84 85 set_scalar(::Mysqlx::Datatypes::Scalar & scalar,const std::string & value)86 static void set_scalar(::Mysqlx::Datatypes::Scalar &scalar, const std::string &value) 87 { 88 scalar.set_type(::Mysqlx::Datatypes::Scalar::V_STRING); 89 scalar.set_allocated_v_string(new ::Mysqlx::Datatypes::Scalar_String()); 90 91 scalar.mutable_v_string()->set_value(value); 92 } 93 94 95 template<typename ValueType> set_scalar(::Mysqlx::Datatypes::Any & any,const ValueType value)96 static void set_scalar(::Mysqlx::Datatypes::Any &any, const ValueType value) 97 { 98 any.set_type(::Mysqlx::Datatypes::Any::SCALAR); 99 100 set_scalar(*any.mutable_scalar(), value); 101 } 102 103 template<typename ValueType> set_array(::Mysqlx::Datatypes::Any & any,const std::vector<ValueType> & values)104 static void set_array(::Mysqlx::Datatypes::Any &any, const std::vector<ValueType> &values) 105 { 106 ::Mysqlx::Datatypes::Array &array = *any.mutable_array(); 107 108 any.set_type(::Mysqlx::Datatypes::Any::ARRAY); 109 110 typename std::vector<ValueType>::const_iterator i = values.begin(); 111 112 for (; i != values.end(); ++i) 113 { 114 set_scalar(*array.add_value(), *i); 115 } 116 } 117 }; 118 119 120 } // namespace ngs 121 122 123 #endif // _NGS_SETTER_ANY_H_ 124