OpenMAMA C++ API
MamaPrice.h
Go to the documentation of this file.
1 /* $Id$
2  *
3  * OpenMAMA: The open middleware agnostic messaging API
4  * Copyright (C) 2011 NYSE Technologies, Inc.
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301 USA
20  */
21 
22 #ifndef MAMA_PRICE_CPP_H__
23 #define MAMA_PRICE_CPP_H__
24 
25 #include <mama/price.h>
26 
27 static const int MAX_PRICE_STR_LEN = 32;
28 
29 namespace Wombat
30 {
31 
43  class MAMACPPExpDLL MamaPrice
44  {
45  public:
46  MamaPrice ();
47  MamaPrice (double value,
48  mamaPricePrecision precision = MAMA_PRICE_PREC_100);
49  MamaPrice (const MamaPrice& copy);
50 
51  ~MamaPrice ();
52 
53  MamaPrice& operator= (const MamaPrice& rhs);
54  MamaPrice& operator+= (const MamaPrice& rhs);
55  MamaPrice& operator-= (const MamaPrice& rhs);
56 
57  bool operator== (const MamaPrice& rhs) const;
58  bool operator== (double rhs) const;
59  bool operator!= (const MamaPrice& rhs) const
60  {
61  return ! operator== (rhs);
62  }
63  bool operator!= (double rhs) const
64  {
65  return ! operator== (rhs);
66  }
67  bool operator< (const MamaPrice& rhs) const;
68  bool operator< (double rhs) const;
69  bool operator> (const MamaPrice& rhs) const;
70  bool operator> (double rhs) const;
71 
76  MamaPrice operator- (const MamaPrice& rhs) const
77  {
78  return MamaPrice (getValue() - rhs.getValue(),
79  rhs.getPrecision ());
80  }
81 
86  MamaPrice operator- (double rhs) const
87  {
88  return MamaPrice (getValue () - rhs,
89  getPrecision ());
90  }
91 
96  MamaPrice operator- () const
97  {
98  return MamaPrice (-getValue (),
99  getPrecision ());
100  }
101 
105  MamaPrice operator+ (const MamaPrice& rhs) const
106  {
107  return MamaPrice (getValue () + rhs.getValue (),
108  rhs.getPrecision ());
109  }
110 
115  MamaPrice operator+ (double rhs) const
116  {
117  return MamaPrice (getValue () + rhs,
118  getPrecision ());
119  }
120 
121  double compare (const MamaPrice& rhs) const;
122 
123  void clear ();
124 
125  void set (double priceValue,
126  mamaPriceHints hints = 0);
127  void setValue (double value);
128  void setPrecision (mamaPricePrecision precision);
129  void setHints (mamaPriceHints hints);
130  void setIsValidPrice (bool valid);
131 
132  double getValue () const;
133  mamaPricePrecision getPrecision () const;
134  mamaPriceHints getHints () const;
135  bool getIsValidPrice () const;
136 
137 
138  void setFromString (const char* str);
139  void getAsString (char* result,
140  mama_size_t maxLen) const;
141 
148  const char* getAsString () const;
149 
153  void negate ();
154 
159  bool isZero () const;
160 
165  static mamaPricePrecision decimals2Precision (mama_i32_t places);
166 
171  static mamaPricePrecision denom2Precision (mama_i32_t denominator);
172 
176  static mama_i32_t precision2Decimals (mamaPricePrecision precision);
177 
181  static mama_i32_t precision2Denom (mamaPricePrecision precision);
182 
183  mamaPrice getCValue();
184  const mamaPrice getCValue() const;
185 
186  private:
187  mamaPrice mPrice;
188  mutable char* mStrRep;
189 };
190 
191 } // namespace Wombat
192 
193 
194 #endif // MAMA_PRICE_CPP_H__
double getValue() const
Definition: MamaConnection.h:29
MamaPrice is a special data type for representing floating point numbers that often require special f...
Definition: MamaPrice.h:43
mamaPricePrecision getPrecision() const