Open source Production Planning v2.1
open source Production PLanning
Home
Documentation
C++ API
C++ API - customer.cpp Source File
Main Page
Namespaces
Classes
Files
File List
File Members
src
model
customer.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
* *
3
* Copyright (C) 2007-2013 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
Customer>
DECLARE_EXPORT
Tree
utils::HasName<Customer>::st;
28
DECLARE_EXPORT
const
MetaCategory
*
Customer::metadata
;
29
DECLARE_EXPORT
const
MetaClass
*
CustomerDefault::metadata
;
30
31
32
int
Customer::initialize
()
33
{
34
// Initialize the metadata
35
metadata
=
new
MetaCategory
(
"customer"
,
"customers"
,
reader
,
writer
);
36
37
// Initialize the Python class
38
return
FreppleCategory<Customer>::initialize
();
39
}
40
41
42
int
CustomerDefault::initialize
()
43
{
44
// Initialize the metadata
45
CustomerDefault::metadata
=
new
MetaClass
(
46
"customer"
,
47
"customer_default"
,
48
Object::createString<CustomerDefault>,
true
);
49
50
// Initialize the Python class
51
return
FreppleClass<CustomerDefault,Customer>::initialize
();
52
}
53
54
55
DECLARE_EXPORT
void
Customer::writeElement
(
XMLOutput
* o,
const
Keyword
& tag,
mode
m)
const
56
{
57
// Writing a reference
58
if
(m ==
REFERENCE
)
59
{
60
o->
writeElement
(tag,
Tags::tag_name
,
getName
());
61
return
;
62
}
63
64
// Write the head
65
if
(m !=
NOHEAD
&& m !=
NOHEADTAIL
)
66
o->
BeginObject
(tag,
Tags::tag_name
,
XMLEscape
(
getName
()));
67
68
// Write the fields
69
HasDescription::writeElement(o, tag);
70
HasHierarchy<Customer>::writeElement
(o, tag);
71
72
// Write the tail
73
if
(m !=
NOTAIL
&& m !=
NOHEADTAIL
) o->
EndObject
(tag);
74
}
75
76
77
DECLARE_EXPORT
void
Customer::beginElement
(
XMLInput
& pIn,
const
Attribute
& pAttr)
78
{
79
HasHierarchy<Customer>::beginElement
(pIn, pAttr);
80
}
81
82
83
DECLARE_EXPORT
void
Customer::endElement
(
XMLInput
& pIn,
const
Attribute
& pAttr,
const
DataElement
& pElement)
84
{
85
HasDescription::endElement(pIn, pAttr, pElement);
86
HasHierarchy<Customer>::endElement
(pIn, pAttr, pElement);
87
}
88
89
90
DECLARE_EXPORT
Customer::~Customer
()
91
{
92
// Remove all references from demands to this customer
93
for
(Demand::iterator i =
Demand::begin
(); i !=
Demand::end
(); ++i)
94
if
(i->getCustomer() ==
this
) i->setCustomer(NULL);
95
}
96
97
98
DECLARE_EXPORT
PyObject*
Customer::getattro
(
const
Attribute
& attr)
99
{
100
if
(attr.
isA
(
Tags::tag_name
))
101
return
PythonObject
(
getName
());
102
if
(attr.
isA
(
Tags::tag_description
))
103
return
PythonObject
(
getDescription
());
104
if
(attr.
isA
(
Tags::tag_category
))
105
return
PythonObject
(
getCategory
());
106
if
(attr.
isA
(
Tags::tag_subcategory
))
107
return
PythonObject
(
getSubCategory
());
108
if
(attr.
isA
(
Tags::tag_owner
))
109
return
PythonObject
(
getOwner
());
110
if
(attr.
isA
(
Tags::tag_hidden
))
111
return
PythonObject
(
getHidden
());
112
if
(attr.
isA
(
Tags::tag_members
))
113
return
new
CustomerIterator
(
this
);
114
return
NULL;
115
}
116
117
118
DECLARE_EXPORT
int
Customer::setattro
(
const
Attribute
& attr,
const
PythonObject
& field)
119
{
120
if
(attr.
isA
(
Tags::tag_name
))
121
setName
(field.
getString
());
122
else
if
(attr.
isA
(
Tags::tag_description
))
123
setDescription
(field.
getString
());
124
else
if
(attr.
isA
(
Tags::tag_category
))
125
setCategory
(field.
getString
());
126
else
if
(attr.
isA
(
Tags::tag_subcategory
))
127
setSubCategory
(field.
getString
());
128
else
if
(attr.
isA
(
Tags::tag_owner
))
129
{
130
if
(!field.
check
(
Customer::metadata
))
131
{
132
PyErr_SetString(
PythonDataException
,
"customer owner must be of type customer"
);
133
return
-1;
134
}
135
Customer
* y =
static_cast<
Customer
*
>
(
static_cast<
PyObject*
>
(field));
136
setOwner
(y);
137
}
138
else
if
(attr.
isA
(
Tags::tag_hidden
))
139
setHidden
(field.
getBool
());
140
else
141
return
-1;
142
return
0;
143
}
144
145
146
}
// end namespace