mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-14 08:59:50 -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
|
#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<>
|
template<>
|
||||||
uint32_t RsTlvParamRef<uint32_t>::TlvSize()
|
uint32_t RsTlvParamRef<uint32_t>::TlvSize()
|
||||||
{
|
{
|
||||||
@ -51,15 +61,16 @@ void RsTlvParamRef<uint32_t>::TlvClear()
|
|||||||
template<>
|
template<>
|
||||||
bool RsTlvParamRef<uint32_t>::SetTlv(void *data, uint32_t size, uint32_t *offset)
|
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<>
|
template<>
|
||||||
bool RsTlvParamRef<uint32_t>::GetTlv(void *data, uint32_t size, uint32_t *offset)
|
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<>
|
template<>
|
||||||
std::ostream & RsTlvParamRef<uint32_t>::print(std::ostream &out, uint16_t indent)
|
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;
|
out << mParam;
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/***** std::string ****/
|
/***** std::string ****/
|
||||||
template<>
|
template<>
|
||||||
@ -84,22 +96,24 @@ void RsTlvParamRef<std::string>::TlvClear()
|
|||||||
template<>
|
template<>
|
||||||
bool RsTlvParamRef<std::string>::SetTlv(void *data, uint32_t size, uint32_t *offset)
|
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<>
|
template<>
|
||||||
bool RsTlvParamRef<std::string>::GetTlv(void *data, uint32_t size, uint32_t *offset)
|
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<>
|
template<>
|
||||||
std::ostream & RsTlvParamRef<std::string>::print(std::ostream &out, uint16_t indent)
|
std::ostream & RsTlvParamRef<std::string>::print(std::ostream &out, uint16_t indent)
|
||||||
{
|
{
|
||||||
printIndent(out, indent);
|
printIndent(out, indent);
|
||||||
out << mParam;
|
out << "Type: " << mParamType << "Param: " << mParam;
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// declare likely combinations.
|
// declare likely combinations.
|
||||||
template class RsTlvParamRef<uint32_t>;
|
template class RsTlvParamRef<uint32_t>;
|
||||||
@ -110,8 +124,8 @@ template class RsTlvParamRef<std::string>;
|
|||||||
template<class K, class V>
|
template<class K, class V>
|
||||||
void RsTlvGenericPairRef<K, V>::TlvClear()
|
void RsTlvGenericPairRef<K, V>::TlvClear()
|
||||||
{
|
{
|
||||||
RsTlvParamRef<K> key(mKey);
|
RsTlvParamRef<K> key(mKeyType, mKey);
|
||||||
RsTlvParamRef<V> value(mValue);
|
RsTlvParamRef<V> value(mValueType, mValue);
|
||||||
key.TlvClear();
|
key.TlvClear();
|
||||||
value.TlvClear();
|
value.TlvClear();
|
||||||
}
|
}
|
||||||
@ -120,8 +134,8 @@ template<class K, class V>
|
|||||||
uint32_t RsTlvGenericPairRef<K, V>::TlvSize()
|
uint32_t RsTlvGenericPairRef<K, V>::TlvSize()
|
||||||
{
|
{
|
||||||
uint32_t s = TLV_HEADER_SIZE; /* header */
|
uint32_t s = TLV_HEADER_SIZE; /* header */
|
||||||
RsTlvParamRef<K> key(mKey);
|
RsTlvParamRef<K> key(mKeyType, mKey);
|
||||||
RsTlvParamRef<V> value(mValue);
|
RsTlvParamRef<V> value(mValueType, mValue);
|
||||||
|
|
||||||
s += key.TlvSize();
|
s += key.TlvSize();
|
||||||
s += value.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] */
|
/* start at data[offset] */
|
||||||
ok &= SetTlvBase(data, tlvend, offset, mPairType, tlvsize);
|
ok &= SetTlvBase(data, tlvend, offset, mPairType, tlvsize);
|
||||||
|
|
||||||
RsTlvParamRef<K> key(mKey);
|
RsTlvParamRef<K> key(mKeyType, mKey);
|
||||||
RsTlvParamRef<V> value(mValue);
|
RsTlvParamRef<V> value(mValueType, mValue);
|
||||||
ok &= key.SetTlv(data, tlvend, offset);
|
ok &= key.SetTlv(data, tlvend, offset);
|
||||||
ok &= value.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 */
|
/* ready to load */
|
||||||
TlvClear();
|
TlvClear();
|
||||||
|
|
||||||
RsTlvParamRef<K> key(mKey);
|
RsTlvParamRef<K> key(mKeyType, mKey);
|
||||||
RsTlvParamRef<V> value(mValue);
|
RsTlvParamRef<V> value(mValueType, mValue);
|
||||||
ok &= key.GetTlv(data, tlvend, offset);
|
ok &= key.GetTlv(data, tlvend, offset);
|
||||||
ok &= value.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);
|
printBase(out, "RsTlvGenericPairRef", indent);
|
||||||
uint16_t int_Indent = indent + 2;
|
uint16_t int_Indent = indent + 2;
|
||||||
|
|
||||||
RsTlvParamRef<K> key(mKey);
|
RsTlvParamRef<K> key(mKeyType, mKey);
|
||||||
RsTlvParamRef<V> value(mValue);
|
RsTlvParamRef<V> value(mValueType, mValue);
|
||||||
|
|
||||||
printIndent(out, int_Indent);
|
printIndent(out, int_Indent);
|
||||||
out << "Key:";
|
out << "Key:";
|
||||||
@ -241,7 +255,7 @@ uint32_t RsTlvGenericMapRef<K, V>::TlvSize()
|
|||||||
typename std::map<K, V>::iterator it;
|
typename std::map<K, V>::iterator it;
|
||||||
for(it = mRefMap.begin(); it != mRefMap.end(); ++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();
|
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;
|
typename std::map<K, V>::iterator it;
|
||||||
for(it = mRefMap.begin(); it != mRefMap.end(); ++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);
|
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;
|
K k;
|
||||||
V v;
|
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);
|
ok &= pair.GetTlv(data, size, offset);
|
||||||
if (ok)
|
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;
|
typename std::map<K, V>::iterator it;
|
||||||
for(it = mRefMap.begin(); it != mRefMap.end() ; ++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);
|
pair.print(out, int_Indent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ template<class T>
|
|||||||
class RsTlvParamRef: public RsTlvItem
|
class RsTlvParamRef: public RsTlvItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RsTlvParamRef(T &p): mParam(p) {}
|
RsTlvParamRef(uint16_t param_type, T &p): mParamType(param_type), mParam(p) {}
|
||||||
virtual ~RsTlvParamRef() { return; }
|
virtual ~RsTlvParamRef() { return; }
|
||||||
virtual uint32_t TlvSize();
|
virtual uint32_t TlvSize();
|
||||||
virtual void TlvClear();
|
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 bool GetTlv(void *data, uint32_t size, uint32_t *offset); /* deserialise */
|
||||||
virtual std::ostream &print(std::ostream &out, uint16_t indent);
|
virtual std::ostream &print(std::ostream &out, uint16_t indent);
|
||||||
|
|
||||||
|
uint16_t mParamType;
|
||||||
T &mParam;
|
T &mParam;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -60,8 +61,11 @@ template<class K, class V>
|
|||||||
class RsTlvGenericPairRef: public RsTlvItem
|
class RsTlvGenericPairRef: public RsTlvItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RsTlvGenericPairRef(uint16_t pair_type, K &k, V &v)
|
RsTlvGenericPairRef(uint16_t pair_type,
|
||||||
:mPairType(pair_type), mKey(k), mValue(v) { return; }
|
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 ~RsTlvGenericPairRef() { return; }
|
||||||
virtual uint32_t TlvSize();
|
virtual uint32_t TlvSize();
|
||||||
virtual void TlvClear();
|
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);
|
virtual std::ostream &print(std::ostream &out, uint16_t indent);
|
||||||
|
|
||||||
uint16_t mPairType;
|
uint16_t mPairType;
|
||||||
|
uint16_t mKeyType;
|
||||||
|
uint16_t mValueType;
|
||||||
K &mKey;
|
K &mKey;
|
||||||
V &mValue;
|
V &mValue;
|
||||||
};
|
};
|
||||||
@ -81,8 +87,11 @@ template<class K, class V>
|
|||||||
class RsTlvGenericMapRef: public RsTlvItem
|
class RsTlvGenericMapRef: public RsTlvItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RsTlvGenericMapRef(uint16_t map_type, uint16_t pair_type, std::map<K, V> &refmap)
|
RsTlvGenericMapRef(uint16_t map_type, uint16_t pair_type,
|
||||||
:mMapType(map_type), mPairType(pair_type), mRefMap(refmap) { return; }
|
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 ~RsTlvGenericMapRef() { return; }
|
||||||
virtual uint32_t TlvSize();
|
virtual uint32_t TlvSize();
|
||||||
virtual void TlvClear();
|
virtual void TlvClear();
|
||||||
@ -92,6 +101,8 @@ virtual std::ostream &print(std::ostream &out, uint16_t indent);
|
|||||||
|
|
||||||
uint16_t mMapType;
|
uint16_t mMapType;
|
||||||
uint16_t mPairType;
|
uint16_t mPairType;
|
||||||
|
uint16_t mKeyType;
|
||||||
|
uint16_t mValueType;
|
||||||
std::map<K, V> &mRefMap;
|
std::map<K, V> &mRefMap;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user