EPICS ARCHIVER V4
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups
RawValue.h
1 // -*- c++ -*-
2 
3 #ifndef __RAW_VALUE_H__
4 #define __RAW_VALUE_H__
5 
6 #include <stdio.h>
7 #include <cstring>
8 #include <string>
9 
10 // epics
11 #include <db_access.h>
12 
13 // tools
14 #include "tools/NoCopy.h"
15 #include "tools/MemoryBuffer.h"
16 
17 // storage
18 #include "storage/StorageTypes.h"
19 
22 
24 typedef unsigned short DbrType;
25 
27 typedef unsigned short DbrCount;
28 
32 {
33  ARCH_BASE_MASK = 0x0007, // Mask for bits used by EPICS base
34  ARCH_EST_REPEAT = 0x0f80,
35  ARCH_DISCONNECT = 0x0f40,
36  ARCH_STOPPED = 0x0f20,
37  ARCH_REPEAT = 0x0f10,
38  ARCH_DISABLED = 0x0f08
39 };
40 
42 
49 class RawValue
50 {
51 public:
55  typedef dbr_time_double Data;
56 
60  static Data * allocate(DbrType type, DbrCount count, size_t num);
61 
63  static void free(Data *value);
64 
66  static size_t getSize(DbrType type, DbrCount count);
67 
69  static bool equal(DbrType type, DbrCount count,
70  const Data *lhs, const Data *rhs)
71  { return memcmp(lhs, rhs, getSize(type, count)) == 0; }
72 
77  static bool hasSameValue(DbrType type, DbrCount count,
78  size_t size, const Data *lhs, const Data *rhs);
79 
81  static bool hasSameValue(DbrType type, DbrCount count,
82  const Data *lhs, const Data *rhs);
83 
85  static void copy(DbrType type, DbrCount count, Data *lhs, const Data *rhs)
86  { memcpy(lhs, rhs, getSize(type, count)); }
87 
89  static short getStat(const Data *value)
90  { return value->status; }
91 
93  static short getSevr(const Data *value)
94  { return value->severity; }
95 
97  static void getStatus(const Data* value, std::string& status);
98 
101  static bool isInfo(const Data* value)
102  {
103  short s = value->severity;
104  return s==ARCH_DISCONNECT || s==ARCH_STOPPED || s==ARCH_DISABLED;
105  }
106 
108 
112  static bool isAboveZero(DbrType type, const Data* value);
113 
115  static void setStatus(Data *value, short status, short severity)
116  {
117  value->status = status;
118  value->severity = severity;
119  }
120 
122  static bool parseStatus(const std::string& text, short& stat, short& sevr);
123 
125  static const epicsTime getTime(const Data* value)
126  { return epicsTime(value->stamp); }
127 
129  static void getTime(const Data* value, std::string& time);
130 
132  static void setTime(Data* value, const epicsTime& stamp)
133  { value->stamp = (epicsTimeStamp)stamp; }
134 
136 
140  static bool getDouble(DbrType type, DbrCount count,
141  const Data* value, double& d, int i=0);
142 
144 
148  static bool getLong(DbrType type, DbrCount count,
149  const Data *value, long &l, int i=0);
150 
152 
156  static bool setDouble(DbrType type, DbrCount count,
157  Data *value, double d);
158 
161  {
166  };
167 
169  static size_t formatDouble(double number, NumberFormat format, int prec,
170  char *buffer, size_t max_len);
171 
178  static void getValueString(std::string& text,
179  DbrType type, DbrCount count, const Data* value,
180  const class CtrlInfo *info=0,
181  NumberFormat format = DECIMAL,
182  int prec = -1);
183 
188  static void toString(std::string& text, DbrType type, DbrCount count,
189  const Data *value, const class CtrlInfo *info=0);
190 
191 
193  static void show(FILE *file,
194  DbrType type, DbrCount count, const Data *value,
195  const class CtrlInfo *info=0);
196 
197 };
198 
199 
202 {
203 public:
204  RawValueAutoPtr() : ptr(0) {};
205 
207  RawValueAutoPtr(RawValue::Data *in) : ptr(in) {};
208 
211  {
212  ptr = rhs.release();
213  }
214 
217  {
218  assign(0);
219  }
220 
223  {
224  assign(rhs.release());
225  return *this;
226  }
227 
230  {
231  assign(p);
232  return *this;
233  }
234 
236  operator bool () const
237  {
238  return ptr != 0;
239  }
240 
243  {
244  return *ptr;
245  }
246 
249  {
250  return ptr;
251  }
252 
254  operator RawValue::Data * () const
255  {
256  return ptr;
257  }
258 
260  void assign(RawValue::Data *new_ptr)
261  {
262  if (ptr)
263  RawValue::free(ptr);
264  ptr = new_ptr;
265  }
266 
269  {
270  RawValue::Data *tmp = ptr;
271  ptr = 0;
272  return tmp;
273  }
274 
275 private:
276  PROHIBIT_DEFAULT_COPY(RawValueAutoPtr);
277  RawValue::Data *ptr;
278 };
279 
281 
282 #endif
~RawValueAutoPtr()
Destructor deletes owned pointer.
Definition: RawValue.h:216
RawValueSpecialSeverities
Non-CA events to the archiver; some are archived - some are directives.
Definition: RawValue.h:31
unsigned short DbrType
DbrType is used to hold dbr_time_xxx types.
Definition: RawValue.h:24
static bool getDouble(DbrType type, DbrCount count, const Data *value, double &d, int i=0)
Get data as a double or return false.
Exponential notation.
Definition: RawValue.h:165
Meta-information for values: Units, limits, etc .
Definition: CtrlInfo.h:75
RawValue::Data * operator->() const
Allow access just like ordinary pointer.
Definition: RawValue.h:248
NumberFormat
Used by getValueString.
Definition: RawValue.h:160
RawValue::Data * release()
Release ownership.
Definition: RawValue.h:268
void assign(RawValue::Data *new_ptr)
Assign a new pointer, deleting existing one.
Definition: RawValue.h:260
static short getStat(const Data *value)
Get status.
Definition: RawValue.h:89
static void setStatus(Data *value, short status, short severity)
Set status and severity.
Definition: RawValue.h:115
Decimal or exponential, &quot;%g&quot; format.
Definition: RawValue.h:162
static void setTime(Data *value, const epicsTime &stamp)
Set time stamp.
Definition: RawValue.h:132
Exponential 0.000e000 with exponent = 3*N.
Definition: RawValue.h:164
static size_t formatDouble(double number, NumberFormat format, int prec, char *buffer, size_t max_len)
Concert value to buffer.
static short getSevr(const Data *value)
Get severity.
Definition: RawValue.h:93
Helper class for raw dbr_time_xxx values.
Definition: RawValue.h:49
unsigned short DbrCount
DbrCount is used to hold the array size of CA channels.
Definition: RawValue.h:27
static void getValueString(std::string &text, DbrType type, DbrCount count, const Data *value, const class CtrlInfo *info=0, NumberFormat format=DECIMAL, int prec=-1)
Convert value to txt, using CtrlInfo if available.
static void show(FILE *file, DbrType type, DbrCount count, const Data *value, const class CtrlInfo *info=0)
Display value, using CtrlInfo if available.
RawValueAutoPtr & operator=(RawValueAutoPtr &rhs)
Copying from other AutoPtr causes rhs to release ownership.
Definition: RawValue.h:222
static void copy(DbrType type, DbrCount count, Data *lhs, const Data *rhs)
Full copy (stat, time, value). Only valid for Values of same type.
Definition: RawValue.h:85
static bool isAboveZero(DbrType type, const Data *value)
Check the value to see if it&#39;s above zero.
static bool isInfo(const Data *value)
Does the severity represent one of the special ARCH_xxx values that does not carry any value...
Definition: RawValue.h:101
static size_t getSize(DbrType type, DbrCount count)
Calculate size of a single value of type/count.
RawValueAutoPtr(RawValue::Data *in)
Assign pointer to AutoPtr.
Definition: RawValue.h:207
static const epicsTime getTime(const Data *value)
Get time stamp.
Definition: RawValue.h:125
static bool hasSameValue(DbrType type, DbrCount count, size_t size, const Data *lhs, const Data *rhs)
Compare the value part of two RawValues, not the time stamp or status! (for full comparison, use equal()).
static void toString(std::string &text, DbrType type, DbrCount count, const Data *value, const class CtrlInfo *info=0)
Convert current value to string.
RawValue::Data & operator*() const
Allow access just like ordinary pointer.
Definition: RawValue.h:242
static bool parseStatus(const std::string &text, short &stat, short &sevr)
Parse stat/sevr from text.
RawValueAutoPtr(RawValueAutoPtr &rhs)
Copying from other AutoPtr causes rhs to release ownership.
Definition: RawValue.h:210
static Data * allocate(DbrType type, DbrCount count, size_t num)
Allocate space (via calloc) for num samples of type/count.
static bool setDouble(DbrType type, DbrCount count, Data *value, double d)
Set data from a double or return false.
static bool getLong(DbrType type, DbrCount count, const Data *value, long &l, int i=0)
Get data as a long or return false.
static bool equal(DbrType type, DbrCount count, const Data *lhs, const Data *rhs)
Are two values equal?
Definition: RawValue.h:69
static void getStatus(const Data *value, std::string &status)
Get status/severity as string.
dbr_time_double Data
Type for accessing the raw data and its common fields.
Definition: RawValue.h:55
Decimal notation, 0.000.
Definition: RawValue.h:163
AutoPtr for RawValue.
Definition: RawValue.h:201
static void free(Data *value)
Free space for num samples of type/count.