OnixS C++ FMX UST BIMP Market Data Handler 1.2.0
API documentation
Loading...
Searching...
No Matches
String.h
Go to the documentation of this file.
1// Copyright Onix Solutions Limited [OnixS]. All rights reserved.
2//
3// This software owned by Onix Solutions Limited [OnixS] and is
4// protected by copyright law and international copyright treaties.
5//
6// Access to and use of the software is governed by the terms of the applicable
7// OnixS Software Services Agreement (the Agreement) and Customer end user license
8// agreements granting a non-assignable, non-transferable and non-exclusive license
9// to use the software for it's own data processing purposes under the terms defined
10// in the Agreement.
11//
12// Except as otherwise granted within the terms of the Agreement, copying or
13// reproduction of any part of this source code or associated reference material
14// to any other location for further reproduction or redistribution, and any
15// amendments to this copyright notice, are expressly prohibited.
16//
17// Any reproduction or redistribution for sale or hiring of the Software not in
18// accordance with the terms of the Agreement is a violation of copyright law.
19//
20
21#pragma once
22
24
25#include <cstddef>
26#include <cstring>
27#include <string>
28#include <stdexcept>
29
30#include <algorithm>
31#include <ostream>
32
33namespace OnixS
34{
35 namespace FmxUST
36 {
37 namespace MarketData
38 {
39 namespace Bimp
40 {
42 typedef char Char;
43
45 class StrRef
46 {
47 public:
49 typedef const Char* Iterator;
50
55 , size_(0)
56 {
57 }
58
61 const Char* chars,
62 size_t size)
64 : items_(chars)
65 , size_(size)
66 {
67 }
68
69 template <size_t Size>
70 explicit
72 StrRef(const char (&value)[Size])
74 : items_(value)
75 , size_(Size - 1)
76 {
77 }
78
84 const StrRef& other)
86 : items_(other.items_)
87 , size_(other.size_)
88 {
89 }
90
92 bool empty() const
94 {
95 return (0 == size_);
96 }
97
99 const Char* items() const
101 {
102 return items_;
103 }
104
106 size_t size() const
108 {
109 return size_;
110 }
111
115 {
116 return items_;
117 }
118
120 Iterator end() const
122 {
123 return (items_ + size_);
124 }
125
132
134 void
136 const Char* chars,
137 size_t size)
139 {
140 items_ = chars;
141 size_ = size;
142 }
143
144 const Char&
146 size_t index) const
147 {
148 return items_[index];
149 }
150
151 const Char&
153 size_t index) const
154 {
155 if (index < size_)
156 return items_[index];
157
158 throw std::invalid_argument("index");
159 }
160
162 StrRef&
164 const StrRef& other)
166 {
167 items_ = other.items_;
168 size_ = other.size_;
169
170 return *this;
171 }
172
174 void
176 StrRef& other)
178 {
179 std::swap(items_, other.items_);
180 std::swap(size_, other.size_);
181 }
182
183
184 // Get trimmed presentation of the current string
185 StrRef trim() const
187 {
188 size_t length = size();
189
190 while(length > 0 && isspace(operator[](length - 1)))
191 --length;
192
193 return StrRef(items(), length);
194 }
195
196 private:
198 const Char* items_;
199
201 size_t size_;
202 };
203
205 inline
206 StrRef
208 const std::string& str)
209 {
210 return StrRef(str.data(), str.size());
211 }
212
214 inline
215 StrRef
217 const Char* cStr)
218 {
219 return
220 StrRef(
221 cStr,
222 cStr
223 ? strlen(cStr)
224 : 0
225 );
226 }
227
229 inline
230 std::string
232 const StrRef& ref)
233 {
234 return std::string(ref.items(), ref.size());
235 }
236
238 inline
239 void
241 std::string& str,
242 const StrRef& ref)
243 {
244 str.append(ref.items(), ref.size());
245 }
246
248 inline
249 std::string
251 Char character)
252 {
253 return std::string(1, character);
254 }
255
257 inline
258 void
260 std::string& str,
261 Char character)
262 {
263 str.append(1, character);
264 }
265
267 inline
268 void
270 std::string& str,
271 const std::string& value)
272 {
273 str.append(value);
274 }
275
277 inline
278 bool
280 const StrRef& left,
281 const StrRef& right)
282 {
283 return (
284 left.size() == right.size()
285 &&
286 0 == memcmp(
287 left.items(), right.items(), left.size()));
288 }
289
291 inline
292 bool
294 const StrRef& left,
295 const StrRef& right)
296 {
297 return !(left == right);
298 }
299
301 inline
302 bool
304 const StrRef& ref,
305 const std::string& str)
306 {
307 return ref == toStrRef(str);
308 }
309
311 inline
312 bool
314 const StrRef& ref,
315 const std::string& str)
316 {
317 return ref != toStrRef(str);
318 }
319
321 inline
322 bool
324 const std::string& str,
325 const StrRef& ref)
326 {
327 return ref == toStrRef(str);
328 }
329
331 inline
332 bool
334 const std::string& str,
335 const StrRef& ref)
336 {
337 return ref != toStrRef(str);
338 }
339
341 inline
342 bool
344 const StrRef& ref,
345 const Char* str)
346 {
347 return ref == toStrRef(str);
348 }
349
351 inline
352 bool
354 const StrRef& ref,
355 const Char* str)
356 {
357 return ref != toStrRef(str);
358 }
359
361 inline
362 bool
364 const Char* str,
365 const StrRef& ref)
366 {
367 return ref == toStrRef(str);
368 }
369
371 inline
372 bool
374 const Char* str,
375 const StrRef& ref)
376 {
377 return ref != toStrRef(str);
378 }
379
381 inline
382 bool
384 const StrRef& left,
385 const StrRef& right)
386 {
387 ptrdiff_t
388 compareResult =
389 memcmp(
390 left.items(),
391 right.items(),
392 left.size() < right.size()
393 ? left.size()
394 : right.size());
395
396 if (0 == compareResult)
397 {
398 compareResult =
399 static_cast<ptrdiff_t>(
400 left.size() - right.size());
401 }
402
403 return (0 > compareResult);
404 }
405
407 inline
408 bool
410 const StrRef& left,
411 const StrRef& right)
412 {
413 return (right < left);
414 }
415
417 inline
418 std::ostream&
420 std::ostream& stream,
421 const StrRef& text)
422 {
423 stream.write(text.items(), text.size());
424
425 return stream;
426 }
427
428 }
429 }
430 }
431}
#define ONIXS_FMXUST_BIMP_NOTHROW
Definition Compiler.h:108
#define ONIXS_FMXUST_BIMP_CONSTEXPR
Definition Compiler.h:114
#define ONIXS_FMXUST_BIMP_NULLPTR
Definition Compiler.h:122
Provides efficient way of accessing text-based FIX field values.
Definition String.h:46
StrRef(const Char *chars, size_t size) ONIXS_FMXUST_BIMP_NOTHROW
Full initialization.
Definition String.h:60
bool empty() const ONIXS_FMXUST_BIMP_NOTHROW
Indicates whether array of zero length.
Definition String.h:92
const Char * items() const ONIXS_FMXUST_BIMP_NOTHROW
Read-only content.
Definition String.h:99
Iterator begin() const ONIXS_FMXUST_BIMP_NOTHROW
STL-like begin().
Definition String.h:113
StrRef() ONIXS_FMXUST_BIMP_NOTHROW
Initializes blank instance.
Definition String.h:52
void reset(const Char *chars, size_t size) ONIXS_FMXUST_BIMP_NOTHROW
Updates data being referenced.
Definition String.h:135
StrRef & operator=(const StrRef &other) ONIXS_FMXUST_BIMP_NOTHROW
Reinitializes from another instance.
Definition String.h:163
ONIXS_FMXUST_BIMP_CONSTEXPR StrRef(const char(&value)[Size]) ONIXS_FMXUST_BIMP_NOTHROW
Definition String.h:72
size_t size() const ONIXS_FMXUST_BIMP_NOTHROW
Number of chars.
Definition String.h:106
const Char * Iterator
STL-like iterator.
Definition String.h:49
void swap(StrRef &other) ONIXS_FMXUST_BIMP_NOTHROW
Swaps content with other instance.
Definition String.h:175
void reset() ONIXS_FMXUST_BIMP_NOTHROW
Resets reference to nothing.
Definition String.h:127
Iterator end() const ONIXS_FMXUST_BIMP_NOTHROW
STL-like end().
Definition String.h:120
StrRef trim() const ONIXS_FMXUST_BIMP_NOTHROW
Definition String.h:185
StrRef(const StrRef &other) ONIXS_FMXUST_BIMP_NOTHROW
Definition String.h:83
const Char & operator[](size_t index) const
Definition String.h:145
const Char & at(size_t index) const
Definition String.h:152
bool operator>(const FixedPointDecimal< Mantissa, Exponent > &left, const FixedPointDecimal< Mantissa, Exponent > &right)
Compares two fixed-point decimals.
Definition Decimal.h:144
bool operator!=(const FixedPointDecimal< Mantissa, Exponent > &left, const FixedPointDecimal< Mantissa, Exponent > &right)
Compares two fixed-point decimals.
Definition Decimal.h:126
ONIXS_FMXUST_BIMP_API void toStr(std::string &, EventCode::Enum)
Appends string presentation of object.
char Char
Character type alias.
Definition String.h:42
StrRef toStrRef(const std::string &str)
Constructs StrRef instance over std::string content.
Definition String.h:207
bool operator<(const FixedPointDecimal< Mantissa, Exponent > &left, const FixedPointDecimal< Mantissa, Exponent > &right)
Compares two fixed-point decimals.
Definition Decimal.h:135
bool operator==(const PriceLevel &l, const PriceLevel &r) ONIXS_FMXUST_BIMP_NOTHROW
compare
Definition OrderBook.h:302
ONIXS_FMXUST_BIMP_API std::ostream & operator<<(std::ostream &stream, const ServiceDescriptor &descriptor)