more const, use relative filenames

This commit is contained in:
john30
2017-04-22 12:20:26 +02:00
parent f8463fbf74
commit 07091c17cc
3 changed files with 36 additions and 22 deletions
+1 -1
View File
@@ -1076,7 +1076,7 @@ int main(int argc, char* argv[]) {
setFacilitiesLogLevel(opt.logAreas, opt.logLevel);
}
s_messageMap = new MessageMap(opt.checkConfig && opt.scanConfig && arg_index >= argc);
s_messageMap = new MessageMap(string(opt.configPath)+"/", opt.checkConfig && opt.scanConfig && arg_index >= argc);
if (opt.checkConfig) {
logNotice(lf_main, PACKAGE_STRING "." REVISION " performing configuration check...");
+17 -15
View File
@@ -1676,13 +1676,6 @@ result_t LoadInstruction::execute(MessageMap* messages, ostringstream& log, Cond
result_t temp;
symbol_t address = (symbol_t)parseInt(m_defaults["zz"].c_str(), 16, 0, 0xff, temp);
if (temp == RESULT_OK) {
size_t pos = m_filename.find_last_of('/');
string filename;
if (pos == string::npos) {
filename = m_filename;
} else {
filename = m_filename.substr(pos+1);
}
string comment;
if (condition) {
ostringstream out;
@@ -1690,7 +1683,7 @@ result_t LoadInstruction::execute(MessageMap* messages, ostringstream& log, Cond
comment = out.str();
log << " ("+comment+")";
}
messages->addLoadedFile(address, filename, comment);
messages->addLoadedFile(address, m_filename, comment);
}
}
return result;
@@ -1699,6 +1692,13 @@ result_t LoadInstruction::execute(MessageMap* messages, ostringstream& log, Cond
vector<string> MessageMap::s_noFiles;
const string MessageMap::getRelativePath(const string filename) const {
if (filename.length() >= m_configPath.length() && filename.substr(0, m_configPath.length()) == m_configPath) {
return filename.substr(m_configPath.length());
}
return filename;
}
result_t MessageMap::add(Message* message, bool storeByName) {
uint64_t key = message->getKey();
bool conditional = message->isConditional();
@@ -2105,9 +2105,10 @@ result_t MessageMap::readFromFile(const string filename, string& errorDescriptio
}
result_t result = MappedFileReader::readFromFile(filename, errorDescription, verbose, defaults, hash, size, time);
if (result == RESULT_OK) {
m_loadedFileInfos[filename].m_hash = *hash;
m_loadedFileInfos[filename].m_size = *size;
m_loadedFileInfos[filename].m_time = *time;
const string file = getRelativePath(filename);
m_loadedFileInfos[file].m_hash = *hash;
m_loadedFileInfos[file].m_size = *size;
m_loadedFileInfos[file].m_time = *time;
}
return result;
}
@@ -2296,9 +2297,10 @@ result_t MessageMap::executeInstructions(ostringstream& log, void (*readMessageF
return overallResult;
}
void MessageMap::addLoadedFile(symbol_t address, string file, string comment) {
if (!file.empty()) {
void MessageMap::addLoadedFile(const symbol_t address, const string filename, string const comment) {
if (!filename.empty()) {
vector<string>& files = m_loadedFiles[address];
const string file = getRelativePath(filename);
files.push_back(file);
if (!comment.empty()) {
m_loadedFileInfos[file].m_comment = comment;
@@ -2306,7 +2308,7 @@ void MessageMap::addLoadedFile(symbol_t address, string file, string comment) {
}
}
const vector<string>& MessageMap::getLoadedFiles(symbol_t address) const {
const vector<string>& MessageMap::getLoadedFiles(const symbol_t address) const {
auto files = m_loadedFiles.find(address);
if (files != m_loadedFiles.end()) {
return files->second;
@@ -2444,7 +2446,7 @@ deque<Message*> MessageMap::findAll(const string& circuit, const string& name, c
return ret;
}
Message* MessageMap::find(MasterSymbolString& master, bool anyDestination,
Message* MessageMap::find(MasterSymbolString& master, const bool anyDestination,
const bool withRead, const bool withWrite, const bool withPassive, const bool onlyAvailable) const {
if (anyDestination && master.size() >= 5 && master[4] == 0 && master[2] == 0x07 && master[3] == 0x04) {
return m_scanMessage;
+18 -6
View File
@@ -1212,11 +1212,13 @@ class MessageMap : public MappedFileReader {
public:
/**
* Construct a new instance.
* @param configPath the path to the configuration files.
* @param addAll whether to add all messages, even if duplicate.
* @param preferLanguage the preferred language to use, or empty.
*/
explicit MessageMap(const bool addAll = false, const string preferLanguage = "")
explicit MessageMap(const string configPath, const bool addAll = false, const string preferLanguage = "")
: MappedFileReader::MappedFileReader(true),
m_configPath(configPath),
m_addAll(addAll), m_additionalScanMessages(false), m_maxIdLength(0), m_maxBroadcastIdLength(0),
m_messageCount(0), m_conditionalMessageCount(0), m_passiveMessageCount(0) {
m_scanMessage = Message::createScanMessage();
@@ -1238,6 +1240,13 @@ class MessageMap : public MappedFileReader {
}
}
/**
* Return the relative file name of the given filename.
* @param filename the name of the configuration file (including relative path).
* @return the relative file name.
*/
const string getRelativePath(const string filename) const;
/**
* Add a @a Message instance to this set.
* @param message the @a Message instance to add.
@@ -1319,17 +1328,17 @@ class MessageMap : public MappedFileReader {
/**
* Add a loaded file to a participant.
* @param address the slave address.
* @param file the name of the file from which a configuration part was loaded for the participant.
* @param filename the name of the configuration file (including relative path).
* @param comment an optional comment.
*/
void addLoadedFile(symbol_t address, string file, string comment = "");
void addLoadedFile(const symbol_t address, const string filename, const string comment = "");
/**
* Get the loaded files for a participant.
* @param address the slave address.
* @return the loaded configuration files (list of file names with relative path).
*/
const vector<string>& getLoadedFiles(symbol_t address) const;
const vector<string>& getLoadedFiles(const symbol_t address) const;
/**
* Get all loaded files.
@@ -1408,7 +1417,7 @@ class MessageMap : public MappedFileReader {
* @return the @a Message instance, or NULL.
* Note: the caller may not free the returned instance.
*/
Message* find(MasterSymbolString& master, bool anyDestination = false, const bool withRead = true,
Message* find(MasterSymbolString& master, const bool anyDestination = false, const bool withRead = true,
const bool withWrite = true, const bool withPassive = true, const bool onlyAvailable = true) const;
/**
@@ -1493,6 +1502,9 @@ class MessageMap : public MappedFileReader {
/** empty vector for @a getLoadedFiles(). */
static vector<string> s_noFiles;
/** the path to the configuration files. */
const string m_configPath;
/** whether to add all messages, even if duplicate. */
const bool m_addAll;
@@ -1505,7 +1517,7 @@ class MessageMap : public MappedFileReader {
/** whether additional scan @a Message instances are available. */
bool m_additionalScanMessages;
/** the loaded configuration files by slave address ((list of file names with relative path). */
/** the loaded configuration files by slave address (list of file names with relative path). */
map<symbol_t, vector<string>> m_loadedFiles;
/** the @a LoadedFileInfo by for load configuration files (by file name with relative path). */