aqbanking 5.0.14
|
00001 /*************************************************************************** 00002 $RCSfile$ 00003 ------------------- 00004 begin : Mon March 1 2011 00005 copyright : (C) 2011 by Christian Stimming 00006 email : christian@cstimming.de 00007 00008 *************************************************************************** 00009 * This file is part of the project "AqBanking". * 00010 * Please see toplevel file COPYING of that project for license details. * 00011 ***************************************************************************/ 00012 00013 00014 #ifndef AB_VALUE_HPP 00015 #define AB_VALUE_HPP 00016 00017 #include <aqbanking/value.h> 00018 #include <aqbankingpp/cxxwrap.hpp> 00019 #include <string> 00020 00021 namespace AB 00022 { 00023 00025 class /*AQBANKING_API*/ Value 00026 // note: AQBANKING_API isn't needed as long as this class is defined 00027 // purely in the header. 00028 { 00029 public: 00030 typedef AB_VALUE wrapped_type; 00031 private: 00032 wrapped_type* m_ptr; 00033 public: 00034 00035 AB_CXXWRAP_CONSTRUCTOR0(Value, AB_Value); 00036 AB_CXXWRAP_CONSTRUCTORS(Value, AB_Value); 00037 00040 Value(double d) 00041 : m_ptr(AB_Value_fromDouble(d)) 00042 {} 00043 00046 Value(long int num, long int denom) 00047 : m_ptr(AB_Value_fromInt(num, denom)) 00048 {} 00049 00051 void toString(GWEN_BUFFER *buf) const 00052 { 00053 AB_Value_toString(m_ptr, buf); 00054 } 00055 00057 std::string toString() const 00058 { 00059 GWEN_BUFFER *buf = GWEN_Buffer_new(NULL, 100, 0, 0); 00060 toString(buf); 00061 std::string result(GWEN_Buffer_GetStart(buf)); 00062 GWEN_Buffer_free(buf); 00063 return result; 00064 } 00065 00066 00067 long int AB_CXXWRAP_GET0_CONST(getNum, AB_Value_Num); 00068 long int AB_CXXWRAP_GET0_CONST(getDenom, AB_Value_Denom); 00069 double AB_CXXWRAP_GET0_CONST(getValueAsDouble, AB_Value_GetValueAsDouble); 00070 00071 AB_CXXWRAP_SET1(setValueFromDouble, double, AB_Value_SetValueFromDouble); 00072 AB_CXXWRAP_SET0(setZero, AB_Value_SetZero); 00073 00074 bool AB_CXXWRAP_GET0_CONST(isZero, AB_Value_IsZero); 00075 bool AB_CXXWRAP_GET0_CONST(isNegative, AB_Value_IsNegative); 00076 bool AB_CXXWRAP_GET0_CONST(isPositive, AB_Value_IsPositive); 00077 00078 int AB_CXXWRAP_GET1_CONST(compare, const Value&, AB_Value_Compare); 00079 bool AB_CXXWRAP_GET1_CONST(equal, const Value&, AB_Value_Equal); 00080 00081 int AB_CXXWRAP_GET1(addValue, const Value&, AB_Value_AddValue); 00082 int AB_CXXWRAP_GET1(subValue, const Value&, AB_Value_SubValue); 00083 int AB_CXXWRAP_GET1(multValue, const Value&, AB_Value_MultValue); 00084 int AB_CXXWRAP_GET1(divValue, const Value&, AB_Value_DivValue); 00085 00086 int AB_CXXWRAP_GET0(negate, AB_Value_Negate); 00087 00088 std::string AB_CXXWRAP_GET0_CONST(getCurrency, AB_Value_GetCurrency); 00089 void setCurrency(const std::string& s) 00090 { 00091 AB_Value_SetCurrency(m_ptr, s.c_str()); 00092 } 00093 00095 static Value fromString(const std::string& s) 00096 { 00097 return Value(AB_Value_fromString(s.c_str())); 00098 } 00099 }; 00100 00101 bool operator==(const Value& v1, const Value& v2) 00102 { 00103 return v1.equal(v2); 00104 } 00105 bool operator!=(const Value& v1, const Value& v2) 00106 { 00107 return !(v1 == v2); 00108 } 00109 bool operator>(const Value& v1, const Value& v2) 00110 { 00111 return v1.compare(v2) > 0; 00112 } 00113 bool operator<(const Value& v1, const Value& v2) 00114 { 00115 return v1.compare(v2) < 0; 00116 } 00117 00118 } // END namespace AB 00119 00120 00121 #endif // AB_VALUE_HPP 00122