00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056 #ifndef XIMOL_XML_CONTENT_HPP_
00057 #define XIMOL_XML_CONTENT_HPP_
00058
00059 #include <ximol/stream.hpp>
00060 #include <ximol/assignment.hpp>
00061 #include <ximol/parser/utils.hpp>
00062 #include <ximol/parser/def_signs.hpp>
00063 #include <sstream>
00064
00065 XIMOL_XML_BEGIN_NAMESPACE
00066
00067
00068
00069
00070 class XIMOL_EXPORT manipulator_char_data_content
00071 {
00072 public:
00073 manipulator_char_data_content(const xstring& xstr);
00074 manipulator_char_data_content(const manipulator_char_data_content& x);
00075
00076 manipulator_char_data_content& operator=(const manipulator_char_data_content& x);
00077 manipulator_char_data_content& operator=(const xstring& xstr);
00078
00079 ::std::basic_istringstream<xchar_t>& istr();
00080 xstring xstr() const;
00081 void xstr(const xstring & xstr);
00082
00083 ::std::string str() const;
00084 void str(const ::std::string & str);
00085
00086 private:
00087 ::std::basic_istringstream<xchar_t> content_;
00088 };
00089
00090
00091
00092
00093
00094
00095
00096 XIMOL_EXPORT
00097 manipulator_char_data_content char_data_content(xistream& xis);
00098
00099
00100
00101
00102 template < typename T >
00103 class manipulator_char_content
00104 {
00105 public:
00106 typedef T string_type;
00107
00108 public:
00109 manipulator_char_content(string_type & x)
00110 :x_(x)
00111 {};
00112
00113 manipulator_char_content(const manipulator_char_content<T> & x)
00114 :x_(x.x_)
00115 {};
00116
00117 void set(const xstring & x)
00118 {
00119 assignment_to_string::equality(x_, x);
00120 };
00121
00122 xstring get() const
00123 {
00124 return str<std::wstring>::cast(x_);
00125 };
00126
00127 private:
00128 const manipulator_char_content<T> & operator=(const manipulator_char_content<T> & x);
00129
00130 private:
00131 string_type & x_;
00132
00133 };
00134
00135
00136
00137
00138 template < typename T >
00139 xostream& operator<<(xostream& xos, const manipulator_char_content<T>& m)
00140 {
00141 XIMOL_PARSER_USING_NAMESPACE;
00142
00143 xstring buffer(m.get());
00144 xstring::const_iterator i(buffer.begin()), i_end(buffer.end());
00145
00146 for(;i!=i_end;++i)
00147 {
00148 switch (*i)
00149 {
00150 case XCHAR_AMPERSAND:
00151 case XCHAR_LESS_THAN_SIGN:
00152 case XCHAR_RIGHT_SQUARE_BRACKET:
00153 write_char_ref(xos,*i);
00154 break;
00155 default:
00156 write_xchar(xos,*i);
00157 }
00158 }
00159 return xos;
00160 };
00161
00162
00163
00164
00165 template < typename T >
00166 xistream& operator>>(xistream& xis, manipulator_char_content<T> m)
00167 {
00168 XIMOL_PARSER_USING_NAMESPACE;
00169 m.set(char_data_content(xis).xstr());
00170 return xis;
00171 };
00172
00173
00174
00175
00176 template < typename T >
00177 class manipulator_data_content
00178 {
00179 public:
00180 typedef T object_type;
00181
00182 public:
00183 manipulator_data_content(object_type & x)
00184 :x_(x)
00185 {};
00186
00187 manipulator_data_content(const manipulator_data_content<T> & x)
00188 :x_(x.x_)
00189 {};
00190
00191 void set(const object_type & x)
00192 {
00193 assignment_std::equality(x_, x);
00194 };
00195
00196 void set_string(const xstring & xstr)
00197 {
00198 assignment_char_serialization::equality(x_, xstr);
00199 };
00200
00201 const object_type & get() const
00202 {
00203 return x_;
00204 };
00205
00206 xstring get_string() const
00207 {
00208 return str<std::wstring>::cast(x_);
00209 };
00210
00211 private:
00212 const manipulator_data_content<T> & operator=(const manipulator_data_content<T> & x);
00213
00214 private:
00215 object_type & x_;
00216
00217 };
00218
00219
00220
00221
00222 template < typename T >
00223 xostream& operator<<(xostream& xos, const manipulator_data_content<T>& m)
00224 {
00225 XIMOL_PARSER_USING_NAMESPACE;
00226 xos << manipulator_char_content<xstring>(m.get_string());
00227 return xos;
00228 };
00229
00230
00231
00232
00233 template < typename T >
00234 xistream& operator>>(xistream& xis, manipulator_data_content<T>& m)
00235 {
00236 XIMOL_PARSER_USING_NAMESPACE;
00237 xstring xstr;
00238 manipulator_char_content<xstring> manip(xstr);
00239 xis >> manip;
00240 m.set_string(xstr);
00241 return xis;
00242 };
00243
00244
00245 #define XIMOL_CONTENT_CHAR_SPECIALIZATION(type) \
00246 inline manipulator_char_content<type> content(type& t, bool = false) { \
00247 return manipulator_char_content<type>(t); \
00248 }
00249
00250 XIMOL_CONTENT_CHAR_SPECIALIZATION(std::string)
00251 XIMOL_CONTENT_CHAR_SPECIALIZATION(const std::string)
00252 XIMOL_CONTENT_CHAR_SPECIALIZATION(std::wstring)
00253 XIMOL_CONTENT_CHAR_SPECIALIZATION(const std::wstring)
00254 XIMOL_CONTENT_CHAR_SPECIALIZATION(char *)
00255 XIMOL_CONTENT_CHAR_SPECIALIZATION(const char *)
00256 XIMOL_CONTENT_CHAR_SPECIALIZATION(wchar_t *)
00257 XIMOL_CONTENT_CHAR_SPECIALIZATION(const wchar_t *)
00258
00259 #undef XIMOL_CONTENT_CHAR_SPECIALIZATION
00260
00261
00262 template<typename T>
00263 manipulator_data_content<T> content(T& t)
00264 {
00265 return manipulator_data_content<T>(t);
00266 }
00267
00268
00269 XIMOL_XML_END_NAMESPACE
00270
00271 #endif // #ifndef XIMOL_XML_CONTENT_HPP_