BLPAPI C++  3.24.6
blpapi_name.h
Go to the documentation of this file.
1 /* Copyright 2012. Bloomberg Finance L.P.
2  *
3  * Permission is hereby granted, free of charge, to any person obtaining a copy
4  * of this software and associated documentation files (the "Software"), to
5  * deal in the Software without restriction, including without limitation the
6  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7  * sell copies of the Software, and to permit persons to whom the Software is
8  * furnished to do so, subject to the following conditions: The above
9  * copyright notice and this permission notice shall be included in all copies
10  * or substantial portions of the Software.
11  *
12  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
17  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
18  * IN THE SOFTWARE.
19  */
20 
28 #ifndef INCLUDED_BLPAPI_NAME
29 #define INCLUDED_BLPAPI_NAME
30 
60 #include <blpapi_defs.h>
61 #include <blpapi_types.h>
62 
63 #include <stddef.h>
64 
65 #ifdef __cplusplus
66 extern "C" {
67 #endif
68 
70 blpapi_Name_t *blpapi_Name_create(const char *nameString);
71 
74 
77 
79 int blpapi_Name_equalsStr(const blpapi_Name_t *name, const char *string);
80 
82 const char *blpapi_Name_string(const blpapi_Name_t *name);
83 
85 size_t blpapi_Name_length(const blpapi_Name_t *name);
86 
88 blpapi_Name_t *blpapi_Name_findName(const char *nameString);
89 
90 #ifdef __cplusplus
91 }
92 
93 #include <cstring> // for strcmp
94 #include <iostream>
95 #include <utility> // for swap
96 
104 namespace BloombergLP {
105 namespace blpapi {
106 
150 class Name {
151 
152  blpapi_Name_t *d_impl_p;
153 
154  public:
155  // CLASS METHODS
156 
157  static Name findName(const char *nameString);
167  static bool hasName(const char *nameString);
175  Name();
182  explicit Name(blpapi_Name_t *handle);
183 
184  Name(const Name& original);
190  explicit Name(const char *nameString);
202  ~Name();
207  // MANIPULATORS
208 
209  Name& operator=(const Name& rhs);
215  // ACCESSORS
216 
217  const char *string() const;
224  size_t length() const;
232  size_t hash() const;
240  blpapi_Name_t *impl() const;
241 };
242 
246 // FREE OPERATORS
247 bool operator==(const Name& lhs, const Name& rhs);
255 bool operator!=(const Name& lhs, const Name& rhs);
264 bool operator==(const Name& lhs, const char *rhs);
273 bool operator!=(const Name& lhs, const char *rhs);
282 bool operator==(const char *lhs, const Name& rhs);
291 bool operator!=(const char *lhs, const Name& rhs);
300 bool operator<(const Name& lhs, const Name& rhs);
311 bool operator<=(const Name& lhs, const Name& rhs);
322 bool operator>(const Name& lhs, const Name& rhs);
333 bool operator>=(const Name& lhs, const Name& rhs);
344 std::ostream& operator<<(std::ostream& stream, const Name& name);
352 //=============================================================================
353 // INLINE FUNCTION DEFINITIONS
354 //=============================================================================
355 
356 // ----------
357 // class Name
358 // ----------
359 
360 inline Name::Name(blpapi_Name_t *handle)
361  : d_impl_p(handle)
362 {
363 }
364 
365 inline Name::Name()
366  : d_impl_p(0)
367 {
368 }
369 
370 inline Name::Name(const Name& original)
371  : d_impl_p(blpapi_Name_duplicate(original.d_impl_p))
372 {
373 }
374 
375 inline Name::Name(const char *nameString)
376 {
377  d_impl_p = blpapi_Name_create(nameString);
378 }
379 
380 inline Name::~Name()
381 {
382  if (d_impl_p) {
383  blpapi_Name_destroy(d_impl_p);
384  }
385 }
386 
387 inline Name& Name::operator=(const Name& rhs)
388 {
389  using std::swap;
390 
391  Name tmp(rhs);
392  swap(tmp.d_impl_p, d_impl_p);
393  return *this;
394 }
395 
396 inline const char *Name::string() const
397 {
398  return blpapi_Name_string(d_impl_p);
399 }
400 
401 inline size_t Name::length() const { return blpapi_Name_length(d_impl_p); }
402 
403 inline blpapi_Name_t *Name::impl() const { return d_impl_p; }
404 
405 inline Name Name::findName(const char *nameString)
406 {
407  return Name(blpapi_Name_findName(nameString));
408 }
409 
410 inline bool Name::hasName(const char *nameString)
411 {
412  return blpapi_Name_findName(nameString) ? true : false;
413 }
414 
415 inline size_t Name::hash() const { return reinterpret_cast<size_t>(impl()); }
416 
417 } // close namespace blpapi
418 
419 inline bool blpapi::operator==(const Name& lhs, const Name& rhs)
420 {
421  return (lhs.impl() == rhs.impl());
422 }
423 
424 inline bool blpapi::operator!=(const Name& lhs, const Name& rhs)
425 {
426  return !(lhs == rhs);
427 }
428 
429 inline bool blpapi::operator==(const Name& lhs, const char *rhs)
430 {
431  return blpapi_Name_equalsStr(lhs.impl(), rhs) != 0;
432 }
433 
434 inline bool blpapi::operator!=(const Name& lhs, const char *rhs)
435 {
436  return !(lhs == rhs);
437 }
438 
439 inline bool blpapi::operator==(const char *lhs, const Name& rhs)
440 {
441  return rhs == lhs;
442 }
443 
444 inline bool blpapi::operator!=(const char *lhs, const Name& rhs)
445 {
446  return !(rhs == lhs);
447 }
448 
449 inline bool blpapi::operator<(const Name& lhs, const Name& rhs)
450 {
451  return lhs.impl() < rhs.impl();
452 }
453 
454 inline bool blpapi::operator<=(const Name& lhs, const Name& rhs)
455 {
456  return !(rhs < lhs);
457 }
458 
459 inline bool blpapi::operator>(const Name& lhs, const Name& rhs)
460 {
461  return rhs < lhs;
462 }
463 
464 inline bool blpapi::operator>=(const Name& lhs, const Name& rhs)
465 {
466  return !(lhs < rhs);
467 }
468 
469 inline std::ostream& blpapi::operator<<(std::ostream& stream, const Name& name)
470 {
471  return stream << name.string();
472 }
473 
474 } // close namespace BloombergLP
475 
476 #endif // __cplusplus
477 
478 #endif // #ifndef INCLUDED_BLPAPI_NAME
static Name findName(const char *nameString)
Definition: blpapi_name.h:405
bool operator!=(const CorrelationId &lhs, const CorrelationId &rhs)
Definition: blpapi_correlationid.h:582
blpapi_Name_t * blpapi_Name_duplicate(const blpapi_Name_t *src)
void blpapi_Name_destroy(blpapi_Name_t *name)
const char * string() const
Definition: blpapi_name.h:396
Common definitions used by the library.
bool operator==(const CorrelationId &lhs, const CorrelationId &rhs)
Definition: blpapi_correlationid.h:562
bool operator<=(const Datetime &lhs, const Datetime &rhs)
Definition: blpapi_datetime.h:2083
void swap(Event::iterator &lhs, Event::iterator &rhs)
Swap the contents of the lhs and rhs iterators.
Definition: blpapi_event.h:723
size_t hash() const
Definition: blpapi_name.h:415
bool operator<(const CorrelationId &lhs, const CorrelationId &rhs)
Definition: blpapi_correlationid.h:587
Definition: blpapi_abstractsession.h:220
Definition: blpapi_name.h:150
blpapi_Name_t * impl() const
Definition: blpapi_name.h:403
struct blpapi_Name blpapi_Name_t
Definition: blpapi_types.h:154
bool operator>=(const Datetime &lhs, const Datetime &rhs)
Definition: blpapi_datetime.h:2093
blpapi_Name_t * blpapi_Name_findName(const char *nameString)
const char * blpapi_Name_string(const blpapi_Name_t *name)
blpapi_Name_t * blpapi_Name_create(const char *nameString)
size_t blpapi_Name_length(const blpapi_Name_t *name)
Name()
Definition: blpapi_name.h:365
std::ostream & operator<<(std::ostream &os, const CorrelationId &correlator)
Definition: blpapi_correlationid.h:592
static bool hasName(const char *nameString)
Definition: blpapi_name.h:410
bool operator>(const Datetime &lhs, const Datetime &rhs)
Definition: blpapi_datetime.h:2088
int blpapi_Name_equalsStr(const blpapi_Name_t *name, const char *string)
~Name()
Definition: blpapi_name.h:380
size_t length() const
Definition: blpapi_name.h:401
#define BLPAPI_EXPORT
Definition: blpapi_defs.h:171
Provide BLPAPI types.
Name & operator=(const Name &rhs)
Definition: blpapi_name.h:387