Panda3D
clientAnalogDevice.cxx
1 // Filename: clientAnalogDevice.cxx
2 // Created by: drose (26Jan01)
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 #include "clientAnalogDevice.h"
17 
18 #include "indent.h"
19 
20 TypeHandle ClientAnalogDevice::_type_handle;
21 
22 
23 
24 ////////////////////////////////////////////////////////////////////
25 // Function: ClientAnalogDevice::ensure_control_index
26 // Access: Private
27 // Description: Guarantees that there is a slot in the array for the
28 // indicated index number, by filling the array up to
29 // that index if necessary.
30 ////////////////////////////////////////////////////////////////////
31 void ClientAnalogDevice::
32 ensure_control_index(int index) {
33  nassertv(index >= 0);
34 
35  _controls.reserve(index + 1);
36  while ((int)_controls.size() <= index) {
37  _controls.push_back(AnalogState());
38  }
39 }
40 
41 ////////////////////////////////////////////////////////////////////
42 // Function: ClientAnalogDevice::write
43 // Access: Public, Virtual
44 // Description:
45 ////////////////////////////////////////////////////////////////////
46 void ClientAnalogDevice::
47 write(ostream &out, int indent_level) const {
48  indent(out, indent_level) << get_type() << " " << get_device_name() << ":\n";
49  write_controls(out, indent_level + 2);
50 }
51 
52 ////////////////////////////////////////////////////////////////////
53 // Function: ClientAnalogDevice::write_analogs
54 // Access: Public
55 // Description: Writes a multi-line description of the current analog
56 // control states.
57 ////////////////////////////////////////////////////////////////////
59 write_controls(ostream &out, int indent_level) const {
60  bool any_controls = false;
61  Controls::const_iterator ai;
62  for (ai = _controls.begin(); ai != _controls.end(); ++ai) {
63  const AnalogState &state = (*ai);
64  if (state._known) {
65  any_controls = true;
66 
67  indent(out, indent_level)
68  << (int)(ai - _controls.begin()) << ". " << state._state << "\n";
69  }
70  }
71 
72  if (!any_controls) {
73  indent(out, indent_level)
74  << "(no known analog controls)\n";
75  }
76 }
void write_controls(ostream &out, int indent_level) const
Writes a multi-line description of the current analog control states.
const string & get_device_name() const
Returns the device name reported to the ClientBase.
Definition: clientDevice.I:62
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85