Commit c7ff1cac authored by Martin Heistermann's avatar Martin Heistermann

FileManager: introduce verbosity levels to optionally silence output

parent ce0d2040
Pipeline #7319 passed with stage
in 6 minutes and 11 seconds
...@@ -126,7 +126,9 @@ bool FileManager::getCleanLine(std::istream& _ifs, std::string& _string, bool _s ...@@ -126,7 +126,9 @@ bool FileManager::getCleanLine(std::istream& _ifs, std::string& _string, bool _s
} }
if(_ifs.eof()) { if(_ifs.eof()) {
if (verbosity_level_ >= 2) {
std::cerr << "End of file reached while searching for input!" << std::endl; std::cerr << "End of file reached while searching for input!" << std::endl;
}
return false; return false;
} }
} }
...@@ -141,7 +143,9 @@ bool FileManager::isHexahedralMesh(const std::string& _filename) const { ...@@ -141,7 +143,9 @@ bool FileManager::isHexahedralMesh(const std::string& _filename) const {
std::ifstream iff(_filename.c_str(), std::ios::in); std::ifstream iff(_filename.c_str(), std::ios::in);
if(!iff.good()) { if(!iff.good()) {
if (verbosity_level_ >= 1) {
std::cerr << "Could not open file " << _filename << " for reading!" << std::endl; std::cerr << "Could not open file " << _filename << " for reading!" << std::endl;
}
iff.close(); iff.close();
return false; return false;
} }
...@@ -185,7 +189,9 @@ bool FileManager::isTetrahedralMesh(const std::string& _filename) const { ...@@ -185,7 +189,9 @@ bool FileManager::isTetrahedralMesh(const std::string& _filename) const {
std::ifstream iff(_filename.c_str(), std::ios::in); std::ifstream iff(_filename.c_str(), std::ios::in);
if(!iff.good()) { if(!iff.good()) {
if (verbosity_level_ >= 1) {
std::cerr << "Could not open file " << _filename << " for reading!" << std::endl; std::cerr << "Could not open file " << _filename << " for reading!" << std::endl;
}
iff.close(); iff.close();
return false; return false;
} }
......
...@@ -68,6 +68,13 @@ public: ...@@ -68,6 +68,13 @@ public:
/// Default destructor /// Default destructor
~FileManager(); ~FileManager();
/**
* \brief set minimum level for errors that are printed to std::cerr
* @param _level 0: no output; 1: only errors; 2: warnings/info
*/
void setVerbosityLevel(int _level) { verbosity_level_ = _level;}
/** /**
* \brief Read a mesh from an std::istream * \brief Read a mesh from an std::istream
* *
...@@ -167,6 +174,9 @@ private: ...@@ -167,6 +174,9 @@ private:
// Get a whole line from file // Get a whole line from file
bool getCleanLine(std::istream& ifs, std::string& _string, bool _skipEmptyLines = true) const; bool getCleanLine(std::istream& ifs, std::string& _string, bool _skipEmptyLines = true) const;
int verbosity_level_ = 3;
}; };
} // Namespace IO } // Namespace IO
......
...@@ -96,7 +96,9 @@ bool FileManager::readStream(std::istream &_istream, MeshT &_mesh, ...@@ -96,7 +96,9 @@ bool FileManager::readStream(std::istream &_istream, MeshT &_mesh,
if(s_tmp != "OVM") { if(s_tmp != "OVM") {
//_istream.close(); //_istream.close();
header_found = false; header_found = false;
if (verbosity_level_ >= 1) {
std::cerr << "The specified file might not be in OpenVolumeMesh format!" << std::endl; std::cerr << "The specified file might not be in OpenVolumeMesh format!" << std::endl;
}
//return false; //return false;
} }
...@@ -104,7 +106,9 @@ bool FileManager::readStream(std::istream &_istream, MeshT &_mesh, ...@@ -104,7 +106,9 @@ bool FileManager::readStream(std::istream &_istream, MeshT &_mesh,
sstr >> s_tmp; sstr >> s_tmp;
std::transform(s_tmp.begin(), s_tmp.end(), s_tmp.begin(), ::toupper); std::transform(s_tmp.begin(), s_tmp.end(), s_tmp.begin(), ::toupper);
if(s_tmp == "BINARY") { if(s_tmp == "BINARY") {
if (verbosity_level_ >= 1) {
std::cerr << "Binary files are not supported at the moment!" << std::endl; std::cerr << "Binary files are not supported at the moment!" << std::endl;
}
return false; return false;
} }
...@@ -123,7 +127,9 @@ bool FileManager::readStream(std::istream &_istream, MeshT &_mesh, ...@@ -123,7 +127,9 @@ bool FileManager::readStream(std::istream &_istream, MeshT &_mesh,
sstr >> s_tmp; sstr >> s_tmp;
std::transform(s_tmp.begin(), s_tmp.end(), s_tmp.begin(), ::toupper); std::transform(s_tmp.begin(), s_tmp.end(), s_tmp.begin(), ::toupper);
if(s_tmp != "VERTICES") { if(s_tmp != "VERTICES") {
if (verbosity_level_ >= 1) {
std::cerr << "No vertex section defined!" << std::endl; std::cerr << "No vertex section defined!" << std::endl;
}
return false; return false;
} else { } else {
...@@ -155,7 +161,9 @@ bool FileManager::readStream(std::istream &_istream, MeshT &_mesh, ...@@ -155,7 +161,9 @@ bool FileManager::readStream(std::istream &_istream, MeshT &_mesh,
sstr >> s_tmp; sstr >> s_tmp;
std::transform(s_tmp.begin(), s_tmp.end(), s_tmp.begin(), ::toupper); std::transform(s_tmp.begin(), s_tmp.end(), s_tmp.begin(), ::toupper);
if(s_tmp != "EDGES") { if(s_tmp != "EDGES") {
if (verbosity_level_ >= 2) {
std::cerr << "No edge section defined!" << std::endl; std::cerr << "No edge section defined!" << std::endl;
}
return false; return false;
} else { } else {
...@@ -188,7 +196,9 @@ bool FileManager::readStream(std::istream &_istream, MeshT &_mesh, ...@@ -188,7 +196,9 @@ bool FileManager::readStream(std::istream &_istream, MeshT &_mesh,
sstr >> s_tmp; sstr >> s_tmp;
std::transform(s_tmp.begin(), s_tmp.end(), s_tmp.begin(), ::toupper); std::transform(s_tmp.begin(), s_tmp.end(), s_tmp.begin(), ::toupper);
if(s_tmp != "FACES") { if(s_tmp != "FACES") {
if (verbosity_level_ >= 2) {
std::cerr << "No face section defined!" << std::endl; std::cerr << "No face section defined!" << std::endl;
}
return false; return false;
} else { } else {
...@@ -232,7 +242,9 @@ bool FileManager::readStream(std::istream &_istream, MeshT &_mesh, ...@@ -232,7 +242,9 @@ bool FileManager::readStream(std::istream &_istream, MeshT &_mesh,
sstr >> s_tmp; sstr >> s_tmp;
std::transform(s_tmp.begin(), s_tmp.end(), s_tmp.begin(), ::toupper); std::transform(s_tmp.begin(), s_tmp.end(), s_tmp.begin(), ::toupper);
if(s_tmp != "POLYHEDRA") { if(s_tmp != "POLYHEDRA") {
if (verbosity_level_ >= 2) {
std::cerr << "No polyhedra section defined!" << std::endl; std::cerr << "No polyhedra section defined!" << std::endl;
}
return false; return false;
} else { } else {
...@@ -280,12 +292,14 @@ bool FileManager::readStream(std::istream &_istream, MeshT &_mesh, ...@@ -280,12 +292,14 @@ bool FileManager::readStream(std::istream &_istream, MeshT &_mesh,
_mesh.enable_bottom_up_incidences(true); _mesh.enable_bottom_up_incidences(true);
} }
if (verbosity_level_ >= 2) {
std::cerr << "######## openvolumemesh info #########" << std::endl; std::cerr << "######## openvolumemesh info #########" << std::endl;
std::cerr << "#vertices: " << _mesh.n_vertices() << std::endl; std::cerr << "#vertices: " << _mesh.n_vertices() << std::endl;
std::cerr << "#edges: " << _mesh.n_edges() << std::endl; std::cerr << "#edges: " << _mesh.n_edges() << std::endl;
std::cerr << "#faces: " << _mesh.n_faces() << std::endl; std::cerr << "#faces: " << _mesh.n_faces() << std::endl;
std::cerr << "#cells: " << _mesh.n_cells() << std::endl; std::cerr << "#cells: " << _mesh.n_cells() << std::endl;
std::cerr << "######################################" << std::endl; std::cerr << "######################################" << std::endl;
}
return true; return true;
} }
...@@ -297,7 +311,9 @@ bool FileManager::readFile(const std::string& _filename, MeshT& _mesh, ...@@ -297,7 +311,9 @@ bool FileManager::readFile(const std::string& _filename, MeshT& _mesh,
std::ifstream iff(_filename.c_str(), std::ios::in); std::ifstream iff(_filename.c_str(), std::ios::in);
if(!iff.good()) { if(!iff.good()) {
if (verbosity_level_ >= 1) {
std::cerr << "Error: Could not open file " << _filename << " for reading!" << std::endl; std::cerr << "Error: Could not open file " << _filename << " for reading!" << std::endl;
}
iff.close(); iff.close();
return false; return false;
} }
...@@ -325,7 +341,9 @@ void FileManager::readProperty(std::istream& _iff, MeshT& _mesh) const { ...@@ -325,7 +341,9 @@ void FileManager::readProperty(std::istream& _iff, MeshT& _mesh) const {
name = line; name = line;
extractQuotedText(name); extractQuotedText(name);
if (verbosity_level_ >= 2) {
std::cerr << "OVM read property " << name << " of type " << prop_t << std::endl; std::cerr << "OVM read property " << name << " of type " << prop_t << std::endl;
}
if(prop_t == typeName<int>()) generateGenericProperty<int, MeshT>(entity_t, name, _iff, _mesh); if(prop_t == typeName<int>()) generateGenericProperty<int, MeshT>(entity_t, name, _iff, _mesh);
else if(prop_t == typeName<unsigned int>()) generateGenericProperty<unsigned int, MeshT>(entity_t, name, _iff, _mesh); else if(prop_t == typeName<unsigned int>()) generateGenericProperty<unsigned int, MeshT>(entity_t, name, _iff, _mesh);
...@@ -501,7 +519,9 @@ bool FileManager::writeFile(const std::string& _filename, const MeshT& _mesh) co ...@@ -501,7 +519,9 @@ bool FileManager::writeFile(const std::string& _filename, const MeshT& _mesh) co
std::ofstream off(_filename.c_str(), std::ios::out); std::ofstream off(_filename.c_str(), std::ios::out);
if(!off.good()) { if(!off.good()) {
if (verbosity_level_ >= 1) {
std::cerr << "Error: Could not open file " << _filename << " for writing!" << std::endl; std::cerr << "Error: Could not open file " << _filename << " for writing!" << std::endl;
}
return false; return false;
} }
writeStream(off, _mesh); writeStream(off, _mesh);
...@@ -518,7 +538,9 @@ void FileManager::writeProps(std::ostream& _ostr, const IteratorT& _begin, const ...@@ -518,7 +538,9 @@ void FileManager::writeProps(std::ostream& _ostr, const IteratorT& _begin, const
p_it != _end; ++p_it) { p_it != _end; ++p_it) {
if(!(*p_it)->persistent()) continue; if(!(*p_it)->persistent()) continue;
if((*p_it)->anonymous()) { if((*p_it)->anonymous()) {
if (verbosity_level_ >= 2) {
std::cerr << "Serialization of anonymous properties is not supported!" << std::endl; std::cerr << "Serialization of anonymous properties is not supported!" << std::endl;
}
continue; continue;
} }
...@@ -526,7 +548,9 @@ void FileManager::writeProps(std::ostream& _ostr, const IteratorT& _begin, const ...@@ -526,7 +548,9 @@ void FileManager::writeProps(std::ostream& _ostr, const IteratorT& _begin, const
try { try {
type_name = (*p_it)->typeNameWrapper(); type_name = (*p_it)->typeNameWrapper();
} catch (std::runtime_error &e) { // type not serializable } catch (std::runtime_error &e) { // type not serializable
std::cerr << "Failed to save property, skipping: " << e.what() << std::endl; if (verbosity_level_ >= 1) {
std::cerr << "Failed to save property " << (*p_it)->name() << " , skipping: " << e.what() << std::endl;
}
continue; continue;
} }
_ostr << (*p_it)->entityType() << " "; _ostr << (*p_it)->entityType() << " ";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment