// ================================================== // 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 #include #include namespace Teamcenter { namespace Util { /** Copies all elements in the @c Container into the back of the @c Vector.
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.
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'").
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( pvmValues.size() ); @endcode */ template< typename T > T array_length( size_t s ) { return static_cast(s); } } } #include #endif