25 #ifndef __AMPS_FIELD_HPP__ 26 #define __AMPS_FIELD_HPP__ 32 #define AMPS_TIMESTAMP_LEN 16 33 #define AMPS_MAX_BOOKMARK_LEN 42 35 #define AMPS_MAX_SUBID_LEN 1048576 // 1MB, NOT FIXED IN AMPS 57 Field() : _data(NULL), _len(0) {;}
58 Field(
const char *data_)
61 _len = ::strlen(data_);
63 Field(
const char *data_,
size_t len_)
79 Field(
const std::string& string_)
81 _data = string_.c_str();
82 _len = string_.length();
85 bool contains(
const char* searchString,
size_t len)
const 87 const char *dataEnd = _data+_len;
88 return std::search(_data,dataEnd,searchString,searchString+len) != dataEnd;
101 operator std::string ()
const 103 return _len?std::string(_data, _len):std::string();
113 if ( _len == rhs_._len )
114 return ::memcmp(_data, rhs_._data, _len) == 0;
127 return (!_data && !rhs_);
129 return ::strncmp(_data, rhs_, _len) == 0 && rhs_[_len] ==
'\0';
132 bool operator<(
const Field& rhs)
const;
140 return strncmp(_data, rhs_, _len) != 0 || rhs_[_len] !=
'\0';
151 return rhs_.compare(0, rhs_.length(), _data, _len) != 0;
161 return rhs_.compare(0, rhs_.length(), _data, _len) == 0;
172 _data =
new char[orig_._len];
173 ::memcpy(static_cast<void*>(const_cast<char*>(_data)),
174 orig_._data, orig_._len);
198 if (!_data || !_len)
return;
219 void assign(
const char*ptr,
size_t len)
226 inline size_t hash_function()
const 229 const char* p_ = _data;
233 c = (
unsigned long)*p_;
242 size_t operator()(
const Field& f)
const 244 return f.hash_function();
247 bool operator()(
const Field& f1,
const Field& f2)
const 249 if (f1.
len() < f2.
len())
return true;
250 if (f1.
len() > f2.
len())
return false;
252 if (f1.
len() == 0)
return true;
258 static void parseBookmark(
const Field& field_,
259 amps_uint64_t& publisherId_,
260 amps_uint64_t& sequenceNumber_)
262 publisherId_ = sequenceNumber_ = (amps_uint64_t)0;
264 size_t len = field_.
len();
266 if (len == AMPS_TIMESTAMP_LEN &&
267 data[AMPS_TIMESTAMP_LEN-1] ==
'Z' &&
268 data[8] ==
'T')
return;
277 publisherId_ += (amps_uint64_t)(data[i] -
'0');
279 for(i=i+1; i<
len; ++i)
285 sequenceNumber_ *= 10;
286 sequenceNumber_ += (amps_uint64_t)(data[i] -
'0');
bool operator==(const char *rhs_) const
String comparison operator Returns `true' if self and rhs are equivalent, `false' otherwise...
Definition: Field.hpp:123
bool operator!=(const std::string &rhs_) const
String comparison operator Returns `true' if self and rhs are not equivalent.
Definition: Field.hpp:149
bool operator==(const Field &rhs_) const
Comparison operator Returns `true' if self and rhs are equivalent, `false' otherwise.
Definition: Field.hpp:111
void clear()
Deletes the data associated with this Field, should only be used on Fields that were created as deepC...
Definition: Field.hpp:196
const char * data() const
Returns the (non-null-terminated) data underlying this field.
Definition: Field.hpp:206
bool empty() const
Returns 'true' if empty, 'false' otherwise.
Definition: Field.hpp:93
size_t len() const
Returns the length of the data underlying this field.
Definition: Field.hpp:213
bool operator!=(const char *rhs_) const
String comparison operator Returns true if self and rhs are not equivalent.
Definition: Field.hpp:138
Field represents the value of a single field in a Message.
Definition: Field.hpp:52
void deepCopy(const Field &orig_)
Makes self a deep copy of the original field.
Definition: Field.hpp:167
Definition: ampsplusplus.hpp:136
bool operator==(const std::string &rhs_) const
String comparison operator Returns `true' if self and rhs are equivalent.
Definition: Field.hpp:159
Field deepCopy() const
Makes a deep copy of self, returns it.
Definition: Field.hpp:186