template<class OutputIterator> inline void tws::core::copy_string_array(const rapidjson::Value& jvalues, OutputIterator result) { if(!jvalues.IsArray()) throw conversion_error() << tws::error_description("copy_string_array: can only copy arrays of strings."); if(jvalues.Empty()) return; const rapidjson::SizeType nelements = jvalues.Size(); for(rapidjson::SizeType i = 0; i != nelements; ++i) { const rapidjson::Value& jelement = jvalues[i]; if(!jelement.IsString()) throw conversion_error() << tws::error_description("copy_string_array: only string elements are allowed in array."); if(jelement.IsNull()) continue; *result++ = jelement.GetString(); } }
typename document_info_context_from<DocumentInfo>::data_type document_info_context_from<DocumentInfo>:: from_string(const std::string& from) const { // Read document and owner id unsigned int owner_id, document_id; std::stringstream stream(from); on_stream_setup(stream); stream >> owner_id >> document_id; // Successful conversion? if(stream.bad() ) throw conversion_error("Document ID ought to be two integers"); // Lookup document data_type info = m_buffer.document_find(owner_id, document_id); if(info == NULL) { // No such document obby::format_string str("Document ID %0%/%1% does not exist"); str << owner_id << document_id; throw conversion_error(str.str() ); } return info; }
void conversion_error::throw_(const char* file, std::size_t line, std::string const& descr) { boost::throw_exception(boost::enable_error_info(conversion_error(descr)) << boost::throw_file(file) << boost::throw_line(line) ); }
ostream::string path_to_stream(fs::path const& path) { cygwin_conv_path_t flags = CCP_WIN_W_TO_POSIX | CCP_RELATIVE; ssize_t size = cygwin_conv_path(flags, path.native().c_str(), NULL, 0); if (size < 0) throw conversion_error("Error converting windows path to cygwin."); boost::scoped_array<char> result(new char[size]); if(cygwin_conv_path(flags, path.native().c_str(), result.get(), size)) throw conversion_error("Error converting windows path to cygwin."); return std::string(result.get()); }
encoder operator<<(encoder e, const value& v) { data edata = e.data(); if (edata == v.data_) throw conversion_error("cannot insert into self"); data vdata = v.decode().data(); check(edata.append(vdata), e.pn_object()); return e; }
Reader& Reader::operator() (uint8_t &i,const char *fmt) { uint64_t val; if (! (*this)(val)) return *this; if (val > UINT8_MAX) return conversion_error("uchar",val,true); i = (uint8_t)val; return *this; }
Reader& Reader::operator() (int16_t &i,const char *fmt) { int64_t val; if (! (*this)(val)) return *this; if (val < INT16_MIN || val > INT16_MAX) return conversion_error("int16",val,false); i = (int16_t)val; return *this; }
inline conversion_error make_conversion_error(type_id want, type_id got, const std::string& msg=std::string()) { std::ostringstream s; s << "unexpected type, want: " << want << " got: " << got; if (!msg.empty()) s << ": " << msg; return conversion_error(s.str()); }
fs::path command_line_to_path(command_line_string const& path) { cygwin_conv_path_t flags = CCP_POSIX_TO_WIN_W | CCP_RELATIVE; ssize_t size = cygwin_conv_path(flags, path.c_str(), NULL, 0); if (size < 0) throw conversion_error("Error converting cygwin path to windows."); boost::scoped_array<char> result(new char[size]); void* ptr = result.get(); if(cygwin_conv_path(flags, path.c_str(), ptr, size)) throw conversion_error("Error converting cygwin path to windows."); return fs::path(static_cast<wchar_t*>(ptr)); }
fs::path input_to_path(input_string const& path) { cygwin_conv_path_t flags = CCP_POSIX_TO_WIN_W | CCP_RELATIVE; ssize_t size = cygwin_conv_path(flags, path.c_str(), NULL, 0); if (size < 0) throw conversion_error("Error converting cygwin path to windows."); // TODO: size is in bytes. boost::scoped_array<wchar_t> result(new wchar_t[size]); if(cygwin_conv_path(flags, path.c_str(), result.get(), size)) throw conversion_error("Error converting cygwin path to windows."); return fs::path(result.get()); }
encoder operator<<(encoder e, const start& s) { switch (s.type) { case ARRAY: pn_data_put_array(e.pn_object(), s.is_described, pn_type_t(s.element)); break; case MAP: pn_data_put_map(e.pn_object()); break; case LIST: pn_data_put_list(e.pn_object()); break; case DESCRIBED: pn_data_put_described(e.pn_object()); break; default: throw conversion_error(MSG("" << s.type << " is not a container type")); } pn_data_enter(e.pn_object()); return e; }
template<class InputIterator> inline void tws::core::copy_numeric_array(InputIterator first, InputIterator last, rapidjson::Value& jvalues, rapidjson::Document::AllocatorType& allocator) { if(!jvalues.IsArray()) throw conversion_error() << tws::error_description("copy_numeric_array: can only copy arrays of numeric data."); while(first != last) { jvalues.PushBack(*first, allocator); ++first; } }
std::basic_string<CharOut> utf_to_utf(CharIn const *begin,CharIn const *end,method_type how = default_method) { std::basic_string<CharOut> result; result.reserve(end-begin); typedef std::back_insert_iterator<std::basic_string<CharOut> > inserter_type; inserter_type inserter(result); utf::code_point c; while(begin!=end) { c=utf::utf_traits<CharIn>::template decode<CharIn const *>(begin,end); if(c==utf::illegal || c==utf::incomplete) { if(how==stop) throw conversion_error(); } else { utf::utf_traits<CharOut>::template encode<inserter_type>(c,inserter); } } return result; }
conversion_error make_coercion_error(const char* cpp, type_id amqp) { return conversion_error(std::string("invalid proton::coerce<") + cpp + ">(" + type_name(amqp) + ")"); }
template <class T> T check(T result) { if (result < 0) throw conversion_error(error_str(result)); return result; }