More profile file cleanup

This commit is contained in:
Alexander Bock
2020-06-18 09:37:38 +02:00
parent fe989d1ea1
commit 1e0f427dcf
2 changed files with 34 additions and 156 deletions
+3 -121
View File
@@ -169,10 +169,11 @@ struct ProfileStruct {
};
std::string serialize(const ProfileStruct& ps);
ProfileStruct deserialize(const std::string& filename);
ProfileStruct deserialize(const std::vector<std::string>& content);
std::string convertToSceneFile(const ProfileStruct& ps);
class ProfileFile {
public:
ProfileStruct profile;
@@ -185,7 +186,7 @@ public:
* proper sections; it does not parse the tab-delimited fields of each line.
* \param filename The profile file to read
*/
ProfileFile(std::string filename);
ProfileFile(const std::string& filename);
/**
* Writes the formatted contents of this object to a file.
@@ -194,125 +195,6 @@ public:
* \param filename The filename to write to.
*/
void writeToFile(const std::string& filename) const;
/**
* Updates the full string that defines the starting time. The format for this line
* is defined by ProfileFile::parseTime and Profile::convertToAsset_time
* \param line The time entry line to replace current time entry
*/
//void updateTime(std::string line);
/**
* Updates the full string that defines the starting camera position. The format for
* this line is defined by ProfileFile::parseCamera & Profile::convertToAsset_camera
* \param line The camera entry line to replace current camera entry
*/
//void updateCamera(std::string line);
/**
* Adds a new module line to the list of module lines to be analyzed by the profile
* at startup. The format for a module line is defined by ProfileFile::parseModule
* and Profile::convertToAsset_modules
* \param line The module name to be added
*/
//void addModuleLine(std::string line);
/**
* Adds a new asset to the list of assets to be loaded at startup. The format for an
* asset line is defined by ProfileFile::parseAsset & Profile::convertToAsset_assets
* \param line The asset name to be added
*/
//void addAssetLine(std::string line);
/**
* Clears all asset entries
*/
//void clearAssets();
/**
* Adds a new property set command to the list of property settings to be
* performed at startup. The format for a property set command line is defined by
* ProfileFile::parseProperty and Profile::convertToAsset_properties
* \param line The property set command to be added
*/
//void addPropertyLine(std::string line);
/**
* Adds a new keybinding shortcut to the list of keybindings. The format for a
* keybinding line is defined by ProfileFile::parseKeybinding and
* Profile::convertToAsset_keybindings
* \param line The keyboard shortcut line to be added
*/
//void addKeybindingLine(std::string line);
/**
* Adds a new scenegraph node name to be added to the list of those marked as
* 'interesting'. The format for a mark nodes line is defined by
* ProfileFile::parseMarkNodes and Profile::convertToAsset_markNodes
* \param line The scenegraph node to be added
*/
//void addMarkNodesLine(std::string line);
/**
* Returns the format version number (profiles syntax version) string
* \return The version string
*/
//const std::string& version() const;
/**
* Sets the format version number (profiles syntax version) string
* \param The version string to set
*/
//void setVersion(std::string);
/**
* Returns the profile's time string. See updateTime comment header for notes on
* syntax of this time string
* \return The time string
*/
//std::string time() const;
/**
* Returns the profile's camera string. See updateCamera comment header for notes on
* syntax of this camera string
* \return The camera string
*/
//std::string camera() const;
/**
* Returns the vector of OpenSpace modules listed in this profile. See addModuleLine
* comment header for notes on the syntax of each entry.
* \return The vector of module lines
*/
//std::vector<std::string> modules() const;
/**
* Returns the vector of OpenSpace assets listed in this profile. See addAssetLine
* comment header for notes on the syntax of each entry.
* \return The vector of asset lines
*/
//Lines assets() const;
/**
* Returns the vector of OpenSpace property set commands included in this profile.
* See addPropertyLine comment header for notes on the syntax of each entry.
* \return The vector of property set commands
*/
//Lines properties() const;
/**
* Returns the vector of OpenSpace keybinding shortcut definitions included in this
* profile. See addKeybindingLine comment header for syntax notes of each entry.
* \return The vector of keybinding shortcut definitions
*/
//Lines keybindings() const;
/**
* Returns the vector of OpenSpace scenegraph nodes marked as 'interesting'.
* See addMarkNodesLine comment header for syntax notes of each entry.
* \return The vector of nodes to be marked as interesting.
*/
//Lines markNodes() const;
};
} // namespace openspace
+31 -35
View File
@@ -395,26 +395,25 @@ std::string serialize(const ProfileStruct& ps) {
return output;
}
ProfileStruct deserialize(const std::string& filename) {
ProfileStruct deserialize(const std::vector<std::string>& content) {
ProfileStruct result;
int lineNum = 1;
std::ifstream inFile;
try {
inFile.open(filename, std::ifstream::in);
}
catch (const std::ifstream::failure& e) {
throw ProfileError(fmt::format(
"Exception opening profile file for read: {} ({})", filename, e.what())
);
}
//int lineNum = 1;
//std::ifstream inFile;
//try {
// inFile.open(filename, std::ifstream::in);
//}
//catch (const std::ifstream::failure& e) {
// throw ProfileError(fmt::format(
// "Exception opening profile file for read: {} ({})", filename, e.what())
// );
//}
Section currentSection = Section::None;
std::string line;
while (std::getline(inFile, line)) {
for (int lineNum = 1; lineNum <= static_cast<int>(content.size()); ++lineNum) {
std::string line = content[lineNum - 1];
if (std::all_of(line.begin(), line.end(), ::isspace)) {
currentSection = Section::None;
lineNum++;
continue;
}
@@ -449,8 +448,6 @@ ProfileStruct deserialize(const std::string& filename) {
default:
throw ghoul::MissingCaseException();
}
lineNum++;
}
return result;
@@ -589,26 +586,25 @@ std::string convertToSceneFile(const ProfileStruct& ps) {
return output;
}
ProfileFile::ProfileFile(std::string filename) {
profile = deserialize(filename);
}
ProfileFile::ProfileFile(const std::string& filename) {
std::ifstream inFile;
try {
inFile.open(filename, std::ifstream::in);
}
catch (const std::ifstream::failure& e) {
throw ProfileError(fmt::format(
"Exception opening profile file for read: {} ({})", filename, e.what())
);
}
//void ProfileFile::processIndividualLine(bool& insideSection, std::string line) {
// if (insideSection) {
// if (std::all_of(line.begin(), line.end(), ::isspace)) {
// insideSection = false;
// }
// else {
// if (parseCurrentSection != nullptr) {
// (this->*parseCurrentSection)(line);
// }
// }
// }
// else if (line.substr(0, 1) == "#") {
// determineSection(line);
// insideSection = true;
// }
//}
std::vector<std::string> content;
std::string line;
while (std::getline(inFile, line)) {
content.push_back(std::move(line));
}
profile = deserialize(content);
}
void ProfileFile::writeToFile(const std::string& filename) const {
if (filename.find('/') != std::string::npos) {