Debian Codegraph @

Xpjproject/pjlib/include/pj++/types.hpp

raw symbols SCIP
1 /*
2 * Copyright (C) 2008-2009 Teluu Inc. (http://www.teluu.com)
3 * Copyright (C) 2003-2008 Benny Prijono <[email protected]>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19 #ifndef __PJPP_TYPES_HPP__
20 #define __PJPP_TYPES_HPP__
21
22 #include <pj/types.h>
23
24 class Pj_Pool;
25 class Pj_Socket ;
26 class Pj_Lock;
27
28
29 //
30 // PJLIB initializer.
31 //
32 class Pjlib
33 {
34 public:
35 Pjlib()
36 {
37 pj_init();
38 }
39 };
40
41 //
42 // Class Pj_Object is declared in pool.hpp
43 //
44
45 //
46 // Time value wrapper.
47 //
48 class Pj_Time_Val : public pj_time_val
49 {
50 public:
51 Pj_Time_Val()
52 {
53 }
54
55 Pj_Time_Val(long init_sec, long init_msec)
56 {
57 sec = init_sec;
58 msec = init_msec;
59 }
60
61 Pj_Time_Val(const Pj_Time_Val &rhs)
62 {
63 sec=rhs.sec;
64 msec=rhs.msec;
65 }
66
67 explicit Pj_Time_Val(const pj_time_val &tv)
68 {
69 sec = tv.sec;
70 msec = tv.msec;
71 }
72
73 long get_sec() const
74 {
75 return sec;
76 }
77
78 long get_msec() const
79 {
80 return msec;
81 }
82
83 void set_sec (long s)
84 {
85 sec = s;
86 }
87
88 void set_msec(long ms)
89 {
90 msec = ms;
91 normalize();
92 }
93
94 long to_msec() const
95 {
96 return PJ_TIME_VAL_MSEC((*this));
97 }
98
99 bool operator == (const Pj_Time_Val &rhs) const
100 {
101 return PJ_TIME_VAL_EQ((*this), rhs);
102 }
103
104 bool operator > (const Pj_Time_Val &rhs) const
105 {
106 return PJ_TIME_VAL_GT((*this), rhs);
107 }
108
109 bool operator >= (const Pj_Time_Val &rhs) const
110 {
111 return PJ_TIME_VAL_GTE((*this), rhs);
112 }
113
114 bool operator < (const Pj_Time_Val &rhs) const
115 {
116 return PJ_TIME_VAL_LT((*this), rhs);
117 }
118
119 bool operator <= (const Pj_Time_Val &rhs) const
120 {
121 return PJ_TIME_VAL_LTE((*this), rhs);
122 }
123
124 Pj_Time_Val & operator = (const Pj_Time_Val &rhs)
125 {
126 sec = rhs.sec;
127 msec = rhs.msec;
128 return *this;
129 }
130
131 Pj_Time_Val & operator += (const Pj_Time_Val &rhs)
132 {
133 PJ_TIME_VAL_ADD((*this), rhs);
134 return *this;
135 }
136
137 Pj_Time_Val & operator -= (const Pj_Time_Val &rhs)
138 {
139 PJ_TIME_VAL_SUB((*this), rhs);
140 return *this;
141 }
142
143 /* Must include os.hpp to use these, otherwise unresolved in linking */
144 inline pj_status_t gettimeofday();
145 inline pj_parsed_time decode();
146 inline pj_status_t encode(const pj_parsed_time *pt);
147 inline pj_status_t to_gmt();
148 inline pj_status_t to_local();
149
150
151 private:
152 void normalize()
153 {
154 pj_time_val_normalize(this);
155 }
156
157 };
158
159 //
160 // Macro to declare common object comparison operators.
161 //
162 #define PJ_DECLARE_OPERATORS(rhs_type) \
163 bool operator!=(rhs_type rhs) const { \
164 return !operator==(rhs); } \
165 bool operator<=(rhs_type rhs) const { \
166 return operator<(rhs) || operator==(rhs); } \
167 bool operator>(rhs_type rhs) const { \
168 return !operator<=(rhs); } \
169 bool operator>=(rhs_type rhs) const { \
170 return !operator<(rhs); }
171
172
173 #endif /* __PJPP_TYPES_HPP__ */
174