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_CPP_H_FIELD
00047 #define OPENRJ_INCL_OPENRJ_CPP_H_FIELD
00048
00049
00050
00051
00052
00053 #ifndef OPENRJ_DOCUMENTATION_SKIP_SECTION
00054 # define OPENRJ_VER_OPENRJ_CPP_H_FIELD_MAJOR 1
00055 # define OPENRJ_VER_OPENRJ_CPP_H_FIELD_MINOR 4
00056 # define OPENRJ_VER_OPENRJ_CPP_H_FIELD_REVISION 3
00057 # define OPENRJ_VER_OPENRJ_CPP_H_FIELD_EDIT 16
00058 #endif
00059
00060
00061
00062
00063
00064 #include <openrj/cpp/openrj.hpp>
00065
00066 #include <stlsoft/string/shim_string.hpp>
00067 #include <stlsoft/shims/access/string.hpp>
00068
00069 #include <string.h>
00070
00071
00072
00073
00074
00075 namespace openrj
00076 {
00077 namespace cpp
00078 {
00079
00080
00081
00082
00083
00085 class Field
00086 {
00089 public:
00090 typedef Field class_type;
00092
00095 public:
00096 Field(ORJField const *field)
00097 : m_field(field)
00098 {}
00099
00101 Field()
00102 : m_field(NULL)
00103 {}
00105 Field(class_type const &rhs)
00106 : m_field(rhs.m_field)
00107 {}
00108
00110 class_type &operator =(class_type const &rhs)
00111 {
00112 m_field = rhs.m_field;
00113
00114 return *this;
00115 }
00117
00120 public:
00122 char const *GetName() const
00123 {
00124 ORJString const *name;
00125
00126 ORJ_Field_GetNameA(m_field, &name);
00127
00128 return name->ptr;
00129 }
00131 char const *GetValue() const
00132 {
00133 ORJString const *value;
00134
00135 ORJ_Field_GetValueA(m_field, &value);
00136
00137 return value->ptr;
00138 }
00140
00143 public:
00144 bool IsEqual(class_type const &rhs) const
00145 {
00146 return 0 == strcmp(GetName(), rhs.GetName()) && 0 == strcmp(GetValue(), rhs.GetValue());
00147 }
00149
00152 public:
00154 ORJField const *GetField() const
00155 {
00156 return m_field;
00157 }
00160 ORJRecord const *GetRecord() const
00161 {
00162 openrj_assert(NULL != m_field);
00163
00164 return ORJ_Field_GetRecordA(m_field);
00165 }
00167
00168
00169 private:
00170 ORJField const *m_field;
00171 };
00172
00173
00174
00175
00176
00178 inline bool operator ==(Field const &lhs, Field const &rhs)
00179 {
00180 return lhs.IsEqual(rhs);
00181 }
00182
00184 inline bool operator !=(Field const &lhs, Field const &rhs)
00185 {
00186 return !lhs.IsEqual(rhs);
00187 }
00188
00189
00190
00191
00192
00196 inline ::stlsoft::basic_shim_string<char, true> c_str_ptr_null(Field const &f)
00197 {
00198 ORJField const *pf = f.GetField();
00199 size_t cch = pf->name.len + 1 + pf->value.len;
00200 ::stlsoft::basic_shim_string<char, true> ss(cch);
00201
00202 if(cch < ss.size())
00203 {
00204 char *s = ss.data();
00205
00206 strncpy(s, pf->name.ptr, pf->name.len);
00207 s += pf->name.len;
00208 *s++ = '=';
00209 strncpy(s, pf->value.ptr, pf->value.len);
00210 }
00211
00212 return ss;
00213 }
00214
00218 inline ::stlsoft::basic_shim_string<char> c_str_ptr(Field const &f)
00219 {
00220 ORJField const *pf = f.GetField();
00221 size_t cch = pf->name.len + 1 + pf->value.len;
00222 ::stlsoft::basic_shim_string<char> ss(cch);
00223
00224 if(cch < ss.size())
00225 {
00226 char *s = ss.data();
00227
00228 strncpy(s, pf->name.ptr, pf->name.len);
00229 s += pf->name.len;
00230 *s++ = '=';
00231 strncpy(s, pf->value.ptr, pf->value.len);
00232 }
00233
00234 return ss;
00235 }
00236
00240 inline ::stlsoft::basic_shim_string<char> c_str_data(Field const &f)
00241 {
00242 return c_str_ptr(f);
00243 }
00244
00248 inline size_t c_str_len(Field const &f)
00249 {
00250 ORJField const *pf = f.GetField();
00251
00252 return pf->name.len + 1 + pf->value.len;
00253 }
00254
00258 template <class S>
00259 inline S &operator <<(S &s, Field const &field)
00260 {
00261 s << field.GetName() << "=" << field.GetValue();
00262
00263 return s;
00264 }
00265
00266
00267
00268
00269
00270 }
00271 }
00272
00273 namespace stlsoft
00274 {
00275 using ::openrj::cpp::c_str_ptr_null;
00276 using ::openrj::cpp::c_str_ptr;
00277 using ::openrj::cpp::c_str_data;
00278 using ::openrj::cpp::c_str_len;
00279 }
00280
00281
00282
00283 #endif
00284
00285