// @<COPYRIGHT_START>@
// ===============================================
// Copyright 2006 UGS Corp. All Rights Reserved.
// ===============================================
// @<COPYRIGHT_END>@

/**
    @file

    This file defines common types and typedefs that use smart pointer.
    <BR> These resources are owned by either a class or by a smart pointer, which makes them easier for cleanup.
*/

#ifndef TEAMCENTER_BASE_UTILS_BASE_TYPES_HXX
#define TEAMCENTER_BASE_UTILS_BASE_TYPES_HXX

#include <string>
#include <vector>
#include <map>
#include <set>
#include <sstream>
#include <unidefs.h>

#include <base_utils/SmAllocator.hxx>

#include <base_utils/libbase_utils_exports.h>

namespace Teamcenter
{

/**
    Helper class to typedef std::vector with an sm_allocator.

    There are two different memory allocation schemes used Teamcenter server for dynamic memory allocation.
    <ul>
    <li>use of the standard memory allocator
    <li>SM, the NX Storage Management module, which offers tracking and profiling capabilities in addition to the releasing of memory back to the Operating System after use.
    </ul>

    @code
    StdSmVector< const char* >::Vector names;
    names.reserve( 1 );
    names.push_back( "name" );
    @endcode
*/
template< typename Value >
struct StdSmVector
{
    typedef std::vector< Value, sm_allocator< Value > > Vector;
};

/**
    Helper class to typedef std::map with an sm_allocator.

    Example.
    @code
    StdSmMap< tag_t, TagList >::Map aMap;
    StdSmMap< tag_t, TagList >::Map::iterator iter = aMap.find( aTag );
    if ( aMap.end() != iter )
    {
        aMap[ tag_t ] = aTagList;
    }
    @endcode
*/
template< typename Key, typename Value, typename Predicate=std::less< Key > >
struct StdSmMap
{
    /*  */
    typedef std::map< Key, Value, Predicate, std::allocator< std::pair< const Key, Value > > > Map;
};

/**
    Helper class to typedef std::set with an #sm_allocator.

    Example.
    @code
    StdSmSet<std::string>::Set aSet;
    StdSmSet<std::string>::Set::iterator iter = aSet.begin();
    for( ; iter != aSet.end(); ++iter )
    {
        printf( "%s", iter->c_str() );
    }
    @endcode
*/
template< typename Key, typename Predicate=std::less< Key > >
struct StdSmSet
{
    /*  */
    typedef std::set< Key, Predicate, std::allocator< Key > > Set;
};

/**
    Define typedefs of std::vector with an #sm_allocator for basic types
*/
typedef StdSmVector< bool >::Vector BoolVector;
typedef StdSmVector< char >::Vector CharVector;
typedef StdSmVector< date_t >::Vector DateVector;
typedef StdSmVector< double >::Vector DoubleVector;
typedef StdSmVector< int >::Vector IntVector;
typedef StdSmVector< tag_t >::Vector TagVector;
typedef StdSmVector< const char* >::Vector CharPtrVector;

/**
    String class, using std::string for interface, and #sm_allocator for memory.
*/
typedef std::basic_string< char, std::char_traits< char >, sm_allocator< char > > StdSmString;
typedef StdSmVector<StdSmString>::Vector StdSmStringVector;
typedef StdSmStringVector StringVector;

/**
    Stream buffer using #StdSmString.
*/
typedef std::basic_stringstream< char, std::char_traits< char >, sm_allocator< char > > StdSmStringStream;

}

#include <base_utils/libbase_utils_undef.h>
#endif
