OnixS C++ Eurex T7 Market and Reference Data (EMDI, MDI, RDI, EOBI) Handlers 18.2.0
API documentation
Loading...
Searching...
No Matches
StringRef.h
Go to the documentation of this file.
1/*
2* Copyright Onix Solutions Limited [OnixS]. All rights reserved.
3*
4* This software owned by Onix Solutions Limited [OnixS] and is protected by copyright law
5* and international copyright treaties.
6*
7* Access to and use of the software is governed by the terms of the applicable OnixS Software
8* Services Agreement (the Agreement) and Customer end user license agreements granting
9* a non-assignable, non-transferable and non-exclusive license to use the software
10* for it's own data processing purposes under the terms defined in the Agreement.
11*
12* Except as otherwise granted within the terms of the Agreement, copying or reproduction of any part
13* of this source code or associated reference material to any other location for further reproduction
14* or redistribution, and any amendments to this copyright notice, are expressly prohibited.
15*
16* Any reproduction or redistribution for sale or hiring of the Software not in accordance with
17* the terms of the Agreement is a violation of copyright law.
18*/
19
20#pragma once
21
22#include <string>
23#include <cstring>
24#include <functional>
25#include <stdexcept>
26
30
31namespace OnixS
32{
33 namespace Eurex
34 {
35 namespace MarketData
36 {
51 class
52 ONIXS_EUREX_EMDI_API
54 {
55 public:
57 typedef const char* ConstIterator;
58
62 size_ (0)
63 {
64 }
65
67 StringRef (const char* chars, size_t size) :
68 chars_ (chars),
69 size_ (size)
70
71 {
72 }
73
78 StringRef (const StringRef& other) :
79 chars_ (other.chars_),
80 size_ (other.size_)
81
82 {
83 }
84
86 explicit StringRef (const std::string& stdStr) :
87 chars_ (stdStr.c_str() ),
88 size_ (stdStr.size() )
89 {
90 }
91
93 StringRef (const char* cStr) :
94 chars_ (cStr),
95 size_ (cStr ? strlen (cStr) : 0)
96 {
97 }
98
100 bool empty() const
101 {
102 return (0 == size_);
103 }
104
106 const char* data() const
107 {
108 return chars_;
109 }
110
113 {
114 return chars_;
115 }
116
119 {
120 return chars_ + size_;
121 }
122
124 size_t size() const
125 {
126 return size_;
127 }
128
130 void reset()
131 {
133 }
134
136 void
138 const char* chars,
139 size_t size)
140 {
141 chars_ = chars;
142 size_ = size;
143 }
144
145 const char&
146 operator [] (size_t index) const
147 {
148 return chars_[index];
149 }
150
151 const char&
152 at (size_t index) const
153 {
154 if (index < size_)
155 return chars_[index];
156
157 throw std::invalid_argument ("index");
158 }
159
162 template
163 <
164 typename NumericType
165 >
166 bool
167 toNumber (NumericType& number) const
168 {
170 tryParse (chars_, size_, number);
171 }
172
173 // Appends copy of text to the std::string.
174 void
175 toString (std::string& str) const
176 {
177 str.append (chars_, size_);
178 }
179
180 // Return copy of text as std::string.
181 std::string
182 toString() const
183 {
184 return std::string (chars_, size_);
185 }
186
188 bool
190 const StringRef& other) const
191 {
192 return (
193 size_ == other.size_
194 &&
195 0 == memcmp (
196 chars_, other.chars_, size_) );
197 }
198
200 bool
202 const StringRef& other) const
203 {
204 return (
205 size_ != other.size_
206 ||
207 0 != memcmp (
208 chars_, other.chars_, size_) );
209 }
210
212 StringRef&
213 operator = (
214 const StringRef& other)
215 {
216 chars_ = other.chars_;
217 size_ = other.size_;
218
219 return *this;
220 }
221
223 void
225 {
226 std::swap (chars_, other.chars_);
227 std::swap (size_, other.size_);
228 }
229
230 private:
232 const char* chars_;
233
235 size_t size_;
236 };
237
238 inline
239 bool
241 const StringRef& ref,
242 const std::string& str)
243 {
244 return ref == StringRef (str);
245 }
246
247 inline
248 bool
250 const StringRef& ref,
251 const std::string& str)
252 {
253 return ref != StringRef (str);
254 }
255
256 inline
257 bool
259 const std::string& str,
260 const StringRef& ref)
261 {
262 return ref == StringRef (str);
263 }
264
265 inline
266 bool
268 const std::string& str,
269 const StringRef& ref)
270 {
271 return ref != StringRef (str);
272 }
273
274 //
275
276 inline
277 bool
279 const StringRef& ref,
280 const char* str)
281 {
282 return ref == StringRef (str);
283 }
284
285 inline
286 bool
288 const StringRef& ref,
289 const char* str)
290 {
291 return ref != StringRef (str);
292 }
293
294 inline
295 bool
297 const char* str,
298 const StringRef& ref)
299 {
300 return ref == StringRef (str);
301 }
302
303 inline
304 bool
306 const char* str,
307 const StringRef& ref)
308 {
309 return ref != StringRef (str);
310 }
311 }
312 }
313}
314
315namespace std
316{
318 template<>
319 struct
320 ONIXS_EUREX_EMDI_API
321 less<OnixS::Eurex::MarketData::StringRef>
322 {
323 bool
324 operator () (
326 const OnixS::Eurex::MarketData::StringRef& right) const
327 {
328 ptrdiff_t
329 compareResult = memcmp (
330 left.data(), right.data(),
331 left.size() < right.size()
332 ? left.size() : right.size() );
333
334 if (0 == compareResult)
335 {
336 compareResult =
337 static_cast<ptrdiff_t> (
338 left.size() - right.size() );
339 }
340
341 return (0 > compareResult);
342 }
343 };
344}
#define ONIXS_EUREX_EMDI_NULLPTR
Definition Compiler.h:143
bool toNumber(NumericType &number) const
Definition StringRef.h:167
size_t size() const
Number of chars.
Definition StringRef.h:124
StringRef()
Initializes blank instance.
Definition StringRef.h:60
void toString(std::string &str) const
Definition StringRef.h:175
bool empty() const
Indicates whether array of zero length.
Definition StringRef.h:100
ConstIterator end() const
STL-like end().
Definition StringRef.h:118
const char * ConstIterator
Immutable iterator over chars.
Definition StringRef.h:57
StringRef(const char *cStr)
Initializes instance from zero-terminated string.
Definition StringRef.h:93
void swap(StringRef &other)
Swaps content with other instance.
Definition StringRef.h:224
StringRef(const StringRef &other)
Definition StringRef.h:78
const char * data() const
Read-only content.
Definition StringRef.h:106
const char & at(size_t index) const
Definition StringRef.h:152
StringRef(const char *chars, size_t size)
Full initialization.
Definition StringRef.h:67
void reset()
Resets reference to nothing.
Definition StringRef.h:130
ConstIterator begin() const
STL-like begin().
Definition StringRef.h:112
void reset(const char *chars, size_t size)
Updates data being referenced.
Definition StringRef.h:137
StringRef(const std::string &stdStr)
Initializes instance from string content.
Definition StringRef.h:86
bool operator==(const FieldValueRef &ref, const std::string &str)
bool operator!=(const FieldValueRef &ref, const std::string &str)
STL namespace.
static bool tryParse(const char *buffer, size_t bufferSize, Int32 &number)