0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Crontab.h
Go to the documentation of this file.
1 /* -*- c++ -*-
2  * Copyright (C) 2007-2015 Hypertable, Inc.
3  *
4  * This file is part of Hypertable.
5  *
6  * Hypertable is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 3
9  * of the License, or any later version.
10  *
11  * Hypertable is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301, USA.
20  */
21 
26 
27 #ifndef Common_Crontab_h
28 #define Common_Crontab_h
29 
30 #include "String.h"
31 
32 #include <bitset>
33 #include <ctime>
34 
35 namespace Hypertable {
36 
39 
41  struct crontab_entry {
42  std::bitset<60> minute;
43  std::bitset<24> hour;
44  std::bitset<31> dom;
45  std::bitset<12> month;
46  std::bitset<8> dow;
47  };
48 
55  class Crontab {
56  public:
57 
59  Crontab() { };
60 
73  Crontab(const String &spec);
74 
79  time_t next_event(time_t now);
80 
83  crontab_entry &entry() { return m_entry; }
84 
85  private:
86 
96  void next_matching_day(struct tm *next_tm, bool increment);
97 
101  void parse_entry(const String &spec, crontab_entry *_entry);
102 
108  template <int N> void parse_range(const String &spec, std::bitset<N> &bits,
109  bool zero_based = true);
110 
112  };
113 
118  std::ostream &operator<<(std::ostream &os, const crontab_entry &entry);
119 
125  template <int N> void reconstruct_spec(const std::bitset<N> &bits,
126  String &spec);
127 
129 
130 } // namespace Hypertable
131 
132 #endif // Common_Crontab_h
time_t next_event(time_t now)
Retrieves the timestamp of the next event.
Definition: Crontab.cc:46
std::string String
A String is simply a typedef to std::string.
Definition: String.h:44
std::bitset< 24 > hour
Definition: Crontab.h:43
std::bitset< 31 > dom
Definition: Crontab.h:44
void parse_entry(const String &spec, crontab_entry *_entry)
Parses a crontab spec into a crontab_entry.
Definition: Crontab.cc:121
Binary representation of crontab spec.
Definition: Crontab.h:41
Tracks timing of periodic events.
Definition: Crontab.h:55
std::bitset< 12 > month
Definition: Crontab.h:45
std::ostream & operator<<(std::ostream &os, const crontab_entry &entry)
Helper function to write crontab_entry to an ostream.
Definition: Crontab.cc:301
Hypertable definitions
void parse_range(const String &spec, std::bitset< N > &bits, bool zero_based=true)
Parses a crontab field and sets corresponding bits in bits.
Definition: Crontab.cc:206
crontab_entry m_entry
Definition: Crontab.h:111
A String class based on std::string.
Crontab()
Default constructor.
Definition: Crontab.h:59
void next_matching_day(struct tm *next_tm, bool increment)
Determines next day on which event will occur.
Definition: Crontab.cc:92
void reconstruct_spec(const std::bitset< N > &bits, String &spec)
Converts binary crontab spec back into string spec.
Definition: Crontab.cc:319
std::bitset< 60 > minute
Definition: Crontab.h:42
std::bitset< 8 > dow
Definition: Crontab.h:46
crontab_entry & entry()
Get the internal crontab_entry structure.
Definition: Crontab.h:83