------------------------------------------------------------ revno: 22 committer: [email protected] branch nick: dev timestamp: Fri 2010-12-31 06:46:54 -0500 message: Create new serializer class. It is a thread safe functor class returning a sequence of numbers increaseing by 1 on each call. It has been unit tested as is believed ready to use. added: common/serializer/ common/serializer/Makefile common/serializer/serializer.cpp common/serializer/serializer.h common/serializer/serializer_test.cpp
-- lp:~fpstovall/nrtb/cpp_common https://code.launchpad.net/~fpstovall/nrtb/cpp_common Your team NRTB Core is subscribed to branch lp:~fpstovall/nrtb/cpp_common. To unsubscribe from this branch go to https://code.launchpad.net/~fpstovall/nrtb/cpp_common/+edit-subscription
=== added directory 'common/serializer' === added file 'common/serializer/Makefile' --- common/serializer/Makefile 1970-01-01 00:00:00 +0000 +++ common/serializer/Makefile 2010-12-31 11:46:54 +0000 @@ -0,0 +1,36 @@ +#*********************************************** +#This file is part of the NRTB project (https://launchpad.net/nrtb). +# +# NRTB is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# NRTB is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with NRTB. If not, see <http://www.gnu.org/licenses/>. +# +#*********************************************** + +lib: serializer_test + @./serializer_test + @cp -v serializer.h ../include + @cp -v serializer.o ../obj + @echo build complete + +serializer.o: serializer.h serializer.cpp Makefile + @rm -f serializer.o + g++ -c serializer.cpp -I ../include + +serializer_test: serializer.o serializer_test.cpp + @rm -f serializer_test + g++ -c serializer_test.cpp + g++ -o serializer_test serializer_test.o serializer.o -lPocoFoundation -lPocoUtil + +clean: + @rm -rvf *.o serializer_test ../include/serializer.h ../obj/serializer.o + @echo all objects and executables have been erased. === added file 'common/serializer/serializer.cpp' --- common/serializer/serializer.cpp 1970-01-01 00:00:00 +0000 +++ common/serializer/serializer.cpp 2010-12-31 11:46:54 +0000 @@ -0,0 +1,43 @@ +/*********************************************** + T his file is part of the NRTB project (https://*launchpad.net/nrtb). + + NRTB is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + NRTB is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with NRTB. If not, see <http://www.gnu.org/licenses/>. + + **********************************************/ + +#include "serializer.h" +#include <Poco/ScopedLock.h> + +using namespace nrtb; + +nrtb::serializer::serializer() +{ + counter = 0; +}; + +nrtb::serializer::serializer(unsigned long long start) +{ + counter = start; +}; + +serializer::~serializer() +{ + // nop destructor +}; + +unsigned long long serializer::operator()() +{ + Poco::ScopedLock<Poco::Mutex> mylock(lock); + return counter++; +} === added file 'common/serializer/serializer.h' --- common/serializer/serializer.h 1970-01-01 00:00:00 +0000 +++ common/serializer/serializer.h 2010-12-31 11:46:54 +0000 @@ -0,0 +1,42 @@ +/*********************************************** + T his file is part of the NRTB project (https://*launchpad.net/nrtb). + + NRTB is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + NRTB is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with NRTB. If not, see <http://www.gnu.org/licenses/>. + + **********************************************/ + +#ifndef nrtb_serializer_h +#define nrtb_serializer_h +#include <boost/concept_check.hpp> + +#include <Poco/Mutex.h> + +namespace nrtb +{ + + class serializer + { + public: + serializer(); + serializer(unsigned long long start); + ~serializer(); + unsigned long long operator ()(); + private: + Poco::Mutex lock; + unsigned long long int counter; + }; + +} + +#endif // nrtb_serializer_h \ No newline at end of file === added file 'common/serializer/serializer_test.cpp' --- common/serializer/serializer_test.cpp 1970-01-01 00:00:00 +0000 +++ common/serializer/serializer_test.cpp 2010-12-31 11:46:54 +0000 @@ -0,0 +1,56 @@ +/*********************************************** + T his file is part of the NRTB project (https://*launchpad.net/nrtb). + + NRTB is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + NRTB is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with NRTB. If not, see <http://www.gnu.org/licenses/>. + + **********************************************/ + +#include "serializer.h" +#include <iostream> + +using namespace nrtb; +using namespace std; + +int main() +{ + cout << "** nrtb::serializer unit test **" << endl; + bool set_if_failed = false; + serializer set_default; + serializer set_start(20); + serializer rollover((unsigned long long)(0 - 1)); + cout << "Default initialization" << endl; + cout << " " << set_default(); + cout << " " << set_default(); + cout << " " << set_default(); + cout << endl; + if (set_default() != 3) + set_if_failed = true; + cout << "Started from twenty" << endl; + cout << " " << set_start(); + cout << " " << set_start(); + cout << " " << set_start(); + cout << endl; + if (set_start() != 23) + set_if_failed = true; + cout << "Rollover Demonstration" << endl; + cout << " " << rollover(); + cout << " " << rollover(); + cout << " " << rollover(); + cout << endl; + if (rollover() != 2) + set_if_failed = true; + if (set_if_failed) + cout << "UNIT TEST FAILED" << endl; + return set_if_failed; +}; \ No newline at end of file
_______________________________________________ Mailing list: https://launchpad.net/~nrtb-core Post to : [email protected] Unsubscribe : https://launchpad.net/~nrtb-core More help : https://help.launchpad.net/ListHelp

