Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
Alexander Afanasyev | 8722d87 | 2014-07-02 13:00:29 -0700 | [diff] [blame^] | 3 | * Copyright (c) 2012-2014 University of California, Los Angeles |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 4 | * |
Alexander Afanasyev | 8722d87 | 2014-07-02 13:00:29 -0700 | [diff] [blame^] | 5 | * This file is part of ChronoSync, synchronization library for distributed realtime |
| 6 | * applications for NDN. |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 7 | * |
Alexander Afanasyev | 8722d87 | 2014-07-02 13:00:29 -0700 | [diff] [blame^] | 8 | * ChronoSync is free software: you can redistribute it and/or modify it under the terms |
| 9 | * of the GNU General Public License as published by the Free Software Foundation, either |
| 10 | * version 3 of the License, or (at your option) any later version. |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 11 | * |
Alexander Afanasyev | 8722d87 | 2014-07-02 13:00:29 -0700 | [diff] [blame^] | 12 | * ChronoSync is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 13 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 | * PURPOSE. See the GNU General Public License for more details. |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 15 | * |
Alexander Afanasyev | 8722d87 | 2014-07-02 13:00:29 -0700 | [diff] [blame^] | 16 | * You should have received a copy of the GNU General Public License along with |
| 17 | * ChronoSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * @author Zhenkai Zhu <http://irl.cs.ucla.edu/~zhenkai/> |
| 20 | * @author Chaoyi Bian <bcy@pku.edu.cn> |
| 21 | * @author Alexander Afanasyev <http://lasr.cs.ucla.edu/afanasyev/index.html> |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 22 | */ |
| 23 | |
| 24 | #ifndef SYNC_NAME_INFO_H |
| 25 | #define SYNC_NAME_INFO_H |
| 26 | |
Alexander Afanasyev | b5547e3 | 2012-03-01 21:59:38 -0800 | [diff] [blame] | 27 | #include <boost/shared_ptr.hpp> |
Alexander Afanasyev | a4ce9cf | 2012-03-06 14:29:58 -0800 | [diff] [blame] | 28 | #include <boost/weak_ptr.hpp> |
Alexander Afanasyev | b5547e3 | 2012-03-01 21:59:38 -0800 | [diff] [blame] | 29 | #include <map> |
| 30 | #include <string> |
Alexander Afanasyev | 017784c | 2012-03-02 11:44:13 -0800 | [diff] [blame] | 31 | #include "sync-digest.h" |
Alexander Afanasyev | b5547e3 | 2012-03-01 21:59:38 -0800 | [diff] [blame] | 32 | |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 33 | namespace Sync { |
| 34 | |
| 35 | /** |
Alexander Afanasyev | b5547e3 | 2012-03-01 21:59:38 -0800 | [diff] [blame] | 36 | * @ingroup sync |
| 37 | * @brief Templated class for the leaf name |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 38 | */ |
| 39 | class NameInfo |
| 40 | { |
Alexander Afanasyev | b5547e3 | 2012-03-01 21:59:38 -0800 | [diff] [blame] | 41 | private: |
Alexander Afanasyev | a4ce9cf | 2012-03-06 14:29:58 -0800 | [diff] [blame] | 42 | typedef boost::weak_ptr<const NameInfo> const_weak_ptr; |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame] | 43 | |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 44 | public: |
Alexander Afanasyev | b5547e3 | 2012-03-01 21:59:38 -0800 | [diff] [blame] | 45 | virtual ~NameInfo () { }; |
| 46 | |
| 47 | /** |
| 48 | * @brief Get ID of the record (should be locally-unique, but not really necessary---this is be used for hashing purposes) |
| 49 | */ |
| 50 | size_t |
| 51 | getHashId () const { return m_id; } |
Alexander Afanasyev | a562532 | 2012-03-06 00:03:41 -0800 | [diff] [blame] | 52 | |
| 53 | /** |
| 54 | * @brief Check if two names are equal |
| 55 | * @param info name to check with |
| 56 | */ |
Alexander Afanasyev | b5547e3 | 2012-03-01 21:59:38 -0800 | [diff] [blame] | 57 | virtual bool |
| 58 | operator == (const NameInfo &info) const = 0; |
| 59 | |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 60 | /** |
Alexander Afanasyev | a562532 | 2012-03-06 00:03:41 -0800 | [diff] [blame] | 61 | * @brief Check if two names are in order |
| 62 | * @param info name to check with |
| 63 | */ |
| 64 | virtual bool |
| 65 | operator < (const NameInfo &info) const = 0; |
| 66 | |
| 67 | /** |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 68 | * @brief Calculates digest of the name |
| 69 | */ |
Alexander Afanasyev | cf9d65b | 2012-03-02 11:34:22 -0800 | [diff] [blame] | 70 | const Digest & |
| 71 | getDigest () const { return m_digest; } |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 72 | |
Alexander Afanasyev | b5547e3 | 2012-03-01 21:59:38 -0800 | [diff] [blame] | 73 | /** |
| 74 | * @brief Convert prefix to string |
| 75 | * @returns string representation of prefix |
| 76 | */ |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 77 | virtual std::string |
| 78 | toString () const = 0; |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame] | 79 | |
Alexander Afanasyev | b5547e3 | 2012-03-01 21:59:38 -0800 | [diff] [blame] | 80 | protected: |
| 81 | // actual stuff |
| 82 | 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] | 83 | Digest m_digest; |
Alexander Afanasyev | b5547e3 | 2012-03-01 21:59:38 -0800 | [diff] [blame] | 84 | |
| 85 | // static stuff |
Alexander Afanasyev | a4ce9cf | 2012-03-06 14:29:58 -0800 | [diff] [blame] | 86 | typedef std::map<std::string, const_weak_ptr> NameMap; |
Alexander Afanasyev | b5547e3 | 2012-03-01 21:59:38 -0800 | [diff] [blame] | 87 | static size_t m_ids; |
| 88 | static NameMap m_names; |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 89 | }; |
| 90 | |
| 91 | typedef boost::shared_ptr<NameInfo> NameInfoPtr; |
| 92 | typedef boost::shared_ptr<const NameInfo> NameInfoConstPtr; |
| 93 | |
Alexander Afanasyev | a4ce9cf | 2012-03-06 14:29:58 -0800 | [diff] [blame] | 94 | inline std::ostream & |
| 95 | operator << (std::ostream &os, const NameInfo &info) |
| 96 | { |
| 97 | os << info.toString (); |
| 98 | return os; |
| 99 | } |
Alexander Afanasyev | b5547e3 | 2012-03-01 21:59:38 -0800 | [diff] [blame] | 100 | |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 101 | } // Sync |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 102 | |
| 103 | #endif // SYNC_NAME_INFO_H |