location.cpp
Go to the documentation of this file.00001 /*************************************************************************** 00002 file : $URL: https://frepple.svn.sourceforge.net/svnroot/frepple/trunk/src/model/location.cpp $ 00003 version : $LastChangedRevision: 746 $ $LastChangedBy: jdetaeye $ 00004 date : $LastChangedDate: 2008-04-19 11:23:51 +0200 (Sat, 19 Apr 2008) $ 00005 ***************************************************************************/ 00006 00007 /*************************************************************************** 00008 * * 00009 * Copyright (C) 2007 by Johan De Taeye * 00010 * * 00011 * This library is free software; you can redistribute it and/or modify it * 00012 * under the terms of the GNU Lesser General Public License as published * 00013 * by the Free Software Foundation; either version 2.1 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 * This library is distributed in the hope that it will be useful, * 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser * 00019 * General Public License for more details. * 00020 * * 00021 * You should have received a copy of the GNU Lesser General Public * 00022 * License along with this library; if not, write to the Free Software * 00023 * Foundation Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA * 00024 * * 00025 ***************************************************************************/ 00026 00027 #define FREPPLE_CORE 00028 #include "frepple/model.h" 00029 00030 namespace frepple 00031 { 00032 00033 template<class Location> DECLARE_EXPORT Tree HasName<Location>::st; 00034 00035 00036 DECLARE_EXPORT void Location::writeElement(XMLOutput* o, const Keyword& tag, mode m) const 00037 { 00038 // Writing a reference 00039 if (m == REFERENCE) 00040 { 00041 o->writeElement(tag, Tags::tag_name, getName()); 00042 return; 00043 } 00044 00045 // Write the complete object 00046 if (m != NOHEADER) o->BeginObject(tag, Tags::tag_name, getName()); 00047 00048 // Write the fields 00049 HasDescription::writeElement(o, tag); 00050 HasHierarchy<Location>::writeElement(o, tag); 00051 o->writeElement(Tags::tag_available, available); 00052 o->EndObject(tag); 00053 } 00054 00055 00056 DECLARE_EXPORT void Location::beginElement(XMLInput& pIn, const Attribute& pAttr) 00057 { 00058 if (pAttr.isA(Tags::tag_available) || pAttr.isA(Tags::tag_maximum)) 00059 pIn.readto( Calendar::reader(Calendar::metadata,pIn.getAttributes()) ); 00060 else 00061 HasHierarchy<Location>::beginElement(pIn, pAttr); 00062 } 00063 00064 00065 DECLARE_EXPORT void Location::endElement(XMLInput& pIn, const Attribute& pAttr, const DataElement& pElement) 00066 { 00067 if (pAttr.isA(Tags::tag_available)) 00068 { 00069 CalendarBool *cal = dynamic_cast<CalendarBool*>(pIn.getPreviousObject()); 00070 if (cal) 00071 setAvailable(cal); 00072 else 00073 { 00074 Calendar *c = dynamic_cast<Calendar*>(pIn.getPreviousObject()); 00075 if (!c) 00076 throw LogicException("Incorrect object type during read operation"); 00077 throw DataException("Calendar '" + c->getName() + 00078 "' has invalid type for use as location calendar"); 00079 } 00080 } 00081 else 00082 { 00083 HasDescription::endElement(pIn, pAttr, pElement); 00084 HasHierarchy<Location>::endElement(pIn, pAttr, pElement); 00085 } 00086 } 00087 00088 00089 DECLARE_EXPORT Location::~Location() 00090 { 00091 // Remove all references from buffers to this location 00092 for (Buffer::iterator buf = Buffer::begin(); 00093 buf != Buffer::end(); ++buf) 00094 if (buf->getLocation() == this) buf->setLocation(NULL); 00095 00096 // Remove all references from resources to this location 00097 for (Resource::iterator res = Resource::begin(); 00098 res != Resource::end(); ++res) 00099 if (res->getLocation() == this) res->setLocation(NULL); 00100 00101 // Remove all references from operations to this location 00102 for (Operation::iterator oper = Operation::begin(); 00103 oper != Operation::end(); ++oper) 00104 if (oper->getLocation() == this) oper->setLocation(NULL); 00105 } 00106 00107 }
Documentation generated by
