v2.0
open source Production PLanning
Home
Documentation
Getting started
Modeling guide
User guide
Installation guide
Developer guide
FAQ
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-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
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 complete object
65
if
(m !=
NOHEADER
) o->
BeginObject
(tag,
Tags::tag_name
,
XMLEscape
(
getName
()));
66
67
// Write the fields
68
HasDescription::writeElement
(o, tag);
69
HasHierarchy<Customer>::writeElement
(o, tag);
70
o->
EndObject
(tag);
71
}
72
73
74
DECLARE_EXPORT
void
Customer::beginElement
(
XMLInput
& pIn,
const
Attribute
& pAttr)
75
{
76
HasHierarchy<Customer>::beginElement
(pIn, pAttr);
77
}
78
79
80
DECLARE_EXPORT
void
Customer::endElement
(
XMLInput
& pIn,
const
Attribute
& pAttr,
const
DataElement
& pElement)
81
{
82
HasDescription::endElement
(pIn, pAttr, pElement);
83
HasHierarchy<Customer>::endElement
(pIn, pAttr, pElement);
84
}
85
86
87
DECLARE_EXPORT
Customer::~Customer
()
88
{
89
// Remove all references from demands to this customer
90
for
(Demand::iterator i =
Demand::begin
(); i !=
Demand::end
(); ++i)
91
if
(i->getCustomer() ==
this
) i->setCustomer(NULL);
92
}
93
94
95
DECLARE_EXPORT
PyObject*
Customer::getattro
(
const
Attribute
& attr)
96
{
97
if
(attr.
isA
(
Tags::tag_name
))
98
return
PythonObject
(
getName
());
99
if
(attr.
isA
(
Tags::tag_description
))
100
return
PythonObject
(
getDescription
());
101
if
(attr.
isA
(
Tags::tag_category
))
102
return
PythonObject
(
getCategory
());
103
if
(attr.
isA
(
Tags::tag_subcategory
))
104
return
PythonObject
(
getSubCategory
());
105
if
(attr.
isA
(
Tags::tag_owner
))
106
return
PythonObject
(
getOwner
());
107
if
(attr.
isA
(
Tags::tag_hidden
))
108
return
PythonObject
(
getHidden
());
109
if
(attr.
isA
(
Tags::tag_members
))
110
return
new
CustomerIterator
(
this
);
111
return
NULL;
112
}
113
114
115
DECLARE_EXPORT
int
Customer::setattro
(
const
Attribute
& attr,
const
PythonObject
& field)
116
{
117
if
(attr.
isA
(
Tags::tag_name
))
118
setName
(field.
getString
());
119
else
if
(attr.
isA
(
Tags::tag_description
))
120
setDescription
(field.
getString
());
121
else
if
(attr.
isA
(
Tags::tag_category
))
122
setCategory
(field.
getString
());
123
else
if
(attr.
isA
(
Tags::tag_subcategory
))
124
setSubCategory
(field.
getString
());
125
else
if
(attr.
isA
(
Tags::tag_owner
))
126
{
127
if
(!field.
check
(
Customer::metadata
))
128
{
129
PyErr_SetString(
PythonDataException
,
"customer owner must be of type customer"
);
130
return
-1;
131
}
132
Customer
* y =
static_cast<
Customer
*
>
(
static_cast<
PyObject*
>
(field));
133
setOwner
(y);
134
}
135
else
if
(attr.
isA
(
Tags::tag_hidden
))
136
setHidden
(field.
getBool
());
137
else
138
return
-1;
139
return
0;
140
}
141
142
143
}
// end namespace