BLPAPI C++  3.24.6
blpapi_constant.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_CONSTANT
29 #define INCLUDED_BLPAPI_CONSTANT
30 
65 #ifndef INCLUDED_BLPAPI_TYPES
66 #include <blpapi_types.h>
67 #endif
68 
69 #ifndef INCLUDED_BLPAPI_NAME
70 #include <blpapi_name.h>
71 #endif
72 
73 #ifndef INCLUDED_BLPAPI_DEFS
74 #include <blpapi_defs.h>
75 #endif
76 
77 #ifndef INCLUDED_BLPAPI_DATETIME
78 #include <blpapi_datetime.h>
79 #endif
80 
81 #ifndef INCLUDED_BLPAPI_EXCEPTION
82 #include <blpapi_exception.h>
83 #endif
84 
85 #include <stddef.h>
86 
87 #ifdef __cplusplus
88 extern "C" {
89 #endif
90 
92 void blpapi_Constant_setUserData(blpapi_Constant_t *constant, void *userdata);
93 
96 
98 const char *blpapi_Constant_description(const blpapi_Constant_t *constant);
99 
101 int blpapi_Constant_status(const blpapi_Constant_t *constant);
102 
104 int blpapi_Constant_datatype(const blpapi_Constant_t *constant);
105 
108  const blpapi_Constant_t *constant, blpapi_Char_t *buffer);
109 
112  const blpapi_Constant_t *constant, blpapi_Int32_t *buffer);
113 
116  const blpapi_Constant_t *constant, blpapi_Int64_t *buffer);
117 
120  const blpapi_Constant_t *constant, blpapi_Float32_t *buffer);
121 
124  const blpapi_Constant_t *constant, blpapi_Float64_t *buffer);
125 
128  const blpapi_Constant_t *constant, blpapi_Datetime_t *buffer);
129 
132  const blpapi_Constant_t *constant, const char **buffer);
133 
135 void *blpapi_Constant_userData(const blpapi_Constant_t *constant);
136 
139  blpapi_ConstantList_t *constant, void *userdata);
140 
143 
146 
149 
152 
155 
158  const blpapi_ConstantList_t *constant,
159  const char *nameString,
160  const blpapi_Name_t *name);
161 
164  const blpapi_ConstantList_t *constant, size_t index);
165 
168 
169 #ifdef __cplusplus
170 }
171 
172 #include <cassert>
173 
181 namespace BloombergLP {
182 namespace blpapi {
183 
210 class Constant {
211 
212  blpapi_Constant_t *d_impl_p;
213 
214  public:
215  explicit Constant(blpapi_Constant_t *handle);
216  /*
217  * Create a <code>Constant</code> object having the same value as the
218  * specified <code>original</code>. Note that this function does
219  * <em>not</em> require cross-object thread synchronization, as it does not
220  * directly read or modify the <code>userData</code> field.
221  */
222 
223  void setUserData(void *userData);
232  Name name() const;
237  const char *description() const;
244  int status() const;
250  int datatype() const;
257  int getValueAs(char *buffer) const;
265  int getValueAs(Int32 *buffer) const;
273  int getValueAs(Int64 *buffer) const;
281  int getValueAs(Float32 *buffer) const;
289  int getValueAs(Float64 *buffer) const;
297  int getValueAs(Datetime *buffer) const;
305  int getValueAs(std::string *buffer) const;
313  char getValueAsChar() const;
319  Int32 getValueAsInt32() const;
325  Int64 getValueAsInt64() const;
331  Float32 getValueAsFloat32() const;
337  Float64 getValueAsFloat64() const;
349  std::string getValueAsString() const;
355  void *userData() const;
367  const blpapi_Constant_t *impl() const;
368 };
369 
397 
398  blpapi_ConstantList_t *d_impl_p;
399 
400  public:
401  explicit ConstantList(blpapi_ConstantList_t *handle);
402  /*
403  * Create a <code>ConstantList</code> object having the same value as
404  * the specified <code>original</code>. Note that this function does
405  * <em>not</em> require cross-object thread synchronization, as it does not
406  * directly read or modify the <code>userData</code> field.
407  */
408 
409  void setUserData(void *userData);
418  Name name() const;
423  const char *description() const;
430  int status() const;
436  int numConstants() const;
442  int datatype() const;
449  Constant getConstant(const Name& name) const;
457  Constant getConstant(const char *name) const;
465  Constant getConstantAt(size_t index) const;
473  void *userData() const;
485  const blpapi_ConstantList_t *impl() const;
489 };
490 
494 //=============================================================================
495 // INLINE FUNCTION DEFINITIONS
496 //=============================================================================
497 
499  : d_impl_p(handle)
500 {
501 }
502 
503 inline Name Constant::name() const
504 {
505  return Name(blpapi_Constant_name(d_impl_p));
506 }
507 
508 inline const char *Constant::description() const
509 {
510  return blpapi_Constant_description(d_impl_p);
511 }
512 
513 inline int Constant::status() const
514 {
515  return blpapi_Constant_status(d_impl_p);
516 }
517 
518 inline int Constant::datatype() const
519 {
520  return blpapi_Constant_datatype(d_impl_p);
521 }
522 
523 inline const blpapi_Constant_t *Constant::impl() const { return d_impl_p; }
524 
525 inline int Constant::getValueAs(char *buffer) const
526 {
527  return blpapi_Constant_getValueAsChar(d_impl_p, buffer);
528 }
529 
530 inline int Constant::getValueAs(Int32 *buffer) const
531 {
532  return blpapi_Constant_getValueAsInt32(d_impl_p, buffer);
533 }
534 
535 inline int Constant::getValueAs(Int64 *buffer) const
536 {
537  return blpapi_Constant_getValueAsInt64(d_impl_p, buffer);
538 }
539 
540 inline int Constant::getValueAs(Float32 *buffer) const
541 {
542  return blpapi_Constant_getValueAsFloat32(d_impl_p, buffer);
543 }
544 
545 inline int Constant::getValueAs(Float64 *buffer) const
546 {
547  return blpapi_Constant_getValueAsFloat64(d_impl_p, buffer);
548 }
549 
550 inline int Constant::getValueAs(Datetime *buffer) const
551 {
552  assert(buffer);
553 
554  return blpapi_Constant_getValueAsDatetime(d_impl_p, &buffer->rawValue());
555 }
556 
557 inline int Constant::getValueAs(std::string *result) const
558 {
559  const char *buffer = 0;
560  int rc = blpapi_Constant_getValueAsString(d_impl_p, &buffer);
561  if (!rc) {
562  *result = buffer;
563  }
564  return rc;
565 }
566 
567 inline char Constant::getValueAsChar() const
568 {
569  char value = 0;
571  return value;
572 }
573 
575 {
576  int value = 0;
578  return value;
579 }
580 
582 {
583  Int64 value = 0;
585  return value;
586 }
587 
588 inline float Constant::getValueAsFloat32() const
589 {
590  Float32 value = 0.0;
592  return value;
593 }
594 
595 inline double Constant::getValueAsFloat64() const
596 {
597  Float64 value = 0.0;
599  return value;
600 }
601 
603 {
604  Datetime value;
606  return value;
607 }
608 
609 inline std::string Constant::getValueAsString() const
610 {
611  std::string value;
613  return value;
614 }
615 
616 inline void Constant::setUserData(void *newUserData)
617 {
618  blpapi_Constant_setUserData(d_impl_p, newUserData);
619 }
620 
621 inline void *Constant::userData() const
622 {
623  return blpapi_Constant_userData(d_impl_p);
624 }
625 
627  : d_impl_p(handle)
628 {
629 }
630 
631 inline Name ConstantList::name() const
632 {
633  return Name(blpapi_ConstantList_name(d_impl_p));
634 }
635 
636 inline const char *ConstantList::description() const
637 {
638  return blpapi_ConstantList_description(d_impl_p);
639 }
640 
641 inline int ConstantList::status() const
642 {
643  return blpapi_ConstantList_status(d_impl_p);
644 }
645 
646 inline int ConstantList::datatype() const
647 {
648  return blpapi_ConstantList_datatype(d_impl_p);
649 }
650 
651 inline int ConstantList::numConstants() const
652 {
653  return blpapi_ConstantList_numConstants(d_impl_p);
654 }
655 
656 inline Constant ConstantList::getConstant(const Name& constantName) const
657 {
658  return Constant(
659  blpapi_ConstantList_getConstant(d_impl_p, 0, constantName.impl()));
660 }
661 
662 inline Constant ConstantList::getConstant(const char *nameString) const
663 {
664  return Constant(blpapi_ConstantList_getConstant(d_impl_p, nameString, 0));
665 }
666 
667 inline Constant ConstantList::getConstantAt(size_t index) const
668 {
669  return Constant(blpapi_ConstantList_getConstantAt(d_impl_p, index));
670 }
671 
673 {
674  return d_impl_p;
675 }
676 
677 inline void ConstantList::setUserData(void *newUserData)
678 {
679  blpapi_ConstantList_setUserData(d_impl_p, newUserData);
680 }
681 
682 inline void *ConstantList::userData() const
683 {
684  return blpapi_ConstantList_userData(d_impl_p);
685 }
686 
687 } // close namespace blpapi
688 } // close namespace BloombergLP
689 
690 #endif // #ifndef __cplusplus
691 
692 #endif // #ifndef INCLUDED_BLPAPI_CONSTANT
int getValueAs(char *buffer) const
Definition: blpapi_constant.h:525
BLPAPI_EXPORT int blpapi_Constant_getValueAsChar(const blpapi_Constant_t *constant, blpapi_Char_t *buffer)
BLPAPI_EXPORT void * blpapi_Constant_userData(const blpapi_Constant_t *constant)
Name name() const
Definition: blpapi_constant.h:503
BLPAPI_EXPORT void * blpapi_ConstantList_userData(const blpapi_ConstantList_t *constant)
Float32 getValueAsFloat32() const
Definition: blpapi_constant.h:588
Common definitions used by the library.
int status() const
Definition: blpapi_constant.h:513
int datatype() const
Definition: blpapi_constant.h:518
int datatype() const
Definition: blpapi_constant.h:646
blpapi_Int32_t Int32
Definition: blpapi_types.h:469
Represents a date and/or time.
Definition: blpapi_abstractsession.h:220
Definition: blpapi_name.h:150
blpapi_Float64_t Float64
Definition: blpapi_types.h:474
Definition: blpapi_constant.h:396
BLPAPI_EXPORT blpapi_Name_t * blpapi_ConstantList_name(const blpapi_ConstantList_t *list)
BLPAPI_EXPORT int blpapi_Constant_getValueAsFloat64(const blpapi_Constant_t *constant, blpapi_Float64_t *buffer)
BLPAPI_EXPORT int blpapi_Constant_getValueAsString(const blpapi_Constant_t *constant, const char **buffer)
BLPAPI_EXPORT blpapi_Constant_t * blpapi_ConstantList_getConstantAt(const blpapi_ConstantList_t *constant, size_t index)
void * userData() const
Definition: blpapi_constant.h:621
blpapi_Name_t * impl() const
Definition: blpapi_name.h:403
int blpapi_Int32_t
Definition: blpapi_types.h:67
const blpapi_ConstantList_t * impl() const
Definition: blpapi_constant.h:672
struct blpapi_Name blpapi_Name_t
Definition: blpapi_types.h:154
BLPAPI_EXPORT int blpapi_Constant_datatype(const blpapi_Constant_t *constant)
const char * description() const
Definition: blpapi_constant.h:508
Constant getConstant(const Name &name) const
Definition: blpapi_constant.h:656
Float64 getValueAsFloat64() const
Definition: blpapi_constant.h:595
int status() const
Definition: blpapi_constant.h:641
blpapi_Float32_t Float32
Definition: blpapi_types.h:473
BLPAPI_EXPORT blpapi_Constant_t * blpapi_ConstantList_getConstant(const blpapi_ConstantList_t *constant, const char *nameString, const blpapi_Name_t *name)
static void throwOnError(int errorCode)
Definition: blpapi_exception.h:526
struct blpapi_ConstantList blpapi_ConstantList_t
Definition: blpapi_types.h:133
struct blpapi_Constant blpapi_Constant_t
Definition: blpapi_types.h:130
int numConstants() const
Definition: blpapi_constant.h:651
BLPAPI_EXPORT void blpapi_Constant_setUserData(blpapi_Constant_t *constant, void *userdata)
const char * description() const
Definition: blpapi_constant.h:636
const blpapi_Constant_t * impl() const
Definition: blpapi_constant.h:523
BLPAPI_EXPORT int blpapi_Constant_getValueAsInt32(const blpapi_Constant_t *constant, blpapi_Int32_t *buffer)
ConstantList(blpapi_ConstantList_t *handle)
Definition: blpapi_constant.h:626
blpapi_Datetime_t & rawValue()
Definition: blpapi_datetime.h:1952
BLPAPI_EXPORT const char * blpapi_Constant_description(const blpapi_Constant_t *constant)
void setUserData(void *userData)
Definition: blpapi_constant.h:616
Int32 getValueAsInt32() const
Definition: blpapi_constant.h:574
blpapi_Int64_t Int64
Definition: blpapi_types.h:471
Int64 getValueAsInt64() const
Definition: blpapi_constant.h:581
BLPAPI_EXPORT int blpapi_Constant_getValueAsDatetime(const blpapi_Constant_t *constant, blpapi_Datetime_t *buffer)
BLPAPI_EXPORT int blpapi_ConstantList_datatype(const blpapi_ConstantList_t *constant)
Definition: blpapi_datetime.h:102
BLPAPI_EXPORT int blpapi_Constant_getValueAsInt64(const blpapi_Constant_t *constant, blpapi_Int64_t *buffer)
BLPAPI_EXPORT void blpapi_ConstantList_setUserData(blpapi_ConstantList_t *constant, void *userdata)
double blpapi_Float64_t
Definition: blpapi_types.h:72
BLPAPI_EXPORT const char * blpapi_ConstantList_description(const blpapi_ConstantList_t *list)
char blpapi_Char_t
Definition: blpapi_types.h:63
long long blpapi_Int64_t
Definition: blpapi_types.h:69
void * userData() const
Definition: blpapi_constant.h:682
BLPAPI_EXPORT blpapi_Name_t * blpapi_Constant_name(const blpapi_Constant_t *constant)
BLPAPI_EXPORT int blpapi_ConstantList_numConstants(const blpapi_ConstantList_t *list)
void setUserData(void *userData)
Definition: blpapi_constant.h:677
char getValueAsChar() const
Definition: blpapi_constant.h:567
Defines Exceptions that can be thrown by the blpapi library.
Definition: blpapi_constant.h:210
BLPAPI_EXPORT int blpapi_Constant_status(const blpapi_Constant_t *constant)
float blpapi_Float32_t
Definition: blpapi_types.h:71
BLPAPI_EXPORT int blpapi_ConstantList_status(const blpapi_ConstantList_t *list)
Constant(blpapi_Constant_t *handle)
Definition: blpapi_constant.h:498
Constant getConstantAt(size_t index) const
Definition: blpapi_constant.h:667
Datetime getValueAsDatetime() const
Definition: blpapi_constant.h:602
#define BLPAPI_EXPORT
Definition: blpapi_defs.h:171
std::string getValueAsString() const
Definition: blpapi_constant.h:609
Definition: blpapi_datetime.h:245
Provide BLPAPI types.
Name name() const
Definition: blpapi_constant.h:631
Provide a representation of strings for use as container keys.
BLPAPI_EXPORT int blpapi_Constant_getValueAsFloat32(const blpapi_Constant_t *constant, blpapi_Float32_t *buffer)