Наши проекты:
Журнал · Discuz!ML · Wiki · DRKB · Помощь проекту |
||
ПРАВИЛА | FAQ | Помощь | Поиск | Участники | Календарь | Избранное | RSS |
[18.223.196.171] |
|
Страницы: (3) 1 [2] 3 все ( Перейти к последнему сообщению ) |
Сообщ.
#16
,
|
|
|
да он собирается без ошибок и предупреждений. Но вот при выполнении вываливает при сериализацции typedef std::vector <std::pair<int, IBase *> > VecType; тоесть пары, содержащей интерфейс Unhandled exception at 0x7c81eb33 in serialyze.exe: Microsoft C++ exception: boost::archive::archive_exception at memory location 0x0012d640.. посмотрел в отладке на template<class E> inline void throw_exception(E const & e) { throw e; } который бросается, так вот код вроде = unregistered_cast |
Сообщ.
#17
,
|
|
|
Цитата zss @ код вроде = unregistered_cast Ты сериализируешь производный класс по указателю на базовый. Помочь бусту нужно - пропиши в началале Some::serialize строчку: archive.register_type(static_cast<Base*>(NULL)); |
Сообщ.
#18
,
|
|
|
Hryak, я тут немного изврвщаюсь и опять не пойму, что от меня хочет boost.
Есть подозрение, что что-то с типами не так это устройство для контейнера template<typename Container> class rcontainer /*: public boost::iostreams::source*/ { private: typedef typename Container::size_type size_type; const Container& m_container; size_type m_index; public: typedef typename Container::value_type char_type; typedef boost::iostreams::source_tag category; rcontainer (const Container& container) : m_container(container), m_index(0) {} ~rcontainer () {} std::streamsize read (char_type* value, std::streamsize size) { std::streamsize delta = static_cast<std::streamsize> ( m_container.size() - m_index ); std::streamsize result = std::min<std::streamsize> (size, delta); if (!result) return -1; std::copy ( m_container.begin() + m_index, m_container.begin() + m_index + result, value ); m_index += result; return result; } }; template<typename Container> class wcontainer /*: public boost::iostreams::sink*/ { private: Container& m_container; public: typedef typename Container::value_type char_type; typedef boost::iostreams::sink_tag category; wcontainer (Container& container) : m_container(container) {} ~wcontainer () {} std::streamsize write (const char_type* value, std::streamsize size) { m_container.insert (m_container.end(), value, value + size); return size; } }; Это сериализация typedef std::vector<char> sbuffer; typedef rcontainer <sbuffer> rdevice; typedef wcontainer <sbuffer> wdevice; template <class T> inline void serialize (sbuffer& buffer, const T& rhs) { try { namespace bio = boost::iostreams; wdevice device (buffer); bio::stream_buffer<wdevice> stream (device); //std::basic_ostream <unsigned char> ostream (&stream); std::ostream ostream (&stream); boost::archive::binary_oarchive archive (ostream); archive << BOOST_SERIALIZATION_NVP (rhs); } catch (std::exception& ex) { std::cerr << ex.what() << std::endl; } } template <class T> inline void deserialize (const sbuffer& buffer, T& rhs) { try { namespace bio = boost::iostreams; rdevice device (buffer); bio::stream_buffer<rdevice> stream (device); //std::basic_istream <unsigned char> istream (&stream); std::istream istream (&stream); boost::archive::binary_iarchive archive (istream); archive >> BOOST_SERIALIZATION_NVP (rhs); } catch (std::exception& ex) { std::cerr << ex.what() << std::endl; } } он предупреждает C:\Program Files\Microsoft Visual Studio 8\VC\include\xutility(2282) : warning C4996: 'std::_Copy_opt' was declared deprecated C:\Program Files\Microsoft Visual Studio 8\VC\include\xutility(2270) : see declaration of 'std::_Copy_opt' Message: 'You have used a std:: construct that is not safe. See documentation on how to use the Safe Standard C++ Library' e:\wcl\stream.h(97) : see reference to function template instantiation '_OutIt std::copy<std::_Vector_const_iterator<_Ty,_Alloc>,char*>(_InIt,_InIt,_OutIt)' being compiled with [ _OutIt=char *, _Ty=char, _Alloc=std::allocator<char>, _InIt=std::_Vector_const_iterator<char,std::allocator<char>> ] e:\wcl\stream.h(86) : while compiling class template member function 'std::streamsize rcontainer<Container>::read(char *,std::streamsize)' with [ Container=parser::sbuffer ] e:\\wcl\parser.h(200) : see reference to class template instantiation 'rcontainer<Container>' being compiled with [ Container=parser::sbuffer ] .\data.cpp(121) : see reference to function template instantiation 'void parser::deserialize<Channels>(const parser::sbuffer &,T &)' being compiled with [ T=Channels ] Что он хочет ? |
Сообщ.
#19
,
|
|
|
Цитата zss @ Что он хочет ? M$ only. std::copy на сырых указателях (не итераторах) M$ объявило опасным. Рекомендуется предварительно преобразовывать сырой указатель в checked_array_iterator. |
Сообщ.
#20
,
|
|
|
Цитата Hryak @ M$ only. std::copy на сырых указателях (не итераторах) M$ объявило опасными. Рекомендуется предварительно преобразовывать сырой указатель в checked_array_iterator. stdext::checked_array_iterator<char *> (...) Это ? |
Сообщ.
#21
,
|
|
|
Да. В MSDN есть примеры с пояснениями - понятно, что к чему.
|
Сообщ.
#22
,
|
|
|
тоесть ты хочешь сказать, что это предупреждение относится толко к методу read
получится что-то вроде std::streamsize read (char_type* value, std::streamsize size) { std::streamsize delta = static_cast<std::streamsize> ( m_container.size() - m_index ); std::streamsize result = std::min<std::streamsize> (size, delta); if (!result) return -1; std::copy ( m_container.begin() + m_index, m_container.begin() + m_index + result, stdext::checked_array_iterator<char_type *> (value) ); m_index += result; return result; } |
Сообщ.
#23
,
|
|
|
Цитата zss @ тоесть ты хочешь сказать, что это предупреждение относится толко к методу read По тексту сообщения так получается. Компилировать я не пытался. Цитата получится что-то вроде Не совсем. Суть во втором параметре конструктора этого итератора. А у тебя его нет. Пропиши туда количество копируемых символов |
Сообщ.
#24
,
|
|
|
Цитата Hryak @ Не совсем. Суть во втором параметре конструктора этого итератора. А у тебя его нет. Пропиши туда количество копируемых символов так для read std::streamsize result = std::min<std::streamsize> (size, delta); if (!result) return -1; std::copy ( m_container.begin() + m_index, m_container.begin() + m_index + result, stdext::checked_array_iterator<char_type *> (value, relult) ); а для write у меня диапазон. Тоесть первый checked_array_iterator размером 0 ? m_container.insert ( m_container.end(), stdext::checked_array_iterator<const char_type *> (value, 0), stdext::checked_array_iterator<const char_type *> (value, size)); Добавлено что-то это не избавило от варнинга |
Сообщ.
#25
,
|
|
|
Цитата zss @ а для write у меня диапазон. Тоесть первый insert не трогай. Цитата что-то это не избавило от варнинга И эта строчка осталась на месте? while compiling class template member function 'std::streamsize rcontainer<Container>::read(char *,std::streamsize)' |
Сообщ.
#26
,
|
|
|
Цитата Hryak @ И эта строчка осталась на месте? не - исчезла гадина осталось только это C:\boost\boost/iostreams/detail/streambuf/indirect_streambuf.hpp(241) : warning C4996: 'std::char_traits<char>::move' was declared deprecated C:\Program Files\Microsoft Visual Studio 8\VC\include\iosfwd(470) : see declaration of 'std::char_traits<char>::move' Message: 'You have used a std:: construct that is not safe. See documentation on how to use the Safe Standard C++ Library' C:\boost\boost/iostreams/detail/streambuf/indirect_streambuf.hpp(230) : while compiling class template member function 'int boost::iostreams::detail::indirect_streambuf<T,Tr,Alloc,Mode>::underflow(void)' with [ T=parser::wdevice, Tr=std::char_traits<char>, Alloc=std::allocator<char>, Mode=boost::iostreams::detail::io_mode_impl<2>::type ] C:\boost\boost/iostreams/stream_buffer.hpp(64) : see reference to class template instantiation 'boost::iostreams::detail::indirect_streambuf<T,Tr,Alloc,Mode>' being compiled with [ T=parser::wdevice, Tr=std::char_traits<char>, Alloc=std::allocator<char>, Mode=boost::iostreams::detail::io_mode_impl<2>::type ] e:\wcl\parser.h(179) : see reference to class template instantiation 'boost::iostreams::stream_buffer<T>' being compiled with [ T=parser::wdevice ] .\data.cpp(104) : see reference to function template instantiation 'void parser::serialize<Channels>(parser::sbuffer &,const T &)' being compiled with [ T=Channels ] |
Сообщ.
#27
,
|
|
|
В общем я так и не понят почему boost ругается и пришлось отключить варнинг... (не очень правда это хорошо как мне кажется)
Есть еще вопросик class Object; typedef std::list<Object> TList; class Owner { private : friend class boost::serialization::access; int a; int b; TList list; template <class Archive> void serialize (Archive& archive, const unsigned int version) { archive & BOOST_SERIALIZATION_NVP (list); } public : Owner () {} ~Owner() {} } я сериализую Owner. Реально сериализуется лишь только список. Отправляю данные. Могу ли я на другой стороне десериализовать сразу в TList или я обязан десериализовать в Owner ? Аналогично в обратную сторону. Я получил TList, подправил некоторые данные и хочу отправить их обратно. Естественно сериализую я список. Могу ли я его десериализовать в Owner ? |
Сообщ.
#28
,
|
|
|
ну где же ты, Hryak
|
Сообщ.
#29
,
|
|
|
хочу сериализовать класс
template <typename T, class Container = std::deque <T> > class Queue { private : friend class boost::serialization::access; std::queue <T, Container> m_queue; template <class Archive> void serialize (Archive& archive, const unsigned int version) { archive & BOOST_SERIALIZATION_NVP (m_queue); } public : Queue () {} ~Queue() {} }; Но что-то не нашел в boost/serialization ничего подходящего для сериализации std::queue. Как тогда она сериализуется ? |
Сообщ.
#30
,
|
|
|
никто не сериализовал ?
|