forked from panda3d/panda3d
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathppSubroutine.cxx
More file actions
94 lines (88 loc) · 3.4 KB
/
ppSubroutine.cxx
File metadata and controls
94 lines (88 loc) · 3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Filename: ppSubroutine.cxx
// Created by: drose (10Oct00)
//
////////////////////////////////////////////////////////////////////
#include "ppSubroutine.h"
PPSubroutine::Subroutines PPSubroutine::_subroutines;
PPSubroutine::Subroutines PPSubroutine::_functions;
////////////////////////////////////////////////////////////////////
// Function: PPSubroutine::define_sub
// Access: Public, Static
// Description: Adds a subroutine to the global list with the
// indicated name. The subroutine pointer must have
// been recently allocated, and ownership of the pointer
// will be passed to the global list; it may later
// delete it if another subroutine is defined with the
// same name.
////////////////////////////////////////////////////////////////////
void PPSubroutine::
define_sub(const string &name, PPSubroutine *sub) {
Subroutines::iterator si;
si = _subroutines.find(name);
if (si == _subroutines.end()) {
_subroutines.insert(Subroutines::value_type(name, sub));
} else {
delete (*si).second;
(*si).second = sub;
}
}
////////////////////////////////////////////////////////////////////
// Function: PPSubroutine::get_sub
// Access: Public, Static
// Description: Returns the previously-defined subroutine with the
// given name, or NULL if there is no such subroutine
// with that name.
////////////////////////////////////////////////////////////////////
const PPSubroutine *PPSubroutine::
get_sub(const string &name) {
Subroutines::const_iterator si;
si = _subroutines.find(name);
if (si == _subroutines.end()) {
return NULL;
} else {
return (*si).second;
}
}
////////////////////////////////////////////////////////////////////
// Function: PPSubroutine::define_func
// Access: Public, Static
// Description: Adds a function to the global list with the
// indicated name. This is similar to a subroutine
// except it is to be invoked via a variable reference,
// instead of by a #call function. It cannot be
// shadowed by a local variable; it will always override
// any variable definition.
//
// The subroutine pointer must have been recently
// allocated, and ownership of the pointer will be
// passed to the global list; it may later delete it if
// another subroutine is defined with the same name.
////////////////////////////////////////////////////////////////////
void PPSubroutine::
define_func(const string &name, PPSubroutine *sub) {
Subroutines::iterator si;
si = _functions.find(name);
if (si == _functions.end()) {
_functions.insert(Subroutines::value_type(name, sub));
} else {
delete (*si).second;
(*si).second = sub;
}
}
////////////////////////////////////////////////////////////////////
// Function: PPSubroutine::get_func
// Access: Public, Static
// Description: Returns the previously-defined function with the
// given name, or NULL if there is no such function
// with that name.
////////////////////////////////////////////////////////////////////
const PPSubroutine *PPSubroutine::
get_func(const string &name) {
Subroutines::const_iterator si;
si = _functions.find(name);
if (si == _functions.end()) {
return NULL;
} else {
return (*si).second;
}
}