25#include <tqdatetime.h>
28#include <tqvaluelist.h>
36enum State { None=0, NonWorking=1, Working=2 };
39typedef TQMap<TQString, int> DateMapType;
40class DateMap :
public DateMapType
46 virtual bool contains(TQDate date)
const {
return DateMapType::contains(date.toString(TQt::ISODate)); }
48 void insert(TQString date,
int state=Map::NonWorking) {
50 if (state == Map::None)
51 DateMapType::remove(date);
53 DateMapType::insert(date, state);
55 void insert(TQDate date,
int state=Map::NonWorking) { insert(date.toString(TQt::ISODate), state); }
57 void remove(TQDate date) {
59 DateMapType::remove(date.toString(TQt::ISODate));
62 int state(TQString date) {
63 DateMapType::iterator it = find(date);
64 if (it == end())
return 0;
65 else return it.data();
67 int state(TQDate date) {
return state(date.toString(TQt::ISODate)); }
69 bool operator==(
const DateMap &m)
const {
70 return keys() == m.keys() && values() == m.values();
72 bool operator!=(
const DateMap &m)
const {
73 return keys() != m.keys() || values() != m.values();
77 void toggle(TQString date,
int state=Map::NonWorking) {
79 if (DateMapType::contains(date))
80 DateMapType::remove(date);
82 DateMapType::insert(date, state);
84 void toggle(TQDate date,
int state=Map::NonWorking) {
return toggle(date.toString(TQt::ISODate)); }
85 void toggleClear(TQString date,
int state=Map::NonWorking) {
87 bool s = DateMapType::contains(date);
89 if (!s) insert(date, state);
91 void toggleClear(TQDate date,
int state=Map::NonWorking) { toggleClear(date.toString(TQt::ISODate)); }
94typedef TQMap<int, int> IntMapType;
95class IntMap :
public IntMapType
101 void insert(
int key,
int state=Map::NonWorking) {
102 if (state == Map::None)
103 IntMapType::remove(key);
105 IntMapType::insert(key, state); }
107 virtual int state(
int key) {
108 IntMapType::iterator it = IntMapType::find(key);
109 if (it == IntMapType::end())
return 0;
110 else return it.data();
113 bool operator==(
const IntMap &m)
const {
114 return keys() == m.keys() && values() == m.values();
116 bool operator!=(
const IntMap &m)
const {
117 return keys() != m.keys() || values() != m.values();
121 void toggle(
int key,
int state=Map::NonWorking) { IntMapType::contains(key) ? remove(key) : insert(key, state); }
122 void toggleClear(
int key,
int state=Map::NonWorking) {
123 bool s =contains(key);
125 if (!s) insert(key, state);
129class WeekMap :
public IntMap
132 bool contains(
int week,
int year) {
return IntMap::contains(week*10000 + year); }
133 bool contains(TQPair<int,int> week) {
return contains(week.first, week.second); }
135 void insert(
int week,
int year,
int state=Map::NonWorking) {
136 if (week < 1 || week > 53) { kdError()<<k_funcinfo<<
"Illegal week number: "<<week<<endl;
return; }
137 IntMap::insert(week*10000 + year, state);
139 void insert(TQPair<int,int> week,
int state=Map::NonWorking) { insert(week.first, week.second, state); }
141 void insert(WeekMap::iterator it,
int state) { insert(week(it.key()), state); }
143 void remove(TQPair<int,int> week) { IntMap::remove(week.first*10000 + week.second); }
145 static TQPair<int, int> week(
int key) {
return TQPair<int, int>(key/10000, key%10000); }
147 int state(TQPair<int, int> week) {
return IntMap::state(week.first*10000 + week.second); }
148 int state(
int week,
int year) {
return state(TQPair<int, int>(week, year)); }
150 void toggle(TQPair<int,int> week,
int state=Map::NonWorking) {
151 if (week.first < 1 || week.first > 53) { kdError()<<k_funcinfo<<
"Illegal week number: "<<week.first<<endl;
return; }
152 IntMap::toggle(week.first*10000 + week.second, state);
154 void toggleClear(TQPair<int,int> week,
int state=Map::NonWorking) {
155 if (week.first < 1 || week.first > 53) { kdError()<<k_funcinfo<<
"Illegal week number: "<<week.first<<endl;
return; }
156 IntMap::toggleClear(week.first*10000 + week.second, state);