00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef __SOA_TYPES__
00020 #define __SOA_TYPES__
00021
00022 #include <stdint.h>
00023 #include <string>
00024 #include <boost/shared_ptr.hpp>
00025 #include <boost/enable_shared_from_this.hpp>
00026
00027 namespace soa {
00028
00029 enum Type {
00030 ARRAY_TYPE = 0,
00031 COLLECTION_TYPE,
00032 STRING_TYPE,
00033 INT_TYPE,
00034 BOOL_TYPE,
00035 BASE64BIN_TYPE,
00036 QNAME_TYPE
00037 };
00038
00039 class Generic : public boost::enable_shared_from_this<Generic> {
00040 public:
00041 Generic(const std::string& name, Type type)
00042 : name_(name),
00043 type_(type)
00044 {}
00045
00046 virtual ~Generic() {
00047 }
00048
00049 virtual bool complex() {
00050 return false;
00051 }
00052
00053 const std::string& name() const {
00054 return name_;
00055 }
00056
00057 Type type() const {
00058 return type_;
00059 }
00060
00061 template <class T>
00062 boost::shared_ptr<T> as() {
00063 return boost::dynamic_pointer_cast<T>(shared_from_this());
00064 }
00065
00066 template <class T>
00067 boost::shared_ptr<T> as(const std::string& name) {
00068 if (name_ != name)
00069 return boost::shared_ptr<T>();
00070 return boost::dynamic_pointer_cast<T>(shared_from_this());
00071 }
00072
00073 private:
00074 std::string name_;
00075 Type type_;
00076 };
00077 typedef boost::shared_ptr<Generic> GenericPtr;
00078
00079 template <class T, Type Y>
00080 class Primitive : public Generic {
00081 public:
00082 Primitive(const std::string& name, T t)
00083 : Generic(name, Y),
00084 value_(t)
00085 {}
00086
00087 const T& value() const {
00088 return value_;
00089 }
00090
00091 private:
00092 T value_;
00093 };
00094
00095 typedef Primitive<std::string, STRING_TYPE> String;
00096 typedef boost::shared_ptr<String> StringPtr;
00097
00098 typedef Primitive<int64_t, INT_TYPE> Int;
00099 typedef boost::shared_ptr<Int> IntPtr;
00100
00101 typedef Primitive<bool, BOOL_TYPE> Bool;
00102 typedef boost::shared_ptr<Bool> BoolPtr;
00103
00104 class Base64Bin : public Generic {
00105 public:
00106 Base64Bin(const std::string& name, boost::shared_ptr<std::string> data)
00107 : Generic(name, BASE64BIN_TYPE),
00108 m_data(data)
00109 {}
00110
00111 const std::string& value() const {
00112 return *m_data;
00113 }
00114
00115 private:
00116 boost::shared_ptr<std::string> m_data;
00117 };
00118 typedef boost::shared_ptr<Base64Bin> Base64BinPtr;
00119
00120 typedef Primitive<std::string, QNAME_TYPE> QName;
00121 typedef boost::shared_ptr<QName> QNamePtr;
00122
00123 class Complex : public Generic {
00124 public:
00125 Complex(const std::string& name, Type t)
00126 : Generic(name, t)
00127 {}
00128
00129 virtual bool complex() {
00130 return true;
00131 }
00132 };
00133
00134 template <class T>
00135 class Array : public Complex {
00136 public:
00137 Array(const std::string& name)
00138 : Complex(name, ARRAY_TYPE)
00139 {}
00140
00141 size_t size() const {
00142 return values_.size();
00143 }
00144
00145 template <class Y>
00146 boost::shared_ptr< Array< boost::shared_ptr<Y> > > construct() const {
00147 boost::shared_ptr< Array< boost::shared_ptr<Y> > > conv(new Array< boost::shared_ptr<Y> >(name()));
00148 for (typename std::vector< T >::const_iterator it = values_.begin(); it != values_.end(); it++) {
00149 conv->add(Y::construct(*it));
00150 }
00151 return conv;
00152 }
00153
00154 T get(size_t i) {
00155 return values_[i];
00156 }
00157
00158 T operator[](size_t i) {
00159 return values_[i];
00160 }
00161
00162 virtual void add(T element) {
00163 values_.push_back(element);
00164 }
00165
00166 private:
00167 std::vector< T > values_;
00168 };
00169 typedef boost::shared_ptr< Array<GenericPtr> > ArrayPtr;
00170
00171 class Collection : public Complex {
00172 public:
00173 Collection(const std::string& name)
00174 : Complex(name, COLLECTION_TYPE)
00175 {}
00176
00177
00178
00179 size_t size() const {
00180 return values_.size();
00181 }
00182
00183 template <class T>
00184 boost::shared_ptr<T> get(const std::string& name) {
00185 for (std::vector<GenericPtr>::iterator it = values_.begin(); it != values_.end(); it++) {
00186 if ((*it)->name() == name) {
00187 return (*it)->as<T>();
00188 }
00189 }
00190 return boost::shared_ptr<T>();
00191 }
00192
00193 template <class T>
00194 boost::shared_ptr<T> operator[](const std::string& name) {
00195 return get<T>(name);
00196 }
00197
00198 virtual void add(GenericPtr element) {
00199 values_.push_back(element);
00200 }
00201
00202 std::vector<GenericPtr>& values() {
00203 return values_;
00204 }
00205
00206 private:
00207 std::vector<GenericPtr> values_;
00208 };
00209 typedef boost::shared_ptr<Collection> CollectionPtr;
00210
00211 class SoapFault {
00212 public:
00213 SoapFault()
00214 : code_(), string_(), detail_() {
00215 }
00216
00217 SoapFault(QNamePtr code, StringPtr string, StringPtr detail)
00218 : code_(code), string_(string), detail_(detail) {
00219 }
00220
00221 QNamePtr code() const {
00222 return code_;
00223 }
00224
00225 StringPtr string() const {
00226 return string_;
00227 }
00228
00229 StringPtr detail() const {
00230 return detail_;
00231 }
00232
00233 private:
00234 QNamePtr code_;
00235 StringPtr string_;
00236
00237 StringPtr detail_;
00238 };
00239
00240 }
00241
00242 #endif