MOAB: Mesh Oriented datABase  (version 5.2.1)
MBMesquite::StopWatchCollection Class Reference

#include <MsqTimer.hpp>

Public Types

typedef size_t Key

Public Member Functions

MESQUITE_EXPORT StopWatchCollection ()
MESQUITE_EXPORT Key add (const std::string &name, bool fail_if_exists=true)
MESQUITE_EXPORT Key get_key (const std::string &name) const
MESQUITE_EXPORT std::string get_string (const Key key)
 Gets the string associated with a key.
MESQUITE_EXPORT void get_string (const Key key, std::string &new_string)
 Gets the string associated with a key.
MESQUITE_EXPORT void remove (const Key key)
MESQUITE_EXPORT void remove (const std::string &name)
MESQUITE_EXPORT void start (const Key key)
MESQUITE_EXPORT void start (const std::string &name)
MESQUITE_EXPORT void stop (const Key key)
MESQUITE_EXPORT void stop (const std::string &name)
MESQUITE_EXPORT void reset (const Key key)
MESQUITE_EXPORT void reset (const std::string &name)
MESQUITE_EXPORT double total_time (const Key key) const
MESQUITE_EXPORT double total_time (const std::string &name) const
MESQUITE_EXPORT int number_of_starts (const Key key) const
MESQUITE_EXPORT int number_of_starts (const std::string &name) const
MESQUITE_EXPORT int number_of_stop_watches ()
MESQUITE_EXPORT void get_keys_sorted_by_time (std::vector< Key > &sorted_keys)

Private Attributes

std::vector< std::pair
< std::string, StopWatch > > 
mEntries

Detailed Description

Definition at line 102 of file MsqTimer.hpp.


Member Typedef Documentation

Definition at line 105 of file MsqTimer.hpp.


Constructor & Destructor Documentation


Member Function Documentation

MBMesquite::StopWatchCollection::Key MBMesquite::StopWatchCollection::add ( const std::string &  name,
bool  fail_if_exists = true 
)

Definition at line 127 of file MsqTimer.cpp.

References moab::GeomUtil::first().

{
    // Don't allow empty name
    if( name == "" ) return 0;

    Key key = get_key( name );

    // If the named stopwatch doesn't exist...
    if( !key )
    {
        // See if there is an unused existing stopwatch
        size_t i;
        for( i = 0; i < mEntries.size(); i++ )
        {
            if( mEntries[i].first == "" )
            {
                mEntries[i].first = name;
                mEntries[i].second.reset();
                break;
            }
        }
        // If not, create a new one
        if( i == mEntries.size() ) { mEntries.push_back( std::pair< std::string, StopWatch >( name, StopWatch() ) ); }
        key = i + 1;
    }
    // If it already existed...
    else if( fail_if_exists )
        key = 0;

    return key;
}

Definition at line 160 of file MsqTimer.cpp.

References moab::GeomUtil::first().

Referenced by number_of_starts(), remove(), reset(), start(), stop(), and total_time().

{
    Key key = 0;

    for( size_t i = 0; i < mEntries.size(); i++ )
    {
        if( mEntries[i].first == name )
        {
            key = i + 1;
            break;
        }
    }

    return key;
}
void MBMesquite::StopWatchCollection::get_keys_sorted_by_time ( std::vector< Key > &  sorted_keys)

Fills a vector of StopWatchCollection::Key in which the Keys are ordered by the associated StopWatch's total_time. The key associated with the largest total_time StopWatch is in the first position of the vector. The key associated with the smallest total_time StopWatch is in the last position of the vector.

Definition at line 230 of file MsqTimer.cpp.

Referenced by MBMesquite::operator<<().

{
    int num_watches     = mEntries.size();
    int* sorted_indices = new int[num_watches];
    int i               = 0;
    int counter         = 0;
    for( i = 0; i < num_watches; ++i )
    {
        sorted_indices[i] = 0;
    }
    double current_max;
    int index_to_max;
    // While we haven't added all of the Keys to the vector
    while( counter < num_watches )
    {
        current_max  = -1;
        index_to_max = -1;
        // loop over the times and find the largest remaining
        for( i = 0; i < num_watches; ++i )
        {
            if( mEntries[i].second.total_time() > current_max && sorted_indices[i] == 0 )
            {
                current_max  = mEntries[i].second.total_time();
                index_to_max = i;
            }
        }
        // Add the key associated with index_to_max and any subsequent
        // keys which are associated with a StopWatch that has a total
        // time equal to current_max;
        for( i = index_to_max; i < num_watches; ++i )
        {
            if( mEntries[i].second.total_time() >= current_max && sorted_indices[i] == 0 )
            {
                counter++;
                sorted_indices[i] = counter;
                sorted_keys.push_back( i + 1 );
            }
        }
    }
    // clean up
    delete[] sorted_indices;
}

Gets the string associated with a key.

Definition at line 123 of file MsqTimer.hpp.

References mEntries.

Referenced by MBMesquite::operator<<().

    {
        return mEntries[key - 1].first;
    }
MESQUITE_EXPORT void MBMesquite::StopWatchCollection::get_string ( const Key  key,
std::string &  new_string 
) [inline]

Gets the string associated with a key.

Definition at line 128 of file MsqTimer.hpp.

References mEntries.

    {
        new_string = mEntries[key - 1].first;
    }

Definition at line 218 of file MsqTimer.cpp.

Referenced by number_of_starts(), and MBMesquite::operator<<().

{
    if( key > 0 && key <= mEntries.size() && mEntries[key - 1].first != "" )
        return mEntries[key - 1].second.number_of_starts();
    else
        return 0;
}
MESQUITE_EXPORT int MBMesquite::StopWatchCollection::number_of_starts ( const std::string &  name) const [inline]

Definition at line 170 of file MsqTimer.hpp.

References get_key(), and number_of_starts().

    {
        return number_of_starts( get_key( name ) );
    }

Definition at line 176 of file MsqTimer.hpp.

References mEntries.

    {
        return (int)mEntries.size();
    }

Definition at line 176 of file MsqTimer.cpp.

{
    // Get rid of anything at the end of the list
    if( key == mEntries.size() )
    {
        mEntries.pop_back();
        while( !mEntries.empty() && mEntries.back().first == "" )
        {
            mEntries.pop_back();
        }
    }

    else if( key > 0 && key < mEntries.size() )
    {
        // If in the middle of the list, set its name to ""
        mEntries[key - 1].first = "";
    }
}
MESQUITE_EXPORT void MBMesquite::StopWatchCollection::remove ( const std::string &  name) [inline]

Definition at line 135 of file MsqTimer.hpp.

References get_key().

    {
        remove( get_key( name ) );
    }

Definition at line 205 of file MsqTimer.cpp.

Referenced by reset().

{
    if( key > 0 && key <= mEntries.size() ) mEntries[key - 1].second.reset();
}
MESQUITE_EXPORT void MBMesquite::StopWatchCollection::reset ( const std::string &  name) [inline]

Definition at line 156 of file MsqTimer.hpp.

References get_key(), and reset().

    {
        reset( get_key( name ) );
    }

Definition at line 195 of file MsqTimer.cpp.

Referenced by start(), and MBMesquite::FunctionTimer::start().

{
    if( key > 0 && key <= mEntries.size() && mEntries[key - 1].first != "" ) mEntries[key - 1].second.start();
}
MESQUITE_EXPORT void MBMesquite::StopWatchCollection::start ( const std::string &  name) [inline]

Definition at line 142 of file MsqTimer.hpp.

References get_key(), and start().

    {
        start( get_key( name ) );
    }

Definition at line 200 of file MsqTimer.cpp.

Referenced by stop(), and MBMesquite::FunctionTimer::~FunctionTimer().

{
    if( key > 0 && key <= mEntries.size() && mEntries[key - 1].first != "" ) mEntries[key - 1].second.stop();
}
MESQUITE_EXPORT void MBMesquite::StopWatchCollection::stop ( const std::string &  name) [inline]

Definition at line 149 of file MsqTimer.hpp.

References get_key(), and stop().

    {
        stop( get_key( name ) );
    }
double MBMesquite::StopWatchCollection::total_time ( const Key  key) const

Definition at line 210 of file MsqTimer.cpp.

Referenced by MBMesquite::operator<<(), and total_time().

{
    if( key > 0 && key <= mEntries.size() && mEntries[key - 1].first != "" )
        return mEntries[key - 1].second.total_time();
    else
        return 0.0;
}
MESQUITE_EXPORT double MBMesquite::StopWatchCollection::total_time ( const std::string &  name) const [inline]

Definition at line 164 of file MsqTimer.hpp.

References get_key(), and total_time().

    {
        return total_time( get_key( name ) );
    }

Member Data Documentation

std::vector< std::pair< std::string, StopWatch > > MBMesquite::StopWatchCollection::mEntries [private]

Definition at line 184 of file MsqTimer.hpp.

Referenced by get_string(), and number_of_stop_watches().

List of all members.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines