trick/trick_source/sim_services/VariableServer/VariableReference.cpp
Alex Lin 19025d77ad Standardize directory names
Reorganized.  Created a new top level include directory that will hold all of Trick's header files. Moved all of the Trick headers to this directory.  Created a libexec directory that holds all of the executables that users don't need to execute directly.  Changed all of the executables remaining in bin to start with "trick-".  In the sim_services directories changed all source files to find the Trick headers in their new location.  Since all of the include files are gone in sim_services, removed the src directories as well, moving all of the source files up a level.  Moved the makefiles, docs, man, and other architecture independent files into a top level share directory.  Renamed lib_${TRICK_HOST_CPU} to lib64 or lib depending on the platform we're currently on.

refs #63
2015-06-09 08:44:42 -05:00

69 lines
2.4 KiB
C++

#include <stdlib.h>
#include <iostream>
#include "trick/VariableServer.hh"
#include "trick/memorymanager_c_intf.h"
#include "trick/wcs_ext.h"
#include "trick/message_proto.h"
#include "trick/message_type.h"
Trick::VariableReference::VariableReference(REF2 * in_ref ) {
int k ;
// VariableReference copy setup: set address & size to copy into buffer
conversion_factor = new UCFn(in_ref->attr->units, in_ref->attr->units, 1.0 , 0.0) ;
ref = in_ref ;
address = ref->address ;
size = ref->attr->size ;
// char* and wchar* in Trick 7 have a type of string and wstring, respectively
// but in Trick 10 they are type char and wchar (probably John Penn's fault),
// so we need to keep track that they are really string and wstring
string_type = ref->attr->type ;
need_deref = false ;
if ( ref->num_index == ref->attr->num_index ) {
// single value
} else if ( ref->attr->index[ref->attr->num_index - 1].size != 0 ) {
// fixed array
for ( k = ref->attr->num_index-1; k > ref->num_index-1 ; k-- ) {
size *= ref->attr->index[k].size ;
}
} else {
// arrays with pointers
if ((ref->attr->num_index - ref->num_index) > 1 ) {
// you cannot request more than one dimension because they are not contiguous
message_publish(MSG_ERROR, "Variable Server Error: var_add(%s) requests more than one dimension of dynamic array.\n", ref->reference);
message_publish(MSG_ERROR, "Data is not contiguous so returned values are unpredictable.\n") ;
}
if ( ref->attr->type == TRICK_CHARACTER ) {
// treat char* like a c++ string (see below)
string_type = TRICK_STRING ;
need_deref = true;
} else if ( ref->attr->type == TRICK_WCHAR ) {
// treat wchar_t* like a wstring (see below)
string_type = TRICK_WSTRING ;
} else {
need_deref = true ;
size *= get_size((char*)address) ;
}
}
// handle strings: set a max buffer size, the copy size may vary so will be set in copy_sim_data
if (( string_type == TRICK_STRING ) || ( string_type == TRICK_WSTRING )) {
size = MAX_ARRAY_LENGTH ;
}
buffer_in = calloc( size, 1 ) ;
buffer_out = calloc( size, 1 ) ;
}
Trick::VariableReference::~VariableReference() {
delete ref ;
free(buffer_in) ;
free(buffer_out) ;
}