/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
/*
 * Copyright (c) 2012 University of California, Los Angeles
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation;
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
 *         Chaoyi Bian <bcy@pku.edu.cn>
 *	   Alexander Afanasyev <alexander.afanasyev@ucla.edu>
 */

#include "sync-std-name-info.h"
#include "boost/thread/locks.hpp"

using namespace std;
using namespace boost;

namespace Sync {


NameInfoConstPtr
StdNameInfo::FindOrCreate (const std::string &key)
{
  mutex::scoped_lock namesLock (m_namesMutex);
  
  // std::cout << "FindOrCreate: " << m_names.size () << "\n";
  
  NameInfoConstPtr ret;
  
  NameMap::iterator item = m_names.find (key);
  if (item != m_names.end ())
    {
      ret = item->second.lock ();
      BOOST_ASSERT (ret != 0);
    }
  else
    {
      ret = NameInfoPtr (new StdNameInfo (key));
      weak_ptr<const NameInfo> value (ret);
      pair<NameMap::iterator,bool> inserted =
        m_names.insert (make_pair (key, value));
      
      BOOST_ASSERT (inserted.second); // previous call has to insert value
      item = inserted.first;
    }

  return ret;
}

StdNameInfo::StdNameInfo (const std::string &name)
  : m_name (name)
{
  m_id = m_ids ++; // set ID for a newly inserted element
  m_digest << name;
  m_digest.finalize ();

  // std::cout << "StdNameInfo: " << name << " = " << m_id << "\n";
}

StdNameInfo::~StdNameInfo ()
{
  mutex::scoped_lock namesLock (m_namesMutex);

  // cout << "Destructor for " << m_name << "\n";
  m_names.erase (toString ());
}

string
StdNameInfo::toString () const
{
  return m_name;
}

bool
StdNameInfo::operator == (const NameInfo &info) const
{
  return m_name == dynamic_cast<const StdNameInfo&> (info).m_name;
}

bool
StdNameInfo::operator < (const NameInfo &info) const
{
  return m_name < dynamic_cast<const StdNameInfo&> (info).m_name;
}

} // Sync
