34 #include <boost/format.hpp>
36 #include <rsc/runtime/Printable.h>
37 #include <rsc/runtime/TypeStringTools.h>
38 #include <rsc/runtime/NoSuchObject.h>
39 #include <rsc/logging/Logger.h>
44 #include "rsb/rsbexports.h"
58 template<
class WireType>
69 logger(rsc::logging::Logger::getLogger(
"rsb.converter.Repository")) {
77 for (
typename ConverterMap::const_iterator it =
79 std::string wireSchema = it->first.first;
80 std::string dataType = it->first.second;
84 if (selection.find(dataType) == selection.end()) {
87 }
catch (
const std::invalid_argument& e) {
88 std::set<std::string> wireSchemas;
89 for (
typename ConverterMap::const_iterator it_ =
92 if (dataType == it_->first.second)
93 wireSchemas.insert(it_->first.first);
95 throw std::runtime_error(
98 "Ambiguous converter set for wire-type `%1%' and data-type `%2%': candidate wire-schemas are %3%; hint: add a configuration option `transport.<name>.converter.cpp.<one of %3%> = %2%' to resolve the ambiguity.")
99 % rsc::runtime::typeName<WireType>()
100 % dataType % wireSchemas));
105 else if (wireSchema == selection.find(dataType)->second) {
107 "Found configured converter signature " << it->first);
119 for (
typename ConverterMap::const_iterator it =
121 std::string wireSchema = it->first.first;
122 std::string dataType = it->first.second;
126 if (selection.find(wireSchema) == selection.end()) {
129 }
catch (
const std::invalid_argument& e) {
130 std::set<std::string> dataTypes;
131 for (
typename ConverterMap::const_iterator it_ =
134 if (wireSchema == it_->first.first)
135 dataTypes.insert(it_->first.second);
137 throw std::runtime_error(
140 "Ambiguous converter set for wire-type `%1%' and wire-schema `%2%': candidate data-types are %3%; hint: add a configuration option `transport.<name>.converter.cpp.%2% = <one of %3%>' to resolve the ambiguity.")
141 % rsc::runtime::typeName<WireType>()
142 % wireSchema % dataTypes));
147 else if (dataType == selection.find(wireSchema)->second) {
149 "Found configured converter signature " << it->first);
164 std::string wireSchema = converter->getWireSchema();
165 std::string dataType = converter->getDataType();
166 if (this->
converters.find(std::make_pair(wireSchema, dataType))
169 throw std::invalid_argument(
172 "There already is a converter for wire-schema `%1%' and data-type `%2%'")
173 % wireSchema % dataType));
175 this->
converters[std::make_pair(wireSchema, dataType)] = converter;
179 const std::string& dataType)
const {
180 typename ConverterMap::const_iterator it = this->
converters.find(
181 std::make_pair(wireSchema, dataType));
183 throw rsc::runtime::NoSuchObject(
186 "Could not find a converter for wire-schema `%1%' and data-type `%2%'")
187 % wireSchema % dataType));
200 typedef boost::shared_ptr<Repository<WireType> >
Ptr;
209 return "Repository<" + rsc::runtime::typeName<WireType>() +
">";
214 for (
typename ConverterMap::const_iterator it =
216 stream <<
"\t" << std::setw(16) << std::left << it->first.first
217 <<
" <-> " << std::setw(16) << std::left << it->first.second
218 <<
": " << *it->second << std::endl;
262 virtual void* create() = 0;
285 template<
class WireType>
304 template<
class WireType>
309 rsc::runtime::typeName<WireType>(), creater),
310 rsc::misc::NullDeleter());