reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
QValue.hxx
Go to the documentation of this file.
1#if !defined(RESIP_QVALUE_HXX)
2#define RESIP_QVALUE_HXX
3
4#include "rutil/Data.hxx"
6
7#ifndef RESIP_FIXED_POINT
8#include <math.h>
9// Required due to float point inaccuracies and platform dependent issues (ie. rounding)
10static int doubleToInt(const double d) { double f = floor(d); double c = ceil(d); return (((c-d) >= (d-f)) ? (int)f :(int)c); }
11#endif
12
13namespace resip
14{
15 class QValue
16 {
17 public:
18 explicit QValue() : mValue(0) { }
19 explicit QValue(int val) : mValue(val) { }
20 explicit QValue(const Data& data) { setValue(data); }
21
22 operator int() const { return mValue; }
23
24 bool operator<(const QValue& rhs) const { return mValue < rhs.mValue; }
25 bool operator>(const QValue& rhs) const { return mValue > rhs.mValue; }
26 bool operator<=(const QValue& rhs) const { return mValue <= rhs.mValue; }
27 bool operator>=(const QValue& rhs) const { return mValue >= rhs.mValue; }
28 bool operator==(const QValue& rhs) const { return mValue == rhs.mValue; }
29 bool operator!=(const QValue& rhs) const { return mValue != rhs.mValue; }
30
31 bool operator<(const int rhs) const { return mValue < rhs; }
32 bool operator>(const int rhs) const { return mValue > rhs; }
33 bool operator<=(const int rhs) const { return mValue <= rhs; }
34 bool operator>=(const int rhs) const { return mValue >= rhs; }
35 bool operator==(const int rhs) const { return mValue == rhs; }
36 bool operator!=(const int rhs) const { return mValue != rhs; }
37
38 bool operator<(const long rhs) const { return mValue < rhs; }
39 bool operator>(const long rhs) const { return mValue > rhs; }
40 bool operator<=(const long rhs) const { return mValue <= rhs; }
41 bool operator>=(const long rhs) const { return mValue >= rhs; }
42 bool operator==(const long rhs) const { return mValue == rhs; }
43 bool operator!=(const long rhs) const { return mValue != rhs; }
44
45 QValue& operator=(const QValue& rhs) { mValue = rhs.mValue; return (*this); }
46 QValue& operator=(const int rhs) { setValue(rhs); return (*this); }
47 QValue& operator=(const long rhs) { setValue(rhs); return (*this); }
48
49#ifndef RESIP_FIXED_POINT
50
51 float floatVal() const { return mValue/float(1000.0); }
52
53 operator float() const { return floatVal(); }
54 operator double() const { return (double) floatVal(); }
55
56 bool operator<(const float rhs) const { return mValue < doubleToInt(rhs*1000.0); }
57 bool operator>(const float rhs) const { return mValue > doubleToInt(rhs*1000.0); }
58 bool operator<=(const float rhs) const { return mValue <= doubleToInt(rhs*1000.0); }
59 bool operator>=(const float rhs) const { return mValue >= doubleToInt(rhs*1000.0); }
60 bool operator==(const float rhs) const { return mValue == doubleToInt(rhs*1000.0); }
61 bool operator!=(const float rhs) const { return mValue != doubleToInt(rhs*1000.0); }
62
63 bool operator<(const double rhs) const { return mValue < doubleToInt(rhs*1000.0); }
64 bool operator>(const double rhs) const { return mValue > doubleToInt(rhs*1000.0); }
65 bool operator<=(const double rhs) const { return mValue <= doubleToInt(rhs*1000.0); }
66 bool operator>=(const double rhs) const { return mValue >= doubleToInt(rhs*1000.0); }
67 bool operator==(const double rhs) const { return mValue == doubleToInt(rhs*1000.0); }
68 bool operator!=(const double rhs) const { return mValue != doubleToInt(rhs*1000.0); }
69
70 QValue& operator=(const float rhs) { setValue(doubleToInt(rhs*1000.0)); return (*this); }
71 QValue& operator=(const double rhs) { setValue(doubleToInt(rhs*1000.0)); return (*this); }
72#endif
73 void setValue(int val) { mValue = (val<0) || (val>1000) ? 1000 : val; }
74 void setValue(const Data& data) { ParseBuffer pb(data); mValue = pb.qVal(); }
75 int getValue() const { return mValue; }
76 const Data& getData() const;
77 EncodeStream& encode(EncodeStream& stream) const;
78
79 private:
80 int mValue;
81 mutable Data mDataValue;
82 };
83}
84
85#endif
86
87/* ====================================================================
88 * The Vovida Software License, Version 1.0
89 *
90 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
91 *
92 * Redistribution and use in source and binary forms, with or without
93 * modification, are permitted provided that the following conditions
94 * are met:
95 *
96 * 1. Redistributions of source code must retain the above copyright
97 * notice, this list of conditions and the following disclaimer.
98 *
99 * 2. Redistributions in binary form must reproduce the above copyright
100 * notice, this list of conditions and the following disclaimer in
101 * the documentation and/or other materials provided with the
102 * distribution.
103 *
104 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
105 * and "Vovida Open Communication Application Library (VOCAL)" must
106 * not be used to endorse or promote products derived from this
107 * software without prior written permission. For written
108 * permission, please contact vocal@vovida.org.
109 *
110 * 4. Products derived from this software may not be called "VOCAL", nor
111 * may "VOCAL" appear in their name, without prior written
112 * permission of Vovida Networks, Inc.
113 *
114 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
115 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
116 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
117 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
118 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
119 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
120 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
121 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
122 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
123 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
124 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
125 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
126 * DAMAGE.
127 *
128 * ====================================================================
129 *
130 * This software consists of voluntary contributions made by Vovida
131 * Networks, Inc. and many individuals on behalf of Vovida Networks,
132 * Inc. For more information on Vovida Networks, Inc., please see
133 * <http://www.vovida.org/>.
134 *
135 */
static int doubleToInt(const double d)
Definition QValue.hxx:10
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
Definition Data.hxx:90
Provides string-parsing functionality with protection from buffer overflow.
bool operator==(const float rhs) const
Definition QValue.hxx:60
int getValue() const
Definition QValue.hxx:75
bool operator>=(const long rhs) const
Definition QValue.hxx:41
bool operator>(const float rhs) const
Definition QValue.hxx:57
bool operator!=(const QValue &rhs) const
Definition QValue.hxx:29
bool operator>=(const QValue &rhs) const
Definition QValue.hxx:27
bool operator==(const int rhs) const
Definition QValue.hxx:35
bool operator>(const long rhs) const
Definition QValue.hxx:39
bool operator!=(const int rhs) const
Definition QValue.hxx:36
QValue & operator=(const double rhs)
Definition QValue.hxx:71
float floatVal() const
Definition QValue.hxx:51
bool operator!=(const long rhs) const
Definition QValue.hxx:43
bool operator>=(const float rhs) const
Definition QValue.hxx:59
EncodeStream & encode(EncodeStream &stream) const
Definition QValue.cxx:22
bool operator>=(const int rhs) const
Definition QValue.hxx:34
QValue & operator=(const float rhs)
Definition QValue.hxx:70
bool operator<(const QValue &rhs) const
Definition QValue.hxx:24
bool operator>(const int rhs) const
Definition QValue.hxx:32
QValue(int val)
Definition QValue.hxx:19
QValue & operator=(const int rhs)
Definition QValue.hxx:46
void setValue(int val)
Definition QValue.hxx:73
bool operator<=(const long rhs) const
Definition QValue.hxx:40
bool operator==(const double rhs) const
Definition QValue.hxx:67
bool operator<(const double rhs) const
Definition QValue.hxx:63
bool operator>(const QValue &rhs) const
Definition QValue.hxx:25
bool operator<(const float rhs) const
Definition QValue.hxx:56
bool operator<=(const int rhs) const
Definition QValue.hxx:33
bool operator<=(const double rhs) const
Definition QValue.hxx:65
bool operator!=(const double rhs) const
Definition QValue.hxx:68
QValue & operator=(const long rhs)
Definition QValue.hxx:47
QValue(const Data &data)
Definition QValue.hxx:20
bool operator<=(const QValue &rhs) const
Definition QValue.hxx:26
QValue & operator=(const QValue &rhs)
Definition QValue.hxx:45
bool operator!=(const float rhs) const
Definition QValue.hxx:61
bool operator<(const long rhs) const
Definition QValue.hxx:38
bool operator==(const long rhs) const
Definition QValue.hxx:42
bool operator<(const int rhs) const
Definition QValue.hxx:31
const Data & getData() const
Definition QValue.cxx:14
bool operator<=(const float rhs) const
Definition QValue.hxx:58
bool operator>(const double rhs) const
Definition QValue.hxx:64
bool operator>=(const double rhs) const
Definition QValue.hxx:66
void setValue(const Data &data)
Definition QValue.hxx:74
bool operator==(const QValue &rhs) const
Definition QValue.hxx:28
dcm! – add UnusedChecking(_enum) below;
#define EncodeStream
void list()
Definition userAdmin.cxx:66