SUMO - Simulation of Urban MObility
MSVehicleContainer.h
Go to the documentation of this file.
00001 /****************************************************************************/
00009 // vehicles sorted by their departures
00010 /****************************************************************************/
00011 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00012 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
00013 /****************************************************************************/
00014 //
00015 //   This file is part of SUMO.
00016 //   SUMO is free software: you can redistribute it and/or modify
00017 //   it under the terms of the GNU General Public License as published by
00018 //   the Free Software Foundation, either version 3 of the License, or
00019 //   (at your option) any later version.
00020 //
00021 /****************************************************************************/
00022 #ifndef MSVehicleContainer_h
00023 #define MSVehicleContainer_h
00024 
00025 
00026 // ===========================================================================
00027 // included modules
00028 // ===========================================================================
00029 #ifdef _MSC_VER
00030 #include <windows_config.h>
00031 #else
00032 #include <config.h>
00033 #endif
00034 
00035 #include <vector>
00036 #include <iostream>
00037 #include "MSNet.h"
00038 
00039 
00040 // ===========================================================================
00041 // class declarations
00042 // ===========================================================================
00043 class MSVehicle;
00044 
00045 
00046 // ===========================================================================
00047 // class definitions
00048 // ===========================================================================
00055 class MSVehicleContainer {
00056 public:
00058     typedef std::vector<SUMOVehicle*> VehicleVector;
00059 
00062     typedef std::pair<SUMOTime, VehicleVector> VehicleDepartureVector;
00063 
00064 public:
00066     MSVehicleContainer(size_t capacity = 10);
00067 
00069     ~MSVehicleContainer();
00070 
00072     void add(SUMOVehicle* veh);
00073 
00075     void add(SUMOTime time, const VehicleVector& cont);
00076 
00078     bool anyWaitingFor(SUMOTime time) const;
00079 
00081     const VehicleVector& top();
00082 
00084     SUMOTime topTime() const;
00085 
00087     void pop();
00088 
00090     bool isEmpty() const;
00091 
00093     size_t size() const;
00094 
00096     void showArray() const;
00097 
00099     friend std::ostream& operator << (std::ostream& strm,
00100                                       MSVehicleContainer& cont);
00101 
00102 private:
00105     void addReplacing(const VehicleDepartureVector& cont);
00106 
00108     bool isFull() const;
00109 
00111     class VehicleDepartureVectorSortCrit {
00112     public:
00114         bool operator()(const VehicleDepartureVector& e1,
00115                         const VehicleDepartureVector& e2) const;
00116     };
00117 
00119     class DepartFinder {
00120     public:
00122         explicit DepartFinder(SUMOTime time);
00123 
00125         bool operator()(const VehicleDepartureVector& e) const;
00126 
00127     private:
00129         SUMOTime myTime;
00130     };
00131 
00133     int currentSize;
00134 
00136     typedef std::vector<VehicleDepartureVector> VehicleHeap;
00137 
00139     VehicleHeap array;
00140 
00142     void percolateDown(int hole);
00143 
00144 };
00145 
00146 
00147 #endif
00148 
00149 /****************************************************************************/
00150 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines