Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 1 | /* -*- 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 Afanasyev | b5547e3 | 2012-03-01 21:59:38 -0800 | [diff] [blame] | 26 | #include <boost/shared_ptr.hpp> |
| 27 | #include <map> |
| 28 | #include <string> |
Alexander Afanasyev | 017784c | 2012-03-02 11:44:13 -0800 | [diff] [blame] | 29 | #include "sync-digest.h" |
Alexander Afanasyev | b5547e3 | 2012-03-01 21:59:38 -0800 | [diff] [blame] | 30 | |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 31 | namespace Sync { |
| 32 | |
| 33 | /** |
Alexander Afanasyev | b5547e3 | 2012-03-01 21:59:38 -0800 | [diff] [blame] | 34 | * @ingroup sync |
| 35 | * @brief Templated class for the leaf name |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 36 | */ |
| 37 | class NameInfo |
| 38 | { |
Alexander Afanasyev | b5547e3 | 2012-03-01 21:59:38 -0800 | [diff] [blame] | 39 | private: |
| 40 | typedef boost::shared_ptr<const NameInfo> const_ptr; |
| 41 | |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 42 | public: |
Alexander Afanasyev | b5547e3 | 2012-03-01 21:59:38 -0800 | [diff] [blame] | 43 | 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; } |
Alexander Afanasyev | a562532 | 2012-03-06 00:03:41 -0800 | [diff] [blame] | 50 | |
| 51 | /** |
| 52 | * @brief Check if two names are equal |
| 53 | * @param info name to check with |
| 54 | */ |
Alexander Afanasyev | b5547e3 | 2012-03-01 21:59:38 -0800 | [diff] [blame] | 55 | virtual bool |
| 56 | operator == (const NameInfo &info) const = 0; |
| 57 | |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 58 | /** |
Alexander Afanasyev | a562532 | 2012-03-06 00:03:41 -0800 | [diff] [blame] | 59 | * @brief Check if two names are in order |
| 60 | * @param info name to check with |
| 61 | */ |
| 62 | virtual bool |
| 63 | operator < (const NameInfo &info) const = 0; |
| 64 | |
| 65 | /** |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 66 | * @brief Calculates digest of the name |
| 67 | */ |
Alexander Afanasyev | cf9d65b | 2012-03-02 11:34:22 -0800 | [diff] [blame] | 68 | const Digest & |
| 69 | getDigest () const { return m_digest; } |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 70 | |
Alexander Afanasyev | b5547e3 | 2012-03-01 21:59:38 -0800 | [diff] [blame] | 71 | /** |
| 72 | * @brief Convert prefix to string |
| 73 | * @returns string representation of prefix |
| 74 | */ |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 75 | virtual std::string |
| 76 | toString () const = 0; |
Alexander Afanasyev | b5547e3 | 2012-03-01 21:59:38 -0800 | [diff] [blame] | 77 | |
| 78 | protected: |
| 79 | // actual stuff |
| 80 | size_t m_id; ///< @brief Identifies NameInfo throughout the library (for hash container, doesn't need to be strictly unique) |
Alexander Afanasyev | cf9d65b | 2012-03-02 11:34:22 -0800 | [diff] [blame] | 81 | Digest m_digest; |
Alexander Afanasyev | b5547e3 | 2012-03-01 21:59:38 -0800 | [diff] [blame] | 82 | |
| 83 | // static stuff |
| 84 | typedef std::map<std::string, const_ptr> NameMap; |
| 85 | static size_t m_ids; |
| 86 | static NameMap m_names; |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 87 | }; |
| 88 | |
| 89 | typedef boost::shared_ptr<NameInfo> NameInfoPtr; |
| 90 | typedef boost::shared_ptr<const NameInfo> NameInfoConstPtr; |
| 91 | |
Alexander Afanasyev | b5547e3 | 2012-03-01 21:59:38 -0800 | [diff] [blame] | 92 | |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 93 | } // Sync |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 94 | |
| 95 | #endif // SYNC_NAME_INFO_H |