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
00047 #ifndef FASTFORMAT_INCL_FASTFORMAT_BUNDLES_HPP_OPENRJ_BUNDLE
00048 #define FASTFORMAT_INCL_FASTFORMAT_BUNDLES_HPP_OPENRJ_BUNDLE
00049
00050
00051
00052
00053
00054 #ifndef FASTFORMAT_DOCUMENTATION_SKIP_SECTION
00055 # define FASTFORMAT_VER_FASTFORMAT_BUNDLES_HPP_OPENRJ_BUNDLE_MAJOR 1
00056 # define FASTFORMAT_VER_FASTFORMAT_BUNDLES_HPP_OPENRJ_BUNDLE_MINOR 0
00057 # define FASTFORMAT_VER_FASTFORMAT_BUNDLES_HPP_OPENRJ_BUNDLE_REVISION 9
00058 # define FASTFORMAT_VER_FASTFORMAT_BUNDLES_HPP_OPENRJ_BUNDLE_EDIT 13
00059 #endif
00060
00061
00062
00063
00064
00065 #ifndef __cplusplus
00066 # error This file can only be included in C++ compilation units
00067 #endif
00068
00069
00070
00071
00072
00073
00074 #include <fastformat/fastformat.h>
00075
00076
00077
00078 #include <openrj/openrj.h>
00079 #include <openrj/cpp/openrj.hpp>
00080
00081
00082 #include <stlsoft/shims/access/string.hpp>
00083
00084
00085 #include <stdexcept>
00086
00087
00088
00089
00090
00091 #if !defined(FASTFORMAT_NO_NAMESPACE)
00092 namespace fastformat
00093 {
00094 #endif
00095
00096
00097
00098
00099
00102 class openrj_bundle
00103 {
00106 public:
00107 typedef ::openrj::ORJString string_type;
00108 typedef openrj_bundle class_type;
00110
00113 public:
00114 enum
00115 {
00116 ignoreCaseOnLookup = 0x01
00117 , treatSourceAsMemory = 0x02
00118 };
00120
00123 public:
00124 explicit openrj_bundle(char const *source, unsigned flags = 0);
00125
00126 template <typename S>
00127 explicit openrj_bundle(S const &source, unsigned flags = 0)
00128 : m_database(open_ns_(source, flags))
00129 {}
00130
00131 ~openrj_bundle() throw();
00133
00136 public:
00137 string_type operator [](char const *name) const throw(std::out_of_range);
00138 template <typename S>
00139 string_type operator [](S const& name) const throw(std::out_of_range)
00140 {
00141 FASTFORMAT_DECLARE_c_str_ptr_();
00142
00143 return operator [](FASTFORMAT_INVOKE_c_str_ptr_(FASTFORMAT_INVOKE_c_str_ptr_(source)));
00144 }
00146
00149 private:
00150
00151
00152 template <typename S>
00153 static ::openrj::ORJDatabase const* open_ns_(S const &source, unsigned flags)
00154 {
00155 FASTFORMAT_DECLARE_c_str_ptr_();
00156
00157 return open_(FASTFORMAT_INVOKE_c_str_ptr_(source), flags);
00158 }
00159 static ::openrj::ORJDatabase const *open_(char const *source, unsigned flags);
00161
00164 private:
00165 ::openrj::ORJDatabase const *m_database;
00167
00170 private:
00171 openrj_bundle(class_type const&);
00172 class_type& operator =(class_type const&);
00174 };
00175
00176
00177
00178
00179
00180 #ifndef FASTFORMAT_DOCUMENTATION_SKIP_SECTION
00181
00182 inline ::openrj::ORJDatabase const *openrj_bundle::open_(char const *source, unsigned flags)
00183 {
00184 #if !defined(ORJ_NO_NAMESPACE)
00185 using namespace openrj;
00186 using namespace openrj::cpp;
00187 #endif
00188
00189 unsigned orjFlags = 0
00190 | ORDER_FIELDS
00191 | ELIDE_BLANK_RECORDS
00192 | FORCE_ALL_FIELDS_INTO_1_RECORD
00193 ;
00194
00195 if(ignoreCaseOnLookup & flags)
00196 {
00197 orjFlags |= IGNORE_CASE_ON_LOOKUP;
00198 }
00199
00200 ORJError error;
00201 ORJRC rc;
00202 ORJDatabase const *database;
00203
00204 if(treatSourceAsMemory & flags)
00205 {
00206 rc = ORJ_CreateDatabaseFromMemory(source, ::strlen(source), NULL, orjFlags, &database, &error);
00207 }
00208 else
00209 {
00210 rc = ORJ_ReadDatabase(source, NULL, orjFlags, &database, &error);
00211 }
00212
00213 if(ORJ_RC_SUCCESS != rc)
00214 {
00215 throw DatabaseException(rc, error);
00216 }
00217
00218 return database;
00219 }
00220
00221 inline openrj_bundle::openrj_bundle(char const *source, unsigned flags)
00222 : m_database(open_ns_(source, flags))
00223 {}
00224
00225 inline openrj_bundle::~openrj_bundle() throw()
00226 {
00227 #if !defined(ORJ_NO_NAMESPACE)
00228 using namespace openrj;
00229 #endif
00230
00231 if(NULL != m_database)
00232 {
00233 ORJ_FreeDatabase(m_database);
00234 }
00235 }
00236
00237 inline openrj_bundle::string_type openrj_bundle::operator [](char const *name) const throw(std::out_of_range)
00238 {
00239 #if !defined(ORJ_NO_NAMESPACE)
00240 using namespace openrj;
00241 #endif
00242
00243 FASTFORMAT_CONTRACT_ENFORCE_CLASS_INVARIANT_APPL_LAYER(NULL != m_database, "underlying database cannot be null");
00244
00245 ORJField const *field = ORJ_Record_FindFieldByNameA(&m_database->records[0], name, NULL);
00246
00247 if(NULL == field)
00248 {
00249 throw std::out_of_range("format string not found");
00250 }
00251
00252 return field->value;
00253 }
00254
00255 #endif
00256
00257
00258
00259
00260
00261 #if !defined(FASTFORMAT_NO_NAMESPACE)
00262 }
00263 #endif
00264
00265
00266
00267 #endif
00268
00269