skill.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 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 complete object
66  if (m != NOHEADER) o->BeginObject(tag, Tags::tag_name, XMLEscape(getName()));
67 
68  // That was it
69  o->EndObject(tag);
70 }
71 
72 
74 {
75  if (pAttr.isA(Tags::tag_resourceskill)
76  && pIn.getParentElement().first.isA(Tags::tag_resourceskills))
77  {
78  ResourceSkill *s =
79  dynamic_cast<ResourceSkill*>(MetaCategory::ControllerDefault(ResourceSkill::metadata,pIn.getAttributes()));
80  if (s) s->setSkill(this);
81  pIn.readto(s);
82  }
83 }
84 
85 
86 DECLARE_EXPORT void Skill::endElement (XMLInput& pIn, const Attribute& pAttr, const DataElement& pElement)
87 {
88  // No specific fields to retrieve
89 }
90 
91 
93 {
94  // The ResourceSkill objects are automatically deleted by the destructor
95  // of the Association list class.
96 
97  // Clean up the references on the load models
98  for (Operation::iterator o = Operation::begin(); o != Operation::end(); ++o)
99  for(Operation::loadlist::const_iterator l = o->getLoads().begin();
100  l != o->getLoads().end(); ++l)
101  if (l->getSkill() == this)
102  const_cast<Load&>(*l).setSkill(NULL);
103 }
104 
105 
107 {
108  if (attr.isA(Tags::tag_name))
109  return PythonObject(getName());
110  if (attr.isA(Tags::tag_resourceskills))
111  return new ResourceSkillIterator(this);
112  return NULL;
113 }
114 
115 
116 DECLARE_EXPORT int Skill::setattro(const Attribute& attr, const PythonObject& field)
117 {
118  if (attr.isA(Tags::tag_name))
119  setName(field.getString());
120  else
121  return -1; // Error
122  return 0; // OK
123 }
124 
125 
126 }