SmartFoxServer 2X C++ API
SFSArray.h
1 // ===================================================================
2 //
3 // Description
4 // Contains the definition of SFSArray
5 //
6 // Revision history
7 // Date Description
8 // 30-Nov-2012 First version
9 //
10 // ===================================================================
11 #ifndef __SFSArray__
12 #define __SFSArray__
13 
14 #include "ISFSArray.h"
15 #include "../../Util/ByteArray.h"
16 #include "../../Protocol/Serialization/ISFSDataSerializer.h"
17 #include "../../Entities/Data/SFSDataWrapper.h"
18 
19 #include <boost/shared_ptr.hpp> // Boost Asio shared pointer
20 #include <boost/enable_shared_from_this.hpp> // Boost shared_ptr for this
21 
22 #if defined(_MSC_VER)
23 #pragma warning(disable:4786) // STL library: disable warning 4786; this warning is generated due to a Microsoft bug
24 #endif
25 #include <string> // STL library: string object
26 #include <map> // STL library: map object
27 #include <vector> // STL library: vector object
28 using namespace std; // STL library: declare the STL namespace
29 
30 using namespace Sfs2X::Protocol::Serialization;
31 using namespace Sfs2X::Util;
32 
33 namespace Sfs2X {
34 namespace Entities {
35 namespace Data {
36 
47  class DLLImportExport SFSArray : public ISFSArray, public boost::enable_shared_from_this<SFSArray>
48  {
49  public:
50 
51  // -------------------------------------------------------------------
52  // Public methods
53  // -------------------------------------------------------------------
54 
64  static boost::shared_ptr<SFSArray> NewFromArray(vector<boost::shared_ptr<SFSDataWrapper> > o);
65 
75  static boost::shared_ptr<SFSArray> NewFromBinaryData(boost::shared_ptr<ByteArray> ba);
76 
83  static boost::shared_ptr<SFSArray> NewInstance();
84 
85  SFSArray();
86  virtual ~SFSArray();
87 
88  bool Contains(boost::shared_ptr<void> obj);
89  boost::shared_ptr<SFSDataWrapper> GetWrappedElementAt(long int index);
90  boost::shared_ptr<void> GetElementAt(long int index);
91  boost::shared_ptr<void> RemoveElementAt(unsigned long int index);
92  long int Size();
93  boost::shared_ptr<ByteArray> ToBinary();
94  boost::shared_ptr<string> GetDump();
95  boost::shared_ptr<string> GetDump(bool format);
96  boost::shared_ptr<string> GetHexDump();
97 
98  /*
99  * :::::::::::::::::::::::::::::::::::::::::
100  * Type setters
101  * :::::::::::::::::::::::::::::::::::::::::
102  */
103  void AddNull();
104  void AddBool(boost::shared_ptr<bool> val);
105  void AddBool(bool val);
106  void AddByte(boost::shared_ptr<unsigned char> val);
107  void AddByte(unsigned char val);
108  void AddShort(boost::shared_ptr<short int> val);
109  void AddShort(short int val);
110  void AddInt(boost::shared_ptr<long int> val);
111  void AddInt(long int val);
112  void AddLong(boost::shared_ptr<long long> val);
113  void AddLong(long long val);
114  void AddFloat(boost::shared_ptr<float> val);
115  void AddFloat(float val);
116  void AddDouble(boost::shared_ptr<double> val);
117  void AddDouble(double val);
118  void AddUtfString(boost::shared_ptr<string> val);
119  void AddUtfString(string val);
120  void AddText(boost::shared_ptr<string> val);
121  void AddText(string val);
122  void AddBoolArray(boost::shared_ptr<vector<boost::shared_ptr<bool> > > val);
123  void AddByteArray(boost::shared_ptr<ByteArray> val);
124  void AddShortArray(boost::shared_ptr<vector<boost::shared_ptr<short int> > > val);
125  void AddIntArray(boost::shared_ptr<vector<boost::shared_ptr<long int> > > val);
126  void AddLongArray(boost::shared_ptr<vector<boost::shared_ptr<long long> > > val);
127  void AddFloatArray(boost::shared_ptr<vector<boost::shared_ptr<float> > > val);
128  void AddDoubleArray(boost::shared_ptr<vector<boost::shared_ptr<double> > > val);
129  void AddUtfStringArray(boost::shared_ptr<vector<boost::shared_ptr<string> > > val);
130  void AddSFSArray(boost::shared_ptr<ISFSArray> val);
131  void AddSFSObject(boost::shared_ptr<ISFSObject> val);
132  void AddClass(boost::shared_ptr<void> val);
133  void Add(boost::shared_ptr<SFSDataWrapper> wrappedObject);
134  void AddObject(boost::shared_ptr<void> val, SFSDataType tp);
135 
136  /*
137  * :::::::::::::::::::::::::::::::::::::::::
138  * Type getters
139  * :::::::::::::::::::::::::::::::::::::::::
140  */
141  bool IsNull(unsigned long int index);
142  // T GetValue<T>(int index)
143  bool GetBool(unsigned long int index);
144  unsigned char GetByte(unsigned long int index);
145  short int GetShort(unsigned long int index);
146  long int GetInt(unsigned long int index);
147  long long GetLong(unsigned long int index);
148  float GetFloat(unsigned long int index);
149  double GetDouble(unsigned long int index);
150  boost::shared_ptr<string> GetUtfString(unsigned long int index);
151  boost::shared_ptr<string> GetText(unsigned long int index);
152  boost::shared_ptr<vector<boost::shared_ptr<void> > > GetArray(unsigned long int index);
153  boost::shared_ptr<vector<bool> > GetBoolArray(unsigned long int index);
154  boost::shared_ptr<ByteArray> GetByteArray(unsigned long int index);
155  boost::shared_ptr<vector<short int> > GetShortArray(unsigned long int index);
156  boost::shared_ptr<vector<long int> > GetIntArray(unsigned long int index);
157  boost::shared_ptr<vector<long long> > GetLongArray(unsigned long int index);
158  boost::shared_ptr<vector<float> > GetFloatArray(unsigned long int index);
159  boost::shared_ptr<vector<double> > GetDoubleArray(unsigned long int index);
160  boost::shared_ptr<vector<string> > GetUtfStringArray(unsigned long int index);
161  boost::shared_ptr<ISFSArray> GetSFSArray(unsigned long int index);
162  boost::shared_ptr<void> GetClass(unsigned long int index);
163  boost::shared_ptr<ISFSObject> GetSFSObject(unsigned long int index);
164 
165  // -------------------------------------------------------------------
166  // Public members
167  // -------------------------------------------------------------------
168 
169  protected:
170 
171  // -------------------------------------------------------------------
172  // Protected methods
173  // -------------------------------------------------------------------
174 
175  // -------------------------------------------------------------------
176  // Protected members
177  // -------------------------------------------------------------------
178 
179  private:
180 
181  // -------------------------------------------------------------------
182  // Private methods
183  // -------------------------------------------------------------------
184 
185  boost::shared_ptr<string> Dump();
186 
187  // -------------------------------------------------------------------
188  // Private members
189  // -------------------------------------------------------------------
190 
191  boost::shared_ptr<ISFSDataSerializer> serializer;
192  boost::shared_ptr<vector<boost::shared_ptr<SFSDataWrapper> > > dataHolder;
193  };
194 
195 } // namespace Data
196 } // namespace Entities
197 } // namespace Sfs2X
198 
199 #endif
Definition: DefaultObjectDumpFormatter.cpp:15
SFSArray
Definition: SFSArray.h:47
STL namespace.
Definition: BuddyOnlineState.h:15
SFSArray interface
Definition: ISFSArray.h:46
Definition: SmartFox.cpp:24