[go: up one dir, main page]

Menu

[96b3e1]: / data / jobdata.h  Maximize  Restore  History

Download this file

80 lines (66 with data), 2.3 kB

 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
/////////////////////////////////////////////////////////////////////////////////
// Author: Steven Lamerton
// Copyright: Copyright (C) 2008 - 2010 Steven Lamerton
// License: GNU GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
/////////////////////////////////////////////////////////////////////////////////
#ifndef H_JOBDATA
#define H_JOBDATA
#include <stdexcept>
#include <wx/string.h>
#include <wx/tokenzr.h>
#include <wx/fileconf.h>
#include "../toucan.h"
#include "../basicfunctions.h"
class frmMain;
class RuleSet;
class JobData{
public:
JobData(const wxString &name);
virtual ~JobData();
virtual void TransferToFile() = 0;
virtual void TransferFromFile() = 0;
virtual bool TransferToForm(frmMain* window) = 0;
virtual bool TransferFromForm(frmMain* window) = 0;
void SetName(const wxString& Name) {this->m_Name = Name;}
void SetRules(RuleSet *rules) {this->rules = rules;}
const wxString& GetName() const {return m_Name;}
RuleSet* GetRules() const {return rules;}
protected:
template<class T> T Read(const wxString& key){
T temp;
if(!wxGetApp().m_Jobs_Config->Read(GetName() + "/" + key, &temp)){
throw std::runtime_error(std::string("There was an error reading from the jobs file, looking for " + key));
}
return temp;
}
template<class T> void Write(const wxString& key, T value){
if(!wxGetApp().m_Jobs_Config->Write(GetName() + "/" + key, value)){
throw std::runtime_error(std::string("There was an error writing to the jobs file"));
}
}
wxArrayString Read(const wxString& key){
wxString temp;
if(!wxGetApp().m_Jobs_Config->Read(GetName() + "/" + key, &temp)){
throw std::runtime_error(std::string("There was an error reading from the jobs file, looking for " + key));
}
wxArrayString strings;
wxStringTokenizer tkz(temp, "|", wxTOKEN_STRTOK);
while(tkz.HasMoreTokens()){
strings.Add(tkz.GetNextToken());
}
return strings;
}
void Write(const wxString& key, wxArrayString value){
wxString temp;
for(unsigned int i = 0; i < value.GetCount(); i++){
temp = temp + "|" + value.Item(i);
}
if(!wxGetApp().m_Jobs_Config->Write(GetName() + "/" + key, temp)){
throw std::runtime_error(std::string("There was an error writing to the jobs file"));
}
}
private:
wxString m_Name;
RuleSet *rules;
};
#endif