From 7c70d21ca2d788d4432cfa89851c9b928c9f30aa Mon Sep 17 00:00:00 2001 From: Gordon Sim Date: Fri, 19 Sep 2008 22:31:45 +0000 Subject: Support floats and doubles in field tables. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@697269 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/src/qpid/framing/FieldTable.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'cpp/src/qpid/framing/FieldTable.cpp') diff --git a/cpp/src/qpid/framing/FieldTable.cpp b/cpp/src/qpid/framing/FieldTable.cpp index a85f5e0918..cf8f1b5eed 100644 --- a/cpp/src/qpid/framing/FieldTable.cpp +++ b/cpp/src/qpid/framing/FieldTable.cpp @@ -87,6 +87,14 @@ void FieldTable::setArray(const std::string& name, const Array& value) values[name] = ValuePtr(new ArrayValue(value)); } +void FieldTable::setFloat(const std::string& name, float value){ + values[name] = ValuePtr(new FloatValue(value)); +} + +void FieldTable::setDouble(const std::string& name, double value){ + values[name] = ValuePtr(new DoubleValue(value)); +} + FieldTable::ValuePtr FieldTable::get(const std::string& name) const { ValuePtr value; @@ -131,6 +139,27 @@ bool FieldTable::getArray(const std::string& name, Array& value) const { return getEncodedValue(get(name), value); } +template +bool getRawFixedWidthValue(FieldTable::ValuePtr vptr, T& value) +{ + if (vptr && vptr->getType() == typecode) { + FixedWidthValue* fwv = dynamic_cast< FixedWidthValue* >(&vptr->getData()); + if (fwv) { + fwv->copyInto(reinterpret_cast(&value)); + return true; + } + } + return false; +} + +bool FieldTable::getFloat(const std::string& name, float& value) const { + return getRawFixedWidthValue(get(name), value); +} + +bool FieldTable::getDouble(const std::string& name, double& value) const { + return getRawFixedWidthValue(get(name), value); +} + void FieldTable::encode(Buffer& buffer) const{ buffer.putLong(size() - 4); buffer.putLong(values.size()); -- cgit v1.2.1