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
00046 #ifndef OPENRJ_INCL_OPENRJ_STL_HPP_FIELD
00047 #define OPENRJ_INCL_OPENRJ_STL_HPP_FIELD
00048
00049
00050
00051
00052
00053 #ifndef OPENRJ_DOCUMENTATION_SKIP_SECTION
00054 # define OPENRJ_VER_OPENRJ_STL_HPP_FIELD_MAJOR 1
00055 # define OPENRJ_VER_OPENRJ_STL_HPP_FIELD_MINOR 4
00056 # define OPENRJ_VER_OPENRJ_STL_HPP_FIELD_REVISION 4
00057 # define OPENRJ_VER_OPENRJ_STL_HPP_FIELD_EDIT 18
00058 #endif
00059
00060
00061
00062
00063
00064 #include <openrj/stl/openrj.hpp>
00065
00066 #include <stlsoft/string/shim_string.hpp>
00067 #include <stlsoft/shims/access/string.hpp>
00068
00069 #include <stdexcept>
00070
00071
00072
00073
00074
00075 #ifdef __BORLANDC__
00076 # pragma warn -8027
00077 #endif
00078
00079
00080
00081
00082
00083 namespace openrj
00084 {
00085
00086 namespace stl
00087 {
00088
00089
00090
00091
00092
00094 class field
00095 {
00098 public:
00099 typedef field class_type;
00101
00104 public:
00106 explicit field(ORJField const *field);
00108 field();
00110 field(field const &rhs);
00112 field &operator =(field const &rhs);
00114
00117 public:
00119 string_t name() const;
00121 string_t value() const;
00123
00126 public:
00128 ORJField const *get_field() const;
00131 ORJRecord const *get_record() const;
00133
00134
00135 private:
00136 ORJField const *m_field;
00137 };
00138
00139
00140
00141
00142
00146 inline stlsoft::basic_shim_string<char, true> c_str_ptr_null(field const &f)
00147 {
00148 ORJField const *pf = f.get_field();
00149 string_t s;
00150
00151 s.reserve(pf->name.len + 1 + pf->value.len);
00152
00153 s.append(pf->name.ptr, pf->name.len);
00154 s.append(1, '=');
00155 s.append(pf->value.ptr, pf->value.len);
00156
00157 return stlsoft::basic_shim_string<char, true>(s.c_str(), s.length());
00158 }
00159
00163 inline stlsoft::basic_shim_string<char> c_str_ptr(field const &f)
00164 {
00165 ORJField const *pf = f.get_field();
00166 string_t s;
00167
00168 s.reserve(pf->name.len + 1 + pf->value.len);
00169
00170 s.append(pf->name.ptr, pf->name.len);
00171 s.append(1, '=');
00172 s.append(pf->value.ptr, pf->value.len);
00173
00174 return stlsoft::basic_shim_string<char>(s.c_str(), s.length());
00175 }
00176
00180 inline size_t c_str_len(field const &f)
00181 {
00182 ORJField const *pf = f.get_field();
00183
00184 return pf->name.len + 1 + pf->value.len;
00185 }
00186
00190 inline ::stlsoft::basic_shim_string<char> c_str_data(field const &f)
00191 {
00192 return c_str_ptr(f);
00193 }
00194
00198 template <class S>
00199 inline S &operator <<(S &s, field const &field)
00200 {
00201 s << field.name() << "=" << field.value();
00202
00203 return s;
00204 }
00205
00206
00207
00208
00209
00210 inline field::field(ORJField const *field)
00211 : m_field(field)
00212 {
00213 openrj_assert(NULL != field);
00214 openrj_assert(0 == field->mbz0);
00215 openrj_assert(static_cast<ptrdiff_t>(field->name.len) >= 0);
00216 openrj_assert(static_cast<ptrdiff_t>(field->value.len) >= 0);
00217 }
00218
00219 inline field::field()
00220 : m_field(NULL)
00221 {}
00222
00223 inline field::field(field const &rhs)
00224 : m_field(rhs.m_field)
00225 {
00226 openrj_assert(NULL == m_field || 0 == rhs.m_field->mbz0);
00227 openrj_assert(NULL == m_field || static_cast<ptrdiff_t>(rhs.m_field->name.len) >= 0);
00228 openrj_assert(NULL == m_field || static_cast<ptrdiff_t>(rhs.m_field->value.len) >= 0);
00229 }
00230
00231 inline field &field::operator =(field const &rhs)
00232 {
00233 m_field = rhs.m_field;
00234
00235 return *this;
00236 }
00237
00238 inline string_t field::name() const
00239 {
00240 if(NULL == m_field)
00241 {
00242 return string_t();
00243 }
00244
00245 openrj_assert(NULL != m_field);
00246 openrj_assert(0 == m_field->mbz0);
00247 openrj_assert(static_cast<ptrdiff_t>(m_field->name.len) >= 0);
00248 openrj_assert(static_cast<ptrdiff_t>(m_field->value.len) >= 0);
00249
00250 return string_t(m_field->name.ptr, m_field->name.len);
00251 }
00252
00253 inline string_t field::value() const
00254 {
00255 if(NULL == m_field)
00256 {
00257 return string_t();
00258 }
00259
00260 openrj_assert(NULL != m_field);
00261 openrj_assert(0 == m_field->mbz0);
00262 openrj_assert(static_cast<ptrdiff_t>(m_field->name.len) >= 0);
00263 openrj_assert(static_cast<ptrdiff_t>(m_field->value.len) >= 0);
00264
00265 return string_t(m_field->value.ptr, m_field->value.len);
00266 }
00267
00268 inline ORJField const *field::get_field() const
00269 {
00270 return m_field;
00271 }
00272
00273 inline ORJRecord const *field::get_record() const
00274 {
00275 openrj_assert(NULL != m_field);
00276
00277 return ORJ_Field_GetRecordA(m_field);
00278 }
00279
00280
00281
00282
00283
00284 }
00285 }
00286
00287 namespace stlsoft
00288 {
00289 using ::openrj::stl::c_str_ptr_null;
00290 using ::openrj::stl::c_str_ptr;
00291 using ::openrj::stl::c_str_data;
00292 using ::openrj::stl::c_str_len;
00293 }
00294
00295
00296
00297 #endif
00298
00299