File: main.cpp

package info (click to toggle)
libclaw 1.7.4-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,080 kB
  • sloc: cpp: 13,287; sh: 227; makefile: 8
file content (81 lines) | stat: -rw-r--r-- 2,149 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/**
 * \file main.cpp
 * \brief This program show a basic use of the claw::application class.
 * \author Julien Jorgex
 */
#include <claw/application.hpp>
#include <claw/logger.hpp>

#include <iostream>

/**
 * \brief This class represents the application.
 */
class my_app : public claw::application
{
public:
  my_app( int& argc, char** &argv );
  int run();
}; // class my_app

/*----------------------------------------------------------------------------*/
/**
 * \brief Constructor. Parse the command line and initialize the application.
 */
my_app::my_app( int& argc, char** &argv )
  : claw::application(argc, argv)
{
  m_arguments.add_short("-b", "Sample boolean argument.", true);
  m_arguments.add_long("--string", "Print a string.", true, "any_string");
  m_arguments.add("-h", "--help", "Print this help screen.", true);

  m_arguments.parse(argc, argv);

  if ( m_arguments.get_bool("-h") )
    m_arguments.help( "more_string..." );

  std::cout << "Testing error_level:" << std::endl;

  claw::logger << claw::log_error << "error_level:program_name == "
	       << m_arguments.get_program_name() << claw::lendl;

  std::cout << "Testing warning_level:" << std::endl;

  for (int i=0; i<argc; ++i)
    claw::logger << claw::log_warning << "warning_level:argument " << i
		 << " == " << argv[i] << claw::lendl;

} // my_app::my_app()

/*----------------------------------------------------------------------------*/
/**
 * \brief This is the main loop.
 */
int my_app::run()
{
  std::cout << "Testing verbose_level:" << std::endl;

  claw::logger <<  claw::log_verbose << "verbose_level:m_app is running\n";

  std::cout << "'-b' argument is ";

  if ( m_arguments.get_bool("-b") )
    std::cout << "present.";
  else
    std::cout << "missing.";

  std::cout << std::endl;

  std::cout << "'--string' argument value is '";

  if ( m_arguments.has_value("--string") )
    std::cout << m_arguments.get_string("--string");

  std::cout << "'" << std::endl;

  return 0;
} // my_app::run()

// this macro defines the main function, declare a variable of type my_app and
// call the my_app::run() method.
CLAW_APPLICATION_IMPLEMENT(my_app)