1 #ifndef _framing_FieldValue_h
2 #define _framing_FieldValue_h
70 virtual uint32_t encodedSize()
const = 0;
80 virtual void print(std::ostream& out)
const = 0;
89 bool empty()
const {
return data.get() == 0; }
97 template <
typename T>
bool convertsTo()
const {
return false; }
100 template <
class T,
int W> T getIntegerValue()
const;
101 template <
class T> T getIntegerValue()
const;
102 template <
class T,
int W> T getFloatingPointValue()
const;
103 template <
int W>
void getFixedWidthValue(
unsigned char*)
const;
104 template <
class T>
bool get(T&)
const;
113 std::auto_ptr<Data> data;
118 inline bool FieldValue::convertsTo<int>()
const {
return data->convertsToInt(); }
121 inline bool FieldValue::convertsTo<int64_t>()
const {
return data->convertsToInt(); }
124 inline bool FieldValue::convertsTo<std::string>()
const {
return data->convertsToString(); }
127 inline int FieldValue::get<int>()
const {
return static_cast<int>(data->getInt()); }
130 inline int64_t FieldValue::get<int64_t>()
const {
return data->getInt(); }
133 inline std::string FieldValue::get<std::string>()
const {
return data->getString(); }
149 for (
int i = 0; i < width; i++) octets[i] = data[i];
153 for (
int i = width; i > 1; --i) {
154 octets[i-1] = (
uint8_t) (0xFF & v); v >>= 8;
156 octets[0] = (
uint8_t) (0xFF & v);
163 if (rhs == 0)
return false;
164 else return std::equal(&octets[0], &octets[width], &rhs->octets[0]);
171 for (
int i = 0; i < width-1; ++i) {
172 v |= octets[i]; v <<= 8;
174 v |= octets[width-1];
180 void print(std::ostream& o)
const { o <<
"F" << width <<
":"; };
183 template <
class T,
int W>
190 for (
int i = 0; i < W-1; ++i) {
191 v |= octets[i]; v <<= 8;
208 throw InvalidConversionException();
212 template <
class T,
int W>
219 for (
size_t i = 0; i < W; ++i) target[i] = octets[i];
230 for (
size_t i = 0; i < W; ++i) value[i] = fwv->
rawOctets()[i];
237 inline float FieldValue::get<float>()
const {
238 return getFloatingPointValue<float, 4>();
242 inline double FieldValue::get<double>()
const {
243 return getFloatingPointValue<double, 8>();
257 void print(std::ostream& o)
const { o <<
"F0"; };
260 template <
int lenw
idth>
262 std::vector<uint8_t> octets;
270 buffer.
putUInt<lenwidth>(octets.size());
271 if (octets.size() > 0)
282 if (rhs == 0)
return false;
283 else return octets==rhs->octets;
287 std::string
getString()
const {
return std::string(octets.begin(), octets.end()); }
289 void print(std::ostream& o)
const { o <<
"V" << lenwidth <<
":" << octets.size() <<
":"; };
306 value.encode(buffer);
309 value.decode(buffer);
313 if (rhs == 0)
return false;
314 else return value==rhs->value;
317 void print(std::ostream& o)
const { o <<
"[" << value <<
"]"; };