27 ::msgpack::packer< std::ofstream > *
packer_;
36 explicit Writer(
const std::string& file_name)
38 config_ofs_.open(file_name.c_str());
40 if (!config_ofs_.good())
42 HUMOTO_THROW_MSG(std::string(
"Could not open configuration file for writing: ") + file_name.c_str());
45 packer_ = new ::msgpack::packer< std::ofstream >(config_ofs_);
64 void descend(
const std::string &map_name,
const std::size_t num_entries)
66 packer_->pack(map_name);
67 packer_->pack_map(num_entries);
96 template <
typename t_Scalar,
99 void writeCompound(
const Eigen::Matrix<t_Scalar, t_rows, 1, t_flags> &entry,
100 const std::string & entry_name)
102 HUMOTO_ASSERT(entry.size() <= std::numeric_limits<uint32_t>::max(),
"Vector is too long.");
104 packer_->pack(entry_name);
105 packer_->pack_array(entry.size());
108 packer_->pack(entry[i]);
124 template <
typename t_Scalar,
128 void writeCompound(
const Eigen::Matrix<t_Scalar, t_rows, t_cols, t_flags> &entry,
129 const std::string& entry_name)
131 HUMOTO_ASSERT(entry.size() <= std::numeric_limits<uint32_t>::max(),
"Matrix is too large.");
133 descend(entry_name, 3);
135 writeScalar(entry.cols(),
"cols");
136 writeScalar(entry.rows(),
"rows");
139 packer_->pack(
"data");
140 packer_->pack_array(entry.size());
144 packer_->pack(entry.data()[i]);
159 template <
typename t_VectorEntryType>
160 void writeCompound(
const std::vector< std::vector<t_VectorEntryType> > & entry,
161 const std::string & entry_name)
const 163 HUMOTO_ASSERT(entry.size() <= std::numeric_limits<uint32_t>::max(),
"Vector is too long.");
165 packer_->pack(entry_name);
166 packer_->pack_array(entry.size());
167 for(std::size_t i = 0; i < entry.size(); ++i)
169 packer_->pack(entry[i]);
182 template <
typename t_VectorEntryType>
184 const std::string & entry_name)
186 packer_->pack(entry_name);
187 packer_->pack(entry);
199 template <
typename t_EnumType>
201 const std::string & entry_name)
203 packer_->pack(entry_name);
204 packer_->pack_int64(entry);
216 template <
typename t_EntryType>
218 const std::string & entry_name)
220 packer_->pack(entry_name);
221 packer_->pack(entry);
void flush()
Flush the configuration to the file.
Writer(const std::string &file_name)
Constructor.
void writeCompound(const Eigen::Matrix< t_Scalar, t_rows, 1, t_flags > &entry, const std::string &entry_name)
Write a configuration entry (vector)
void ascend()
Ends a nested map in the configuration file.
void descend(const std::string &map_name, const std::size_t num_entries)
Starts a nested map in the configuration file.
#define HUMOTO_ASSERT(condition, message)
void writeCompound(const std::vector< std::vector< t_VectorEntryType > > &entry, const std::string &entry_name) const
Write configuration entry (std::vector<std::vector<std::string>>)
#define HUMOTO_THROW_MSG(s)
HUMOTO_THROW_MSG throws an error message concatenated with the name of the function (if supported)...
EIGEN_DEFAULT_DENSE_INDEX_TYPE EigenIndex
void writeCompound(const Eigen::Matrix< t_Scalar, t_rows, t_cols, t_flags > &entry, const std::string &entry_name)
Write a configuration entry (matrix)
::msgpack::packer< std::ofstream > * packer_
void writeEnum(const t_EnumType entry, const std::string &entry_name)
Write a configuration entry (enum)
void writeScalar(const t_EntryType entry, const std::string &entry_name)
Write a configuration entry (scalar template)
The root namespace of HuMoTo.
void writeCompound(const std::vector< t_VectorEntryType > &entry, const std::string &entry_name)
Read configuration entry (std::vector)
std::ofstream config_ofs_
output file stream
void initRoot()
Starts a nested map in the configuration file.
Configuration writer class.