FARGOS/VISTA Object Management Environment Core  ..
FARGOS/VISTA Object Management Environment Core Table of Contents
OMEfixed.h
Go to the documentation of this file.
1 #ifndef _OME_FIXED_H
2 #define _OME_FIXED_H "$Id: OMEfixed.h 312 2020-03-21 21:25:35Z geoff $"
4 
6 #include <iostream> /* for debugging */
7 # include <OMErefCount.h>
8 
17 typedef class OMEbaseType *OMEbaseTypeP;
18 
19 # ifndef MAPM_LIB_VERSION
20 typedef struct M_APM_struct *M_APM;
21 # endif
22 
27  double d;
28 };
29 
31 
35 {
36  friend class OMEfixed;
37 
38 private:
40 
41  explicit OMEfixedStorage(M_APM newVal);
42 
43 public:
45 
46  explicit OMEfixedStorage(const int32_t);
47 
48  explicit OMEfixedStorage(const int64_t);
49 
50  explicit OMEfixedStorage(const double);
51 
52  explicit OMEfixedStorage(const char *);
53 
55 
56  virtual OMEreferenceCount *deepCopy() const override;
57 
58  bool operator==(const OMEfixedStorage &arg) const;
59 
60  bool operator!=(const OMEfixedStorage &arg) const;
61 
62  bool operator<=(const OMEfixedStorage &arg) const;
63 
64  bool operator<(const OMEfixedStorage &arg) const;
65 
66  bool operator>=(const OMEfixedStorage &arg) const;
67 
68  bool operator>(const OMEfixedStorage &arg) const;
69 
70  explicit operator char *() const; // not thread safe
71 
72  char *asStringText(char *bfr, uint_fast16_t bfrLen) const;
73 
74  template <typename STREAMTYPE> STREAMTYPE &outputOnStream(STREAMTYPE &outputStream, int_fast16_t indent = 0) const
75  {
76  char outString[256];
77 
78  outputStream << asStringText(outString, sizeof(outString));
79  return (outputStream);
80  }
81 }; // end class OMEfixedStorage
82 
85 class OME_DLL_EXPORT OMEfixed : public OMEreferenceToData<OMEfixedStorage>
86 {
87 private:
89  {
90  data = f;
91  }
92 
93 public:
95  {
96  data = new OMEfixedStorage();
97  }
98 
99  OMEfixed(const OMEfixed &org)
100  {
101  data = org.data;
103  }
104 
105  explicit OMEfixed(const int32_t i)
106  {
107  data = new OMEfixedStorage(i);
108  }
109 
110  explicit OMEfixed(const uint32_t ui)
111  {
112  data = new OMEfixedStorage((int32_t) ui);
113  }
114 
115  explicit OMEfixed(const int64_t i64)
116  {
117  data = new OMEfixedStorage(i64);
118  }
119 
120  explicit OMEfixed(const uint64_t ui64)
121  {
122  data = new OMEfixedStorage((int64_t) ui64);
123  }
124 
125  explicit OMEfixed(const double d)
126  {
127  data = new OMEfixedStorage(d);
128  }
129 
130  explicit OMEfixed(M_APM newVal)
131  {
132  data = new OMEfixedStorage(newVal);
133  }
134 
135  explicit OMEfixed(const char *numberText)
136  {
137  data = new OMEfixedStorage(numberText);
138  }
139 
141 
142  // ASSIGNMENT
144  {
145  if (this->data == arg.data) {
146  std::cerr << "OMEfixed assignment to self, ref=" << totalReferences() << "\n";
147  return (*this); // asignment to self...
148  }
149  arg.data->addReadOnlyReference();
150  dropReference();
151  data = arg.data;
152  return (*this);
153  }
154 
155  OMEfixed &operator=(const int32_t i)
156  {
157  dropReference();
158  data = new OMEfixedStorage(i);
159  return (*this);
160  }
161 
162  OMEfixed &operator=(const uint32_t ui)
163  {
164  dropReference();
165  data = new OMEfixedStorage((int32_t) ui);
166  return (*this);
167  }
168 
169  OMEfixed &operator=(const double d)
170  {
171  dropReference();
172  data = new OMEfixedStorage(d);
173  return (*this);
174  }
175 
176  // COMPARISON
177  bool operator==(const OMEfixed &arg) const
178  {
179  if (data == arg.data) {
180  return (true); // fast path
181  }
182  return (*data == *arg.data);
183  }
184 
185  bool operator!=(const OMEfixed &arg) const
186  {
187  if (data == arg.data) {
188  return (false); // fast path
189  }
190  return (*data != *arg.data);
191  }
192 
193  bool operator<(const OMEfixed &arg) const
194  {
195  return (*data < *arg.data);
196  }
197 
198  bool operator>(const OMEfixed &arg) const
199  {
200  return (*data > *arg.data);
201  }
202 
203  bool operator<=(const OMEfixed &arg) const
204  {
205  return (*data <= *arg.data);
206  }
207 
208  bool operator>=(const OMEfixed &arg) const
209  {
210  return (*data >= *arg.data);
211  }
212 
214  {
215  OMEfixedStorage *storageCopy = static_cast<OMEfixedStorage *>(data->deepCopy());
216  OMEfixed *copy = new OMEfixed(storageCopy);
217  return (copy);
218  }
219 
220  OMEfixed &operator+=(const OMEfixed &arg);
221 
222  OMEfixed &operator+=(const double arg);
223 
224  OMEfixed &operator-=(const OMEfixed &arg);
225 
226  OMEfixed &operator-=(const double arg);
227 
228  OMEfixed &operator*=(const OMEfixed &arg);
229 
230  OMEfixed &operator*=(const double arg);
231 
232  OMEfixed &operator/=(const OMEfixed &arg);
233 
234  OMEfixed &operator/=(const double arg);
235 
236  OMEfixed operator+(const OMEfixed &arg) const;
237  OMEfixed operator-(const OMEfixed &arg) const;
238  OMEfixed operator*(const OMEfixed &arg) const;
239  OMEfixed operator/(const OMEfixed &arg) const;
240 
241  explicit operator double() const;
242 
243  explicit operator float() const;
244 
245  explicit operator int32_t() const;
246 
247  explicit operator int64_t() const;
248 
249  explicit operator uint64_t() const;
250 
251  explicit operator uint32_t() const;
252 
253  explicit operator uint16_t() const;
254 
255  explicit operator uint8_t() const;
256 
257 
258 
259 
260  template <typename STREAMTYPE> STREAMTYPE &outputOnStream(STREAMTYPE &outputStream, int_fast16_t indent = 0) const
261  {
262  data->outputOnStream(outputStream, indent);
263  return (outputStream);
264  }
265 }; // end class OMEfixed
266 
267 template <typename STREAMTYPE>
268 inline STREAMTYPE &operator<<(STREAMTYPE &outputStream, const OMEfixed &data)
269 {
270  data.outputOnStream(outputStream, 0);
271  return (outputStream);
272 }
273 
277 #endif
278 /* vim: set expandtab shiftwidth=4 tabstop=4: */
OMErefCount.h
OME reference count implementation.
ALT_DIR_SEP
#define ALT_DIR_SEP
Definition: OMEfindFile.cpp:25
OMEfixedStorage::deepCopy
virtual OMEreferenceCount * deepCopy() const override
Definition: OMEfixed.cpp:48
OMEfixed::OMEfixed
OMEfixed(const double d)
Definition: OMEfixed.h:125
OMEfixed::OMEfixed
OMEfixed(const char *numberText)
Definition: OMEfixed.h:135
OMEfixed::operator=
OMEfixed & operator=(const uint32_t ui)
Definition: OMEfixed.h:162
OMEfixed::operator-=
OMEfixed & operator-=(const OMEfixed &arg)
Definition: OMEfixed.cpp:168
s
const char s[]
Definition: t.cpp:4
OMEfixed::operator!=
bool operator!=(const OMEfixed &arg) const
Definition: OMEfixed.h:185
OMEfunctions.h
OME utility functions.
operator/
OMEtype operator/(const OMEtype &lArg, const OMEtype &rArg)
Definition: OMEtype_operators.cpp:40694
OMEfixed::operator<=
bool operator<=(const OMEfixed &arg) const
Definition: OMEfixed.h:203
OMEfixed::deepCopy
OMEfixed * deepCopy() const
Definition: OMEfixed.h:213
OMEfixed::operator/=
OMEfixed & operator/=(const OMEfixed &arg)
Definition: OMEfixed.cpp:218
NATIVE_DIR_SEP
#define NATIVE_DIR_SEP
Definition: OMEfindFile.cpp:24
OMEreferenceToData< OMEfixedStorage >::addReadOnlyReference
void addReadOnlyReference() OME_ALWAYS_INLINE
Definition: OMErefCount.h:84
OMEstring
Implements text and binary string storage.
Definition: OMEstring.h:305
OMEfixed::operator>=
bool operator>=(const OMEfixed &arg) const
Definition: OMEfixed.h:208
OMEfixed::operator=
OMEfixed & operator=(const OMEfixed &arg)
Definition: OMEfixed.h:143
OMEfixed::OMEfixed
OMEfixed()
Definition: OMEfixed.h:94
OMEreferenceToData< OMEfixedStorage >::data
OMEfixedStorage * data
Definition: OMErefCount.h:82
OMEarray::indexExists
bool indexExists(const uint32_t i) const
Definition: OMEarray.h:202
operator/=
OMEtype & operator/=(OMEtype &lArg, const OMEtype &rArg)
Definition: OMEtype_operators.cpp:30582
OMEtype::value
union OMEtype::@26 value
OMEtype
Fundamental ANY type for FARGOS/VISTA Object Management Environment.
Definition: OMEbaseType.h:250
OMEfixed::OMEfixed
OMEfixed(M_APM newVal)
Definition: OMEfixed.h:130
OMEfixedStorage::outputOnStream
STREAMTYPE & outputOnStream(STREAMTYPE &outputStream, int_fast16_t indent=0) const
Definition: OMEfixed.h:74
OMEstring::determineCharacterSet
void determineCharacterSet()
Definition: OMEstring.h:391
OMElistDirectory
OMEarray * OMElistDirectory(const OMEstring &dirName, int *errRet)
List all files within a filesystem directory.
Definition: OMEfindFile.cpp:112
OMEtype::s
class OMEstring * s
Definition: OMEbaseType.h:299
INVALID_HANDLE_VALUE
#define INVALID_HANDLE_VALUE
Definition: poll_monitor.hpp:19
OMEfixed.h
OME fixed point number implementation.
OMEfixedStorage::operator>=
bool operator>=(const OMEfixedStorage &arg) const
Definition: OMEfixed.cpp:91
OMEreferenceToData
Templated type-specific reference to a reference-counted object.
Definition: OMErefCount.h:79
OMEfixedStorage
Reference-counted storage for OMEfixedStorage type.
Definition: OMEfixed.h:34
operator-=
OMEtype & operator-=(OMEtype &lArg, const OMEtype &rArg)
Definition: OMEtype_operators.cpp:24618
OMEreferenceCount
Base class for reference-counted data.
Definition: OMErefCount.h:31
OMEfixed::OMEfixed
OMEfixed(OMEfixedStorage *f)
Definition: OMEfixed.h:88
OMEfixed::operator*=
OMEfixed & operator*=(const OMEfixed &arg)
Definition: OMEfixed.cpp:193
OMEfixed::OMEfixed
OMEfixed(const OMEfixed &org)
Definition: OMEfixed.h:99
OMEreferenceToData::totalReferences
int_fast32_t totalReferences() const OME_ALWAYS_INLINE
Get current reference total.
Definition: OMErefCount.h:141
srcID
const char srcID[]
Definition: catSym.c:17
OMEfixedStorage::operator>
bool operator>(const OMEfixedStorage &arg) const
Definition: OMEfixed.cpp:115
OME_STRING
@ OME_STRING
Definition: OMEmanifests.h:85
OMEfixedStorage::asStringText
char * asStringText(char *bfr, uint_fast16_t bfrLen) const
Definition: OMEfixed.cpp:127
OMEfixedStorage::operator<=
bool operator<=(const OMEfixedStorage &arg) const
Definition: OMEfixed.cpp:79
OMEfixed::outputOnStream
STREAMTYPE & outputOnStream(STREAMTYPE &outputStream, int_fast16_t indent=0) const
Definition: OMEfixed.h:260
OMEfixedStorage::operator<
bool operator<(const OMEfixedStorage &arg) const
Definition: OMEfixed.cpp:103
operator*=
OMEtype & operator*=(OMEtype &lArg, const OMEtype &rArg)
Definition: OMEtype_operators.cpp:29166
OMEfixedStorage::operator!=
bool operator!=(const OMEfixedStorage &arg) const
Definition: OMEfixed.cpp:67
OMEtype.h
OME fundamental type implementation.
OMEfixed::operator-
OMEfixed operator-(const OMEfixed &arg) const
Definition: OMEfixed.cpp:250
OMEstring::length
size_t length() const
Definition: OMEstring.h:401
OMEfixed::operator=
OMEfixed & operator=(const double d)
Definition: OMEfixed.h:169
OME_USED
const char srcID[] OME_USED
Definition: tick_time.cpp:24
OMEfindFileInDirectory
OMEstring * OMEfindFileInDirectory(const OMEstring &fileName, const OMEarray &dirNames)
Search for a file located within a list of directories specified as elements of an OMEarray.
Definition: OMEfindFile.cpp:292
operator+
OMEtype operator+(const OMEtype &lArg, const OMEtype &rArg)
Definition: OMEtype_operators.cpp:33691
operator-
OMEtype operator-(const OMEtype &lArg, const OMEtype &rArg)
Definition: OMEtype_operators.cpp:36699
operator<<
STREAMTYPE & operator<<(STREAMTYPE &outputStream, const OMEfixed &data)
Definition: OMEfixed.h:268
OMEfixed::OMEfixed
OMEfixed(const int64_t i64)
Definition: OMEfixed.h:115
OMEfindFileInPathSpec
OMEstring * OMEfindFileInPathSpec(const OMEstring &fileName, const OMEstring &path)
Search for a file located within a set of directories specified by a string path.
Definition: OMEfindFile.cpp:344
OMEreferenceCount::addReadOnlyReference
void addReadOnlyReference()
Definition: OMErefCount.cpp:139
OMEfixedStorage::numberData
M_APM numberData
Definition: OMEfixed.h:39
errno
int errno
Definition: ethers.c:41
OMEfixed::operator+=
OMEfixed & operator+=(const OMEfixed &arg)
Definition: OMEfixed.cpp:143
OME_EXPECT_FALSE
#define OME_EXPECT_FALSE(expr)
Annotation macro for conditional expression expected to be false.
Definition: compiler_hints.h:540
OMEfixed::operator>
bool operator>(const OMEfixed &arg) const
Definition: OMEfixed.h:198
OMEfixed
Public interface to OME fixed-point type.
Definition: OMEfixed.h:85
OMEbaseTypeP
class OMEtype * OMEbaseTypeP
Definition: OMEfixed.h:17
OMEreferenceToData< OMEfixedStorage >::dropReference
void dropReference(OMEfixedStorage *newData=nullptr) OME_ALWAYS_INLINE
Definition: OMErefCount.h:91
OMEfixed::OMEfixed
OMEfixed(const uint32_t ui)
Definition: OMEfixed.h:110
OMEfixed::OMEfixed
OMEfixed(const uint64_t ui64)
Definition: OMEfixed.h:120
_OME_FIXED_H
#define _OME_FIXED_H
Definition: tmp.o.cpp:967
operator+=
OMEtype & operator+=(OMEtype &lArg, const OMEtype &rArg)
Definition: OMEtype_operators.cpp:21683
OMEfixed::operator*
OMEfixed operator*(const OMEfixed &arg) const
Definition: OMEfixed.cpp:257
OMEfixedStorage::~OMEfixedStorage
~OMEfixedStorage()
Definition: OMEfixed.cpp:43
OME_DLL_EXPORT
#define OME_DLL_EXPORT
Definition: compiler_hints.h:464
OMEarray
Implements sparse array of OMEtype elements.
Definition: OMEarray.h:75
OMEfixed::operator<
bool operator<(const OMEfixed &arg) const
Definition: OMEfixed.h:193
OMEfixedStorage::operator==
bool operator==(const OMEfixedStorage &arg) const
Definition: OMEfixed.cpp:55
operator*
OMEtype operator*(const OMEtype &lArg, const OMEtype &rArg)
Definition: OMEtype_operators.cpp:39283
OMEtype::type
uint32_t type
Definition: OMEbaseType.h:304
M_APM
struct M_APM_struct * M_APM
Definition: OMEfixed.h:20
OMEfixed::operator=
OMEfixed & operator=(const int32_t i)
Definition: OMEfixed.h:155
OMEfixed::OMEfixed
OMEfixed(const int32_t i)
Definition: OMEfixed.h:105
OMEarray::ARRAY_SUBSCRIPT_t
OMEarrayStorage::ARRAY_SUBSCRIPT_t ARRAY_SUBSCRIPT_t
Definition: OMEarray.h:90
_OMEfixedConstant
Internal data type to generate fixed-point constant from floating-point value.
Definition: OMEfixed.h:26
_OMEfixedConstant::d
double d
Definition: OMEfixed.h:27
OMEfixedStorage::OMEfixedStorage
OMEfixedStorage()
Definition: OMEfixed.cpp:9
OMEfixed::~OMEfixed
~OMEfixed()
Definition: OMEfixed.h:140
OMEparsePathSpecification
OMEarray * OMEparsePathSpecification(const OMEstring &spec)
Parse a list of directories specified by a string path into an sequence of OMEarray elements.
Definition: OMEfindFile.cpp:236
OMEfixed::operator+
OMEfixed operator+(const OMEfixed &arg) const
Definition: OMEfixed.cpp:243
OMEfixed::operator/
OMEfixed operator/(const OMEfixed &arg) const
Definition: OMEfixed.cpp:264
OMEfixed::operator==
bool operator==(const OMEfixed &arg) const
Definition: OMEfixed.h:177
Generated: Tue Jul 28 2020 16:03:25
Support Information