v2.0
open source Production PLanning
Home
Documentation
Getting started
Modeling guide
User guide
Installation guide
Developer guide
FAQ
C++ API
C++ API - location.cpp Source File
Main Page
Namespaces
Classes
Files
File List
File Members
src
model
location.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
* *
3
* Copyright (C) 2007-2012 by Johan De Taeye, frePPLe bvba *
4
* *
5
* This library is free software; you can redistribute it and/or modify it *
6
* under the terms of the GNU Affero General Public License as published *
7
* by the Free Software Foundation; either version 3 of the License, or *
8
* (at your option) any later version. *
9
* *
10
* This library is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13
* GNU Affero General Public License for more details. *
14
* *
15
* You should have received a copy of the GNU Affero General Public *
16
* License along with this program. *
17
* If not, see <http://www.gnu.org/licenses/>. *
18
* *
19
***************************************************************************/
20
21
#define FREPPLE_CORE
22
#include "
frepple/model.h
"
23
24
namespace
frepple
25
{
26
27
template
<
class
Location>
DECLARE_EXPORT
Tree
utils::HasName<Location>::st;
28
DECLARE_EXPORT
const
MetaCategory
*
Location::metadata
;
29
DECLARE_EXPORT
const
MetaClass
*
LocationDefault::metadata
;
30
31
32
int
Location::initialize
()
33
{
34
// Initialize the metadata
35
metadata
=
new
MetaCategory
(
"location"
,
"locations"
,
reader
,
writer
);
36
37
// Initialize the Python class
38
return
FreppleCategory<Location>::initialize
();
39
}
40
41
42
int
LocationDefault::initialize
()
43
{
44
// Initialize the metadata
45
LocationDefault::metadata
=
new
MetaClass
(
"location"
,
"location_default"
,
46
Object::createString<LocationDefault>,
true
);
47
48
// Initialize the Python class
49
return
FreppleClass<LocationDefault,Location>::initialize
();
50
}
51
52
53
DECLARE_EXPORT
void
Location::writeElement
(
XMLOutput
* o,
const
Keyword
& tag,
mode
m)
const
54
{
55
// Writing a reference
56
if
(m ==
REFERENCE
)
57
{
58
o->
writeElement
(tag,
Tags::tag_name
,
getName
());
59
return
;
60
}
61
62
// Write the complete object
63
if
(m !=
NOHEADER
) o->
BeginObject
(tag,
Tags::tag_name
,
XMLEscape
(
getName
()));
64
65
// Write the fields
66
HasDescription::writeElement
(o, tag);
67
HasHierarchy<Location>::writeElement
(o, tag);
68
o->
writeElement
(
Tags::tag_available
, available);
69
o->
EndObject
(tag);
70
}
71
72
73
DECLARE_EXPORT
void
Location::beginElement
(
XMLInput
& pIn,
const
Attribute
& pAttr)
74
{
75
if
(pAttr.
isA
(
Tags::tag_available
) || pAttr.
isA
(
Tags::tag_maximum
))
76
pIn.
readto
(
Calendar::reader
(
Calendar::metadata
,pIn.
getAttributes
()) );
77
else
78
HasHierarchy<Location>::beginElement
(pIn, pAttr);
79
}
80
81
82
DECLARE_EXPORT
void
Location::endElement
(
XMLInput
& pIn,
const
Attribute
& pAttr,
const
DataElement
& pElement)
83
{
84
if
(pAttr.
isA
(
Tags::tag_available
))
85
{
86
CalendarDouble
*cal =
dynamic_cast<
CalendarDouble
*
>
(pIn.
getPreviousObject
());
87
if
(cal)
88
setAvailable
(cal);
89
else
90
{
91
Calendar
*c =
dynamic_cast<
Calendar
*
>
(pIn.
getPreviousObject
());
92
if
(!c)
93
throw
LogicException
(
"Incorrect object type during read operation"
);
94
throw
DataException
(
"Calendar '"
+ c->
getName
() +
95
"' has invalid type for use as location calendar"
);
96
}
97
}
98
else
99
{
100
HasDescription::endElement
(pIn, pAttr, pElement);
101
HasHierarchy<Location>::endElement
(pIn, pAttr, pElement);
102
}
103
}
104
105
106
DECLARE_EXPORT
Location::~Location
()
107
{
108
// Remove all references from buffers to this location
109
for
(Buffer::iterator buf =
Buffer::begin
();
110
buf !=
Buffer::end
(); ++buf)
111
if
(buf->getLocation() ==
this
) buf->setLocation(NULL);
112
113
// Remove all references from resources to this location
114
for
(Resource::iterator res =
Resource::begin
();
115
res !=
Resource::end
(); ++res)
116
if
(res->getLocation() ==
this
) res->setLocation(NULL);
117
118
// Remove all references from operations to this location
119
for
(Operation::iterator oper =
Operation::begin
();
120
oper !=
Operation::end
(); ++oper)
121
if
(oper->getLocation() ==
this
) oper->setLocation(NULL);
122
}
123
124
125
DECLARE_EXPORT
PyObject*
Location::getattro
(
const
Attribute
& attr)
126
{
127
if
(attr.
isA
(
Tags::tag_name
))
128
return
PythonObject
(
getName
());
129
if
(attr.
isA
(
Tags::tag_description
))
130
return
PythonObject
(
getDescription
());
131
if
(attr.
isA
(
Tags::tag_category
))
132
return
PythonObject
(
getCategory
());
133
if
(attr.
isA
(
Tags::tag_subcategory
))
134
return
PythonObject
(
getSubCategory
());
135
if
(attr.
isA
(
Tags::tag_owner
))
136
return
PythonObject
(
getOwner
());
137
if
(attr.
isA
(
Tags::tag_available
))
138
return
PythonObject
(
getAvailable
());
139
if
(attr.
isA
(
Tags::tag_hidden
))
140
return
PythonObject
(
getHidden
());
141
if
(attr.
isA
(
Tags::tag_members
))
142
return
new
LocationIterator
(
this
);
143
return
NULL;
144
}
145
146
147
DECLARE_EXPORT
int
Location::setattro
(
const
Attribute
& attr,
const
PythonObject
& field)
148
{
149
if
(attr.
isA
(
Tags::tag_name
))
150
setName
(field.
getString
());
151
else
if
(attr.
isA
(
Tags::tag_description
))
152
setDescription
(field.
getString
());
153
else
if
(attr.
isA
(
Tags::tag_category
))
154
setCategory
(field.
getString
());
155
else
if
(attr.
isA
(
Tags::tag_subcategory
))
156
setSubCategory
(field.
getString
());
157
else
if
(attr.
isA
(
Tags::tag_owner
))
158
{
159
if
(!field.
check
(
Location::metadata
))
160
{
161
PyErr_SetString(
PythonDataException
,
"location owner must be of type location"
);
162
return
-1;
163
}
164
Location
* y =
static_cast<
Location
*
>
(
static_cast<
PyObject*
>
(field));
165
setOwner
(y);
166
}
167
else
if
(attr.
isA
(
Tags::tag_available
))
168
{
169
if
(!field.
check
(
CalendarDouble::metadata
))
170
{
171
PyErr_SetString(
PythonDataException
,
"location availability must be of type double calendar"
);
172
return
-1;
173
}
174
CalendarDouble
* y =
static_cast<
CalendarDouble
*
>
(
static_cast<
PyObject*
>
(field));
175
setAvailable
(y);
176
}
177
else
if
(attr.
isA
(
Tags::tag_hidden
))
178
setHidden
(field.
getBool
());
179
else
180
return
-1;
181
return
0;
182
}
183
184
}
// end namespace