Easemob Windows SDK
emattributevalue.h
1 /************************************************************
2  * * EaseMob CONFIDENTIAL
3  * __________________
4  * Copyright (C) 2015 EaseMob Technologies. All rights reserved.
5  *
6  * NOTICE: All information contained herein is, and remains
7  * the property of EaseMob Technologies.
8  * Dissemination of this information or reproduction of this material
9  * is strictly forbidden unless prior written permission is obtained
10  * from EaseMob Technologies.
11  */
12 //
13 // EMAttributeValue.h
14 // easemob
15 //
16 // Created by Neil Cao on 15/7/1.
17 //
18 //
19 
20 #ifndef __easemob__EMAttributeValue__
21 #define __easemob__EMAttributeValue__
22 
23 #include <string>
24 #include <memory>
25 #include "emjsonstring.h"
26 #include <vector>
27 
28 namespace easemob {
29 
30 class EMConfigManager;
31 class EMMessageEncoder;
32 class Connection;
33 class EMHttpRequest;
35 {
36 public:
38  EMAttributeValue(bool value);
39  EMAttributeValue(char value);
40  EMAttributeValue(unsigned char value);
41  EMAttributeValue(short value);
42  EMAttributeValue(unsigned short value);
43  EMAttributeValue(int32_t value);
44  EMAttributeValue(uint32_t value);
45  EMAttributeValue(int64_t value);
46  EMAttributeValue(uint64_t value);
47  EMAttributeValue(float value);
48  EMAttributeValue(double value);
49  EMAttributeValue(const std::string& value);
50  EMAttributeValue(const char* value);
51  EMAttributeValue(const std::vector<std::string>& values);
52  EMAttributeValue(const EMJsonString& value);
54  EMAttributeValue& operator=(const EMAttributeValue& right);
55 
56  template <typename T>
57  bool is() const;
58 
59  template <typename T>
60  bool isType() const
61  {
62  return is<T>();
63  }
64 
65  template <typename T>
66  T value() const;
67 
68  template<typename T>
69  void setValue(const T &value);
70  void setValue(const char* value);
71 
72  template <typename T>
73  void operator=(const T& value)
74  {
75  setValue(value);
76  }
77 
78  void operator=(const char* value)
79  {
80  setValue(value);
81  }
82 
83  int type() const
84  {
85  return (int)mType;
86  }
87 
88 private:
89  enum class EMAttributeValueType
90  {
91  BOOL,
92  CHAR,
93  UCHAR,
94  SHORT,
95  USHORT,
96  INT32,
97  UINT32,
98  INT64,
99  UINT64,
100  FLOAT,
101  DOUBLE,
102  STRING,
103  STRVECTOR,
104  JSONSTRING,
105  NULLOBJ
106  };
107 
108  EMAttributeValue(const std::string& value, EMAttributeValueType type) : mValue(value), mType(type) {}
109  bool write(void *writer);
110  bool bind(void *stmt, int column);
111 
112  std::string mValue;
113  EMAttributeValueType mType;
114  std::vector<std::string> mValues;
115 
116  friend EMConfigManager;
117  friend EMMessageEncoder;
118  friend Connection;
119  friend EMHttpRequest;
120 };
121 
122 typedef std::shared_ptr<easemob::EMAttributeValue> EMAttributeValuePtr;
123 
124 }
125 
126 #endif /* defined(__easemob__EMAttributeValue__) */
Definition: emattributevalue.h:28
Definition: emattributevalue.h:34
Definition: emjsonstring.h:26