File: ruleset.h

package info (click to toggle)
kppp 4:17.08.3-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, sid
  • size: 4,176 kB
  • sloc: cpp: 13,825; tcl: 49; sh: 19; xml: 15; makefile: 5
file content (146 lines) | stat: -rw-r--r-- 3,925 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/* -*- C++ -*-
 *            kPPP: A pppd front end for the KDE project
 *
 * $Id$
 *
 *            Copyright (C) 1997 Bernd Johannes Wuebben
 *                   wuebben@math.cornell.edu
 *
 * This file was contributed by Mario Weilguni <mweilguni@sime.com>
 * Thanks Mario !
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this program; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#ifndef __RULESET__H__
#define __RULESET__H__


#include <qdatetime.h>
#include <qstring.h>
#include <QVector>
// this structure is used to save
// accounting rules
typedef struct {
  int type;
  double costs;
  double len;
  double after;
  QTime from, until;
  struct {
    QDate from, until;
  } date;
  struct {
    int from, until;
  } weekday;
} RULE;

// this class is used for loading and parsing of rules
class RuleSet {
public:
  /// create an empty rule
  RuleSet();

  /// gcc needs a destructor (otherwise compiler error)
  ~RuleSet() {}

  /// returns the name of the ruleset
  QString name() const;

  /** Load a ruleset from a file. If an error occurs,
   *  returns the linenumber the error was in,
   *  otherwise 0. If the file could not be opened,
   *  returns -1
   */
  int load(const QString &filename);

  /// returns the currency symbol
  QString currencySymbol() const;

  /** returns a string representation of the
   *  of a doubleingpoint number using the
   *  currency-settings
   */
  QString currencyString(double val) const;

  /// sets the start time -- must be called when the connection has bee established
  void setStartTime(const QDateTime &dt);

  /// returns the "per-connection" costs
  double perConnectionCosts() const;

  /** returns the minimum number of costs (some
   *  phony companies have this
   */
  double minimumCosts() const;

  /// returns the currently valid rule settings
  void getActiveRule(const QDateTime &dt, double connect_time, double &costs, double &len);

  /// checks if a rulefile is ok (no parse errors...)
  static int checkRuleFile(const QString &);

protected:
  /** converts an english name of a day to integer,
   * beginning with monday=0 .. sunday=6
   */
  int dayNameToInt(const char *s);

  /// returns the date of easter-sunday for a year
  static QDate get_easter(int year);

  /// add a rule to this ruleset
  void addRule(RULE r);

  /// parses on entry of the "on(...)" fields
  bool parseEntry(RULE &ret, QString s, int year);

  /// parses the "on(...)" fields
  bool parseEntries(QString s, int year,
		    QTime t1, QTime t2,
		    double costs, double len, double after);

  /// parses the "between(...)" time fields
  bool parseTime(QTime &t1, QTime &t2, QString s);

  /// parses the "use(...)" fields
  bool parseRate(double &costs, double &len, double &after, QString s);

  /// parses a whole line
  bool parseLine(const QString &line);

  /// returns midnight time (00:00:00.000)
  QTime midnight() const;

  /// returns the last valid time BEFORE midnight
  QTime beforeMidnight() const;

protected:
  QString _name;
  QString _currency_symbol;
  QDateTime starttime;
  int _currency_digits;
  double default_costs;
  double _minimum_costs;
  double  default_len;
  double pcf;
  bool have_flat_init_costs;
  double flat_init_duration;
  double flat_init_costs;

  QVector<RULE> rules;
};

#endif