46 config_ifs_.open(file_name.c_str());
47 if (!config_ifs_.good())
49 std::string file_name_default = std::string(HUMOTO_DEFAULT_CONFIG_PREFIX) + file_name;
50 config_ifs_.open(file_name_default.c_str());
52 if (!config_ifs_.good())
54 HUMOTO_THROW_MSG(std::string(
"Could not open configuration file: ") + file_name.c_str());
57 parser_.Load(config_ifs_),
58 parser_.GetNextDocument(root_node_);
59 node_stack_.push(&root_node_);
70 return(node_stack_.top());
80 explicit Reader(
const std::string& file_name)
104 const YAML::Node * child = getCurrentNode()->FindValue(child_name);
112 node_stack_.push(child);
138 template <
typename t_Scalar,
142 const std::string & entry_name,
143 const bool crash_on_missing_entry =
false)
145 if (descend(entry_name))
147 HUMOTO_ASSERT( (getCurrentNode()->Type() == YAML::NodeType::Sequence),
148 "[Config] Entry is not a sequence.");
150 if (Eigen::Dynamic == t_rows)
152 entry.resize(getCurrentNode()->size());
156 HUMOTO_ASSERT( (static_cast<int>(getCurrentNode()->size()) == t_rows),
157 "[Config] Wrong entry sequence size.");
160 for(
humoto::EigenIndex i = 0; i < (Eigen::Dynamic == t_rows ? entry.rows() : t_rows); ++i)
162 (*getCurrentNode())[i] >> entry(i);
169 if (crash_on_missing_entry)
171 HUMOTO_THROW_MSG(std::string(
"Configuration file does not contain entry '") + entry_name +
"'.");
190 template <
typename t_Scalar,
194 void readCompound( Eigen::Matrix<t_Scalar, t_rows, t_cols, t_flags> &entry,
195 const std::string& entry_name,
196 const bool crash_on_missing_entry =
false)
198 if (descend(entry_name))
203 readScalar(num_rows,
"rows",
true);
204 readScalar(num_cols,
"cols",
true);
208 readCompound(v,
"data",
true);
211 std::string(
"Inconsistent configuration file entry: ") + entry_name);
213 Eigen::Map< Eigen::Matrix<
double,
216 Eigen::RowMajor> > map(v.data(),
225 if (crash_on_missing_entry)
227 HUMOTO_THROW_MSG(std::string(
"Configuration file does not contain entry '") + entry_name +
"'.");
242 template <
typename t_VectorEntryType>
244 const std::string & entry_name,
245 const bool crash_on_missing_entry =
false)
247 if (descend(entry_name))
249 HUMOTO_ASSERT( (getCurrentNode()->Type() == YAML::NodeType::Sequence),
250 "[Config] Entry is not a sequence.");
252 entry.resize(getCurrentNode()->size());
254 for(std::size_t i = 0; i < getCurrentNode()->size(); ++i)
256 (*getCurrentNode())[i] >> entry[i];
263 if (crash_on_missing_entry)
265 HUMOTO_THROW_MSG(std::string(
"Configuration file does not contain entry '") + entry_name +
"'.");
281 template <
typename t_EntryType>
283 const std::string & entry_name,
284 const bool crash_on_missing_entry =
false)
286 if (descend(entry_name))
288 *getCurrentNode() >> entry;
293 if (crash_on_missing_entry)
295 HUMOTO_THROW_MSG(std::string(
"Configuration file does not contain entry '") + entry_name +
"'.");
311 template <
typename t_EnumerationType>
313 const std::string & entry_name,
314 const bool crash_on_missing_entry =
false)
316 if (descend(entry_name))
319 *getCurrentNode() >> tmp_value;
321 entry =
static_cast<t_EnumerationType
> (tmp_value);
326 if (crash_on_missing_entry)
328 HUMOTO_THROW_MSG(std::string(
"Configuration file does not contain entry '") + entry_name +
"'.");
std::stack< const YAML::Node * > node_stack_
Stack of nodes.
void readScalar(t_EntryType &entry, const std::string &entry_name, const bool crash_on_missing_entry=false)
Read configuration entry (scalar template)
Reader()
Default constructor.
void readCompound(std::vector< t_VectorEntryType > &entry, const std::string &entry_name, const bool crash_on_missing_entry=false)
Read configuration entry (std::vector)
void readCompound(Eigen::Matrix< t_Scalar, t_rows, t_cols, t_flags > &entry, const std::string &entry_name, const bool crash_on_missing_entry=false)
Read a configuration entry (matrix)
std::ifstream config_ifs_
input file stream
void ascend()
Ascend from the current entry to its parent.
void readCompound(Eigen::Matrix< t_Scalar, t_rows, 1, t_flags > &entry, const std::string &entry_name, const bool crash_on_missing_entry=false)
Read configuration entry (vector)
Configuration reader class.
YAML::Node root_node_
root node
#define HUMOTO_ASSERT(condition, message)
#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
bool descend(const std::string &child_name)
Descend to the entry with the given name.
void openFile(const std::string &file_name)
open configuration file
void readEnum(t_EnumerationType &entry, const std::string &entry_name, const bool crash_on_missing_entry=false)
Read configuration entry (an enum). This method is added since an explicit casting to integer is need...
YAML::Parser parser_
instance of YAML parser
The root namespace of HuMoTo.
Reader(const std::string &file_name)
Constructor.
const YAML::Node * getCurrentNode()
Get current node.