1 // ANNA - Anna is Not Nothingness Anymore //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
11 #include <anna/core/util/CommandLine.hpp>
12 #include <anna/core/DataBlock.hpp>
13 #include <anna/core/tracing/TraceWriter.hpp>
14 #include <anna/core/tracing/Logger.hpp>
16 #include <anna/comm/comm.hpp>
18 #include <anna/app/Application.hpp>
20 class MyCodec : public Codec {
22 MyCodec () : Codec (0xaa, false)
24 attach ("string", a_string);
25 attach ("integer", a_integer);
28 void set (const char* value) throw () { a_string = value; }
29 void set (const int value) throw () { a_integer = value; }
31 const std::string& getString () const throw () { return a_string; }
32 const int getInteger () const throw () { return a_integer; }
39 class Test : public anna::app::Application {
46 void show (const LargeBinaryCodec& lbc) throw (anna::RuntimeException);
48 void run () throw (anna::RuntimeException);
54 int main (int argc, const char** argv)
56 CommandLine& commandLine (CommandLine::instantiate ());
58 TraceWriter traceWriter ("my.trace", 2048000);
61 commandLine.initialize (argv, argc);
62 commandLine.verify ();
64 Logger::initialize ("testfunctions", &traceWriter);
65 Logger::setLevel (Logger::Debug);
69 catch (Exception& ex) {
70 cout << ex.asString () << endl;
77 anna::app::Application ("testfunctions", "Comprobacin de la clase Codec", "1.0")
79 CommandLine& commandLine (CommandLine::instantiate ());
81 commandLine.add ("i", CommandLine::Argument::Mandatory, "Enterno a enviar");
85 throw (RuntimeException)
87 CommandLine& cm (CommandLine::instantiate ());
88 LargeBinaryCodec input (1, false);
89 LargeBinaryCodec output (1, false);
91 a_input.set ("12345");
92 a_input.set (cm.getIntegerValue ("i"));
93 input += a_input.code ();
96 a_input.set (cm.getIntegerValue ("i") + 10);
97 input += a_input.code ();
99 a_input.set ("abcdefg");
100 a_input.set (cm.getIntegerValue ("i") + 20);
101 input += a_input.code ();
103 cout << "------------- Input LargeBinaryCodec: " << endl;
106 cout << "------------- Output LargeBinaryCodec: " << endl;
107 const DataBlock& all = input.code (); // Codifica el LBC.
108 output.decode (all); // Lo decodific
112 void Test::show (const LargeBinaryCodec& lbc)
113 throw (RuntimeException)
117 cout << "Size: " << lbc.size () << endl;
119 for (LargeBinaryCodec::const_iterator ii = lbc.begin (), maxii = lbc.end (); ii != maxii; ii ++) {
120 const DataBlock& chunk = *LargeBinaryCodec::data (ii);
122 Logger::debug (anna::functions::asString (chunk), ANNA_FILE_LOCATION);
124 output.decode (chunk);
126 cout << "String: " << output.getString () << endl;
127 cout << "Integer: " << output.getInteger () << endl << endl;