Panda3D
 All Classes Functions Variables Enumerations
indexRemapper.cxx
1 // Filename: indexRemapper.cxx
2 // Created by: drose (05Aug00)
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 #include "indexRemapper.h"
16 
17 
18 ////////////////////////////////////////////////////////////////////
19 // Function: IndexRemapper::Constructor
20 // Access: Public
21 // Description:
22 ////////////////////////////////////////////////////////////////////
23 IndexRemapper::
24 IndexRemapper() {
25 }
26 
27 ////////////////////////////////////////////////////////////////////
28 // Function: IndexRemapper::Destructor
29 // Access: Public
30 // Description:
31 ////////////////////////////////////////////////////////////////////
32 IndexRemapper::
33 ~IndexRemapper() {
34 }
35 
36 ////////////////////////////////////////////////////////////////////
37 // Function: IndexRemapper::clear
38 // Access: Public
39 // Description: Removes all mappings from the object.
40 ////////////////////////////////////////////////////////////////////
41 void IndexRemapper::
42 clear() {
43  _map_int.clear();
44 }
45 
46 ////////////////////////////////////////////////////////////////////
47 // Function: IndexRemapper::add_mapping
48 // Access: Public
49 // Description: Adds a mapping from the integer 'from' to 'to'.
50 ////////////////////////////////////////////////////////////////////
51 void IndexRemapper::
52 add_mapping(int from, int to) {
53  _map_int[from] = to;
54 }
55 
56 ////////////////////////////////////////////////////////////////////
57 // Function: IndexRemapper::in_map
58 // Access: Public
59 // Description: Returns true if the given 'from' integer has been
60 // assigned a mapping, false if it has not.
61 ////////////////////////////////////////////////////////////////////
62 bool IndexRemapper::
63 in_map(int from) const {
64  return _map_int.count(from) != 0;
65 }
66 
67 ////////////////////////////////////////////////////////////////////
68 // Function: IndexRemapper::map_from
69 // Access: Public
70 // Description: Returns the integer that the given 'from' integer had
71 // been set to map to, or the same integer if nothing
72 // had been set for it.
73 ////////////////////////////////////////////////////////////////////
75 map_from(int from) const {
76  map<int, int>::const_iterator mi;
77  mi = _map_int.find(from);
78  if (mi == _map_int.end()) {
79  return from;
80  }
81  return (*mi).second;
82 }
bool in_map(int from) const
Returns true if the given &#39;from&#39; integer has been assigned a mapping, false if it has not...
void clear()
Removes all mappings from the object.
int map_from(int from) const
Returns the integer that the given &#39;from&#39; integer had been set to map to, or the same integer if noth...
void add_mapping(int from, int to)
Adds a mapping from the integer &#39;from&#39; to &#39;to&#39;.