aqbanking  5.7.8
value.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  $RCSfile$
3  -------------------
4  begin : Mon March 1 2011
5  copyright : (C) 2011 by Christian Stimming
6  email : christian@cstimming.de
7 
8  ***************************************************************************
9  * This file is part of the project "AqBanking". *
10  * Please see toplevel file COPYING of that project for license details. *
11  ***************************************************************************/
12 
13 
14 #ifndef AB_VALUE_HPP
15 #define AB_VALUE_HPP
16 
17 #include <aqbanking/value.h>
18 #include <aqbankingpp/cxxwrap.hpp>
19 #include <string>
20 
21 namespace AB
22 {
23 
25 class /*AQBANKING_API*/ Value
26 // note: AQBANKING_API isn't needed as long as this class is defined
27 // purely in the header.
28 {
29 public:
31 private:
32  wrapped_type* m_ptr;
33 public:
34 
35  AB_CXXWRAP_CONSTRUCTOR0(Value, AB_Value);
36  AB_CXXWRAP_CONSTRUCTORS(Value, AB_Value);
37 
40  Value(double d)
41  : m_ptr(AB_Value_fromDouble(d))
42  {}
43 
46  Value(long int num, long int denom)
47  : m_ptr(AB_Value_fromInt(num, denom))
48  {}
49 
51  void toString(GWEN_BUFFER *buf) const
52  {
53  AB_Value_toString(m_ptr, buf);
54  }
55 
57  std::string toString() const
58  {
59  GWEN_BUFFER *buf = GWEN_Buffer_new(NULL, 100, 0, 0);
60  toString(buf);
61  std::string result(GWEN_Buffer_GetStart(buf));
62  GWEN_Buffer_free(buf);
63  return result;
64  }
65 
66 
67  long int AB_CXXWRAP_GET0_CONST(getNum, AB_Value_Num);
68  long int AB_CXXWRAP_GET0_CONST(getDenom, AB_Value_Denom);
69  double AB_CXXWRAP_GET0_CONST(getValueAsDouble, AB_Value_GetValueAsDouble);
70 
71  AB_CXXWRAP_SET1(setValueFromDouble, double, AB_Value_SetValueFromDouble);
73 
77 
78  int AB_CXXWRAP_GET1_CONST(compare, const Value&, AB_Value_Compare);
79  bool AB_CXXWRAP_GET1_CONST(equal, const Value&, AB_Value_Equal);
80 
81  int AB_CXXWRAP_GET1(addValue, const Value&, AB_Value_AddValue);
82  int AB_CXXWRAP_GET1(subValue, const Value&, AB_Value_SubValue);
83  int AB_CXXWRAP_GET1(multValue, const Value&, AB_Value_MultValue);
84  int AB_CXXWRAP_GET1(divValue, const Value&, AB_Value_DivValue);
85 
86  int AB_CXXWRAP_GET0(negate, AB_Value_Negate);
87 
88  std::string AB_CXXWRAP_GET0_CONST(getCurrency, AB_Value_GetCurrency);
89  void setCurrency(const std::string& s)
90  {
91  AB_Value_SetCurrency(m_ptr, s.c_str());
92  }
93 
95  static Value fromString(const std::string& s)
96  {
97  return Value(AB_Value_fromString(s.c_str()));
98  }
99 };
100 
101 bool operator==(const Value& v1, const Value& v2)
102 {
103  return v1.equal(v2);
104 }
105 bool operator!=(const Value& v1, const Value& v2)
106 {
107  return !(v1 == v2);
108 }
109 bool operator>(const Value& v1, const Value& v2)
110 {
111  return v1.compare(v2) > 0;
112 }
113 bool operator<(const Value& v1, const Value& v2)
114 {
115  return v1.compare(v2) < 0;
116 }
117 
118 } // END namespace AB
119 
120 
121 #endif // AB_VALUE_HPP
122 
int AB_Value_MultValue(AB_VALUE *v1, const AB_VALUE *v2)
void setCurrency(const std::string &s)
Definition: value.hpp:89
double AB_Value_GetValueAsDouble(const AB_VALUE *v)
AB_VALUE * AB_Value_fromDouble(double i)
int AB_Value_Negate(AB_VALUE *v)
bool operator<(const Value &v1, const Value &v2)
Definition: value.hpp:113
void AB_Value_SetValueFromDouble(AB_VALUE *v, double i)
Value(long int num, long int denom)
Definition: value.hpp:46
struct AB_VALUE AB_VALUE
Definition: value.h:32
AB_CXXWRAP_CONSTRUCTOR0(Value, AB_Value)
int AB_Value_Equal(const AB_VALUE *v1, const AB_VALUE *v2)
AB_VALUE * AB_Value_fromString(const char *s)
long int AB_Value_Denom(const AB_VALUE *v)
const char * AB_Value_GetCurrency(const AB_VALUE *v)
AB_CXXWRAP_SET0(setZero, AB_Value_SetZero)
int AB_Value_IsPositive(const AB_VALUE *v)
void AB_Value_toString(const AB_VALUE *v, GWEN_BUFFER *buf)
void toString(GWEN_BUFFER *buf) const
Definition: value.hpp:51
AB_VALUE * AB_Value_fromInt(long int num, long int denom)
int AB_Value_IsNegative(const AB_VALUE *v)
int AB_Value_IsZero(const AB_VALUE *v)
Value(double d)
Definition: value.hpp:40
bool operator>(const Value &v1, const Value &v2)
Definition: value.hpp:109
int AB_CXXWRAP_GET0(negate, AB_Value_Negate)
int AB_CXXWRAP_GET1(addValue, const Value &, AB_Value_AddValue)
int AB_Value_SubValue(AB_VALUE *v1, const AB_VALUE *v2)
static Value fromString(const std::string &s)
Definition: value.hpp:95
int AB_CXXWRAP_GET1_CONST(compare, const Value &, AB_Value_Compare)
bool operator!=(const Value &v1, const Value &v2)
Definition: value.hpp:105
int AB_Value_AddValue(AB_VALUE *v1, const AB_VALUE *v2)
long int AB_Value_Num(const AB_VALUE *v)
AB_CXXWRAP_SET1(setValueFromDouble, double, AB_Value_SetValueFromDouble)
int AB_Value_Compare(const AB_VALUE *v1, const AB_VALUE *v2)
AB_CXXWRAP_CONSTRUCTORS(Value, AB_Value)
AB_VALUE wrapped_type
Definition: value.hpp:30
std::string toString() const
Definition: value.hpp:57
long int AB_CXXWRAP_GET0_CONST(getNum, AB_Value_Num)
int AB_Value_DivValue(AB_VALUE *v1, const AB_VALUE *v2)
bool operator==(const Value &v1, const Value &v2)
Definition: value.hpp:101
void AB_Value_SetCurrency(AB_VALUE *v, const char *s)
void AB_Value_SetZero(AB_VALUE *v)