Add ability to remove variable from data recording

For the record, I'd like to point out that many of the DataRecordGroup
functions shouldn't be called after init, but we don't prevent anyone
from doing so. Bad Trick!

Refs #350
This commit is contained in:
Derek Bankieris 2016-11-18 08:53:24 -06:00
parent 9ac0f64f10
commit ac3360e87f
3 changed files with 27 additions and 1 deletions

View File

@ -309,10 +309,19 @@ namespace Trick {
@code <dr_group>.add_variable("<in_name>" [,"<alias>"]) @endcode
@param in_name - the name of the variable to record
@param alias - (optional) the name to call the variable in the log file instead of @e in_name
@return 0 if successful, -1 if variable not found
@return always 0
*/
virtual int add_variable(std::string in_name , std::string alias = "" ) ;
/**
@brief @userdesc Command to remove a variable from recording.
@par Python Usage:
@code <dr_group>.remove_variable("<in_name>") @endcode
@param in_name - the name of the variable to not record
@return always 0
*/
virtual int remove_variable(std::string in_name) ;
/**
@brief This routine allows users to add variables through an already created REF2 structure.
@param ref2 - variable reference of the variable to record

View File

@ -1,4 +1,5 @@
#include <algorithm>
#include <string>
#include <iostream>
#include <sstream>
@ -246,6 +247,21 @@ int Trick::DataRecordGroup::add_variable( std::string in_name , std::string alia
return 0 ;
}
int Trick::DataRecordGroup::remove_variable( std::string in_name ) {
// Trim leading spaces
in_name.erase( 0, in_name.find_first_not_of( " \t" ) );
// Trim trailing spaces
in_name.erase( in_name.find_last_not_of( " \t" ) + 1);
rec_buffer.erase( std::remove_if( rec_buffer.begin(), rec_buffer.end(),
[&]( DataRecordBuffer* buffer ) {
return !buffer->name.compare( in_name );
} ),
rec_buffer.end() );
return 0 ;
}
int Trick::DataRecordGroup::add_variable( REF2 * ref2 ) {
if ( ref2 == NULL || ref2->attr == NULL ) {

View File

@ -1,3 +1,4 @@
TRICK_CXXFLAGS += -std=c++11
include ${TRICK_HOME}/share/trick/makefiles/Makefile.common
include ${TRICK_HOME}/share/trick/makefiles/Makefile.tricklib