Commit 7a57e919 authored by Dan Wu's avatar Dan Wu
Browse files

Changed some non-primitive parameters to be passed by const reference (usually...

Changed some non-primitive parameters to be passed by const reference (usually faster and recommended in C++) instead of by value.
parent 4c8ebe39
......@@ -110,7 +110,7 @@ public:
#define ARRAY_INOUT( A ) A.ptr(), &A.capacity(), &A.size()
#define ARRAY_IN( A ) &A[0], A.size()
bool smooth_test(const std::string filename, FBiGeom_Instance);
bool smooth_test(const std::string &filename, FBiGeom_Instance);
bool tags_test(FBiGeom_Instance geom);
bool tag_get_set_test(FBiGeom_Instance geom);
......@@ -307,7 +307,7 @@ int main(int argc, char *argv[]) {
@li Load a mesh file
*/
bool smooth_test(const std::string filename, FBiGeom_Instance geom) {
bool smooth_test(const std::string &filename, FBiGeom_Instance geom) {
int err;
char opts[] = "SMOOTH;";
FBiGeom_load(geom, &filename[0], opts, &err, filename.length(), 8);
......
......@@ -117,7 +117,7 @@ public:
#define ARRAY_INOUT( A ) A.ptr(), &A.capacity(), &A.size()
#define ARRAY_IN( A ) &A[0], A.size()
bool smooth_test(const std::string filename, FBiGeom_Instance);
bool smooth_test(const std::string &filename, FBiGeom_Instance);
bool tags_test(FBiGeom_Instance geom);
bool tag_get_set_test(FBiGeom_Instance geom);
......@@ -337,7 +337,7 @@ int main(int argc, char *argv[]) {
@li Load a mesh file
*/
bool smooth_test(const std::string filename, FBiGeom_Instance geom) {
bool smooth_test(const std::string &filename, FBiGeom_Instance geom) {
int err;
char opts[] = "SMOOTH;";
FBiGeom_load(geom, &filename[0], opts, &err, filename.length(), 8);
......
......@@ -93,7 +93,7 @@ template <typename T> class SimpleArray
#define ARRAY_INOUT( A ) A.ptr(), &A.capacity(), &A.size()
#define ARRAY_IN( A ) &A[0], A.size()
bool gLoad_test(const std::string filename, FBiGeom_Instance);
bool gLoad_test(const std::string &filename, FBiGeom_Instance);
bool tags_test(FBiGeom_Instance geom);
bool tag_get_set_test(FBiGeom_Instance geom);
......@@ -280,7 +280,7 @@ int main( int argc, char *argv[] )
Load Mesh
@li Load a mesh file
*/
bool gLoad_test(const std::string filename, FBiGeom_Instance geom)
bool gLoad_test(const std::string &filename, FBiGeom_Instance geom)
{
int err;
FBiGeom_load( geom, &filename[0], 0, &err, filename.length(), 0 );
......
......@@ -302,7 +302,7 @@ public:
};
inline MeshSet::hdl_iter::difference_type
operator-( const MeshSet::hdl_iter a, const MeshSet::hdl_iter b )
operator-( const MeshSet::hdl_iter &a, const MeshSet::hdl_iter &b )
{ return (MeshSet::hdl_iter::difference_type)a.h
- (MeshSet::hdl_iter::difference_type)b.h; }
......
......@@ -266,7 +266,7 @@ ErrorCode ScdInterface::assign_global_ids(ScdBox *box)
return MB_SUCCESS;
}
ErrorCode ScdInterface::create_scd_sequence(HomCoord low, HomCoord high, EntityType tp,
ErrorCode ScdInterface::create_scd_sequence(const HomCoord &low, const HomCoord &high, EntityType tp,
int starting_id, ScdBox *&new_box,
int *is_periodic)
{
......@@ -315,7 +315,7 @@ ErrorCode ScdInterface::create_scd_sequence(HomCoord low, HomCoord high, EntityT
return MB_SUCCESS;
}
ErrorCode ScdInterface::create_box_set(const HomCoord low, const HomCoord high,
ErrorCode ScdInterface::create_box_set(const HomCoord &low, const HomCoord &high,
EntityHandle &scd_set, int *is_periodic)
{
// create the set and put the entities in it
......
......@@ -139,7 +139,7 @@ ErrorCode WriteUtil::get_node_coords(const int num_arrays,
ErrorCode WriteUtil::get_node_coords(const int which_array, /* 0->X, 1->Y, 2->Z, -1->all */
Range::const_iterator iter,
const Range::const_iterator end,
const Range::const_iterator& end,
const size_t output_array_len,
double* const output_array)
{
......@@ -314,7 +314,7 @@ ErrorCode WriteUtil::get_element_connect(const int num_elements,
}
ErrorCode WriteUtil::get_element_connect(Range::const_iterator iter,
const Range::const_iterator end,
const Range::const_iterator& end,
const int vertices_per_elem,
Tag node_id_tag,
const size_t elem_array_size,
......@@ -420,7 +420,7 @@ ErrorCode WriteUtil::get_element_connect(Range::const_iterator iter,
}
ErrorCode WriteUtil::get_element_connect(Range::const_iterator iter,
const Range::const_iterator end,
const Range::const_iterator& end,
const int vertices_per_elem,
const size_t elem_array_size,
EntityHandle *const element_array)
......@@ -511,14 +511,14 @@ ErrorCode WriteUtil::get_element_connect(Range::const_iterator iter,
}
ErrorCode WriteUtil::get_poly_connect_size(Range::const_iterator /* begin */,
const Range::const_iterator /* end */ ,
const Range::const_iterator& /* end */ ,
int& /* connectivity_size */)
{
return MB_NOT_IMPLEMENTED;
}
ErrorCode WriteUtil::get_poly_connect(Range::const_iterator& /* iter */,
const Range::const_iterator /* end */ ,
const Range::const_iterator& /* end */ ,
const Tag /* node_id_tag */ ,
size_t& /* handle_array_len */,
int *const /* handle_array */,
......
......@@ -79,7 +79,7 @@ public:
*/
ErrorCode get_node_coords(const int which_array,
Range::const_iterator begin,
const Range::const_iterator end,
const Range::const_iterator& end,
const size_t output_size,
double* const output_array);
......@@ -134,7 +134,7 @@ public:
*\author Jason Kraftcheck
*/
ErrorCode get_element_connect(Range::const_iterator begin,
const Range::const_iterator end,
const Range::const_iterator& end,
const int vertices_per_elem,
Tag node_id_tag,
const size_t array_size,
......@@ -167,7 +167,7 @@ public:
*\author Jason Kraftcheck
*/
virtual ErrorCode get_element_connect(Range::const_iterator begin,
const Range::const_iterator end,
const Range::const_iterator& end,
const int vertices_per_elem,
const size_t array_size,
EntityHandle *const element_array);
......@@ -180,7 +180,7 @@ public:
*\author Jason Kraftcheck
*/
virtual ErrorCode get_poly_connect_size(Range::const_iterator begin,
const Range::const_iterator end,
const Range::const_iterator& end,
int& connectivity_size);
/** Get poly (polygon or polyhedron) connectivity.
......@@ -211,7 +211,7 @@ public:
*\author Jason Kraftcheck
*/
virtual ErrorCode get_poly_connect(Range::const_iterator& iter,
const Range::const_iterator end,
const Range::const_iterator& end,
const Tag node_id_tag,
size_t& handle_array_len,
int *const handle_array,
......
......@@ -13,7 +13,7 @@ const char PFX[] = ">>> ";
namespace moab {
IODebugTrack::IODebugTrack( bool enabled,
const std::string name,
const std::string& name,
std::ostream& output_stream,
unsigned long table_size )
: enableOutput(enabled),
......@@ -30,7 +30,7 @@ IODebugTrack::IODebugTrack( bool enabled,
IODebugTrack::IODebugTrack( bool enabled,
const std::string name,
const std::string& name,
unsigned long table_size )
: enableOutput(enabled),
tableName(name),
......
......@@ -42,7 +42,7 @@ class IODebugTrack {
*\param table_size Max table size. No limit if unspecified
*/
IODebugTrack( bool enable,
const std::string table_name,
const std::string& table_name,
std::ostream& output_stream,
unsigned long table_size = 0 ) ;
......@@ -51,7 +51,7 @@ class IODebugTrack {
*\param table_size Max table size. No limit if unspecified
*/
IODebugTrack( bool enable,
const std::string table_name,
const std::string& table_name,
unsigned long table_size = 0 ) ;
/**\brief Destructor prints errors about unaccessed ranges */
......
......@@ -1410,7 +1410,7 @@ ErrorCode ReadABAQUS::get_nodes_by_id(EntityHandle parent_set,
ErrorCode ReadABAQUS::get_set_by_name(EntityHandle parent_set,
int ABQ_set_type,
std::string set_name,
const std::string &set_name,
EntityHandle &set_handle)
{
ErrorCode status;
......@@ -1466,7 +1466,7 @@ ErrorCode ReadABAQUS::get_set_elements(EntityHandle set_handle,
ErrorCode ReadABAQUS::get_set_elements_by_name(EntityHandle parent_set,
int ABQ_set_type,
std::string set_name,
const std::string &set_name,
Range &element_range)
{
ErrorCode status;
......@@ -1487,7 +1487,7 @@ ErrorCode ReadABAQUS::get_set_elements_by_name(EntityHandle parent_set,
ErrorCode ReadABAQUS::get_set_nodes(EntityHandle parent_set,
int ABQ_set_type,
std::string set_name,
const std::string &set_name,
Range &node_range)
{
ErrorCode status;
......@@ -1534,8 +1534,8 @@ Tag ReadABAQUS::get_tag(const char* tag_name,
ErrorCode ReadABAQUS::create_instance_of_part(const EntityHandle file_set,
const EntityHandle assembly_set,
const std::string part_name,
const std::string /*instance_name*/,
const std::string &part_name,
const std::string &/*instance_name*/,
EntityHandle &instance_set,
const std::vector<double> &translation,
const std::vector<double> &rotation)
......@@ -1883,7 +1883,7 @@ ErrorCode ReadABAQUS::create_instance_of_part(const EntityHandle file_set,
ErrorCode ReadABAQUS::add_entity_set(EntityHandle parent_set,
int ABQ_Set_Type,
std::string set_name,
const std::string &set_name,
EntityHandle &entity_set)
{
ErrorCode status;
......@@ -2039,7 +2039,7 @@ std::string ReadABAQUS::match(const std::string &token,
}
// Convert a string to upper case
void ReadABAQUS::stringToUpper(std::string toBeConverted, std::string& converted)
void ReadABAQUS::stringToUpper(const std::string& toBeConverted, std::string& converted)
{
converted = toBeConverted;
......@@ -2048,13 +2048,13 @@ void ReadABAQUS::stringToUpper(std::string toBeConverted, std::string& converted
}
// Extract key/value pairs from parameter list
void ReadABAQUS::extract_keyword_parameters(std::vector<std::string> tokens,
void ReadABAQUS::extract_keyword_parameters(const std::vector<std::string>& tokens,
std::map<std::string, std::string>& params)
{
std::string key, value;
// NOTE: skip first token - it is the keyword
for (std::vector<std::string>::iterator token = tokens.begin() + 1;
for (std::vector<std::string>::const_iterator token = tokens.begin() + 1;
token != tokens.end(); ++token) {
std::string::size_type pos = token->find('=');
stringToUpper(token->substr(0, pos), key);
......
......@@ -373,7 +373,7 @@ private:
ErrorCode get_set_by_name(EntityHandle parent_set,
int ABQ_set_type,
std::string set_name,
const std::string &set_name,
EntityHandle &set_handle);
ErrorCode get_set_elements(EntityHandle set_handle,
......@@ -381,23 +381,23 @@ private:
ErrorCode get_set_elements_by_name(EntityHandle parent_set,
int ABQ_set_type,
std::string set_name,
const std::string &set_name,
Range &element_range);
ErrorCode get_set_nodes(EntityHandle parent_set,
int ABQ_set_type,
std::string set_name,
const std::string &set_name,
Range &node_range);
ErrorCode add_entity_set(EntityHandle parent_set,
int ABQ_set_type,
std::string set_name,
const std::string &set_name,
EntityHandle &entity_set);
ErrorCode create_instance_of_part(const EntityHandle file_set,
const EntityHandle parent_set,
const std::string part_name,
const std::string instance_name,
const std::string &part_name,
const std::string &instance_name,
EntityHandle &entity_set,
const std::vector<double> &translation,
const std::vector<double> &rotation);
......@@ -416,9 +416,9 @@ private:
std::string match(const std::string &token,
std::map<std::string,T> &tokenList);
void stringToUpper(std::string toBeConverted,std::string& converted);
void stringToUpper(const std::string& toBeConverted,std::string& converted);
void extract_keyword_parameters(std::vector<std::string> tokens,
void extract_keyword_parameters(const std::vector<std::string>& tokens,
std::map<std::string, std::string>& params);
//! Interface instance
......
......@@ -204,7 +204,7 @@ ErrorCode ReadNASTRAN::load_file(const char *filename,
large field: 1x8, 4x16, 1x8. Field 1 must have an asterisk following the character string
free field: each line entry must be separated by a comma
Implementation tries to avoid more searches than necessary. */
ErrorCode ReadNASTRAN::determine_line_format(const std::string line,
ErrorCode ReadNASTRAN::determine_line_format(const std::string &line,
line_format &format)
{
std::string::size_type found_asterisk = line.find("*");
......@@ -226,7 +226,7 @@ ErrorCode ReadNASTRAN::determine_line_format(const std::string line,
}
/* Tokenize the line. Continue-lines have not been implemented. */
ErrorCode ReadNASTRAN::tokenize_line(const std::string line, const line_format format,
ErrorCode ReadNASTRAN::tokenize_line(const std::string &line, const line_format format,
std::vector<std::string> &tokens)
{
size_t line_size = line.size();
......@@ -252,7 +252,7 @@ ErrorCode ReadNASTRAN::tokenize_line(const std::string line, const line_format f
return MB_SUCCESS;
}
ErrorCode ReadNASTRAN::determine_entity_type(const std::string first_token,
ErrorCode ReadNASTRAN::determine_entity_type(const std::string &first_token,
EntityType &type)
{
if (0 == first_token.compare("GRID "))
......@@ -284,7 +284,7 @@ ErrorCode ReadNASTRAN::determine_entity_type(const std::string first_token,
has the coordinates: ( 3.980454, 6.9052e-1, 5.6008e-1 )
GRID 200005 04.004752-3.985-15.4955-1
has the coordinates: ( 4.004752, -3.985e-1, 5.4955e-1 ) */
ErrorCode ReadNASTRAN::get_real(const std::string token, double &real)
ErrorCode ReadNASTRAN::get_real(const std::string &token, double &real)
{
std::string significand = token;
std::string exponent = "0";
......@@ -343,7 +343,7 @@ ErrorCode ReadNASTRAN::get_real(const std::string token, double &real)
/* It has been determined that this line is a vertex. Read the rest of
the line and create the vertex. */
ErrorCode ReadNASTRAN::read_node(const std::vector<std::string> tokens,
ErrorCode ReadNASTRAN::read_node(const std::vector<std::string> &tokens,
const bool debug,
double* coords[3],
int& id)
......@@ -376,7 +376,7 @@ ErrorCode ReadNASTRAN::read_node(const std::vector<std::string> tokens,
/* The type of element has already been identified. Read the rest of the
line and create the element. Assume that all of the nodes have already
been created. */
ErrorCode ReadNASTRAN::read_element(const std::vector<std::string> tokens,
ErrorCode ReadNASTRAN::read_element(const std::vector<std::string> &tokens,
std::vector<Range> &materials,
const EntityType element_type,
const bool /*debug*/)
......
......@@ -84,23 +84,23 @@ private:
LARGE_FIELD,
FREE_FIELD };
ErrorCode determine_line_format( const std::string line,
ErrorCode determine_line_format( const std::string &line,
line_format &format );
ErrorCode tokenize_line( const std::string line,
ErrorCode tokenize_line( const std::string &line,
const line_format format,
std::vector<std::string> &tokens );
ErrorCode determine_entity_type( const std::string token, EntityType &type);
ErrorCode determine_entity_type( const std::string &token, EntityType &type);
ErrorCode get_real( const std::string, double &real );
ErrorCode get_real( const std::string&, double &real );
ErrorCode read_node(const std::vector<std::string> tokens,
ErrorCode read_node(const std::vector<std::string> &tokens,
const bool debug,
double* coord_arrays[3],
int &node_id);
ErrorCode read_element(const std::vector<std::string> tokens,
ErrorCode read_element(const std::vector<std::string> &tokens,
std::vector<Range> &materials,
const EntityType element_type,
const bool debug );
......
......@@ -188,7 +188,7 @@ public:
* \param new_box Reference to the newly created box of entities
* \param is_periodic[3] If is_periodic[s] is non-zero, mesh should be periodic in direction s (s=[0,1,2])
*/
ErrorCode create_scd_sequence(HomCoord low, HomCoord high, EntityType type,
ErrorCode create_scd_sequence(const HomCoord &low, const HomCoord &high, EntityType type,
int starting_id, ScdBox *&new_box,
int *is_periodic = NULL);
......@@ -304,7 +304,7 @@ private:
* \param scd_set Entity set created
* \param is_periodic[3] If is_periodic[s] is non-zero, mesh should be periodic in direction s (s=[0,1,2])
*/
ErrorCode create_box_set(const HomCoord low, const HomCoord high,
ErrorCode create_box_set(const HomCoord &low, const HomCoord &high,
EntityHandle &scd_set,
int *is_periodic = NULL);
......@@ -507,7 +507,7 @@ public:
/**
* \param ijk Parametric coordinates being evaluated
*/
EntityHandle get_element(HomCoord ijk) const;
EntityHandle get_element(const HomCoord &ijk) const;
//! Get the element at the specified coordinates
/**
......@@ -521,7 +521,7 @@ public:
/**
* \param ijk Parametric coordinates being evaluated
*/
EntityHandle get_vertex(HomCoord ijk) const;
EntityHandle get_vertex(const HomCoord &ijk) const;
//! Get the vertex at the specified coordinates
/**
......@@ -591,7 +591,7 @@ public:
* \param j Parametric coordinates being evaluated
* \param k Parametric coordinates being evaluated
*/
bool contains(const HomCoord ijk) const;
bool contains(const HomCoord &ijk) const;
//! Set/Get the entity set representing the box
void box_set(EntityHandle this_set);
......@@ -1331,7 +1331,7 @@ inline EntityHandle ScdBox::get_element(int i, int j, int k) const
startElem + (k-boxDims[2])*boxSizeIJM1 + (j-boxDims[1])*boxSizeIM1 + i-boxDims[0]);
}
inline EntityHandle ScdBox::get_element(HomCoord ijk) const
inline EntityHandle ScdBox::get_element(const HomCoord &ijk) const
{
return get_element(ijk[0], ijk[1], ijk[2]);
}
......@@ -1342,12 +1342,12 @@ inline EntityHandle ScdBox::get_vertex(int i, int j, int k) const
(boxDims[1] == -1 && boxDims[4] == -1 ? 0 : (j-boxDims[1]))*boxSize[0] + i-boxDims[0] : get_vertex_from_seq(i, j, k));
}
inline EntityHandle ScdBox::get_vertex(HomCoord ijk) const
inline EntityHandle ScdBox::get_vertex(const HomCoord &ijk) const
{
return get_vertex(ijk[0], ijk[1], ijk[2]);
}
inline bool ScdBox::contains(const HomCoord ijk) const
inline bool ScdBox::contains(const HomCoord &ijk) const
{
return (ijk >= HomCoord(boxDims, 3) &&
ijk <= HomCoord(boxDims+3, 3));
......
......@@ -80,7 +80,7 @@ public:
*/
virtual ErrorCode get_node_coords(const int which_array,
Range::const_iterator begin,
const Range::const_iterator end,
const Range::const_iterator& end,
const size_t output_size,
double* const output_array) = 0;
......@@ -134,7 +134,7 @@ public:
*\author Jason Kraftcheck
*/
virtual ErrorCode get_element_connect(Range::const_iterator begin,
const Range::const_iterator end,
const Range::const_iterator& end,
const int vertices_per_elem,
Tag node_id_tag,
const size_t array_size,
......@@ -167,7 +167,7 @@ public:
*\author Jason Kraftcheck
*/
virtual ErrorCode get_element_connect(Range::const_iterator begin,
const Range::const_iterator end,
const Range::const_iterator& end,
const int vertices_per_elem,
const size_t array_size,
EntityHandle *const element_array) = 0;
......@@ -175,12 +175,12 @@ public:
/** Get poly (polygon or polyhedron) connectivity size
*\param begin First iterator in range of poly
*\param end One past last in range of poly.
*\param connectivity_size The lenght of the connectivity list
*\param connectivity_size The length of the connectivity list
* For the specified range of polyhedra.
*\author Jason Kraftcheck
*/
virtual ErrorCode get_poly_connect_size(Range::const_iterator begin,
const Range::const_iterator end,
const Range::const_iterator& end,
int& connectivity_size) = 0;
/** Get poly (polygon or polyhedron) connectivity.
......@@ -224,7 +224,7 @@ public:
*\author Jason Kraftcheck
*/
virtual ErrorCode get_poly_connect(Range::const_iterator& iter,
const Range::const_iterator end,
const Range::const_iterator& end,
const Tag node_id_tag,
size_t& element_array_len,
int *const element_array,
......
......@@ -535,8 +535,8 @@ ErrorCode skin_hex_elems(Interface *MBI, Range elems, const int dim,
#endif //dead code isolation
// Given a 1D array of data, axis labels, title, and number of bins, create a
// histogram.
void plot_histogram(const std::string title, const std::string x_axis_label,
const std::string y_axis_label, const int n_bins, const double data[],
void plot_histogram(const std::string &title, const std::string &x_axis_label,
const std::string &y_axis_label, const int n_bins, const double data[],
const int n_data)
{
// find max and min
......@@ -609,7 +609,7 @@ void plot_histogram(const std::string title, const std::string x_axis_label,
// This is a helper function that creates data and labels for histograms.
void generate_plots(const double orig[], const double defo[], const int n_elems,
const std::string time_step)
const std::string &time_step)
{
// find volume ratio then max and min
......@@ -698,7 +698,7 @@ double measure(Interface *MBI, const EntityHandle element)
the signed volume will be ~0. If the signed volume is ~0 then offset everything
by a random amount and try again. */
ErrorCode get_signed_volume(Interface *MBI, const EntityHandle surf_set,
const CartVect offset, double &signed_volume)
const CartVect &offset, double &signed_volume)
{
ErrorCode rval;
Range tris;
......
......@@ -107,7 +107,7 @@ ErrorCode update_mcnp5_property_names( Interface* MBI )
*/
static ErrorCode get_signed_volume( Interface *MBI,
const EntityHandle surf_set,
const CartVect offset,
const CartVect &offset,
double &signed_volume)
{
ErrorCode rval;
......
......@@ -64,19 +64,19 @@ struct CartVect3D {
{ return sqrt( x*x + y*y + z*z ); }
};
//static CartVect3D operator-( const CartVect3D a )
//static CartVect3D operator-( const CartVect3D &a )
// { return CartVect3D(-a.z, -a.y, -a.z); }
//static CartVect3D operator+( const CartVect3D a, const CartVect3D b )
//static CartVect3D operator+( const CartVect3D &a, const CartVect3D &b )
// { return CartVect3D(a.x+b.x, a.y+b.y, a.z+b.z); }
static CartVect3D operator-( const CartVect3D a, const CartVect3D b )
static CartVect3D operator-( const CartVect3D &a, const CartVect3D &b )
{ return CartVect3D(a.x-b.x, a.y-b.y, a.z-b.z); }
static double operator%( const CartVect3D a, const CartVect3D b )
static double operator%( const CartVect3D &a, const CartVect3D &b )
{ return a.x*b.x + a.y*b.y + a.z*b.z; }
static CartVect3D operator*( const CartVect3D a, const CartVect3D b )
static CartVect3D operator*( const CartVect3D &a, const CartVect3D &b )
{
CartVect3D result;
result.x = a.y * b.z - a.z * b.y;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment