X-Git-Url: https://git.teslayout.com/public/public/public/?a=blobdiff_plain;f=source%2Fcomm%2FCompatCodec.cpp;h=39b44757c43df173e8d21903f24bf56ceeece7f8;hb=5a6cba5fde2b2f538a7515f8293cc0a8d9589dfa;hp=1243fb639b5e0b11f29488461f611d347392937e;hpb=4e12ac57e93c052f716a6305ad8fc099c45899d1;p=anna.git diff --git a/source/comm/CompatCodec.cpp b/source/comm/CompatCodec.cpp index 1243fb6..39b4475 100644 --- a/source/comm/CompatCodec.cpp +++ b/source/comm/CompatCodec.cpp @@ -1,37 +1,9 @@ -// ANNA - Anna is Not 'N' Anymore -// -// (c) Copyright 2005-2014 Eduardo Ramos Testillano & Francisco Ruiz Rayo -// -// https://bitbucket.org/testillano/anna -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions -// are met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Authors: eduardo.ramos.testillano@gmail.com -// cisco.tierra@gmail.com +// ANNA - Anna is Not Nothingness Anymore // +// // +// (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo // +// // +// See project site at http://redmine.teslayout.com/projects/anna-suite // +// See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE // #include @@ -57,7 +29,7 @@ bool comm::CompatCodec::st_initScramble(false); // static template comm::Variable* insert(const char* name, const short int id, M& theVector, T& value) -throw(RuntimeException) { +noexcept(false) { comm::Variable* result = theVector.find(id); if(result != NULL) @@ -74,7 +46,7 @@ throw(RuntimeException) { // static template comm::Variable* insertRef(const char* name, const short int id, M& theVector, T& value) -throw(RuntimeException) { +noexcept(false) { comm::Variable* result = theVector.find(id); if(result != NULL) @@ -108,28 +80,28 @@ comm::CompatCodec::~CompatCodec() { } const comm::Variable* comm::CompatCodec::attach(const char* name, const short int id, std::string& value) -throw(RuntimeException) { +noexcept(false) { return insert(name, id, a_variables, value); } const comm::Variable* comm::CompatCodec::attach(const char* name, const short int id, int& value) -throw(RuntimeException) { +noexcept(false) { const int backup(value); const Variable* result = insert(name, id, a_variables, value); value = backup; return result; } -const comm::Variable* comm::CompatCodec::attach(const char* name, const short int id, Integer64& value) -throw(RuntimeException) { - const Integer64 backup(value); +const comm::Variable* comm::CompatCodec::attach(const char* name, const short int id, S64& value) +noexcept(false) { + const S64 backup(value); const Variable* result = insert(name, id, a_variables, value); value = backup; return result; } const comm::Variable* comm::CompatCodec::attach(const char* name, const short int id, bool& value) -throw(RuntimeException) { +noexcept(false) { const bool backup(value); const Variable* result = insert(name, id, a_variables, value); value = backup; @@ -137,12 +109,12 @@ throw(RuntimeException) { } const comm::Variable* comm::CompatCodec::attach(const char* name, const short int id, DataBlock& value) -throw(RuntimeException) { +noexcept(false) { return insert(name, id, a_variables, value); } const comm::Variable* comm::CompatCodec::attach(const char* name, const short int id, float& value) -throw(RuntimeException) { +noexcept(false) { const float backup(value); const Variable* result = insert(name, id, a_variables, value); value = backup; @@ -150,7 +122,7 @@ throw(RuntimeException) { } const comm::Variable* comm::CompatCodec::attach(const char* name, const short int id, double& value) -throw(RuntimeException) { +noexcept(false) { const double backup(value); const Variable* result = insert(name, id, a_variables, value); value = backup; @@ -158,7 +130,7 @@ throw(RuntimeException) { } const comm::Variable* comm::CompatCodec::attach(const char* name, const short int id, Second& value) -throw(RuntimeException) { +noexcept(false) { const Second backup(value); const Variable* result = insertRef(name, id, a_variables, value); value = backup; @@ -166,7 +138,7 @@ throw(RuntimeException) { } const comm::Variable* comm::CompatCodec::attach(const char* name, const short int id, Millisecond& value) -throw(RuntimeException) { +noexcept(false) { const Millisecond backup(value); const Variable* result = insertRef(name, id, a_variables, value); value = backup; @@ -174,7 +146,7 @@ throw(RuntimeException) { } const comm::Variable* comm::CompatCodec::attach(const char* name, const short int id, Microsecond& value) -throw(RuntimeException) { +noexcept(false) { const Microsecond backup(value); const Variable* result = insertRef(name, id, a_variables, value); value = backup; @@ -182,7 +154,7 @@ throw(RuntimeException) { } const comm::Variable* comm::CompatCodec::attach(const char* name, const short int id, comm::CompatCodec& value) -throw(RuntimeException) { +noexcept(false) { if(&value == this) { String msg("comm::CompatCodec::attach | Variable: "); msg << name << " | Can not link with itself"; @@ -193,48 +165,36 @@ throw(RuntimeException) { } void comm::CompatCodec::setNull(const short int id, const bool isNull) -throw(RuntimeException) { +noexcept(false) { Variable* variable = a_variables.find(id); if(variable == NULL) throw RuntimeException(functions::asString("Id %d is not defined", id), ANNA_FILE_LOCATION); - switch(variable->isNull()) { - case true: - + if(variable->isNull()) { if(isNull == false) a_nullCounter --; - - break; - case false: - + } + else { if(isNull == true) a_nullCounter ++; - - break; } variable->setNull(isNull); } void comm::CompatCodec::setNull(const comm::Variable* variable, const bool isNull) -throw() { - switch(variable->isNull()) { - case true: - +{ + if(variable->isNull()) { if(isNull == false) a_nullCounter --; - - break; - case false: - + } + else { if(isNull == true) a_nullCounter ++; - - break; } const_cast (variable)->setNull(isNull); } bool comm::CompatCodec::isNull(const short int id) const -throw(RuntimeException) { +noexcept(false) { const Variable* variable = a_variables.find(id); if(variable == NULL) @@ -244,7 +204,7 @@ throw(RuntimeException) { } const comm::Variable& comm::CompatCodec::find(const short int id) const -throw(RuntimeException) { +noexcept(false) { const Variable* variable = a_variables.find(id); if(variable == NULL) @@ -280,14 +240,14 @@ throw(RuntimeException) { // la recogida de datos. //----------------------------------------------------------------------- const DataBlock& comm::CompatCodec::code() -throw(RuntimeException) { - register unsigned char c(0); +noexcept(false) { + unsigned char c(0); iterator ii; iterator maxii(a_variables.end()); - register Variable* variable; + Variable* variable; int stringLen; const char* string; - char aux [sizeof(Integer64)]; + char aux [sizeof(S64)]; if(a_scramble == true) // (1) while(c == 0) c = rand() % 0xff; @@ -317,7 +277,7 @@ throw(RuntimeException) { break; case Variable::Type::Integer64: self += variable->codec(); - self.append(comm::functions::codeInteger64(aux, variable->getInteger64()), sizeof(Integer64)); + self.append(comm::functions::codeInteger64(aux, variable->getInteger64()), sizeof(S64)); break; case Variable::Type::Boolean: self.append(comm::functions::codeShort(aux, variable->getId()), sizeof(short int)); // (3) @@ -349,6 +309,7 @@ throw(RuntimeException) { self += codec; } break; + default: break; } } @@ -364,7 +325,7 @@ throw(RuntimeException) { char* data = const_cast (self.getData()); int size = self.getSize(); - for(register int i = 1, key = data [0]; i < size; i ++) + for(int i = 1, key = data [0]; i < size; i ++) data [i] ^= key ++; } @@ -373,7 +334,7 @@ throw(RuntimeException) { //------------------------------------------------------------------------------------------- void comm::CompatCodec::decode(const DataBlock& dataBlock) -throw(RuntimeException) { +noexcept(false) { const char* data = dataBlock.getData(); const int size = dataBlock.getSize(); @@ -381,7 +342,7 @@ throw(RuntimeException) { throw RuntimeException("Can not decode an empty DataBlock", ANNA_FILE_LOCATION); if(data [0] != 0) - for(register int i = 1, key(data [0]); i < size; i ++) + for(int i = 1, key(data [0]); i < size; i ++) const_cast (data)[i] ^= key ++; LOGDEBUG(Logger::write(Logger::Debug, "comm::CompatCodec::decode", dataBlock, ANNA_FILE_LOCATION)); @@ -403,7 +364,7 @@ throw(RuntimeException) { // Decodifica los buffers que pueden contener variables nulas. //------------------------------------------------------------------------------------------- void comm::CompatCodec::normalDecode(const char* data, const int size, const int maxdata) -throw(RuntimeException) { +noexcept(false) { // Mientras no se demuestre lo contrario todas las variables son nulas a_nullCounter = a_variables.size(); @@ -440,7 +401,7 @@ throw(RuntimeException) { break; case Variable::Type::Integer64: variable->setValue(comm::functions::decodeInteger64(++ data)); - data += sizeof(Integer64); + data += sizeof(S64); break; case Variable::Type::Boolean: variable->setBoolean((*data & 0x80) ? true : false); @@ -493,7 +454,7 @@ throw(RuntimeException) { // (1) El codigo de la variable //------------------------------------------------------------------------------------------- bool comm::CompatCodec::optimizedDecode(const char* data, const int size) -throw(RuntimeException) { +noexcept(false) { int nbytes; Variable* variable; const char* top = data + size; @@ -515,7 +476,7 @@ throw(RuntimeException) { break; case Variable::Type::Integer64: variable->setValue(comm::functions::decodeInteger64(++ data)); - data += sizeof(Integer64); + data += sizeof(S64); break; case Variable::Type::Boolean: variable->setBoolean((*data & 0x80) ? true : false); @@ -549,7 +510,7 @@ throw(RuntimeException) { } comm::CompatCodec::Type comm::CompatCodec::getType(const DataBlock& dataBlock) -throw(RuntimeException) { +noexcept(false) { const int size(dataBlock.getSize()); if(size <= 1) @@ -570,7 +531,7 @@ comm::CompatCodec::VariableContainer::VariableContainer() { } void comm::CompatCodec::VariableContainer::add(comm::Variable* variable) -throw() { +{ if(a_size == a_maxSize) { int maxSize = (a_maxSize << 1) - (a_maxSize >> 1); Variable** variables = new Variable* [maxSize]; @@ -585,8 +546,8 @@ throw() { } comm::Variable* comm::CompatCodec::VariableContainer::find(const int id) -throw() { - for(register int ii = 0; ii < a_size; ii ++) { +{ + for(int ii = 0; ii < a_size; ii ++) { if(a_variables [ii]->getId() == id) return a_variables [ii]; } @@ -595,8 +556,8 @@ throw() { } const comm::Variable* comm::CompatCodec::VariableContainer::find(const int id) const -throw() { - for(register int ii = 0; ii < a_size; ii ++) { +{ + for(int ii = 0; ii < a_size; ii ++) { if(a_variables [ii]->getId() == id) return a_variables [ii]; } @@ -605,7 +566,7 @@ throw() { } void comm::CompatCodec::VariableContainer::clear() -throw() { +{ delete [] a_variables; a_maxSize = a_size = 0; }