OverSim
NTreeHelper.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2006 Institut fuer Telematik, Universitaet Karlsruhe (TH)
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 //
18 
24 #ifndef __NTREEHELPER_H_
25 #define __NTREEHELPER_H_
26 
27 #include <NodeHandle.h>
28 #include <Vector2D.h>
29 
31 {
32  public:
33  NTreeScope();
34  NTreeScope(const Vector2D& _origin, double _size);
35  void resize(const Vector2D& _origin, double _size);
36  bool contains(const Vector2D&) const;
37  NTreeScope getSubScope( unsigned int quadrant ) const;
38 
39  bool isValid() const { return size >= 0; }
41  double size;
42 
43  friend bool operator==(const NTreeScope& a, const NTreeScope& b);
44  friend bool operator<(const NTreeScope& a, const NTreeScope& b);
45  friend std::ostream& operator<<(std::ostream& Stream, const NTreeScope& scope);
46 };
47 
48 
50 {
51  public:
53  std::set<NodeHandle> members;
56 
57  bool isInScope(const Vector2D& p) const;
58  NTreeGroup(const NTreeScope& _scope);
59  NTreeGroup(const Vector2D& _origin, double _size);
60 
61  friend bool operator==(const NTreeGroup& a, const NTreeGroup& b);
62  friend bool operator<(const NTreeGroup& a, const NTreeGroup& b);
63  friend std::ostream& operator<<(std::ostream& Stream, const NTreeGroup& group);
64 };
65 
66 class NTreeNode
67 {
68  public:
72  // On leafs, group points to the corresponding group. NULL else.
74  // for computing when to collapse trees
75  unsigned int aggChildCount[4];
76  // for backup on node failure
78  std::set<NodeHandle> childChildren[4];
79  simtime_t lastPing;
81 
82  bool isInScope(const Vector2D& p) const;
83  const NodeHandle& getChildForPos( const Vector2D& pos ) const;
84  NTreeNode(const NTreeScope& _scope);
85  NTreeNode(const Vector2D& _origin, double _size);
86 
87  friend bool operator==(const NTreeNode& a, const NTreeNode& b);
88  friend bool operator<(const NTreeNode& a, const NTreeNode& b);
89  friend std::ostream& operator<<(std::ostream& Stream, const NTreeNode& node);
90 };
91 
93 {
94  public:
97 };
98 
99 class NTreeGroupDivideContextPtr : public cPolymorphic
100 {
101  public:
103 };
104 
105 class NTreePingContext : public cPolymorphic
106 {
107  public:
108  NTreePingContext(const NTreeScope& _scope, unsigned int _quadrant);
110  unsigned int quadrant;
111 };
112 
113 #endif