EPICS ARCHIVER V4
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups
Conversions.h
1 // -*- c++ -*-
2 
3 #include "tools/ToolsConfig.h"
4 #include "tools/epicsTimeHelper.h"
5 
6 #ifdef CONVERSION_REQUIRED
7 
8 // system
9 #include <stdint.h>
10 
11 // epics
12 #include <osiSock.h>
13 #include <db_access.h>
14 
15 inline void ULONGFromDisk(uint32_t &item)
16 { item = ntohl (item); }
17 
18 inline void ULONGToDisk(uint32_t &item)
19 { item = htonl (item); }
20 
21 inline void USHORTFromDisk(uint16_t &item)
22 { item = ntohs (item); }
23 
24 inline void USHORTToDisk(uint16_t &item)
25 {
26  uint16_t big_endian;
27  uint8_t *p = (uint8_t *)&big_endian;
28  p[0] = item >> 8;
29  p[1] = item & 0xFF;
30  item = big_endian;
31 }
32 
33 inline void DoubleFromDisk(double &d)
34 {
35  uint32_t cvrt_tmp = ntohl(((uint32_t *)&d)[0]);
36  ((uint32_t *)&d)[0] = ntohl(((uint32_t *)&d)[1]);
37  ((uint32_t *)&d)[1] = cvrt_tmp;
38 }
39 
40 inline void DoubleToDisk(double &d)
41 {
42  uint32_t cvrt_tmp = htonl(((uint32_t *)&d)[0]);
43  ((uint32_t *)&d)[0] = htonl(((uint32_t *)&d)[1]);
44  ((uint32_t *)&d)[1] = cvrt_tmp;
45 }
46 
47 inline void FloatFromDisk(float &d)
48 { *((uint32_t *)&d) = ntohl(*((uint32_t *)&d)); }
49 
50 inline void FloatToDisk(float &d)
51 { *((uint32_t *)&d) = htonl(*((uint32_t *)&d)); }
52 
53 inline void epicsTimeStampFromDisk(epicsTimeStamp &ts)
54 {
55  ts.secPastEpoch = ntohl(ts.secPastEpoch);
56  ts.nsec = ntohl(ts.nsec);
57 }
58 
59 inline void epicsTimeStampToDisk(epicsTimeStamp &ts)
60 {
61  ts.secPastEpoch = ntohl(ts.secPastEpoch);
62  ts.nsec = ntohl(ts.nsec);
63 }
64 
65 #define SHORTFromDisk(s) USHORTFromDisk((uint16_t &)s)
66 #define SHORTToDisk(s) USHORTToDisk((uint16_t &)s)
67 #define LONGFromDisk(l) ULONGFromDisk((uint32_t &)l)
68 #define LONGToDisk(l) ULONGToDisk((uint32_t &)l)
69 
70 #else
71 
72 #define ULONGFromDisk(s) {}
73 #define ULONGToDisk(i) {}
74 #define USHORTFromDisk(i) {}
75 #define USHORTToDisk(i) {}
76 #define DoubleFromDisk(i) {}
77 #define DoubleToDisk(i) {}
78 #define FloatFromDisk(i) {}
79 #define FloatToDisk(i) {}
80 #define epicsTimeStampFromDisk(i) {}
81 #define epicsTimeStampToDisk(i) {}
82 #define SHORTFromDisk(i) {}
83 #define SHORTToDisk(i) {}
84 #define LONGFromDisk(i) {}
85 #define LONGToDisk(i) {}
86 
87 #endif // CONVERSION_REQUIRED
88 
100 bool safeEpicsTimeStampFromDisk(epicsTimeStamp &stamp);
101 
102 #define FileOffsetFromDisk ULONGFromDisk
103 #define FileOffsetToDisk ULONGToDisk
104