SVN_SILENT made messages (.desktop file)
[kdeadmin.git] / kcron / ctunit.h
blob6dc91d539888551a7405bb0e9f9b80404b846779
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 ***************************************************************************/
12 #ifndef CTUNIT_H
13 #define CTUNIT_H
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
18 #include <string>
19 #include <iostream>
21 /**
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
28 public:
30 /**
31 * Constant indicating short format.
33 static const bool shortFormat = 0;
35 /**
36 * Constant indicating long format.
38 static const bool longFormat = 1;
40 /**
41 * Initialize including parsing and saving initial image.
43 CTUnit(const std::string &tokStr = "");
45 /**
46 * Base initial image as empty and copy enabled intervals.
48 CTUnit(const CTUnit& source);
50 /**
51 * Destructor.
53 virtual ~CTUnit();
55 /**
56 * Copy enabled intervals.
58 void operator = (const CTUnit<min,max>& unit);
60 /**
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))
66 outStr << "*";
67 else
68 outStr << ((const CTUnit<min, max>) unit).tokenize();
69 return outStr;
72 /**
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 = "");
78 /**
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 = "");
84 /**
85 * Tokenizes unit into string such as
86 * "0,1,2,3,5,6,10,15,20,25,30".
88 std::string tokenize() const;
90 /**
91 * Get default natural language description.
93 virtual std::string describe(const std::string *label) const;
95 /**
96 * Lower bound.
98 int begin();
101 * Upper bound.
103 int end();
106 * Accessor.
108 bool get(int pos) const;
111 * Mutator.
113 void set(int pos, bool value);
116 * Enable.
118 void enable(int pos);
121 * Disable.
123 void disable(int pos);
126 * Indicates whether enabled intervals have been modified.
128 bool dirty() const;
131 * Total count of enabled intervals.
133 int count() const;
136 * Mark changes as applied.
138 void apply();
141 * Mark cancel changes and revert to initial or last applied
142 * image.
144 void cancel();
146 private:
148 int fieldToValue(std::string entry) const;
149 bool isDirty;
150 bool enabled[max+1];
151 bool initialEnabled[max+1];
152 std::string initialTokStr;
156 #include "ctunit.cpp"
158 #endif // CTUNIT_H