2013-03-25 10 views
0

boost::archive::text_oarchive에 여러 데이터를로드 했으므로 이제 데이터를 추출해야합니다. 그러나 아카이브에 여러 레코드가 포함되어 있으므로 반복자가 필요합니다.boost :: serialization에서 아카이브를 반복하는 방법

//input archive 
boost::archive::text_iarchive iarch(ifs); 

//read until the end of file 
while (!iarch.eof()){ 

//read current value 
iarch >> temp; 
...//do something with temp 

} 

아카이브의 요소를 반복하는 표준 방법이

같은? 나는 iarchive.iterator_type 만 찾았지만 필요한 것은 무엇이며 어떻게 사용합니까?

+1

"레코드"벡터를 직렬화하는 방법 ([직렬화는 STL의 벡터 등을 처리합니다] (http://www.boost.org/doc/libs/1_53_0/libs/serialization/doc/) index.html)) 또는 "레코드"컨테이너의 여러 요소를 초기에 serialize하고 컨테이너 자체를 serialize 한 후 – megabyte1024

+0

메가 바이트와 비슷한 말을하려고했습니다. http://www.boost.org/doc/libs/1_53_0/libs/serialization/doc/index.html (STL 컬렉션 검색) – Caribou

+0

예, 생각했습니다. 하지만, 그게 내가'std :: vector '을 가지고있는 것입니다. 어떤 복잡한 복합 데이터 타입에 대한 포인터는 private로 구현 된'serialize'를 가지고 있습니다. 전체 벡터를 archive로 푸시하고 싶을 때, 컴파일러는 그 메소드를 불평합니다 'serialize'가 객체'std :: vector '에서 빠져 있습니다. 따라서 벡터로부터'Derived *'타입의 요소에 의해 요소를 저장해야했습니다. –

답변

0

실제로보고있는 반복자 타입은 오히려 내가 생각하는 외부 사용을위한 반복자 것보다 아카이브의 부하 중에 사용됩니다

class shared_ptr_helper { 
    ... 
    typedef std::set< 
     boost::shared_ptr<const void>, 
     collection_type_compare 
    > collection_type; 
    typedef collection_type::const_iterator iterator_type; 

에서 온다. 즉 당신은 아마 무시 부하 볼 필요가 다음 필요 확실히 무엇을하지 않으면

#include <boost/serialization/list.hpp> 

class bus_route 
{ 
    friend class boost::serialization::access; 
    std::list<bus_stop *> stops; 
    template<class Archive> 
    void serialize(Archive & ar, const unsigned int version) 
    { 
     ar & stops; 
    } 
public: 
    bus_route(){} 
}; 

: - 당신이 튜토리얼 아래의 링크를 http://www.boost.org/doc/libs/1_53_0/libs/serialization/doc/index.html 보면

은> STL 컬렉션은 다음과 같은 예를 볼 수 있습니다 http://www.boost.org/doc/libs/1_53_0/libs/serialization/doc/tutorial.html#splitting 으로 저장하고 필요에 따라 처리를 추가하십시오.

+0

처음에는 내 계획 이었지만 컴파일러에서는'class std :: list '에'serialize '라는 멤버가 없다고 말합니다. 비록 'serialize'가'Derived'에 구현되었지만 –

+0

이 있습니다. boost/serialization/list.hpp를 포함하는 것을 잊었습니다. –