blob: bc04c33beb5d1cba009a166a0af3bbe4d72d2e42 [file] [log] [blame]
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -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#ifndef SYNC_NAME_INFO_H
24#define SYNC_NAME_INFO_H
25
Alexander Afanasyevb5547e32012-03-01 21:59:38 -080026#include <boost/shared_ptr.hpp>
27#include <map>
28#include <string>
Alexander Afanasyev017784c2012-03-02 11:44:13 -080029#include "sync-digest.h"
Alexander Afanasyevb5547e32012-03-01 21:59:38 -080030
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080031namespace Sync {
32
33/**
Alexander Afanasyevb5547e32012-03-01 21:59:38 -080034 * @ingroup sync
35 * @brief Templated class for the leaf name
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080036 */
37class NameInfo
38{
Alexander Afanasyevb5547e32012-03-01 21:59:38 -080039private:
40 typedef boost::shared_ptr<const NameInfo> const_ptr;
41
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080042public:
Alexander Afanasyevb5547e32012-03-01 21:59:38 -080043 virtual ~NameInfo () { };
44
45 /**
46 * @brief Get ID of the record (should be locally-unique, but not really necessary---this is be used for hashing purposes)
47 */
48 size_t
49 getHashId () const { return m_id; }
50
51 virtual bool
52 operator == (const NameInfo &info) const = 0;
53
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080054 /**
55 * @brief Calculates digest of the name
56 */
Alexander Afanasyevcf9d65b2012-03-02 11:34:22 -080057 const Digest &
58 getDigest () const { return m_digest; }
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080059
Alexander Afanasyevb5547e32012-03-01 21:59:38 -080060 /**
61 * @brief Convert prefix to string
62 * @returns string representation of prefix
63 */
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080064 virtual std::string
65 toString () const = 0;
Alexander Afanasyevb5547e32012-03-01 21:59:38 -080066
67protected:
68 // actual stuff
69 size_t m_id; ///< @brief Identifies NameInfo throughout the library (for hash container, doesn't need to be strictly unique)
Alexander Afanasyevcf9d65b2012-03-02 11:34:22 -080070 Digest m_digest;
Alexander Afanasyevb5547e32012-03-01 21:59:38 -080071
72 // static stuff
73 typedef std::map<std::string, const_ptr> NameMap;
74 static size_t m_ids;
75 static NameMap m_names;
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080076};
77
78typedef boost::shared_ptr<NameInfo> NameInfoPtr;
79typedef boost::shared_ptr<const NameInfo> NameInfoConstPtr;
80
Alexander Afanasyevb5547e32012-03-01 21:59:38 -080081
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080082} // Sync
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080083
84#endif // SYNC_NAME_INFO_H