1#define BIORBD_API_EXPORTS
2#include "Utils/IfStream.h"
7#include "Utils/Equation.h"
8#include "Utils/Error.h"
9#include "Utils/Vector3d.h"
11using namespace BIORBD_NAMESPACE;
15 :
m_isOpen(std::make_shared<bool>(false)),
16 m_ifs(std::make_shared<std::ifstream>()),
17 m_path(std::make_shared<utils::
Path>()) {
18 setlocale(LC_ALL,
"C");
22 std::ios_base::openmode mode = std::ios_base::in)
23 :
m_isOpen(std::make_shared<bool>(false)),
24 m_ifs(std::make_shared<std::ifstream>()),
25 m_path(std::make_shared<utils::
Path>(path)) {
26 open(m_path->absolutePath().c_str(), mode);
27 setlocale(LC_ALL,
"C");
31 std::ios_base::openmode mode = std::ios_base::in)
32 :
m_isOpen(std::make_shared<bool>(false)),
33 m_ifs(std::make_shared<std::ifstream>()),
34 m_path(std::make_shared<utils::
Path>(path)) {
35 open(m_path->absolutePath().c_str(), mode);
36 setlocale(LC_ALL,
"C");
42 std::ios_base::openmode mode = std::ios_base::in) {
45 *m_ifs = std::ifstream(path.
absolutePath().c_str(), mode);
63 while (
read(text) && i < maxTag) {
64 if (!text.
tolower().compare(tag)) {
71 tag +
" parameter could not be found in Data file..");
82 std::streamoff positionInFile(m_ifs->tellg());
89 if (!text.compare(tag)) {
97 m_ifs->seekg(positionInFile);
102 bool out(*m_ifs >> text);
108 if (!text(0, 1).compare(
"//")) {
111 }
else if (!text(0, 1).compare(
"/*")) {
113 if (!text(0, 1).compare(
"*/") ||
114 (text.length() >= 2 &&
115 !text(text.length() - 2, text.length() - 1).compare(
"*/"))) {
124 bool out(*m_ifs >> text);
128 std::map<utils::Equation, double> dumb;
129 return read(val, dumb);
131#ifdef BIORBD_USE_CASADI_MATH
133 std::map<utils::Equation, double> dumb;
134 return read(val, dumb);
139 const std::map<Equation, double>& variables) {
145 }
catch (std::runtime_error) {
147 "The following expression cannot be parsed properly: \"" + tp +
"\"");
153 m_ifs->read(output, n_elements);
175#ifdef BIORBD_USE_CASADI_MATH
177 RBDLCasadiMath::MX_Xd_SubMatrix result,
178 const std::map<utils::Equation, double>& variables) {
184 }
catch (std::runtime_error) {
186 "The following expression cannot be parsed properly: \"" + tp +
"\"");
200 val =
static_cast<size_t>(std::stoul(tp));
206 val = std::stoi(tp) != 0;
211 std::getline(*m_ifs, text);
Strings that are to be interpreted as equation that can be evaluated.
static double evaluateEquation(std::vector< Equation > wholeEq)
Evaluate and return an equation.
static void raise(const String &message)
Throw an error message.
static void check(bool cond, const String &message)
Assert that raises the error message if false.
bool reachSpecificTag(const String &tag, size_t maxTag=-1)
Advance in the file to a specific tag.
bool close()
Close the file.
bool eof()
Return if the file is at the end.
int countTagsInAConsecutiveLines(const String &tag)
Counts the number of consecutive lines starting with the same tag and then brings it back to the init...
char m_floatBuffer[sizeof(float)]
Buffer for reading float in binaries.
bool readFromBinary(char *output, int n_elements)
Read a certain amounts of bits in binary.
std::shared_ptr< bool > m_isOpen
If file is open.
bool readSpecificTag(const String &tag, String &text)
Advance in the file to a specific tag.
IfStream()
Construct IfStream.
void getline(String &text)
Read a whole line.
bool open(const Path &path, std::ios_base::openmode mode)
Open the file.
bool readAWord(String &text)
Read a word in the file.
bool read(String &text)
Read a word in the file skipping the word if it is c-like commented.
void resetCursor()
Reset the file cursor to the 0 position.
Collection of methods to manipulate path.
String absolutePath() const
Return the absolute path relative to root.
bool isFileExist() const
Test if file exist on the computer.
Wrapper around the std::string class with augmented functionality.
static String tolower(const String &str)
Convert a string to a lower case string.
Wrapper around Eigen Vector3d and attach it to a parent.