1 #ifndef PI_PROPERTIES_NETCDFHEADER_SERIALIZER 2 #define PI_PROPERTIES_NETCDFHEADER_SERIALIZER 4 #include <rtt/Property.hpp> 5 #include <boost/lexical_cast.hpp> 9 #define DIMENSION_VAR 1 10 #define DIMENSION_ARRAY 2 21 :
public marsh::MarshallInterface
35 virtual void serialize(base::PropertyBase* v)
37 Property<PropertyBag>* bag =
dynamic_cast< Property<PropertyBag>*
>( v );
39 this->serialize( *bag );
41 Property<char>* Pc =
dynamic_cast< Property<char>*
>( v );
47 Property<short>* Ps =
dynamic_cast< Property<short>*
>( v );
53 Property<int>* Pi =
dynamic_cast< Property<int>*
>( v );
59 Property<float>* Pf =
dynamic_cast< Property<float>*
>( v );
65 Property<double>* Pd =
dynamic_cast< Property<double>*
>( v );
71 Property<std::vector<double> >* Pv =
dynamic_cast< Property<std::vector<double>
>* >( v );
92 retval = nc_redef(ncid);
94 log(Error) <<
"Could not enter define mode in NetcdfHeaderMarshaller, error "<< retval <<endlog();
100 PropertyBag::const_iterator i = v.getProperties().begin();
101 i != v.getProperties().end();
111 log(Info) <<
"Serializer still in progress" <<endlog();
113 retval = nc_enddef(ncid);
115 log(Error) <<
"Could not leave define mode, error" << retval <<endlog();
119 virtual void serialize(
const Property<PropertyBag> &v)
121 std::string oldpref = prefix;
125 prefix = v.getName();
127 prefix +=
"." + v.getName();
129 serialize(v.rvalue());
132 nameless_counter = 0;
142 std::string sname = composeName(v->getName());
147 retval = nc_def_var(ncid, sname.c_str(), NC_BYTE, DIMENSION_VAR,
150 log(Error) <<
"Could not create variable " << sname <<
", error " << retval <<endlog();
152 log(Info) <<
"Variable "<< sname <<
" successfully created" <<endlog();
162 std::string sname = composeName(v->getName());
167 retval = nc_def_var(ncid, sname.c_str(), NC_SHORT, DIMENSION_VAR,
170 log(Error) <<
"Could not create variable " << sname <<
", error " << retval <<endlog();
172 log(Info) <<
"Variable "<< sname <<
" successfully created" <<endlog();
182 std::string sname = composeName(v->getName());
187 retval = nc_def_var(ncid, sname.c_str(), NC_INT, DIMENSION_VAR,
190 log(Error) <<
"Could not create variable " << sname <<
", error " << retval <<endlog();
192 log(Info) <<
"Variable "<< sname <<
" successfully created" <<endlog();
202 std::string sname = composeName(v->getName());
207 retval = nc_def_var(ncid, sname.c_str(), NC_FLOAT, DIMENSION_VAR,
210 log(Error) <<
"Could not create variable " << sname <<
", error " << retval <<endlog();
212 log(Info) <<
"Variable "<< sname <<
" successfully created" <<endlog();
222 std::string sname = composeName(v->getName());
227 retval = nc_def_var(ncid, sname.c_str(), NC_DOUBLE, DIMENSION_VAR,
231 log(Error) <<
"Could not create variable " << sname <<
", error " << retval <<endlog();
233 log(Info) <<
"Variable "<< sname <<
" successfully created" <<endlog();
239 void store(Property<std::vector<double> > *v)
244 std::string dim_name = v->getName().c_str();
246 const char *dimname = dim_name.c_str();
248 const char *name = v->getName().c_str();
250 int dims[ DIMENSION_ARRAY ];
254 retval = nc_def_dim(ncid, dimname, v->rvalue().size(), &var_dim);
256 log(Error) <<
"Could not create new dimension for "<< dimname <<
", error "<< retval <<endlog();
262 retval = nc_def_var(ncid, name, NC_DOUBLE, DIMENSION_ARRAY,
265 log(Error) <<
"Could not create " << name <<
", error " << retval <<endlog();
267 log(Info) <<
"Variable "<< name <<
" successfully created" <<endlog();
270 std::string composeName(std::string propertyName)
272 std::string last_name;
274 if( propertyName.empty() ) {
276 last_name = boost::lexical_cast<std::string>( nameless_counter );
279 nameless_counter = 0;
280 last_name = propertyName;
282 if ( prefix.empty() )
285 return prefix +
"." + last_name;
288 virtual void flush() {}