You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
2.2 KiB

// ==================================================
// Copyright 2013.
// Siemens Product Lifecycle Management Software Inc.
// All Rights Reserved.
// ==================================================
/**
@file
This file contains useful utility functions.
*/
#ifndef TEAMCENTER_BASE_UTILS_TC_BASE_UTILS_HXX
#define TEAMCENTER_BASE_UTILS_TC_BASE_UTILS_HXX
#include <algorithm>
#include <iterator>
#include <base_utils/libbase_utils_exports.h>
namespace Teamcenter
{
namespace Util
{
/**
Copies all elements in the @c Container into the back of the @c Vector.
<br/>The container can be any of Standard Template Library (STL)-derived container that stores a collection of other objects
and provides access either directly or through iterators.
@code
//tags1, tags2, tags3 are TagVector
TagVector allTags;
Util::copyBack( tags1, allTags );
Util::copyBack( tags2, allTags );
Util::copyBack( tags3, allTags );
//allTags now contains tags1 + tags2 + tags3
@endcode
*/
template< typename Container, typename Vector >
void copyBack(
const Container& container, /**< (I) The container to copy from */
Vector& vector /**< (O) The vector to copy to */
)
{
vector.reserve( vector.size() + container.size() );
std::copy( container.begin(), container.end(), std::back_inserter( vector ) );
}
/**
Converts from one type to another using a static_cast call.
<br/>This template function is of special interest to correct conversion issues from "unsigned_int64" to "int",
which arise with Visual Studio 2013 (error C4244 - "'=' : conversion from 'unsigned __int64' to 'int'").
<br/>The following code would generate a compilation error C4244 with Visual Studio 2013, because std::vector - size() returns the size of an array using the "unsigned __int64" type.
@code
//Compilation error:
//*n_values = pvmValues.size();
*n_values = Util::array_length<int>( pvmValues.size() );
@endcode
*/
template< typename T >
T array_length( size_t s )
{
return static_cast<T>(s);
}
}
}
#include <base_utils/libbase_utils_undef.h>
#endif