# yapf_node.hpp

Go to the documentation of this file.

    00001 /* $Id$ */
    00002
    00003 /*
    00004  * This file is part of OpenTTD.
    00005  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
    00006  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    00007  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
    00008  */
    00009
    00012 #ifndef YAPF_NODE_HPP
    00013 #define YAPF_NODE_HPP
    00014
    00016 struct CYapfNodeKeyExitDir {
    00017   TileIndex      m_tile;
    00018   Trackdir       m_td;
    00019   DiagDirection  m_exitdir;
    00020
    00021   inline void Set(TileIndex tile, Trackdir td)
    00022   {
    00023     m_tile = tile;
    00024     m_td = td;
    00025     m_exitdir = (m_td == INVALID_TRACKDIR) ? INVALID_DIAGDIR : TrackdirToExitdir(m_td);
    00026   }
    00027
    00028   inline int CalcHash() const {return m_exitdir | (m_tile << 2);}
    00029   inline bool operator == (const CYapfNodeKeyExitDir& other) const {return (m_tile == other.m_tile) && (m_exitdir == other.m_exitdir);}
    00030
    00031   void Dump(DumpTarget &dmp) const
    00032   {
    00033     dmp.WriteTile("m_tile", m_tile);
    00034     dmp.WriteEnumT("m_td", m_td);
    00035     dmp.WriteEnumT("m_exitdir", m_exitdir);
    00036   }
    00037 };
    00038
    00039 struct CYapfNodeKeyTrackDir : public CYapfNodeKeyExitDir
    00040 {
    00041   inline int CalcHash() const {return m_td | (m_tile << 4);}
    00042   inline bool operator == (const CYapfNodeKeyTrackDir& other) const {return (m_tile == other.m_tile) && (m_td == other.m_td);}
    00043 };
    00044
    00046 template <class Tkey_, class Tnode>
    00047 struct CYapfNodeT {
    00048   typedef Tkey_ Key;
    00049   typedef Tnode Node;
    00050
    00051   Tkey_       m_key;
    00052   Node       *m_hash_next;
    00053   Node       *m_parent;
    00054   int         m_cost;
    00055   int         m_estimate;
    00056
    00057   inline void Set(Node *parent, TileIndex tile, Trackdir td, bool is_choice)
    00058   {
    00059     m_key.Set(tile, td);
    00060     m_hash_next = NULL;
    00061     m_parent = parent;
    00062     m_cost = 0;
    00063     m_estimate = 0;
    00064   }
    00065
    00066   inline Node *GetHashNext() {return m_hash_next;}
    00067   inline void SetHashNext(Node *pNext) {m_hash_next = pNext;}
    00068   inline TileIndex GetTile() const {return m_key.m_tile;}
    00069   inline Trackdir GetTrackdir() const {return m_key.m_td;}
    00070   inline const Tkey_& GetKey() const {return m_key;}
    00071   inline int GetCost() const {return m_cost;}
    00072   inline int GetCostEstimate() const {return m_estimate;}
    00073   inline bool operator < (const Node& other) const {return m_estimate < other.m_estimate;}
    00074
    00075   void Dump(DumpTarget &dmp) const
    00076   {
    00077     dmp.WriteStructT("m_key", &m_key);
    00078     dmp.WriteStructT("m_parent", m_parent);
    00079     dmp.WriteLine("m_cost = %d", m_cost);
    00080     dmp.WriteLine("m_estimate = %d", m_estimate);
    00081   }
    00082 };
    00083
    00084 #endif /* YAPF_NODE_HPP */