From: Eduardo Ramos Testillano Date: Mon, 6 Apr 2015 00:11:23 +0000 (+0200) Subject: astyle X-Git-Tag: REFACTORING_TESTING_LIBRARY~188 X-Git-Url: https://git.teslayout.com/public/public/public/?a=commitdiff_plain;h=17d687f1070485b0b4d7038b7104cb3ab0f45349;p=anna.git astyle --- diff --git a/example/diameter/stackManagement/main.cpp b/example/diameter/stackManagement/main.cpp index 2526a7a..9b83d21 100644 --- a/example/diameter/stackManagement/main.cpp +++ b/example/diameter/stackManagement/main.cpp @@ -55,51 +55,51 @@ using namespace anna::diameter; void _exit(const std::string & msg) { - std::cout << std::endl << msg << std::endl; - exit(-1); + std::cout << std::endl << msg << std::endl; + exit(-1); } int main(int argc, char** argv) { - Logger::setLevel(Logger::Debug); - Logger::initialize("stackManagement", new TraceWriter("file.trace", 2048000)); - stack::Engine & engine = stack::Engine::instantiate(); - std::string exec = argv[0]; - std::string param = argv[1] ? argv[1] : ""; - - if (argc < 2) { - std::string msg = anna::functions::asString("Usage: %s ,\n i.e. '%s avps.xml commands.xml'", exec.c_str(), exec.c_str()); - _exit(msg); - } - - int index = 1; - const char *xmlFile = argv[index]; - stack::Dictionary *dictionary; - - try { - dictionary = engine.createDictionary(0 /* general unique stack id */); - dictionary->allowUpdates(); - - while (xmlFile) { - dictionary->load(xmlFile); - xmlFile = argv[++index]; - } - - engine.removeStack(0); - // Trace: - LOGINFORMATION(Logger::information(engine.asString(), ANNA_FILE_LOCATION)); - LOGDEBUG(Logger::debug(dictionary->asString(), ANNA_FILE_LOCATION)); - // Output: - std::ofstream out("./result.xml", std::ifstream::out); - std::string buffer = dictionary->asXMLString(); - out.write(buffer.c_str(), buffer.size()); - out.close(); - std::cout << "Written 'result.xml'" << std::endl; - } catch (anna::RuntimeException &ex) { - ex.trace(); - std::cout << ex.getText() << std::endl; - } - - _exit("Open 'file.trace' in order to see the stacks loaded"); + Logger::setLevel(Logger::Debug); + Logger::initialize("stackManagement", new TraceWriter("file.trace", 2048000)); + stack::Engine & engine = stack::Engine::instantiate(); + std::string exec = argv[0]; + std::string param = argv[1] ? argv[1] : ""; + + if(argc < 2) { + std::string msg = anna::functions::asString("Usage: %s ,\n i.e. '%s avps.xml commands.xml'", exec.c_str(), exec.c_str()); + _exit(msg); + } + + int index = 1; + const char *xmlFile = argv[index]; + stack::Dictionary *dictionary; + + try { + dictionary = engine.createDictionary(0 /* general unique stack id */); + dictionary->allowUpdates(); + + while(xmlFile) { + dictionary->load(xmlFile); + xmlFile = argv[++index]; + } + + engine.removeStack(0); + // Trace: + LOGINFORMATION(Logger::information(engine.asString(), ANNA_FILE_LOCATION)); + LOGDEBUG(Logger::debug(dictionary->asString(), ANNA_FILE_LOCATION)); + // Output: + std::ofstream out("./result.xml", std::ifstream::out); + std::string buffer = dictionary->asXMLString(); + out.write(buffer.c_str(), buffer.size()); + out.close(); + std::cout << "Written 'result.xml'" << std::endl; + } catch(anna::RuntimeException &ex) { + ex.trace(); + std::cout << ex.getText() << std::endl; + } + + _exit("Open 'file.trace' in order to see the stacks loaded"); } diff --git a/example/diameter/tme/main.cpp b/example/diameter/tme/main.cpp index 68e2295..2994e5f 100644 --- a/example/diameter/tme/main.cpp +++ b/example/diameter/tme/main.cpp @@ -56,20 +56,24 @@ typedef anna::diameter::codec::tme::Avp tmeAvp; void _exit(const std::string & msg) { - std::cout << std::endl << msg << std::endl; - exit(-1); + std::cout << std::endl << msg << std::endl; + exit(-1); } std::string exec_cmd(const char* cmd) { FILE* pipe = popen(cmd, "r"); - if (!pipe) return ""; + + if(!pipe) return ""; + char buffer[128]; std::string result = ""; + while(!feof(pipe)) { if(fgets(buffer, 128, pipe) != NULL) result += buffer; } + pclose(pipe); return result; } @@ -85,7 +89,7 @@ int main(int argc, char** argv) { std::string exec = argv[0]; std::string param = argv[1] ? argv[1] : ""; - if (argc < 2) { + if(argc < 2) { std::string msg = "Usage: "; msg += exec; msg += " "; msg += "\n xml directory: contains the xml files needed, which are:"; msg += "\n"; @@ -97,15 +101,15 @@ int main(int argc, char** argv) { msg += "\n"; msg += "\n For example: "; msg += exec; msg += " "; std::string projectRoot = exec_cmd("git rev-parse --show-toplevel"); - if (projectRoot != "") { + + if(projectRoot != "") { //projectRoot.resize(projectRoot.size()-1); - projectRoot.erase(projectRoot.size()-1); + projectRoot.erase(projectRoot.size() - 1); msg += projectRoot; msg += "/"; } msg += "source/diameter/stack/setups"; - _exit(msg); } @@ -118,13 +122,11 @@ int main(int argc, char** argv) { dictionary->load(param + "/avps_tme.xml"); dictionary->load(param + "/commands_dccaOCS-CS_HuaweiNGIN_de-es.xml"); codecEngine->setDictionary(dictionary); - // Trace: LOGINFORMATION(Logger::information(stackEngine.asString(), ANNA_FILE_LOCATION)); LOGDEBUG(Logger::debug(dictionary->asString(), ANNA_FILE_LOCATION)); LOGDEBUG(Logger::debug(codecEngine->asString(), ANNA_FILE_LOCATION)); - - } catch (anna::RuntimeException &ex) { + } catch(anna::RuntimeException &ex) { ex.trace(); std::cout << ex.getText() << std::endl; } @@ -132,48 +134,44 @@ int main(int argc, char** argv) { // Build CCA tmeMessage cca; cca.setId("Credit-Control-Answer"); - tmeAvp *sid = (tmeAvp*)cca.addAvp("Session-Id"); tmeAvp *ohst = (tmeAvp*)cca.addAvp("Origin-Host"); tmeAvp *orlm = (tmeAvp*)cca.addAvp("Origin-Realm"); - - sid->getUTF8String()->setValue("grump.example.com:33041;23432;893;0AF3B81"); + sid->getUTF8String()->setValue("grump.example.com:33041;23432;893;0AF3B81"); ohst->getDiameterIdentity()->setValue("c0-10-70-238-74-w5p1vepg1.vepc.ericsson.se"); orlm->getDiameterIdentity()->setValue("vepc.ericsson.se"); int inRange = 65535; int outRange = inRange + 1; //((tmeAvp*)cca.addAvp("CS-Result-Code"))->getUnsigned16()->setValue(inRange); ((tmeAvp*)cca.addAvp("CS-Result-Code"))->getUnsigned16()->setValue(outRange); // WILL BE 0 !! - -/* - - - - - - - - - - - - - - - - - - - - - - - - - -*/ - LOGDEBUG(Logger::debug(cca.asXMLString(), ANNA_FILE_LOCATION)); - - _exit("Open 'file.trace' in order to see traces"); + /* + + + + + + + + + + + + + + + + + + + + + + + + + + */ + LOGDEBUG(Logger::debug(cca.asXMLString(), ANNA_FILE_LOCATION)); + _exit("Open 'file.trace' in order to see traces"); } diff --git a/include/anna/core/util/MultiRangeExpression.hpp b/include/anna/core/util/MultiRangeExpression.hpp index ab3273c..a391bb5 100644 --- a/include/anna/core/util/MultiRangeExpression.hpp +++ b/include/anna/core/util/MultiRangeExpression.hpp @@ -113,10 +113,11 @@ public: * @param l Literal to be added */ void addLiteral(const char * l) throw() { - if (l) { + if(l) { a_literal += ","; a_literal += l; } + refresh(); } }; diff --git a/source/core/util/MultiRangeExpression.cpp b/source/core/util/MultiRangeExpression.cpp index 3c2307d..84e722c 100644 --- a/source/core/util/MultiRangeExpression.cpp +++ b/source/core/util/MultiRangeExpression.cpp @@ -114,37 +114,38 @@ std::string anna::MultiRangeExpression::getExpandedLiteral(void) const throw() { //-------------------------------------- MultiRangeExpression::simplifyLiteral() //------------------------------------------------------------------------------ const char * anna::MultiRangeExpression::simplifyLiteral(void) throw() { - - if (a_data.size() == 0) return NULL; + if(a_data.size() == 0) return NULL; std::map < unsigned int, int/*dummy*/ >::const_iterator it; std::map < unsigned int, int/*dummy*/ >::const_iterator it_min(a_data.begin()); std::map < unsigned int, int/*dummy*/ >::const_iterator it_max(a_data.end()); - unsigned int min = UINT_MAX; unsigned int max = 0; unsigned int value; unsigned int prevValue = a_data.begin()->first; - a_literal = ""; for(it = it_min; it != it_max; it++) { value = (*it).first; - if (value < min) min = value; - if (value - prevValue > 1) { + + if(value < min) min = value; + + if(value - prevValue > 1) { a_literal += anna::functions::asString(min); a_literal += "-"; a_literal += anna::functions::asString(max); a_literal += ","; min = value; } - if (value > max) max = value; + + if(value > max) max = value; prevValue = value; } a_literal += anna::functions::asString(min); - if (max != min) { + + if(max != min) { a_literal += "-"; a_literal += anna::functions::asString(max); }