/***********************************************************************************************************************
 *
 *  stringID.h
 *  Anki::Util
 *
 *  Created by Jarrod Hatfield on 4/10/14.
 *  Copyright (c) 2014 Anki. All rights reserved.
 *
 ***********************************************************************************************************************/

#include "util/stringTable/stringID.h"


namespace Anki{ namespace Util
{

StringID STRID_None;

//----------------------------------------------------------------------------------------------------------------------
StringTable& StringID::GetStringTable()
{
  static StringTable stringTable_;
  return stringTable_;
}

//----------------------------------------------------------------------------------------------------------------------
StringID::StringID() :
  id_( StringTable::STRID_INDEX_NONE )
{
  
}

//----------------------------------------------------------------------------------------------------------------------
StringID::StringID( const StringID& other ) :
  id_( other.id_ )
{
  
}
  
//----------------------------------------------------------------------------------------------------------------------
StringID::StringID( const std::string& name )
{
  Set( name );
}

//----------------------------------------------------------------------------------------------------------------------
StringID::~StringID()
{
  
}

//----------------------------------------------------------------------------------------------------------------------
void StringID::Set( const std::string& name )
{
  id_ = GetStringTable().AddStringID( name );
}

//----------------------------------------------------------------------------------------------------------------------
const std::string& StringID::ToString() const
{
  return GetStringTable().GetString( id_ );
}

//----------------------------------------------------------------------------------------------------------------------
const char* StringID::c_str() const
{
  return ToString().c_str();
}


} // namespace Anki
} //namespace Util


//======================================================================================================================
// C Interface

using namespace Anki::Util;

//----------------------------------------------------------------------------------------------------------------------
unsigned int StringID_Create( const char* name )
{
  return StringID( name ).GetID();
}

//----------------------------------------------------------------------------------------------------------------------
const char* StringID_ToString( unsigned int id )
{
  return StringID::GetStringTable().GetString( id ).c_str();
}