-
Notifications
You must be signed in to change notification settings - Fork 216
Expand file tree
/
Copy pathproject.h
More file actions
184 lines (137 loc) · 5.46 KB
/
project.h
File metadata and controls
184 lines (137 loc) · 5.46 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
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*
BSD 3-Clause License
Copyright (c) Alliance for Energy Innovation, LLC. See also https://github.com/NatLabRockies/SAM/blob/develop/LICENSE
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __project_h
#define __project_h
#include <vector>
#include <lk/env.h>
#include "object.h"
class Case;
class ProjectFile;
#define VERSION_VALUE( maj, min, mic ) ( ((size_t)(maj)) * 10000 + ((size_t)(min))*100 + ((size_t)(mic)) )
class ProjectFileEvent
{
private:
int m_type;
wxString m_str, m_str2;
public:
enum { CASE_ADDED, CASE_DELETED, CASE_RENAMED, PROJECTFILE_DELETED };
ProjectFileEvent(int type) : m_type(type) { }
ProjectFileEvent(int type, const wxString &str) : m_type(type), m_str(str) { }
ProjectFileEvent(int type, const wxString &str, const wxString &str2) : m_type(type), m_str(str), m_str2(str2) { }
int GetType() { return m_type; }
wxString GetString() { return m_str; }
wxString GetString2() { return m_str2; }
};
class ProjectFileEventListener
{
public:
virtual void OnProjectFileEvent(ProjectFile *, ProjectFileEvent &) = 0;
};
class ProjectFile
{
public:
ProjectFile();
ProjectFile( const ProjectFile &cpy );
virtual ~ProjectFile();
void Copy( const ProjectFile &rhs, bool listeners_too = true );
void Clear();
// managing cases
void AddCase( const wxString &name, Case *c );
Case *AddCase( const wxString &name );
bool DeleteCase( const wxString &name );
Case *GetCase( const wxString &name );
wxString GetCaseName( Case *c );
wxArrayString GetCaseNames();
std::vector<Case*> GetCases();
bool RenameCase( const wxString &old_name, const wxString &new_name );
// simple project file properties
wxString GetProperty( const wxString &name );
void SetProperty( const wxString &name, const wxString &value );
wxArrayString GetProperties();
// general purpose data storage objects
void AddObject( const wxString &name, Object * );
void DeleteObject( const wxString &name );
bool RenameObject( const wxString &old_name, const wxString &new_name );
Object *GetObject( const wxString &name );
wxArrayString GetObjects();
void Write( wxOutputStream &out );
bool Read( wxInputStream &in );
bool WriteArchive( const wxString &file );
bool ReadArchive( const wxString &file );
wxString GetLastError() { return m_lastError; }
bool IsModified() { return m_modified; }
void SetModified( bool b ) { m_modified = b; }
void AddListener(ProjectFileEventListener *pel);
void RemoveListener(ProjectFileEventListener *pel);
void ClearListeners();
void SendEvent(ProjectFileEvent e);
void SetSaveHourlyData( bool b ) { m_saveHourlyData = b; }
bool GetSaveHourlyData() { return m_saveHourlyData; }
void SetVersionInfo( int maj, int min, int mic, int patch );
size_t GetVersionInfo( int *maj=0, int *min=0, int *mic=0, int *patch=0 );
private:
ObjectCollection m_cases;
ObjectCollection m_objects;
StringHash m_properties;
wxString m_lastError;
bool m_saveHourlyData;
bool m_modified;
std::vector<ProjectFileEventListener*> m_listeners;
int m_verMajor, m_verMinor, m_verMicro, m_verPatch;
};
class VersionUpgrade
{
public:
enum { FAIL, WARNING, NOTICE, CONFIG_CHANGE, VAR_ADDED, VAR_CHANGED, VAR_DELETED };
struct log {
log() { type = FAIL; }
log( int ty, const wxString &m, const wxString &r=wxEmptyString )
: type(ty), message(m), reason(r) {};
int type;
wxString message;
wxString reason;
};
typedef unordered_map< wxString, std::vector<log>, wxStringHash, wxStringEqual > LogInfo;
public:
VersionUpgrade();
bool Run( ProjectFile &pf );
std::vector<log> &GetLog( const wxString &casename = wxEmptyString );
Case *GetCase() { return m_case; }
wxString GetName() { return m_name; }
void ShowReportDialog( const wxString &file, bool modal = false );
wxString CreateHtmlReport( const wxString &file );
static lk::fcall_t* invoke_functions();
private:
LogInfo m_log;
Case *m_case;
wxString m_name;
lk::env_t m_env;
std::vector<log> m_generalLog;
int m_pfMajor, m_pfMinor, m_pfMicro;
void WriteHtml( const wxString §ion, const std::vector<log> &log, wxString &html );
bool Invoke( Case *c, const wxString &name, lk::node_t *root );
};
#endif