skill.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 Skill> DECLARE_EXPORT Tree utils::HasName<Skill>::st;
30 
31 
33 {
34  // Initialize the metadata
35  metadata = new MetaCategory("skill", "skills", reader, writer);
36 
37  // Initialize the Python class
39 }
40 
41 
43 {
44  // Initialize the metadata
46  "skill",
47  "skill_default",
48  Object::createString<SkillDefault>,
49  true);
50 
51  // Initialize the Python class
53 }
54 
55 
57 {
58  // Write a reference
59  if (m == REFERENCE)
60  {
62  return;
63  }
64 
65  // Write the head
66  if (m != NOHEAD && m != NOHEADTAIL)
68 
69  // Write the tail
70  if (m != NOHEADTAIL && m != NOTAIL) o->EndObject(tag);
71 }
72 
73 
75 {
76  if (pAttr.isA(Tags::tag_resourceskill)
77  && pIn.getParentElement().first.isA(Tags::tag_resourceskills))
78  {
79  ResourceSkill *s =
80  dynamic_cast<ResourceSkill*>(MetaCategory::ControllerDefault(ResourceSkill::metadata,pIn.getAttributes()));
81  if (s) s->setSkill(this);
82  pIn.readto(s);
83  }
84 }
85 
86 
87 DECLARE_EXPORT void Skill::endElement (XMLInput& pIn, const Attribute& pAttr, const DataElement& pElement)
88 {
89  // No specific fields to retrieve
90 }
91 
92 
94 {
95  // The ResourceSkill objects are automatically deleted by the destructor
96  // of the Association list class.
97 
98  // Clean up the references on the load models
99  for (Operation::iterator o = Operation::begin(); o != Operation::end(); ++o)
100  for(Operation::loadlist::const_iterator l = o->getLoads().begin();
101  l != o->getLoads().end(); ++l)
102  if (l->getSkill() == this)
103  const_cast<Load&>(*l).setSkill(NULL);
104 }
105 
106 
108 {
109  if (attr.isA(Tags::tag_name))
110  return PythonObject(getName());
111  if (attr.isA(Tags::tag_resourceskills))
112  return new ResourceSkillIterator(this);
113  return NULL;
114 }
115 
116 
117 DECLARE_EXPORT int Skill::setattro(const Attribute& attr, const PythonObject& field)
118 {
119  if (attr.isA(Tags::tag_name))
120  setName(field.getString());
121  else
122  return -1; // Error
123  return 0; // OK
124 }
125 
126 
127 }