-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSVGHandler.cpp
More file actions
executable file
·99 lines (90 loc) · 2.49 KB
/
SVGHandler.cpp
File metadata and controls
executable file
·99 lines (90 loc) · 2.49 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
//------------------------------------------------------------------------------
/// Filename: SVGHandler.cpp
/// Description: Is the Handler of the Progam
/// Authors:
/// Robin Ankele(0931951)
/// Tutor: Manuel Weber
/// Group: 24
/// Created: 08.09.2011
/// Last change: 08.09.2011
//------------------------------------------------------------------------------
#include "SVGHandler.h"
#include "Database.h"
#include "SVGDocument.h"
#include "Error.h"
#include "UserInterface.h"
#include "ConfigFileException.h"
#include "ErrorCodes.h"
//------------------------------------------------------------------------------
SVGHandler::SVGHandler(unsigned int arg_count,
char **parameters) : ui_(NULL),
db_(NULL),
svgdoc_(NULL),
errors_(0)
{
try
{
error_ = new Error();
if(arg_count < 2 || arg_count > 3)
{
errors_ = USAGE_CONFIG_FILE;
throw ConfigFileException();
}
std::string parameter(parameters[1]);
if(!checkParameter(parameter))
{
errors_ = USAGE_CONFIG_FILE;
throw ConfigFileException();
}
db_ = new Database(parameter, this);
if(!db_->checkConfigFile())
{
errors_ = CANNOT_READ_CONFIG_FILE;
throw ConfigFileException();
}
if(!db_->readConfigFile())
{
if(errors_ != OUT_OF_MEMORY)
errors_ = CONFIG_FILE_CORRUPT;
throw ConfigFileException();
}
svgdoc_ = new SVGDocument(db_, this);
ui_ = new UserInterface(db_, svgdoc_, this, prompt_);
if(errors_ != OUT_OF_MEMORY)
{
svgdoc_->setUI(ui_);
ui_->run();
}
}
catch(std::bad_alloc& exception)
{
errors_ = OUT_OF_MEMORY;
}
catch(ConfigFileException& exception)
{
}
}
//------------------------------------------------------------------------------
SVGHandler::~SVGHandler() throw()
{
freeMemory();
}
//------------------------------------------------------------------------------
bool SVGHandler::checkParameter(std::string parameter)
{
if(!parameter.compare(0,3,"-c="))
return true;
return false;
}
//------------------------------------------------------------------------------
void SVGHandler::freeMemory()
{
if(error_)
delete error_;
if(db_)
delete db_;
if(svgdoc_)
delete svgdoc_;
if(ui_)
delete ui_;
}