1 // ANNA - Anna is Not Nothingness Anymore
3 // (c) Copyright 2005-2014 Eduardo Ramos Testillano & Francisco Ruiz Rayo
5 // http://redmine.teslayout.com/projects/anna-suite
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions
11 // * Redistributions of source code must retain the above copyright
12 // notice, this list of conditions and the following disclaimer.
13 // * Redistributions in binary form must reproduce the above
14 // copyright notice, this list of conditions and the following disclaimer
15 // in the documentation and/or other materials provided with the
17 // * Neither the name of the copyright holder nor the names of its
18 // contributors may be used to endorse or promote products derived from
19 // this software without specific prior written permission.
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 // Authors: eduardo.ramos.testillano@gmail.com
34 // cisco.tierra@gmail.com
39 #include <anna/core/util/CommandLine.hpp>
40 #include <anna/core/DataBlock.hpp>
41 #include <anna/core/tracing/TraceWriter.hpp>
42 #include <anna/core/tracing/Logger.hpp>
44 #include <anna/comm/comm.hpp>
46 #include <anna/app/Application.hpp>
48 class MyCodec : public Codec {
50 MyCodec () : Codec (0xaa, false)
52 attach ("string", a_string);
53 attach ("integer", a_integer);
56 void set (const char* value) throw () { a_string = value; }
57 void set (const int value) throw () { a_integer = value; }
59 const std::string& getString () const throw () { return a_string; }
60 const int getInteger () const throw () { return a_integer; }
67 class Test : public anna::app::Application {
74 void show (const LargeBinaryCodec& lbc) throw (anna::RuntimeException);
76 void run () throw (anna::RuntimeException);
82 int main (int argc, const char** argv)
84 CommandLine& commandLine (CommandLine::instantiate ());
86 TraceWriter traceWriter ("my.trace", 2048000);
89 commandLine.initialize (argv, argc);
90 commandLine.verify ();
92 Logger::initialize ("testfunctions", &traceWriter);
93 Logger::setLevel (Logger::Debug);
97 catch (Exception& ex) {
98 cout << ex.asString () << endl;
105 anna::app::Application ("testfunctions", "Comprobacin de la clase Codec", "1.0")
107 CommandLine& commandLine (CommandLine::instantiate ());
109 commandLine.add ("i", CommandLine::Argument::Mandatory, "Enterno a enviar");
113 throw (RuntimeException)
115 CommandLine& cm (CommandLine::instantiate ());
116 LargeBinaryCodec input (1, false);
117 LargeBinaryCodec output (1, false);
119 a_input.set ("12345");
120 a_input.set (cm.getIntegerValue ("i"));
121 input += a_input.code ();
123 a_input.set ("6789");
124 a_input.set (cm.getIntegerValue ("i") + 10);
125 input += a_input.code ();
127 a_input.set ("abcdefg");
128 a_input.set (cm.getIntegerValue ("i") + 20);
129 input += a_input.code ();
131 cout << "------------- Input LargeBinaryCodec: " << endl;
134 cout << "------------- Output LargeBinaryCodec: " << endl;
135 const DataBlock& all = input.code (); // Codifica el LBC.
136 output.decode (all); // Lo decodific
140 void Test::show (const LargeBinaryCodec& lbc)
141 throw (RuntimeException)
145 cout << "Size: " << lbc.size () << endl;
147 for (LargeBinaryCodec::const_iterator ii = lbc.begin (), maxii = lbc.end (); ii != maxii; ii ++) {
148 const DataBlock& chunk = *LargeBinaryCodec::data (ii);
150 Logger::debug (anna::functions::asString (chunk), ANNA_FILE_LOCATION);
152 output.decode (chunk);
154 cout << "String: " << output.getString () << endl;
155 cout << "Integer: " << output.getInteger () << endl << endl;