Permalink
Browse files

Cleaned up some of the comments and debugging statements in the worki…

…ng code for the data sensing framework.
  • Loading branch information...
apsabelhaus committed Jan 8, 2017
1 parent e082a82 commit d6060b2bbb272c494b8f50cfc046b42d920e5eed
View
@@ -190,11 +190,8 @@ std::vector<tgModel*> tgModel::getDescendants() const
*/
std::vector<tgSenseable*> tgModel::getSenseableDescendants() const
{
//return getDescendants();
//DEBUGGING: test if this is a type issue...
//return std::vector<tgSenseable*>();
// Seems to work. So, how about we make a new list, populate it
// with tgModels, and return that.
// TO-DO: why can't we just return the results of getDescendants?
// There seems to be some polymorphism issue here...
std::vector<tgModel*> myDescendants = getDescendants();
std::vector<tgSenseable*> mySenseableDescendants;
for (size_t i=0; i < myDescendants.size(); i++) {
@@ -211,13 +208,6 @@ void tgModel::addMarker(abstractMarker a){
m_markers.push_back(a);
}
/**
* For tgSenseable.
*/
std::string tgModel::getLabelForSensor(){
return "tgModel";
}
bool tgModel::invariant() const
{
// No child is NULL
View
@@ -22,7 +22,7 @@
/**
* @file tgModel.h
* @brief Contains the definition of class tgModel.
* @author Ryan Adams
* @author Ryan Adams, Drew Sabelhaus
* $Id$
*/
@@ -155,16 +155,11 @@ class tgModel : public tgTaggable, public tgSenseable
void addMarker(abstractMarker a);
/**
* From tgSenseable: give a label of this type of senseable object.
* Note that child classes (e.g. rods) re-define this.
* This is also why the keyword "virtual" is used here.
*/
virtual std::string getLabelForSensor();
/**
* From tgSenseable: need to return all the children of this class.
* Since tgModels are tgSenseables, just return getDescendants().
* @return a vector of tgModels, with pointers changed into pointers
* for tgSenseables.
*/
virtual std::vector<tgSenseable*> getSenseableDescendants() const;
View
@@ -27,18 +27,9 @@
#include "tgSenseable.h"
// From the C++ standard library:
//#include <iostream> //for strings
//#include <vector> //for lists of descendants
//#include <assert.h> //for assertions
// ...
/**
* This function shouldn't ever be called, so output something generic.
*/
std::string tgSenseable::getLabelForSensor(){
return "base_tgSenseable";
}
/**
* Return an empty vector of descendants.
* It's up to child classes to re-implement this.
View
@@ -38,18 +38,6 @@
class tgSenseable
{
public:
/**
* Ideally, this class would have no member functions.
* However, since C++ requires at least one virtual member function
* for polymorphism, we have one here.
* This function returns a label to pre-pend to the header
* of any data coming from this object.
* For example, for a tgRod, this method should return "rod"
* or something like that.
* Include a generic output here that really should be redefined later.
*/
virtual std::string getLabelForSensor();
/**
* In order to create sensors for a whole hierarchy of senseable objects,
@@ -24,13 +24,10 @@
*/
// This module
//#include "tgDataManager.h"
#include "tgDataLogger2.h"
// This application
#include "tgSensor.h"
//#include "tgSensorInfo.h"
// The C++ Standard Library
//#include <stdio.h> // for sprintf
#include <stdexcept>
#include <cassert>
#include <iostream>
@@ -50,9 +47,6 @@ tgDataLogger2::tgDataLogger2(std::string fileNamePrefix) :
tgDataManager(),
m_fileNamePrefix(fileNamePrefix)
{
//DEBUGGING
//std::cout << "tgDataLogger2 constructor." << std::endl;
// Postcondition
// A quick check on the passed-in string: it must not be the empty
// string. Must be a correct linux path.
// TO-DO: a better check on this.
@@ -66,18 +60,15 @@ tgDataLogger2::tgDataLogger2(std::string fileNamePrefix) :
// for these log file names.
// Check if the first character of the string is a tilde:
if (m_fileNamePrefix.at(0) == '~') {
//DEBUGGING
//std::cout << "Automatically converting a tilde ~ to your home directory, as part of the tgDataLogger2 file name..." << std::endl;
// Get the $HOME environment variable
std::string home = std::getenv("HOME");
//DEBUGGING
//std::cout << "$HOME is: " << home << std::endl;
// Remove the tilde (the first element) from the string
m_fileNamePrefix.erase(0,1);
// Concatenate the home directory.
m_fileNamePrefix = home + m_fileNamePrefix;
}
// Postcondition
assert(invariant());
}
@@ -100,8 +91,6 @@ tgDataLogger2::tgDataLogger2()
*/
tgDataLogger2::~tgDataLogger2()
{
//DEBUGGING
//std::cout << "tgDataLogger2 destructor." << std::endl;
// TO-DO: should we double-check and close the tgOutput filestream here too?
}
@@ -180,8 +169,6 @@ void tgDataLogger2::teardown()
{
// Call the parent's teardown method! This is important!
tgDataManager::teardown();
//DEBUGGING
//std::cout << "tgDataLogger2 teardown." << std::endl;
// Close the log file.
tgOutput.close();
// Postcondition
@@ -196,16 +183,12 @@ void tgDataLogger2::teardown()
*/
void tgDataLogger2::step(double dt)
{
//DEBUGGING
//std::cout << "tgDataLogger2 step." << std::endl;
if (dt <= 0.0)
{
throw std::invalid_argument("dt is not positive");
}
else
{
//DEBUGGING
//std::cout << "tgDataLogger2 step:" << std::endl;
// Open the log file for writing, appending and not overwriting.
tgOutput.open(m_fileName.c_str(), std::ios::app);
// For the timestamp: first, add dt to the total time
@@ -42,6 +42,8 @@ class tgDataLogger2 : public tgDataManager
/**
* The constructor for tgDataLogger2 takes in a string that specifies the location
* of the log file to create.
* @param[in] fileNamePrefix a string that specifies the path to the log file that
* will be written. The current time will be appended to this prefix.
*/
tgDataLogger2(std::string fileNamePrefix);
@@ -76,6 +78,7 @@ class tgDataLogger2 : public tgDataManager
* The step function for tgDataLogger2 will open the log file for output,
* write a line of sensor data, then close the log file.
* Declared virtual here just in case any classes inherit from this.
* @param[in] dt a double, the amount of time since the last step.
*/
virtual void step(double dt);
@@ -40,17 +40,15 @@
*/
tgDataManager::tgDataManager()
{
//DEBUGGING
//std::cout << "tgDataManager constructor." << std::endl;
// Postcondition
assert(invariant());
}
/**
* In the destructor, we must be sure to delete everything in both the
* m_sensors and m_sensorInfos lists.
* Ideally, this should be handled by teardown, so this is really a
* double-check for memory leaks more than anything else.
* Teardown only deletes sensors, not sensor infos, so this is a double-check
* for sensors and the only real delete for sensor infos.
*/
tgDataManager::~tgDataManager()
{
@@ -77,7 +75,6 @@ tgDataManager::~tgDataManager()
// Pick out one sensorInfo from the list:
tgSensorInfo* const pSensorInfo = m_sensorInfos[i];
// TO-DO: check if we need this assert...
// It is safe to delete NULL, but this is an invariant
// assert(pChild != NULL);
delete pSensorInfo;
//Null out the deleted pointer.
@@ -140,10 +137,7 @@ void tgDataManager::setup()
* that doesn't require subclasses to copy-and-paste from this teardown method?
*/
void tgDataManager::teardown()
{
//DEBUGGING
//std::cout << "tgDataManager teardown." << std::endl;
{
// First, delete the sensors.
// Note that it's good practice to set deleted pointers to NULL here.
for (std::size_t i = 0; i < m_sensors.size(); i++)
@@ -157,20 +151,10 @@ void tgDataManager::teardown()
// do anything.
m_sensors.clear();
// Next, delete the sensor infos.
// TO-DO: implement this.
// TO-DO: should we actually be deleting these? Or would that make it so no
// sensors would be created after a reset???
// Clear the list of senseable objects.
// Since tgDataManagers don't ever change these objects,
// leave it to other classes to create and delete them.
// Just get rid of the pointers here.
// TO-DO: maybe we don't want to do this? Will this make it so no logs
// are created upon reset???
// TO-DO: could this segfault? Will the pointers in m_senseables be changed
// during reset at all?
//m_senseables.clear();
// Don't touch the list of senseable objects.
// These tgModels are not re-created when teardown is called (I think?),
// so the pointers should remain the same between calls to reset.
// TO-DO: confirm that it's OK to not remove the list of m_senseables.
// Postcondition
assert(invariant());
@@ -183,8 +167,6 @@ void tgDataManager::teardown()
*/
void tgDataManager::step(double dt)
{
//DEBUGGING
//std::cout << "tgDataManager step." << std::endl;
if (dt <= 0.0)
{
throw std::invalid_argument("dt is not positive");
@@ -210,8 +192,7 @@ void tgDataManager::addSensorInfo(tgSensorInfo* pSensorInfo)
// Otherwise, duplicate sensors will be created: e.g., if two tgRodSensorInfos
// are in m_sensorInfos, then multiple tgRodSensors will be created for
// each tgRod.
//DEBUGGING
//std::cout << "tgDataManager addSensorInfo." << std::endl;
// Precondition
if (pSensorInfo == NULL)
{
@@ -232,14 +213,14 @@ void tgDataManager::addSensorInfo(tgSensorInfo* pSensorInfo)
*/
void tgDataManager::addSenseable(tgSenseable* pSenseable)
{
//DEBUGGING
//std::cout << "tgDataManager addSenseable." << std::endl;
// Precondition
if (pSenseable == NULL)
{
throw std::invalid_argument("pSenseable is NULL inside tgDataManager::addSenseable");
}
// TO-DO: should we check to see if this senseable object is already
// in the m_senseables list???
m_senseables.push_back(pSenseable);
// Postcondition
@@ -254,23 +235,12 @@ void tgDataManager::addSenseable(tgSenseable* pSenseable)
*/
std::string tgDataManager::toString() const
{
std::string p = " ";
std::ostringstream os;
// Note that we're using sprintf here to convert an int to a string.
// TO-DO: fix this!
os << "tgDataManager"
<< " with " << m_sensors.size() << " sensors, " << m_sensorInfos.size()
<< " sensorInfos, and " << m_senseables.size() << " senseable objects."
<< std::endl;
/*
os << prefix << p << "Children:" << std::endl;
for(std::size_t i = 0; i < m_children.size(); i++) {
os << m_children[i]->toString(prefix + p) << std::endl;
}
os << prefix << p << "Tags: [" << getTags() << "]" << std::endl;
os << prefix << ")";
*/
return os.str();
}
@@ -27,9 +27,6 @@
*/
// This application
//#include "tgCast.h"
//#include "tgTaggable.h"
//#include "tgTagSearch.h"
#include "core/tgSenseable.h" //not sure why this needs to be included vs. just declared...
// The C++ Standard Library
#include <string>
@@ -38,9 +35,7 @@
#include <vector>
// Forward declarations
//class tgWorld;
class tgSensor;
//class tgSenseable;
class tgSensorInfo;
/**
@@ -89,6 +84,8 @@ class tgDataManager
* Add a tgSenseable object to this data manager.
* These objects will be checked via the sensor infos, and sensors will
* be assigned to them if appropriate.
* @param[in] pSenseable a pointer to a tgSenseable object that will be
* added to this data manager's list of senseable objects.
*/
virtual void addSenseable(tgSenseable* pSenseable);
@@ -111,12 +108,13 @@ class tgDataManager
/**
* A helper function for setup. Since there will be a loop over
* the sensor infos, this function abstracts it away.
* @param[in] pSenseable a pointer to one of this object's senseables.
*/
void addSensorsIfAppropriate(tgSenseable* pSenseable);
protected:
/** Integrity predicate. */
// Integrity predicate.
bool invariant() const;
/**
@@ -44,6 +44,7 @@ class tgRodSensor : public tgSensor
* The constructor for tgRodSensor, will be same as tgSensor, but now
* with a more specific pointer. This should work, since tgRod
* is a tgSenseable.
* @param[in] pRod a pointer to a tgRod that this sensor will attach itself to.
*/
tgRodSensor(tgRod* pRod);
@@ -30,7 +30,7 @@
// This module
#include "tgSensorInfo.h"
// Other includes from NTRTsim
//#include "core/tgRod.h"
// ...
// Other includes from the C++ standard library
// ...
@@ -61,12 +61,18 @@ class tgRodSensorInfo : public tgSensorInfo
/**
* From tgSensorInfo, need to implement a check to see if a particular
* tgSenseable is a tgRod.
* @param[in] pSenseable a pointer to a tgSenseable object, that this sensor info
* may or may not be able to create a sensor for.
* @return true if pSenseable is able to be sensed by the type of sensor that
* this sensor info creates.
*/
virtual bool isThisMySenseable(tgSenseable* pSenseable);
/**
* Similarly, create a sensor if appropriate.
* See tgSensorInfo for more... info.
* @param[in] pSenseable pointer to a senseable object. Sensor will be created
* for this pSenseable.
*/
virtual tgSensor* createSensor(tgSenseable* pSenseable);
Oops, something went wrong.

0 comments on commit d6060b2

Please sign in to comment.