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 #ifndef _terimber_common_h_
00029 #define _terimber_common_h_
00030
00031 #include "base/string.h"
00032 #include "base/template.h"
00033 #include "base/vector.h"
00034 #include "base/date.h"
00035
00036 BEGIN_TERIMBER_NAMESPACE
00037 #pragma pack(4)
00038
00041 enum numeric_radix
00042 {
00043 RADIX2 = 2,
00044 RADIX8 = 8,
00045 RADIX10 = 10,
00046 RADIX16 = 16
00047 };
00048
00050 inline
00051 void*
00052 check_pointer( void* ptr
00053 );
00055 inline
00056 size_t
00057 get8bits( unsigned char x
00058 );
00060 inline
00061 size_t
00062 get16bits( const unsigned char* x
00063 );
00065 template < class T >
00066 inline
00067 size_t
00068 do_hash( const T* x,
00069 size_t len = os_minus_one
00070 );
00072 template < class T >
00073 inline
00074 T*
00075 copy_string( const T* x,
00076 byte_allocator& _allocator,
00077 size_t length = os_minus_one
00078 );
00080 template < class T >
00081 inline
00082 bool
00083 hex_to_binary( ub1_t* dest,
00084 const T* x,
00085 size_t len = os_minus_one
00086 );
00088 template < class T >
00089 inline
00090 bool
00091 symbol_to_byte( ub1_t &dest,
00092 T x,
00093 numeric_radix radix_ = RADIX16
00094 );
00096 template < class T >
00097 inline
00098 bool
00099 hex_to_byte( ub1_t &dest,
00100 const T* x,
00101 numeric_radix radix_ = RADIX16
00102 );
00104 template < class T >
00105 inline
00106 void
00107 binary_to_hex( T* dest,
00108 const ub1_t* x
00109 );
00111 template < class T >
00112 inline
00113 void
00114 byte_to_hex( T* dest,
00115 ub1_t x
00116 );
00118 template < class T >
00119 inline
00120 void
00121 byte_to_symbol( T& dest,
00122 ub1_t x
00123 );
00125 template < class T >
00126 inline
00127 T*
00128 guid_to_string( T* dest,
00129 const guid_t& x
00130 );
00132 template < class T >
00133 inline
00134 bool
00135 string_to_guid( guid_t& dest,
00136 const T* x
00137 );
00139 template < class T >
00140 inline
00141 int
00142 simple_compare( const T& v1,
00143 const T& v2
00144 );
00146 template < class T >
00147 inline
00148 int
00149 memory_compare( const T& v1,
00150 const T& v2
00151 );
00153 inline
00154 int
00155 memory_compare_binary(const ub1_t* v1,
00156 const ub1_t* v2
00157 );
00159 template < class T >
00160 inline
00161 int
00162 simple_compare_ptr( const T* v1,
00163 const T* v2
00164 );
00166 template < class T, class F >
00167 inline
00168 int
00169 string_compare( const T& v1,
00170 const T& v2,
00171 F fn
00172 );
00174 inline
00175 size_t
00176 do_hash( vt_types type,
00177 const terimber_xml_value& x
00178 );
00180 inline
00181 int
00182 compare_value( vt_types type,
00183 const terimber_xml_value& first,
00184 const terimber_xml_value& second,
00185 bool use_hash,
00186 bool case_insensitive
00187 );
00189 inline
00190 terimber_xml_value
00191 copy_value( vt_types type,
00192 const terimber_xml_value& x,
00193 byte_allocator& allocator_
00194 );
00196 terimber_xml_value
00197 parse_value( vt_types type,
00198 const char* x,
00199 size_t len_ = os_minus_one,
00200 byte_allocator* allocator_ = 0
00201 );
00203 const char*
00204 persist_value( vt_types type,
00205 const terimber_xml_value& x,
00206 byte_allocator* allocator_
00207 );
00208
00211 typedef pool< byte_allocator_creator > mem_pool_t;
00213 inline
00214 bool
00215 operator==( const guid_t& first,
00216 const guid_t& second
00217 );
00219 inline
00220 bool
00221 operator!=( const guid_t& first,
00222 const guid_t& second
00223 );
00225 inline
00226 bool
00227 operator<( const guid_t& first,
00228 const guid_t& second
00229 );
00231 inline
00232 bool
00233 operator>( const guid_t& first,
00234 const guid_t& second
00235 );
00236
00237
00238
00239
00240
00243 typedef _vector< ub1_t > paged_vector_t;
00246 typedef _list< paged_vector_t > paged_store_t;
00247
00250 class paged_buffer
00251 {
00252 public:
00254 paged_buffer( byte_allocator& data_allocator,
00255 byte_allocator& tmp_allocator,
00256 size_t page_size
00257 );
00258 ~paged_buffer();
00259
00261 inline
00262 paged_buffer&
00263 operator<<( ub1_t symbol
00264 );
00266 inline
00267 paged_buffer&
00268 operator<<( const char* x
00269 );
00271 inline
00272 paged_buffer&
00273 append( const ub1_t* x,
00274 size_t size
00275 );
00276
00278 inline
00279 const char*
00280 persist();
00281
00283 inline
00284 const ub1_t*
00285 persist( size_t& size_
00286 );
00287
00291 inline
00292 void
00293 reset();
00294
00296 inline
00297 size_t
00298 size() const;
00299
00301 inline
00302 byte_allocator&
00303 get_tmp_allocator();
00304
00306 inline
00307 size_t
00308 get_page_size() const;
00309
00310 private:
00312 void
00313 add_page();
00315 const ub1_t*
00316 _persist( size_t& size_
00317 );
00319 const char*
00320 _persist();
00321
00322 private:
00323 byte_allocator& _data_allocator;
00324 byte_allocator& _tmp_allocator;
00325 paged_store_t _buffer;
00326 size_t _size;
00327 size_t _pos;
00328 ub1_t* _ptr;
00329 ub1_t* _primary;
00330 };
00331
00332
00333 #pragma pack()
00334 END_TERIMBER_NAMESPACE
00335
00336 #endif // _terimber_common_h_
00337