1 /***************************************************************************
2 * CT Unit of Time Interval Header *
3 * -------------------------------------------------------------------- *
4 * Copyright (C) 1999, Gary Meyer <gary@meyer.net> *
5 * -------------------------------------------------------------------- *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 ***************************************************************************/
15 // Do not introduce any Qt or KDE dependencies into the "CT"-prefixed classes.
16 // I want to be able to reuse these classes with another GUI toolkit. -GM 11/99
22 * A cron table unit parser and tokenizer.
23 * Parses/tokenizes unit such as "0-3,5,6,10-30/5"
24 * Also provides default natural language description.
26 template<int min
, int max
> class CTUnit
31 * Constant indicating short format.
33 static const bool shortFormat
= 0;
36 * Constant indicating long format.
38 static const bool longFormat
= 1;
41 * Initialize including parsing and saving initial image.
43 CTUnit(const std::string
&tokStr
= "");
46 * Base initial image as empty and copy enabled intervals.
48 CTUnit(const CTUnit
& source
);
56 * Copy enabled intervals.
58 void operator = (const CTUnit
<min
,max
>& unit
);
61 * Returns tokenization to output stream.
63 friend std::ostream
& operator << (std::ostream
& outStr
, const CTUnit
<min
,max
>& unit
)
65 if (unit
.count() == (max
- min
+ 1))
68 outStr
<< ((const CTUnit
<min
, max
>) unit
).tokenize();
73 * Parses unit such as "0-3,5,6,10-30/5".
74 * And initialize array of enabled intervals.
76 void initialize(const std::string
&tokStr
= "");
79 * Parses unit such as "0-3,5,6,10-30/5".
80 * Does not initialize array of enabled intervals.
82 void parse(std::string tokStr
= "");
85 * Tokenizes unit into string such as
86 * "0,1,2,3,5,6,10,15,20,25,30".
88 std::string
tokenize() const;
91 * Get default natural language description.
93 virtual std::string
describe(const std::string
*label
) const;
108 bool get(int pos
) const;
113 void set(int pos
, bool value
);
118 void enable(int pos
);
123 void disable(int pos
);
126 * Indicates whether enabled intervals have been modified.
131 * Total count of enabled intervals.
136 * Mark changes as applied.
141 * Mark cancel changes and revert to initial or last applied
148 int fieldToValue(std::string entry
) const;
151 bool initialEnabled
[max
+1];
152 std::string initialTokStr
;
156 #include "ctunit.cpp"