/* * This file is part of the Owl Positioning System (OwlPS). * OwlPS is a project of the University of Franche-Comte * (Université de Franche-Comté), France. * * Copyright © Université de Franche-Comté 2007-2012. * * Corresponding author: Matteo Cypriani * *********************************************************************** * * This software is governed by the CeCILL license under French law and * abiding by the rules of distribution of free software. You can use, * modify and/or redistribute the software under the terms of the CeCILL * license as circulated by CEA, CNRS and INRIA at the following URL: * http://www.cecill.info * * As a counterpart to the access to the source code and rights to copy, * modify and redistribute granted by the license, users are provided * only with a limited warranty and the software's authors, the holder * of the economic rights, and the successive licensors have only * limited liability. * * In this respect, the user's attention is drawn to the risks * associated with loading, using, modifying and/or developing or * reproducing the software by the user in light of its specific status * of free software, that may mean that it is complicated to manipulate, * and that also therefore means that it is reserved for developers and * experienced professionals having in-depth computer knowledge. Users * are therefore encouraged to load and test the software's suitability * as regards their requirements in conditions enabling the security of * their systems and/or data to be ensured and, more generally, to use * and operate it in the same conditions as regards security. * * The fact that you are presently reading this means that you have had * knowledge of the CeCILL license and that you accept its terms. * *********************************************************************** */ #include "building.hh" #include "area.hh" #include "waypoint.hh" #include "stock.hh" using namespace std ; using std::tr1::unordered_set ; using std::tr1::unordered_map ; /* *** Constructors *** */ /** * Note: deletes (unallocates) all elements in #areas; deletes elements * in #waypoints that belong only to this Building (waypoints that link * several buildings are preserved). */ Building::~Building() { // Empty Area list for (unordered_map::const_iterator i = areas.begin() ; i != areas.end() ; ++i) delete i->second ; areas.clear() ; // Empty Waypoint list for (unordered_set::const_iterator i = waypoints.begin() ; i != waypoints.end() ; ++i) Stock::waypoint_remove_building(**i, this) ; waypoints.clear() ; } /* *** Write accessors *** */ /** * @param area A pointer to the Area to add. If it is NULL, nothing * will be added. If the Area it points to already exist in #areas, it is * deleted and nullified, unless it is the same pointer (see the code to * understand!); hmm, maybe we should handle that with exceptions… */ void Building::add_area(Area *&area) { if (area == NULL) return ; string area_name = area->get_name() ; // Check if the area already exist in areas unordered_map::const_iterator i = areas.find(area_name) ; if (i != areas.end()) { // Do not delete if area points to the already stored Area if (i->second != area) { delete area ; area = NULL ; } return ; } areas[area_name] = const_cast(area) ; } /* *** Operators *** */ Building& Building::operator=(const Building &source) { if (this == &source) return *this ; name = source.name ; areas = source.areas ; waypoints = source.waypoints ; return *this; } bool Building::operator==(const Building &source) const { if (this == &source) return true ; return name == source.name && areas == source.areas && waypoints == source.waypoints ; } ostream& operator<<(ostream &os, const Building &b) { os << b.name << " (" << b.areas.size() << " areas, " << b.waypoints.size() << " waypoints)" ; return os ; }