blob: 5b57fbe4ec00d45ba476e17c8441848e22cc77d0 [file] [log] [blame]
Alexander Afanasyev2fc2d672012-03-05 16:57:39 -08001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
2/*
3 * Copyright (c) 2012 University of California, Los Angeles
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
19 * 卞超轶 Chaoyi Bian <bcy@pku.edu.cn>
20 * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
21 */
22
23#include "sync-std-name-info.h"
24
25using namespace std;
26
27namespace Sync {
28
29
30NameInfoConstPtr
31StdNameInfo::FindOrCreate (const std::string &key)
32{
33 NameInfoPtr value = NameInfoPtr (new StdNameInfo (key));
34 pair<NameMap::iterator,bool> item =
35 m_names.insert (make_pair (key, value));
36
37 return item.first->second;
38}
39
40StdNameInfo::StdNameInfo (const std::string &name)
41 : m_name (name)
42{
43 m_id = m_ids ++; // set ID for a newly inserted element
44 m_digest << name;
45 m_digest.getHash (); // finalize digest
46}
47
48string
49StdNameInfo::toString () const
50{
51 return m_name;
52}
53
54bool
55StdNameInfo::operator == (const NameInfo &info) const
56{
57 try
58 {
59 return m_name == dynamic_cast<const StdNameInfo&> (info).m_name;
60 }
61 catch (...)
62 {
63 return false;
64 }
65}
66
67} // Sync
68