1#ifndef FASTUIDRAW_DEMO_COMMAND_LINE_LIST_HPP
2#define FASTUIDRAW_DEMO_COMMAND_LINE_LIST_HPP
3
4#include <set>
5#include "generic_command_line.hpp"
6
7template<typename T>
8class command_line_list:
9 public command_line_argument,
10 public std::set<T>
11{
12public:
13 command_line_list(const std::string &nm,
14 const std::string &desc,
15 command_line_register &p):
16 command_line_argument(p),
17 m_name(nm)
18 {
19 std::ostringstream ostr;
20 ostr << "\n\t" << m_name << " value"
21 << format_description_string(m_name, desc);
22 m_description = tabs_to_spaces(ostr.str());
23 }
24
25 virtual
26 int
27 check_arg(const std::vector<std::string> &argv, int location)
28 {
29 int argc(argv.size());
30 if (location + 1 < argc && argv[location] == m_name)
31 {
32 T v;
33 readvalue_from_string(v, argv[location + 1]);
34 this->insert(v);
35 std::cout << "\n\t" << m_name << " added: ";
36 writevalue_to_stream(v, std::cout);
37 return 2;
38 }
39 return 0;
40 }
41
42 virtual
43 void
44 print_command_line_description(std::ostream &ostr) const
45 {
46 ostr << "[" << m_name << " value] ";
47 }
48
49 virtual
50 void
51 print_detailed_description(std::ostream &ostr) const
52 {
53 ostr << m_description;
54 }
55
56private:
57 std::string m_name, m_description;
58};
59
60#endif
61