source: ntrip/trunk/BNC/RTCM/m_data.h@ 201

Last change on this file since 201 was 35, checked in by mervart, 19 years ago

Imported sources

File size: 2.7 KB
RevLine 
[35]1// -*- C++ -*-
2//
3// $Id: m_data.h,v 1.1.1.1 2006/01/11 09:34:31 mervart Exp $
4//
5
6#if !defined(__m_data_h__)
7// protects the header from been included more than once
8#define __m_data_h__
9
10#include <time.h>
11#include <ctype.h>
12
13#include <string>
14#include <vector>
15#include <map>
16
17#include <typeinfo>
18
19#include <cstdarg>
20#include <iomanip>
21
22
23#include <iostream>
24#include <fstream>
25
26#if defined(__GNUC_MINOR__) && ( __GNUC_MINOR__ < 91 )
27#else
28using namespace std;
29#endif
30
31template<class T>
32void WriteNative(ostream &os,const T & data) {
33#if 1
34 os.write(reinterpret_cast<const char *>(&data),sizeof(data));
35#else
36 int i;
37 os << typeid(data).name() << " " << sizeof(data) << " ";
38 for(i= 0;i<sizeof(data);i++) {
39 int byte ( ((unsigned char *)(&data))[i] );
40 os << hex << " " << byte;
41 }
42 os << endl;
43#endif
44}
45
46template<class T1,class T2>
47void WriteNative(ostream & os,const map<T1,T2> &m) {
48 WriteNative(os,m.size());
49 typedef typename map<T1,T2>::iterator I;
50 I i;
51 for(i=m.begin();i<m.end();i++) {
52 WriteNative(os,*i);
53 }
54}
55
56
57// C_Data<T> Wrapper for Scalar types T
58
59template<class T>
60class C_Data {
61public:
62 typedef T DataType;
63
64 explicit C_Data(DataType _data= 0):data(_data) {}
65 C_Data(const C_Data & org):data(org.get()) {}
66 C_Data &operator= ( const C_Data &newValue) {
67 set(newValue.get());
68 return *this;
69 }
70 // bool operator == (T other) { return get() == other.get(); }
71 // bool operator != (T other) { return get() != other.get(); }
72
73 ~C_Data() {}
74
75 void writeNative(ostream &os) const {
76 WriteNative(os,data);
77 }
78
79 void set(const DataType &newValue) {
80 data = newValue;
81 }
82
83 const DataType &get() const {
84 return data;
85 }
86
87protected:
88 DataType data;
89} ;
90
91template <class T>
92bool operator<(const C_Data<T> &d1,const C_Data<T> &d2) {
93 return d1.get() < d2.get();
94}
95
96template <class T>
97bool operator>(const C_Data<T> &d1,const C_Data<T> &d2) {
98 return d1.get() > d2.get();
99}
100
101template <class T>
102bool operator==(const C_Data<T> &d1,const C_Data<T> &d2) {
103 return d1.get() == d2.get();
104}
105
106template <class T>
107bool operator!=(const C_Data<T> &d1,const C_Data<T> &d2) {
108 return d1.get() != d2.get();
109}
110
111template <class T>
112bool operator<=(const C_Data<T> &d1,const C_Data<T> &d2) {
113 return ( d1.get() == d2.get() )
114 || ( d1.get() < d2.get() ) ;
115}
116
117template <class T>
118C_Data<T> operator-(const C_Data<T> &d1,const C_Data<T> &d2) {
119 return C_Data<T>(d1.get() - d2.get());
120}
121
122template <class T>
123void WriteNative(ostream &os,const C_Data<T> c_data) {
124 c_data.writeNative(os);
125}
126
127
128
129
130template <class T2,class T3>
131void divmod(const long numer,const long denom,T2 &quot,T3 &rem) {
132 ldiv_t res;
133 ldiv(numer,denom);
134 quot = res.quot;
135 rem = res.rem;
136}
137
138
139#endif
Note: See TracBrowser for help on using the repository browser.