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;
30 
31 
33 {
34  // Initialize the metadata
35  metadata = new MetaCategory("customer", "customers", reader, writer);
36 
37  // Initialize the Python class
39 }
40 
41 
43 {
44  // Initialize the metadata
46  "customer",
47  "customer_default",
48  Object::createString<CustomerDefault>, true);
49 
50  // Initialize the Python class
52 }
53 
54 
56 {
57  // Writing a reference
58  if (m == REFERENCE)
59  {
61  return;
62  }
63 
64  // Write the head
65  if (m != NOHEAD && m != NOHEADTAIL)
67 
68  // Write the fields
69  HasDescription::writeElement(o, tag);
71 
72  // Write the tail
73  if (m != NOTAIL && m != NOHEADTAIL) o->EndObject(tag);
74 }
75 
76 
78 {
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 
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 
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 
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