newbie question --> invalid application of ?sizeof? to incomplete type ?boost::STATIC_ASSERTION_FAILURE<false>?

Hello ! I am a newbie to Boost ... and trying to use it in order to serialize a complex data structure for one of my project. (the struct particle) You can see the nested data structure at the end of this file. I have started from the 'leafs' and yet trying to serialize a point which is a variable of a PointAccumulator. You can see the point.h file below. Here is the test code I am using to try to serialize it. Note that I read a few succinct tutorials and already succesfully compiled some simple examples. ... GMapping::point<int>p = GMapping::point<int>(); //saveIntoFile<text_oarchive>(particlesSaved[1].map.cell(1,1).acc, "outTest.txt"); saveIntoFile<text_oarchive>(p, "outTest.txt"); ... template <class T> void RobotController::saveIntoFile(GMapping::point<int>& p, const char* file){ std::ofstream ofile(file); T ar(ofile); ar << p; ofile.close(); } However when compiling; it raises the following error: ... /usr/include/boost/archive/detail/oserializer.hpp: In function ‘void boost::archive::save(Archive&, T&) [with Archive = boost::archive::text_oarchive, T = GMapping::point<int>]’: /usr/include/boost/archive/detail/common_oarchive.hpp:64: instantiated from ‘void boost::archive::detail::common_oarchive<Archive>::save_override(T&, int) [with T = GMapping::point<int>, Archive = boost::archive::text_oarchive]’ /usr/include/boost/archive/basic_text_oarchive.hpp:75: instantiated from ‘void boost::archive::basic_text_oarchive<Archive>::save_override(T&, int) [with T = GMapping::point<int>, Archive = boost::archive::text_oarchive]’ /usr/include/boost/archive/detail/interface_oarchive.hpp:64: instantiated from ‘Archive& boost::archive::detail::interface_oarchive<Archive>::operator<<(T&) [with T = GMapping::point<int>, Archive = boost::archive::text_oarchive]’ RobotController.cpp:186: instantiated from ‘void RobotController::saveIntoFile(GMapping::point<int>, const char*) [with T = boost::archive::text_oarchive]’ RobotController.cpp:223: instantiated from here /usr/include/boost/archive/detail/oserializer.hpp:564: error: invalid application of ‘sizeof’ to incomplete type ‘boost::STATIC_ASSERTION_FAILURE<false>’ /usr/include/boost/archive/detail/common_oarchive.hpp:64: instantiated from ‘void boost::archive::detail::common_oarchive<Archive>::save_override(T&, int) [with T = GMapping::point<int>, Archive = boost::archive::text_oarchive]’ /usr/include/boost/archive/basic_text_oarchive.hpp:75: instantiated from ‘void boost::archive::basic_text_oarchive<Archive>::save_override(T&, int) [with T = GMapping::point<int>, Archive = boost::archive::text_oarchive]’ /usr/include/boost/archive/detail/interface_oarchive.hpp:64: instantiated from ‘Archive& boost::archive::detail::interface_oarchive<Archive>::operator<<(T&) [with T = GMapping::point<int>, Archive = boost::archive::text_oarchive]’ RobotController.cpp:186: instantiated from ‘void RobotController::saveIntoFile(GMapping::point<int>, const char*) [with T = boost::archive::text_oarchive]’ RobotController.cpp:223: instantiated from here /usr/include/boost/archive/detail/oserializer.hpp:564: error: invalid application of ‘sizeof’ to incomplete type ‘boost::STATIC_ASSERTION_FAILURE<false>’ make: *** [RobotController.o] Error 1 Anyone understands what is the error ? I read I had to give a constant reference to the object while calling the operator << ... but I don't really understand it. I am using Ubuntu 9.04 / g++ compiler / boost v 1.35 Thanks in advance ! Second quick question I have doubts about: Do you think it is possible to serialize my *Particle* structure ? With all the pointers it contains and the nested structures and the trees (TNode) it points to ... ------------------------------ ----------------------------------------------------------- Data structures *Point.h* #ifndef _POINT_H_ #define _POINT_H_ #include <assert.h> #include <math.h> #include <iostream> #include <sstream> #include <fstream> #include <boost/archive/text_oarchive.hpp> #include <boost/archive/text_iarchive.hpp> #define DEBUG_STREAM cerr << __PRETTY_FUNCTION__ << ":" //FIXME using namespace boost::archive; namespace GMapping { template <class T> struct point{ inline point():x(0),y(0) {} inline point(T _x, T _y):x(_x),y(_y){} T x, y; friend class boost::serialization::access; template <class Archive> void serialize(Archive& ar, const unsigned int version){ ar & x & y; } }; ... Structure to serialize (originally, I want to serialize a Particle ...) Struct Particle{ ScanMatcherMap map; OrientedPoint pose; double weight; double weightSum; double gweight; int previousIndex; TNode* node; }; typedef Map<PointAccumulator, HierarchicalArray2D<PointAccumulator>> ScanMatcherMap; template <class Cell, class Storage, const bool isClass=true> class Map{ Point m_center; double m_worldSizeX, m_worldSizeY, m_delta; Storage m_storage; int m_mapSizeX, m_mapSizeY; int m_sizeX2, m_sizeY2; static const Cell m_unknown; }; struct PointAccumulator{ typedef point<float> FloatPoint; PointAccumulator(): acc(0,0), n(0), visits(0){} PointAccumulator(int i): acc(0,0), n(0), visits(0){assert(i==-1);} static PointAccumulator* unknown_ptr; FloatPoint acc; int n, visits; }; template <class Cell> class HierarchicalArray2D: public Array2D<autoptr< Array2D<Cell> > >{ typedef std::set< point<int>, pointcomparator<int> > PointSet; HierarchicalArray2D(int xsize, int ysize, int patchMagnitude=5); PointSet m_activeArea; int m_patchMagnitude; int m_patchSize; }; template<class Cell, const bool debug=false> class Array2D{ Cell ** m_cells; int m_xsize, m_ysize; }; template <class X> class autoptr{ struct reference{ X* data; unsigned int shares; }; reference * m_reference; }; struct TNode{ /**Constructs a node of the trajectory tree. @param pose: the pose of the robot in the trajectory @param weight: the weight of the particle at that point in the trajectory @param accWeight: the cumulative weight of the particle @param parent: the parent node in the tree @param childs: the number of childs */ TNode(const OrientedPoint& pose, double weight, TNode* parent=0, unsigned int childs=0); OrientedPoint pose; double weight; double accWeight; double gweight; TNode* parent; const RangeReading* reading; unsigned int childs; mutable unsigned int visitCounter; mutable bool flag; }; class RangeReading: public SensorReading, public std::vector<double>{ std::vector<Point> cartesianForm(double maxRange=1e6) const; unsigned int activeBeams(double density=0.) const; OrientedPoint m_pose; };

Ok .. my fault ... The serialization library was not pointed correctly (LD_LIBRARY_PATH ....) That explains why .... Now library is working fine ! And I can compile my simple example ! ----- Original Message ----- From: Simon Ruffieux Newsgroups: gmane.comp.lib.boost.user To: boost-users Sent: Monday, January 11, 2010 3:27 PM Subject: newbie question --> invalid application of ?sizeof?to incomplete type ?boost::STATIC_ASSERTION_FAILURE<false>? Hello ! I am a newbie to Boost ... and trying to use it in order to serialize a complex data structure for one of my project. (the struct particle) You can see the nested data structure at the end of this file. I have started from the 'leafs' and yet trying to serialize a point which is a variable of a PointAccumulator. You can see the point.h file below. Here is the test code I am using to try to serialize it. Note that I read a few succinct tutorials and already succesfully compiled some simple examples. ... GMapping::point<int>p = GMapping::point<int>(); //saveIntoFile<text_oarchive>(particlesSaved[1].map.cell(1,1).acc, "outTest.txt"); saveIntoFile<text_oarchive>(p, "outTest.txt"); ... template <class T> void RobotController::saveIntoFile(GMapping::point<int>& p, const char* file){ std::ofstream ofile(file); T ar(ofile); ar << p; ofile.close(); } However when compiling; it raises the following error: ... /usr/include/boost/archive/detail/oserializer.hpp: In function ‘void boost::archive::save(Archive&, T&) [with Archive = boost::archive::text_oarchive, T = GMapping::point<int>]’: /usr/include/boost/archive/detail/common_oarchive.hpp:64: instantiated from ‘void boost::archive::detail::common_oarchive<Archive>::save_override(T&, int) [with T = GMapping::point<int>, Archive = boost::archive::text_oarchive]’ /usr/include/boost/archive/basic_text_oarchive.hpp:75: instantiated from ‘void boost::archive::basic_text_oarchive<Archive>::save_override(T&, int) [with T = GMapping::point<int>, Archive = boost::archive::text_oarchive]’ /usr/include/boost/archive/detail/interface_oarchive.hpp:64: instantiated from ‘Archive& boost::archive::detail::interface_oarchive<Archive>::operator<<(T&) [with T = GMapping::point<int>, Archive = boost::archive::text_oarchive]’ RobotController.cpp:186: instantiated from ‘void RobotController::saveIntoFile(GMapping::point<int>, const char*) [with T = boost::archive::text_oarchive]’ RobotController.cpp:223: instantiated from here /usr/include/boost/archive/detail/oserializer.hpp:564: error: invalid application of ‘sizeof’ to incomplete type ‘boost::STATIC_ASSERTION_FAILURE<false>’ /usr/include/boost/archive/detail/common_oarchive.hpp:64: instantiated from ‘void boost::archive::detail::common_oarchive<Archive>::save_override(T&, int) [with T = GMapping::point<int>, Archive = boost::archive::text_oarchive]’ /usr/include/boost/archive/basic_text_oarchive.hpp:75: instantiated from ‘void boost::archive::basic_text_oarchive<Archive>::save_override(T&, int) [with T = GMapping::point<int>, Archive = boost::archive::text_oarchive]’ /usr/include/boost/archive/detail/interface_oarchive.hpp:64: instantiated from ‘Archive& boost::archive::detail::interface_oarchive<Archive>::operator<<(T&) [with T = GMapping::point<int>, Archive = boost::archive::text_oarchive]’ RobotController.cpp:186: instantiated from ‘void RobotController::saveIntoFile(GMapping::point<int>, const char*) [with T = boost::archive::text_oarchive]’ RobotController.cpp:223: instantiated from here /usr/include/boost/archive/detail/oserializer.hpp:564: error: invalid application of ‘sizeof’ to incomplete type ‘boost::STATIC_ASSERTION_FAILURE<false>’ make: *** [RobotController.o] Error 1 Anyone understands what is the error ? I read I had to give a constant reference to the object while calling the operator << ... but I don't really understand it. I am using Ubuntu 9.04 / g++ compiler / boost v 1.35 Thanks in advance ! Second quick question I have doubts about: Do you think it is possible to serialize my Particle structure ? With all the pointers it contains and the nested structures and the trees (TNode) it points to ... ------------------------------ ----------------------------------------------------------- Data structures Point.h #ifndef _POINT_H_ #define _POINT_H_ #include <assert.h> #include <math.h> #include <iostream> #include <sstream> #include <fstream> #include <boost/archive/text_oarchive.hpp> #include <boost/archive/text_iarchive.hpp> #define DEBUG_STREAM cerr << __PRETTY_FUNCTION__ << ":" //FIXME using namespace boost::archive; namespace GMapping { template <class T> struct point{ inline point():x(0),y(0) {} inline point(T _x, T _y):x(_x),y(_y){} T x, y; friend class boost::serialization::access; template <class Archive> void serialize(Archive& ar, const unsigned int version){ ar & x & y; } }; ... Structure to serialize (originally, I want to serialize a Particle ...) Struct Particle{ ScanMatcherMap map; OrientedPoint pose; double weight; double weightSum; double gweight; int previousIndex; TNode* node;}; typedef Map<PointAccumulator, HierarchicalArray2D<PointAccumulator>> ScanMatcherMap;template <class Cell, class Storage, const bool isClass=true> class Map{ Point m_center; double m_worldSizeX, m_worldSizeY, m_delta; Storage m_storage; int m_mapSizeX, m_mapSizeY; int m_sizeX2, m_sizeY2; static const Cell m_unknown;};struct PointAccumulator{ typedef point<float> FloatPoint; PointAccumulator(): acc(0,0), n(0), visits(0){} PointAccumulator(int i): acc(0,0), n(0), visits(0){assert(i==-1);} static PointAccumulator* unknown_ptr; FloatPoint acc; int n, visits;};template <class Cell> class HierarchicalArray2D: public Array2D<autoptr< Array2D<Cell> > >{ typedef std::set< point<int>, pointcomparator<int> > PointSet; HierarchicalArray2D(int xsize, int ysize, int patchMagnitude=5); PointSet m_activeArea; int m_patchMagnitude; int m_patchSize;};template<class Cell, const bool debug=false> class Array2D{ Cell ** m_cells; int m_xsize, m_ysize;};template <class X> class autoptr{ struct reference{ X* data; unsigned int shares; }; reference * m_reference; };struct TNode{ /**Constructs a node of the trajectory tree. @param pose: the pose of the robot in the trajectory @param weight: the weight of the particle at that point in the trajectory @param accWeight: the cumulative weight of the particle @param parent: the parent node in the tree @param childs: the number of childs */ TNode(const OrientedPoint& pose, double weight, TNode* parent=0, unsigned int childs=0); OrientedPoint pose; double weight; double accWeight; double gweight; TNode* parent; const RangeReading* reading; unsigned int childs; mutable unsigned int visitCounter; mutable bool flag; };class RangeReading: public SensorReading, public std::vector<double>{ std::vector<Point> cartesianForm(double maxRange=1e6) const; unsigned int activeBeams(double density=0.) const; OrientedPoint m_pose;}; ------------------------------------------------------------------------------ _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (1)
-
Simon Ruffieux