NTRT Simulator  Version: Master
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
tgRodSensorInfo.cpp
Go to the documentation of this file.
1 /*
2  * Copyright © 2012, United States Government, as represented by the
3  * Administrator of the National Aeronautics and Space Administration.
4  * All rights reserved.
5  *
6  * The NASA Tensegrity Robotics Toolkit (NTRT) v1 platform is licensed
7  * under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * http://www.apache.org/licenses/LICENSE-2.0.
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
15  * either express or implied. See the License for the specific language
16  * governing permissions and limitations under the License.
17 */
18 
26 // This module
27 #include "tgRodSensorInfo.h"
28 // Other includes from NTRTsim
29 #include "tgRodSensor.h"
30 #include "core/tgRod.h"
31 #include "core/tgSenseable.h"
32 #include "core/tgCast.h"
33 // Other includes from the C++ standard library
34 #include <stdexcept>
35 
40 {
41 }
42 
47 {
48 }
49 
54 {
55  // The following cast will return 0 if the senseable is not a tgRod.
56  tgRod* m_pRod = tgCast::cast<tgSenseable, tgRod>(pSenseable);
57  if( m_pRod == 0 )
58  return 0;
59  else {
60  return 1;
61  }
62 }
63 
67 std::vector<tgSensor*> tgRodSensorInfo::createSensorsIfAppropriate(tgSenseable* pSenseable)
68 {
69  //CHECK: the caller SHOULD HAVE made sure that pSenseable
70  // was a tgRod pointer. If not, complain!!
71  if (!isThisMySenseable(pSenseable)) {
72  throw std::invalid_argument("pSenseable is NOT a tgRod, inside tgRodSensorInfo.");
73  }
74  // Create the list we'll return
75  std::vector<tgSensor*> newSensors;
76  // Then, if the program hasn't quit, make the sensor.
77  // Note that we cast the pointer here, knowing that it will succeed.
78  newSensors.push_back( new tgRodSensor( tgCast::cast<tgSenseable, tgRod>(pSenseable) ));
79  return newSensors;
80 }
virtual std::vector< tgSensor * > createSensorsIfAppropriate(tgSenseable *pSenseable)
virtual bool isThisMySenseable(tgSenseable *pSenseable)
Utility class for class casting and filtering collections by type.
Constains definition of concrete class tgRodSensor.
Definition of concrete class tgRodSensorInfo.
Contains the definition of class tgRod.
Constains the implementation of mixin class tgSenseable.
Definition: tgRod.h:43