optimized

This commit is contained in:
john30
2017-05-13 17:22:08 +02:00
parent 99340c8d4b
commit a4e1aa65b4
6 changed files with 433 additions and 383 deletions
+26 -25
View File
@@ -931,7 +931,7 @@ void Message::decode(bool leadingSeparator, OutputFormat outputFormat, ostringst
if (leadingSeparator) {
*output << ",";
}
*output << "\n \"" << getName() << "\": {"
*output << "\n \"" << getName() << "\": {" // TODO include read/write/passive for overlapping names
<< "\n \"lastup\": " << setw(0) << dec << static_cast<unsigned>(getLastUpdateTime());
if (getLastUpdateTime() != 0) {
*output << ",\n \"zz\": \"" << setfill('0') << setw(2) << hex << static_cast<unsigned>(getDstAddress()) << "\"";
@@ -1626,31 +1626,31 @@ result_t Instruction::create(const string& contextPath, const string& type,
return RESULT_ERR_INVALID_ARG;
}
string Instruction::getDestination() const {
void Instruction::getDestination(ostringstream* ostream) const {
// ZZ.circuit[.suffix]
string ret;
bool empty = true;
auto it = m_defaults.find("zz");
if (it != m_defaults.end() && !it->second.empty()) {
ret = it->second;
*ostream << it->second;
empty = false;
}
it = m_defaults.find("circuit");
string circuit = it == m_defaults.end() ? "" : it->second;
it = m_defaults.find("suffix");
string suffix = it == m_defaults.end() ? "" : it->second;
if (!circuit.empty() || !suffix.empty()) {
if (!ret.empty()) {
ret += ".";
if (!empty) {
*ostream << ".";
}
if (circuit.empty()) {
ret += "*";
*ostream << "*";
} else {
ret += circuit;
*ostream << circuit;
}
if (!suffix.empty()) {
ret += suffix;
*ostream << suffix;
}
}
return ret;
}
@@ -1661,14 +1661,17 @@ result_t LoadInstruction::execute(MessageMap* messages, ostringstream* log) {
*log << ", ";
}
if (result != RESULT_OK) {
*log << "error " << (isSingleton() ? "loading \"" : "including \"") << m_filename << "\" for \""
<< getDestination() << "\": " << getResultCode(result);
*log << "error " << (isSingleton() ? "loading \"" : "including \"") << m_filename << "\" for \"";
getDestination(log);
*log << "\": " << getResultCode(result);
if (!errorDescription.empty()) {
*log << " " << errorDescription;
}
return result;
}
*log << (isSingleton() ? "loaded \"" : "included \"") << m_filename << "\" for \"" << getDestination() << "\"";
*log << (isSingleton() ? "loaded \"" : "included \"") << m_filename << "\" for \"";
getDestination(log);
*log << "\"";
if (isSingleton() && !m_defaults["zz"].empty()) {
result_t temp;
symbol_t address = (symbol_t)parseInt(m_defaults["zz"].c_str(), 16, 0, 0xff, &temp);
@@ -1678,7 +1681,7 @@ result_t LoadInstruction::execute(MessageMap* messages, ostringstream* log) {
ostringstream out;
m_condition->dump(true, &out);
comment = out.str();
*log << " ("+comment+")";
*log << " (" << comment << ")";
}
messages->addLoadedFile(address, m_filename, comment);
}
@@ -2228,8 +2231,9 @@ result_t MessageMap::executeInstructions(void (*readMessageFunc)(Message* messag
&errorDescription);
if (result != RESULT_OK) {
overallResult = result;
*log << "error resolving condition for \"" << instruction->getDestination() << "\": "
<< getResultCode(result);
*log << "error resolving condition for \"";
instruction->getDestination(log);
*log << "\": " << getResultCode(result);
if (!errorDescription.empty()) {
*log << " " << errorDescription;
}
@@ -2364,11 +2368,9 @@ Message* MessageMap::find(const string& circuit, const string& name, const strin
return NULL;
}
deque<Message*> MessageMap::findAll(const string& circuit, const string& name, const string& levels,
bool completeMatch, bool withRead, bool withWrite, bool withPassive,
bool includeEmptyLevel, bool onlyAvailable,
time_t since, time_t until) const {
deque<Message*> ret;
void MessageMap::findAll(const string& circuit, const string& name, const string& levels,
bool completeMatch, bool withRead, bool withWrite, bool withPassive, bool includeEmptyLevel, bool onlyAvailable,
time_t since, time_t until, deque<Message*>* messages) const {
string lcircuit = circuit;
FileReader::tolower(&lcircuit);
string lname = name;
@@ -2422,12 +2424,10 @@ deque<Message*> MessageMap::findAll(const string& circuit, const string& name, c
}
}
if (!onlyAvailable || message->isAvailable()) {
ret.push_back(message);
messages->push_back(message);
}
}
}
return ret;
}
Message* MessageMap::find(const MasterSymbolString& master, bool anyDestination,
@@ -2510,7 +2510,8 @@ void MessageMap::invalidateCache(Message* message) {
message->m_lastUpdateTime = 0;
string circuit = message->getCircuit();
string name = message->getName();
deque<Message*> messages = findAll(circuit, name, "*", true, true, true, true);
deque<Message*> messages;
findAll(circuit, name, "*", true, true, true, true, true, true, 0, 0, &messages);
for (auto checkMessage : messages) {
if (checkMessage != message) {
checkMessage->m_lastUpdateTime = 0;
+8 -9
View File
@@ -1109,10 +1109,10 @@ class Instruction {
bool isSingleton() const { return m_singleton; }
/**
* Return a string describing the destination from the stored default values.
* @return a string describing the destination.
* Format a string describing the destination from the stored default values.
* @param ostream the @a ostringstream to format the string to.
*/
string getDestination() const;
void getDestination(ostringstream* ostream) const;
/**
* Execute the instruction.
@@ -1363,6 +1363,7 @@ class MessageMap : public MappedFileReader {
/**
* Find all active get @a Message instances for the specified circuit and name.
* Note: the caller may not free the returned instances.
* @param circuit the circuit name, or empty for any.
* @param name the message name, or empty for any.
* @param levels the access levels to match.
@@ -1371,7 +1372,6 @@ class MessageMap : public MappedFileReader {
* @param withRead true to include read messages (default true).
* @param withWrite true to include write messages (default false).
* @param withPassive true to include passive messages (default false).
* @return the found @a Message instances.
* @param includeEmptyLevel true to also include messages with no access level, false to include only messages with
* the specified level.
* @param onlyAvailable true to include only available messages (default true), false to also include messages that
@@ -1380,12 +1380,11 @@ class MessageMap : public MappedFileReader {
* address), or 0 to ignore.
* @param until the end time to which to add updates (exclusive, also removes messages with unset destination
* address), or 0 to ignore.
* Note: the caller may not free the returned instances.
* @param messages the @a deque to which to add the found @a Message instances.
*/
deque<Message*> findAll(const string& circuit, const string& name, const string& levels,
bool completeMatch = true, bool withRead = true, bool withWrite = false,
bool withPassive = false, bool includeEmptyLevel = true, bool onlyAvailable = true,
time_t since = 0, time_t until = 0) const;
void findAll(const string& circuit, const string& name, const string& levels,
bool completeMatch, bool withRead, bool withWrite, bool withPassive, bool includeEmptyLevel, bool onlyAvailable,
time_t since, time_t until, deque<Message*>* messages) const;
/**
* Find the @a Message instance for the specified master data.
+2 -1
View File
@@ -317,7 +317,8 @@ int main() {
if (onlyMap) {
continue;
}
deque<Message*> msgs = messages->findAll("", "", "*", false, true, true, true, true, false);
deque<Message*> msgs;
messages->findAll("", "", "*", false, true, true, true, true, false, 0, 0, &msgs);
if (msgs.empty()) {
message = NULL;
cout << "\"" << check[0] << "\": create error: message not found" << endl;