Panda3D
recorderTable.I
1 // Filename: recorderTable.I
2 // Created by: drose (27Jan04)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 
16 ////////////////////////////////////////////////////////////////////
17 // Function: RecorderTable::Constructor
18 // Access: Published
19 // Description:
20 ////////////////////////////////////////////////////////////////////
21 INLINE RecorderTable::
22 RecorderTable() {
23  _error = false;
24 }
25 
26 ////////////////////////////////////////////////////////////////////
27 // Function: RecorderTable::Copy Constructor
28 // Access: Published
29 // Description:
30 ////////////////////////////////////////////////////////////////////
31 INLINE RecorderTable::
32 RecorderTable(const RecorderTable &copy) {
33  *this = copy;
34 }
35 
36 ////////////////////////////////////////////////////////////////////
37 // Function: RecorderTable::Copy Assignment Operator
38 // Access: Published
39 // Description:
40 ////////////////////////////////////////////////////////////////////
41 INLINE void RecorderTable::
42 operator = (const RecorderTable &copy) {
43  _recorders = copy._recorders;
44  _error = copy._error;
45 
46  Recorders::iterator ri;
47  for (ri = _recorders.begin(); ri != _recorders.end(); ++ri) {
48  ri->second->ref();
49  }
50 }
51 
52 ////////////////////////////////////////////////////////////////////
53 // Function: RecorderTable::add_recorder
54 // Access: Published
55 // Description: Adds the named recorder to the set of recorders.
56 ////////////////////////////////////////////////////////////////////
57 INLINE void RecorderTable::
58 add_recorder(const string &name, RecorderBase *recorder) {
59  nassertv(recorder != (RecorderBase *)NULL);
60  recorder->ref();
61 
62  std::pair<Recorders::iterator, bool> result =
63  _recorders.insert(Recorders::value_type(name, recorder));
64 
65  if (!result.second) {
66  // Take out the previous one first.
67  unref_delete(result.first->second);
68  result.first->second = recorder;
69  }
70 }
71 
72 ////////////////////////////////////////////////////////////////////
73 // Function: RecorderTable::get_recorder
74 // Access: Published
75 // Description: Returns the recorder with the indicated name, or NULL
76 // if there is no such recorder.
77 ////////////////////////////////////////////////////////////////////
79 get_recorder(const string &name) const {
80  Recorders::const_iterator ri = _recorders.find(name);
81  if (ri != _recorders.end()) {
82  return (*ri).second;
83  }
84  return NULL;
85 }
86 
87 ////////////////////////////////////////////////////////////////////
88 // Function: RecorderTable::remove_recorder
89 // Access: Published
90 // Description: Removes the named recorder from the table. Returns
91 // true if successful, false if there was no such
92 // recorder.
93 ////////////////////////////////////////////////////////////////////
94 INLINE bool RecorderTable::
95 remove_recorder(const string &name) {
96  Recorders::iterator ri = _recorders.find(name);
97  if (ri != _recorders.end()) {
98  unref_delete(ri->second);
99  _recorders.erase(ri);
100  return true;
101  }
102  return false;
103 }
bool remove_recorder(const string &name)
Removes the named recorder from the table.
Definition: recorderTable.I:95
This object is used by the RecorderController to write (and read) a record of the set of recorders in...
Definition: recorderTable.h:35
This is the base class to a number of objects that record particular kinds of user input (like a Mous...
Definition: recorderBase.h:55
RecorderBase * get_recorder(const string &name) const
Returns the recorder with the indicated name, or NULL if there is no such recorder.
Definition: recorderTable.I:79
void add_recorder(const string &name, RecorderBase *recorder)
Adds the named recorder to the set of recorders.
Definition: recorderTable.I:58