hce-node application  1.4.3
HCE Hierarchical Cluster Engine node application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
sample.cpp
Go to the documentation of this file.
1 
14 #include <iostream>
15 
16 #include "LoggerStream.hpp"
17 #include "CustomMessage.hpp"
18 #include "RealLoggable.hpp"
19 
21 {
22  HCE::LoggerStream logger;
23  HCE::tests::RealLoggable realLoggable; // some user implemented class (child of interface class Loggable)
24 
25  /* default mode write to buffer */
26  logger << "test 1";
27  std::cout << "MSG1: " << logger.logMsg() << std::endl;
28 
29  logger << "TEST 2" << std::endl;
30  std::cout << "MSG2: " << logger.logMsg() << std::endl;
31 
32  /* below mode write to stream */
33  logger.setLogStream(std::cout); // turn on mode write to stream
34  logger.log() << "TEST CONSOLE" << std::endl;
35 
36  logger.resetLogStream(); // turn off mode write to stream
37  logger.log() << "THIS NEVER BEEN TO STREAM" << std::endl; // message will be write to buffer
38 
39  /* again mode write to buffer */
40  logger.log() << "test 3" << std::endl;
41  std::cout << "MSG3: " << logger.logMsg() << std::endl; // output buffer content (include "THIS NEVER BEEN TO STREAM")
42 
43  /* below used HCE::endl manipulator */
44  logger << "test 4" << HCE::endl;
45  std::cout << "MSG4: " << logger.logMsg() << std::endl;
46 
47  logger.setLoggable(realLoggable); // bind to class describing need behavior
48  logger << "test 5" << std::endl << "test 6" << HCE::endl;
49  std::cout << "MSG 5 and 6: " << logger.logMsg() << std::endl;
50 
51  logger.resetLoggable(); // unbind any classes describing need behavior
52  logger << "test 7";
53  std::cout << "MSG7: " << logger.logMsg() << std::endl;
54 }
55 
57 {
58  // list all messages need to functional objects
59  std::vector<std::pair<unsigned int, std::string> > messages =
60  {
61  {0, "TEST START"},
62  {1, "TEST DATA"},
63  {2, "TEST MSG"},
64  {3, "TEST STOP"}
65  };
66 
67  HCE::MessagesCollection messagesCollection(messages); // initialization collection
68  HCE::CustomMessage msg(messagesCollection);
69 
70  /* output messages with default delimiter tokens */
71  std::cout << msg(0) << std::endl;
72  std::cout << msg(1, 42) << std::endl;
73  std::cout << msg(2, "USER MESSAGE") << std::endl;
74  std::cout << msg(3) << std::endl;
75 
76  /* set custom delimiter tokens */
77  HCE::CustomMessage::MsgConst msgConst = { '*', ';', '-'};
78  msg.setMsgConst(msgConst);
79 
80  /* output messages with custom delimiter tokens */
81  std::cout << msg(0) << std::endl;
82  std::cout << msg(1, 42) << std::endl;
83  std::cout << msg(2, "USER MESSAGE") << std::endl;
84  std::cout << msg(3) << std::endl;
85 }
86 
87 int main(int argc, char** argv)
88 {
91  return 0;
92 }