OverSim
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
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
30
class
NTreeScope
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; }
40
Vector2D
origin
;
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
49
class
NTreeGroup
50
{
51
public
:
52
NodeHandle
leader
;
53
std::set<NodeHandle>
members
;
54
NTreeScope
scope
;
55
bool
dividePending
;
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
:
69
NTreeScope
scope
;
70
NodeHandle
parent
;
71
NodeHandle
children
[4];
72
// On leafs, group points to the corresponding group. NULL else.
73
NTreeGroup
*
group
;
74
// for computing when to collapse trees
75
unsigned
int
aggChildCount
[4];
76
// for backup on node failure
77
NodeHandle
siblings
[4];
78
std::set<NodeHandle>
childChildren
[4];
79
simtime_t
lastPing
;
80
bool
parentIsRoot
;
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
92
class
NTreeGroupDivideContext
93
{
94
public
:
95
NodeHandle
newChild
[4];
96
NTreeScope
nodeScope
;
97
};
98
99
class
NTreeGroupDivideContextPtr
:
public
cPolymorphic
100
{
101
public
:
102
NTreeGroupDivideContext
*
ptr
;
103
};
104
105
class
NTreePingContext
:
public
cPolymorphic
106
{
107
public
:
108
NTreePingContext
(
const
NTreeScope
& _scope,
unsigned
int
_quadrant);
109
NTreeScope
nodeScope
;
110
unsigned
int
quadrant
;
111
};
112
113
#endif
src
overlay
ntree
NTreeHelper.h
Generated on Fri Dec 7 2012 13:37:53 for OverSim by
1.8.1.2