mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-14 00:49:41 -05:00
added extra parameters to generic map
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7166 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
e21564f72e
commit
15449cdc74
@ -36,6 +36,16 @@
|
||||
|
||||
#define TLV_DEBUG 1
|
||||
|
||||
/* generic print */
|
||||
template<class T>
|
||||
std::ostream & RsTlvParamRef<T>::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printIndent(out, indent);
|
||||
out << "Type: " << mParamType << "Param: " << mParam;
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
uint32_t RsTlvParamRef<uint32_t>::TlvSize()
|
||||
{
|
||||
@ -51,15 +61,16 @@ void RsTlvParamRef<uint32_t>::TlvClear()
|
||||
template<>
|
||||
bool RsTlvParamRef<uint32_t>::SetTlv(void *data, uint32_t size, uint32_t *offset)
|
||||
{
|
||||
return SetTlvUInt32(data, size, offset, TLV_TYPE_UINT32_PARAM, mParam);
|
||||
return SetTlvUInt32(data, size, offset, mParamType, mParam);
|
||||
}
|
||||
|
||||
template<>
|
||||
bool RsTlvParamRef<uint32_t>::GetTlv(void *data, uint32_t size, uint32_t *offset)
|
||||
{
|
||||
return GetTlvUInt32(data, size, offset, TLV_TYPE_UINT32_PARAM, &mParam);
|
||||
return GetTlvUInt32(data, size, offset, mParamType, &mParam);
|
||||
}
|
||||
|
||||
#if 0
|
||||
template<>
|
||||
std::ostream & RsTlvParamRef<uint32_t>::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
@ -67,6 +78,7 @@ std::ostream & RsTlvParamRef<uint32_t>::print(std::ostream &out, uint16_t indent
|
||||
out << mParam;
|
||||
return out;
|
||||
}
|
||||
#endif
|
||||
|
||||
/***** std::string ****/
|
||||
template<>
|
||||
@ -84,22 +96,24 @@ void RsTlvParamRef<std::string>::TlvClear()
|
||||
template<>
|
||||
bool RsTlvParamRef<std::string>::SetTlv(void *data, uint32_t size, uint32_t *offset)
|
||||
{
|
||||
return SetTlvString(data, size, offset, TLV_TYPE_STR_PARAM, mParam);
|
||||
return SetTlvString(data, size, offset, mParamType, mParam);
|
||||
}
|
||||
|
||||
template<>
|
||||
bool RsTlvParamRef<std::string>::GetTlv(void *data, uint32_t size, uint32_t *offset)
|
||||
{
|
||||
return GetTlvString(data, size, offset, TLV_TYPE_STR_PARAM, mParam);
|
||||
return GetTlvString(data, size, offset, mParamType, mParam);
|
||||
}
|
||||
|
||||
#if 0
|
||||
template<>
|
||||
std::ostream & RsTlvParamRef<std::string>::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printIndent(out, indent);
|
||||
out << mParam;
|
||||
out << "Type: " << mParamType << "Param: " << mParam;
|
||||
return out;
|
||||
}
|
||||
#endif
|
||||
|
||||
// declare likely combinations.
|
||||
template class RsTlvParamRef<uint32_t>;
|
||||
@ -110,8 +124,8 @@ template class RsTlvParamRef<std::string>;
|
||||
template<class K, class V>
|
||||
void RsTlvGenericPairRef<K, V>::TlvClear()
|
||||
{
|
||||
RsTlvParamRef<K> key(mKey);
|
||||
RsTlvParamRef<V> value(mValue);
|
||||
RsTlvParamRef<K> key(mKeyType, mKey);
|
||||
RsTlvParamRef<V> value(mValueType, mValue);
|
||||
key.TlvClear();
|
||||
value.TlvClear();
|
||||
}
|
||||
@ -120,8 +134,8 @@ template<class K, class V>
|
||||
uint32_t RsTlvGenericPairRef<K, V>::TlvSize()
|
||||
{
|
||||
uint32_t s = TLV_HEADER_SIZE; /* header */
|
||||
RsTlvParamRef<K> key(mKey);
|
||||
RsTlvParamRef<V> value(mValue);
|
||||
RsTlvParamRef<K> key(mKeyType, mKey);
|
||||
RsTlvParamRef<V> value(mValueType, mValue);
|
||||
|
||||
s += key.TlvSize();
|
||||
s += value.TlvSize();
|
||||
@ -144,8 +158,8 @@ bool RsTlvGenericPairRef<K, V>::SetTlv(void *data, uint32_t size, uint32_t *off
|
||||
/* start at data[offset] */
|
||||
ok &= SetTlvBase(data, tlvend, offset, mPairType, tlvsize);
|
||||
|
||||
RsTlvParamRef<K> key(mKey);
|
||||
RsTlvParamRef<V> value(mValue);
|
||||
RsTlvParamRef<K> key(mKeyType, mKey);
|
||||
RsTlvParamRef<V> value(mValueType, mValue);
|
||||
ok &= key.SetTlv(data, tlvend, offset);
|
||||
ok &= value.SetTlv(data, tlvend, offset);
|
||||
|
||||
@ -173,8 +187,8 @@ bool RsTlvGenericPairRef<K, V>::GetTlv(void *data, uint32_t size, uint32_t *off
|
||||
/* ready to load */
|
||||
TlvClear();
|
||||
|
||||
RsTlvParamRef<K> key(mKey);
|
||||
RsTlvParamRef<V> value(mValue);
|
||||
RsTlvParamRef<K> key(mKeyType, mKey);
|
||||
RsTlvParamRef<V> value(mValueType, mValue);
|
||||
ok &= key.GetTlv(data, tlvend, offset);
|
||||
ok &= value.GetTlv(data, tlvend, offset);
|
||||
|
||||
@ -202,8 +216,8 @@ std::ostream &RsTlvGenericPairRef<K, V>::print(std::ostream &out, uint16_t inden
|
||||
printBase(out, "RsTlvGenericPairRef", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
RsTlvParamRef<K> key(mKey);
|
||||
RsTlvParamRef<V> value(mValue);
|
||||
RsTlvParamRef<K> key(mKeyType, mKey);
|
||||
RsTlvParamRef<V> value(mValueType, mValue);
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "Key:";
|
||||
@ -241,7 +255,7 @@ uint32_t RsTlvGenericMapRef<K, V>::TlvSize()
|
||||
typename std::map<K, V>::iterator it;
|
||||
for(it = mRefMap.begin(); it != mRefMap.end(); ++it)
|
||||
{
|
||||
RsTlvGenericPairRef<const K, V> pair(mPairType, it->first, it->second);
|
||||
RsTlvGenericPairRef<const K, V> pair(mPairType, mKeyType, mValueType, it->first, it->second);
|
||||
s += pair.TlvSize();
|
||||
}
|
||||
|
||||
@ -267,7 +281,7 @@ bool RsTlvGenericMapRef<K, V>::SetTlv(void *data, uint32_t size, uint32_t *offs
|
||||
typename std::map<K, V>::iterator it;
|
||||
for(it = mRefMap.begin(); it != mRefMap.end(); ++it)
|
||||
{
|
||||
RsTlvGenericPairRef<const K, V> pair(mPairType, it->first, it->second);
|
||||
RsTlvGenericPairRef<const K, V> pair(mPairType, mKeyType, mValueType, it->first, it->second);
|
||||
ok &= pair.SetTlv(data, size, offset);
|
||||
}
|
||||
|
||||
@ -308,7 +322,7 @@ bool RsTlvGenericMapRef<K, V>::GetTlv(void *data, uint32_t size, uint32_t *offs
|
||||
{
|
||||
K k;
|
||||
V v;
|
||||
RsTlvGenericPairRef<const K, V> pair(mPairType, k, v);
|
||||
RsTlvGenericPairRef<const K, V> pair(mPairType, mKeyType, mValueType, k, v);
|
||||
ok &= pair.GetTlv(data, size, offset);
|
||||
if (ok)
|
||||
{
|
||||
@ -355,7 +369,7 @@ std::ostream &RsTlvGenericMapRef<K, V>::print(std::ostream &out, uint16_t indent
|
||||
typename std::map<K, V>::iterator it;
|
||||
for(it = mRefMap.begin(); it != mRefMap.end() ; ++it)
|
||||
{
|
||||
RsTlvGenericPairRef<const K, V> pair(mPairType, it->first, it->second);
|
||||
RsTlvGenericPairRef<const K, V> pair(mPairType, mKeyType, mValueType, it->first, it->second);
|
||||
pair.print(out, int_Indent);
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,7 @@ template<class T>
|
||||
class RsTlvParamRef: public RsTlvItem
|
||||
{
|
||||
public:
|
||||
RsTlvParamRef(T &p): mParam(p) {}
|
||||
RsTlvParamRef(uint16_t param_type, T &p): mParamType(param_type), mParam(p) {}
|
||||
virtual ~RsTlvParamRef() { return; }
|
||||
virtual uint32_t TlvSize();
|
||||
virtual void TlvClear();
|
||||
@ -50,6 +50,7 @@ virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset); /* seriali
|
||||
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset); /* deserialise */
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent);
|
||||
|
||||
uint16_t mParamType;
|
||||
T &mParam;
|
||||
};
|
||||
|
||||
@ -60,8 +61,11 @@ template<class K, class V>
|
||||
class RsTlvGenericPairRef: public RsTlvItem
|
||||
{
|
||||
public:
|
||||
RsTlvGenericPairRef(uint16_t pair_type, K &k, V &v)
|
||||
:mPairType(pair_type), mKey(k), mValue(v) { return; }
|
||||
RsTlvGenericPairRef(uint16_t pair_type,
|
||||
uint16_t key_type, uint16_t value_type, K &k, V &v)
|
||||
:mPairType(pair_type), mKeyType(key_type),
|
||||
mValueType(value_type), mKey(k), mValue(v) { return; }
|
||||
|
||||
virtual ~RsTlvGenericPairRef() { return; }
|
||||
virtual uint32_t TlvSize();
|
||||
virtual void TlvClear();
|
||||
@ -70,6 +74,8 @@ virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset); /* deseria
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent);
|
||||
|
||||
uint16_t mPairType;
|
||||
uint16_t mKeyType;
|
||||
uint16_t mValueType;
|
||||
K &mKey;
|
||||
V &mValue;
|
||||
};
|
||||
@ -81,8 +87,11 @@ template<class K, class V>
|
||||
class RsTlvGenericMapRef: public RsTlvItem
|
||||
{
|
||||
public:
|
||||
RsTlvGenericMapRef(uint16_t map_type, uint16_t pair_type, std::map<K, V> &refmap)
|
||||
:mMapType(map_type), mPairType(pair_type), mRefMap(refmap) { return; }
|
||||
RsTlvGenericMapRef(uint16_t map_type, uint16_t pair_type,
|
||||
uint16_t key_type, uint16_t value_type, std::map<K, V> &refmap)
|
||||
:mMapType(map_type), mPairType(pair_type),
|
||||
mKeyType(key_type), mValueType(value_type), mRefMap(refmap) { return; }
|
||||
|
||||
virtual ~RsTlvGenericMapRef() { return; }
|
||||
virtual uint32_t TlvSize();
|
||||
virtual void TlvClear();
|
||||
@ -92,6 +101,8 @@ virtual std::ostream &print(std::ostream &out, uint16_t indent);
|
||||
|
||||
uint16_t mMapType;
|
||||
uint16_t mPairType;
|
||||
uint16_t mKeyType;
|
||||
uint16_t mValueType;
|
||||
std::map<K, V> &mRefMap;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user