#pragma once #include #include "ApiTypes.h" namespace resource_api { // note: pass the KeyValueReference and ValueReference objects by value to enable such things: // stream << somefunc(); // can't get a reference to the return value of somefunc // uint32_t to std::string with decimal numbers StreamBase& operator <<(StreamBase& left, KeyValueReference ref); // convert retroshare ids to strings and back //template //StreamBase& operator <<(StreamBase& left, t_RsGenericIdType& id); // operators for retroshare ids /* template StreamBase& operator <<(StreamBase& left, ValueReference& ref); */ template StreamBase& operator <<(StreamBase& left, KeyValueReference ref); template StreamBase& operator <<(StreamBase& left, ValueReference ref); //template //StreamBase& operator <<(StreamBase& left, KeyValueReference >& ref); // implementations // idea: each rs generic id type has a number // put this number in front of the id data to make the ids type safe, even across languages template StreamBase& operator <<(StreamBase& left, KeyValueReference ref) //template //StreamBase& operator <<(StreamBase& left, KeyValueReference >& ref) { if(left.serialise()) { std::string idStr = ref.value.toStdString(); left << makeKeyValueReference(ref.key, idStr); } else { std::string str; left << makeKeyValueReference(ref.key, str); //t_RsGenericIdType id(str); T_ID id(str); if(id.isNull()) { left.setError(); left.addErrorMsg("operator for retroshare id keyValue: id is null\n"); } ref.value = id; } return left; } template StreamBase& operator <<(StreamBase& left, ValueReference ref) { if(left.serialise()) { std::string idStr = ref.value.toStdString(); left << makeValueReference(idStr); } else { std::string str; left << makeValueReference(str); T_ID id(str); if(id.isNull()) { left.setError(); left.addErrorMsg("operator for retroshare id Value: id is null\n"); } ref.value = id; } return left; } } // namespace resource_api