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