LOGIN / SIGN UP
Replace CfgParserKeyInt with CfgParserKeyNumeric.
2008-11-30 15:54 0ee68..f41ff

src/Config.cc
 
542 @@ -542,10 +542,10 @@
542 }
543
544 list<CfgParserKey*> key_list;
545 key_list.push_back(new CfgParserKeyInt("EDGEATTRACT", _moveresize_edgeattract, 0, 0));
546 key_list.push_back(new CfgParserKeyInt("EDGERESIST", _moveresize_edgeresist, 0, 0));
547 key_list.push_back(new CfgParserKeyInt("WINDOWATTRACT",_moveresize_woattract, 0, 0));
548 key_list.push_back(new CfgParserKeyInt("WINDOWRESIST", _moveresize_woresist, 0, 0));
549 key_list.push_back(new CfgParserKeyNumeric<int>("EDGEATTRACT", _moveresize_edgeattract, 0, 0));
550 key_list.push_back(new CfgParserKeyNumeric<int>("EDGERESIST", _moveresize_edgeresist, 0, 0));
551 key_list.push_back(new CfgParserKeyNumeric<int>("WINDOWATTRACT",_moveresize_woattract, 0, 0));
552 key_list.push_back(new CfgParserKeyNumeric<int>("WINDOWRESIST", _moveresize_woresist, 0, 0));
553 key_list.push_back(new CfgParserKeyBool("OPAQUEMOVE", _moveresize_opaquemove));
554 key_list.push_back(new CfgParserKeyBool("OPAQUERESIZE", _moveresize_opaqueresize));
555
...
570 @@ -570,13 +570,13 @@
570 CfgParser::Entry *value;
571
572 list<CfgParserKey*> key_list;
573 key_list.push_back(new CfgParserKeyInt("WORKSPACES", _screen_workspaces, 4, 1));
574 key_list.push_back(new CfgParserKeyInt("PIXMAPCACHESIZE", _screen_pixmap_cache_size));
575 key_list.push_back(new CfgParserKeyInt("WORKSPACESPERROW", _screen_workspaces_per_row, 0, 0));
576 key_list.push_back(new CfgParserKeyNumeric<int>("WORKSPACES", _screen_workspaces, 4, 1));
577 key_list.push_back(new CfgParserKeyNumeric<int>("PIXMAPCACHESIZE", _screen_pixmap_cache_size));
578 key_list.push_back(new CfgParserKeyNumeric<int>("WORKSPACESPERROW", _screen_workspaces_per_row, 0, 0));
579 key_list.push_back(new CfgParserKeyString("WORKSPACENAMES", workspace_names));
580 key_list.push_back(new CfgParserKeyString("EDGESIZE", edge_size));
581 key_list.push_back(new CfgParserKeyBool("EDGEINDENT", _screen_edge_indent));
582 key_list.push_back(new CfgParserKeyInt("DOUBLECLICKTIME", _screen_doubleclicktime, 250, 0));
583 key_list.push_back(new CfgParserKeyNumeric<int>("DOUBLECLICKTIME", _screen_doubleclicktime, 250, 0));
584 key_list.push_back(new CfgParserKeyString("TRIMTITLE", trim_title));
585 key_list.push_back(new CfgParserKeyBool("FULLSCREENABOVE", _screen_fullscreen_above, true));
586 key_list.push_back(new CfgParserKeyBool("FULLSCREENDETECT", _screen_fullscreen_detect, true));
...
584 @@ -584,9 +584,9 @@
584 key_list.push_back(new CfgParserKeyBool("SHOWSTATUSWINDOW", _screen_show_status_window));
585 key_list.push_back(new CfgParserKeyBool("SHOWSTATUSWINDOWCENTEREDONROOT", _screen_show_status_window_on_root, false));
586 key_list.push_back(new CfgParserKeyBool("SHOWCLIENTID", _screen_show_client_id));
587 key_list.push_back(new CfgParserKeyInt("SHOWWORKSPACEINDICATOR",
588 key_list.push_back(new CfgParserKeyNumeric<int>("SHOWWORKSPACEINDICATOR",
589 _screen_show_workspace_indicator, 500, 0));
590 key_list.push_back(new CfgParserKeyInt("WORKSPACEINDICATORSCALE",
591 key_list.push_back(new CfgParserKeyNumeric<int>("WORKSPACEINDICATORSCALE",
592 _screen_workspace_indicator_scale, 16, 2));
593 key_list.push_back(new CfgParserKeyBool("PLACENEW", _screen_place_new));
594 key_list.push_back(new CfgParserKeyBool("FOCUSNEW", _screen_focus_new));
...
652 @@ -652,8 +652,8 @@
652 key_list.push_back(new CfgParserKeyBool("ROW", _screen_placement_row));
653 key_list.push_back(new CfgParserKeyBool("LEFTTORIGHT", _screen_placement_ltr));
654 key_list.push_back(new CfgParserKeyBool("TOPTOBOTTOM", _screen_placement_ttb));
655 key_list.push_back(new CfgParserKeyInt("OFFSETX", _screen_placement_offset_x, 0, 0));
656 key_list.push_back(new CfgParserKeyInt("OFFSETY", _screen_placement_offset_y, 0, 0));
657 key_list.push_back(new CfgParserKeyNumeric<int>("OFFSETX", _screen_placement_offset_x, 0, 0));
658 key_list.push_back(new CfgParserKeyNumeric<int>("OFFSETY", _screen_placement_offset_y, 0, 0));
659
660 // Do the parsing
661 sub_2->parse_key_values(key_list.begin(), key_list.end());
...
726 @@ -726,9 +726,9 @@
726 list<CfgParserKey*> key_list;
727
728 key_list.push_back(new CfgParserKeyBool("HISTORYUNIQUE", _cmd_dialog_history_unique));
729 key_list.push_back(new CfgParserKeyInt("HISTORYSIZE", _cmd_dialog_history_size, 1024, 1));
730 key_list.push_back(new CfgParserKeyNumeric<int>("HISTORYSIZE", _cmd_dialog_history_size, 1024, 1));
731 key_list.push_back(new CfgParserKeyPath("HISTORYFILE", _cmd_dialog_history_file, "~/.pekwm/history"));
732 key_list.push_back(new CfgParserKeyInt("HISTORYSAVEINTERVAL", _cmd_dialog_history_save_interval, 16, 0));
733 key_list.push_back(new CfgParserKeyNumeric<int>("HISTORYSAVEINTERVAL", _cmd_dialog_history_save_interval, 16, 0));
734
735 section->parse_key_values(key_list.begin(), key_list.end());
736
...
749 @@ -749,7 +749,7 @@
749
750 key_list.push_back(new CfgParserKeyBool("ONTOP", _harbour_ontop));
751 key_list.push_back(new CfgParserKeyBool("MAXIMIZEOVER", _harbour_maximize_over));
752 key_list.push_back(new CfgParserKeyInt("HEAD", _harbour_head_nr, 0, 0));
753 key_list.push_back(new CfgParserKeyNumeric<int>("HEAD", _harbour_head_nr, 0, 0));
754 key_list.push_back(new CfgParserKeyString("PLACEMENT", value_placement, "RIGHT", 0));
755 key_list.push_back(new CfgParserKeyString("ORIENTATION", value_orientation, "TOPTOBOTTOM", 0));
756
...
771 @@ -771,8 +771,8 @@
771
772 CfgParser::Entry *sub = section->find_section("DOCKAPP");
773 if (sub) {
774 key_list.push_back(new CfgParserKeyInt("SIDEMIN", _harbour_da_min_s, 64, 0));
775 key_list.push_back(new CfgParserKeyInt("SIDEMAX", _harbour_da_max_s, 64, 0));
776 key_list.push_back(new CfgParserKeyNumeric<int>("SIDEMIN", _harbour_da_min_s, 64, 0));
777 key_list.push_back(new CfgParserKeyNumeric<int>("SIDEMAX", _harbour_da_max_s, 64, 0));
778
779 // Parse data
780 sub->parse_key_values(key_list.begin(), key_list.end());
...

src/CfgParserKey.hh
 
10 @@ -10,6 +10,7 @@
10
11 #include <string>
12 #include <limits>
13 #include <cstdlib>
14
15 #include "Util.hh"
16
...
18 @@ -17,7 +18,7 @@
18 enum CfgParserKeyType {
19 KEY_SECTION, //!< Subsection.
20 KEY_BOOL, //!< Boolean value.
20 KEY_INT, //!< Integer value.
22 KEY_NUMERIC, //!< Integer value.
23 KEY_STRING, //!< String value.
24 KEY_PATH //!< Path value.
25 };
...
44 @@ -43,31 +44,77 @@
44 const char *_name; //!< Key name.
45 };
46
46
47 //! @brief CfgParser Key integer value parser.
48 class CfgParserKeyInt : public CfgParserKey {
50 /**
51 * CfgParserKey numeric type with minimum, maximum and default
52 * value. The type must be available in numeric_limits.
53 */
54 template<typename T>
55 class CfgParserKeyNumeric : public CfgParserKey {
56 public:
56 //! @brief CfgParserKeyInt constructor.
57 CfgParserKeyInt(const char *name,
58 int &set, const int default_val = 0,
59 const int value_min = std::numeric_limits<int>::min(),
60 const int value_max = std::numeric_limits<int>::max())
62 /**
63 * CfgParserKeyNumeric constructor, sets default values
64 *
65 * @param name Name of the key.
66 * @param set Variable to store parsed value in.
67 * @param default_val Default value for key, defaults to 0.
68 * @param value_min Minimum value for key, defaults to limits<T>::min().
69 * @param value_min Maximum value for key, defaults to limits<T>::max().
70 */
71 CfgParserKeyNumeric(const char *name, T &set, const T default_val = 0,
72 const T value_min = std::numeric_limits<T>::min(),
73 const T value_max = std::numeric_limits<T>::max())
74 : CfgParserKey(name),
75 _set(set), _default(default_val),
76 _value_min(value_min), _value_max(value_max)
77 {
77 _type = KEY_INT;
79 _type = KEY_NUMERIC;
80 }
80 //! @brief CfgParserKeyInt destructor.
81 virtual ~CfgParserKeyInt(void) { }
83
83 virtual void parse_value(const std::string &value_str) throw (std::string&);
85 /**
86 * CfgParserKeyNumeric destructor.
87 */
88 virtual ~CfgParserKeyNumeric(void) { }
89
90 /**
91 * Parses and store integer value.
92 *
93 * @param value Reference to string representing integer value.
94 */
95 virtual void
96 parse_value(const std::string &value_str)
97 throw (std::string&)
98 {
99 long double value;
100 char *endptr;
101
102 // Get long value.
103 value = strtold(value_str.c_str(), &endptr);
104
105 // Check for validity, 0 is returned on failiure with endptr set to the
106 // beginning of the string, else we are (semi) ok.
107 if ((value == 0) && (endptr == value_str.c_str())) {
108 _set = _default;
109
110 } else {
111 T value_for_type = static_cast<T>(value);
112
113 if (value_for_type < _value_min) {
114 _set = _value_min;
115 throw std::string("value to low, min value " + Util::to_string<T>(_value_min));
116 } if (value_for_type > _value_max) {
117 _set = _value_max;
118 throw std::string("value to high, max value " + Util::to_string<T>(_value_max));
119 }
120
121 _set = value_for_type;
122 }
123 }
124
125 private:
125 int &_set; //! Reference to store parsed value in.
126 const int _default; //! Default value.
127 const int _value_min; //! Minimum value.
128 const int _value_max; //! Maximum value.
130 T &_set; /**< Reference to store parsed value in. */
131 const T _default; /**< Default value. */
132 const T _value_min; /**< Minimum value. */
133 const T _value_max; /**< Maximum value. */
134 };
135
136 //! @brief CfgParser Key boolean value parser.
...

src/Theme.cc
 
226 @@ -226,9 +226,9 @@
226 list<CfgParserKey*> key_list;
227 string value_pad, value_focused, value_unfocused;
228
229 key_list.push_back(new CfgParserKeyInt("HEIGHT", _title_height, 10, 0));
230 key_list.push_back(new CfgParserKeyInt("WIDTHMIN", _title_width_min, 0));
231 key_list.push_back(new CfgParserKeyInt("WIDTHMAX", _title_width_max, 100, 0, 100));
232 key_list.push_back(new CfgParserKeyNumeric<int>("HEIGHT", _title_height, 10, 0));
233 key_list.push_back(new CfgParserKeyNumeric<int>("WIDTHMIN", _title_width_min, 0));
234 key_list.push_back(new CfgParserKeyNumeric<int>("WIDTHMAX", _title_width_max, 100, 0, 100));
235 key_list.push_back(new CfgParserKeyBool("WIDTHSYMETRIC", _title_width_symetric));
236 key_list.push_back(new CfgParserKeyBool("HEIGHTADAPT", _title_height_adapt));
237 key_list.push_back(new CfgParserKeyString("PAD", value_pad, "0 0 0 0", 7));
...
752 @@ -752,8 +752,8 @@
752 key_list.push_back(new CfgParserKeyString("BACKGROUND", value_tex_bg));
753 key_list.push_back(new CfgParserKeyString("WORKSPACE", value_tex_ws));
754 key_list.push_back(new CfgParserKeyString("WORKSPACEACTIVE", value_tex_ws_act));
755 key_list.push_back(new CfgParserKeyInt("EDGEPADDING", edge_padding, 5, 0));
756 key_list.push_back(new CfgParserKeyInt("WORKSPACEPADDING", workspace_padding, 2, 0));
757 key_list.push_back(new CfgParserKeyNumeric<int>("EDGEPADDING", edge_padding, 5, 0));
758 key_list.push_back(new CfgParserKeyNumeric<int>("WORKSPACEPADDING", workspace_padding, 2, 0));
759
760 section->parse_key_values(key_list.begin(), key_list.end());
761 for_each(key_list.begin(), key_list.end(), Util::Free<CfgParserKey*>());
...