Zhenkai Zhu | f47109b | 2013-01-02 19:41:34 -0800 | [diff] [blame] | 1 | #ifndef CCNX_NAME_H |
| 2 | #define CCNX_NAME_H |
| 3 | #include <boost/shared_ptr.hpp> |
| 4 | #include "ccnx-common.h" |
| 5 | |
| 6 | namespace Ccnx { |
| 7 | |
Zhenkai Zhu | cb2d0dd | 2013-01-03 14:10:48 -0800 | [diff] [blame] | 8 | class CcnxCharbuf; |
| 9 | typedef boost::shared_ptr<CcnxCharbuf> CcnxCharbufPtr; |
| 10 | |
Zhenkai Zhu | f47109b | 2013-01-02 19:41:34 -0800 | [diff] [blame] | 11 | // This class is mostly used in CcnxWrapper; users should not be directly using this class |
| 12 | // The main purpose of this class to is avoid manually create and destroy charbuf everytime |
| 13 | class CcnxCharbuf |
| 14 | { |
| 15 | public: |
| 16 | CcnxCharbuf(); |
| 17 | CcnxCharbuf(ccn_charbuf *buf); |
Zhenkai Zhu | b0adefe | 2013-01-04 21:56:38 -0800 | [diff] [blame^] | 18 | CcnxCharbuf(const CcnxCharbuf &other); |
Zhenkai Zhu | f47109b | 2013-01-02 19:41:34 -0800 | [diff] [blame] | 19 | ~CcnxCharbuf(); |
| 20 | |
| 21 | // expose internal data structure, use with caution!! |
| 22 | ccn_charbuf * |
| 23 | getBuf() { return m_buf; } |
Zhenkai Zhu | cb2d0dd | 2013-01-03 14:10:48 -0800 | [diff] [blame] | 24 | static CcnxCharbufPtr Null; |
Zhenkai Zhu | f47109b | 2013-01-02 19:41:34 -0800 | [diff] [blame] | 25 | |
Zhenkai Zhu | b0adefe | 2013-01-04 21:56:38 -0800 | [diff] [blame^] | 26 | private: |
| 27 | void init(ccn_charbuf *buf); |
| 28 | |
Zhenkai Zhu | f47109b | 2013-01-02 19:41:34 -0800 | [diff] [blame] | 29 | protected: |
| 30 | ccn_charbuf *m_buf; |
| 31 | }; |
| 32 | |
Zhenkai Zhu | f47109b | 2013-01-02 19:41:34 -0800 | [diff] [blame] | 33 | |
| 34 | struct NameException: |
| 35 | virtual boost::exception, virtual exception {}; |
Zhenkai Zhu | cb2d0dd | 2013-01-03 14:10:48 -0800 | [diff] [blame] | 36 | |
Zhenkai Zhu | f47109b | 2013-01-02 19:41:34 -0800 | [diff] [blame] | 37 | class Name |
| 38 | { |
| 39 | public: |
| 40 | Name(); |
| 41 | Name(const string &name); |
| 42 | Name(const vector<Bytes> &comps); |
| 43 | Name(const Name &other); |
| 44 | Name(const unsigned char *data, const ccn_indexbuf *comps); |
| 45 | virtual ~Name() {} |
| 46 | |
| 47 | CcnxCharbufPtr |
| 48 | toCcnxCharbuf() const; |
| 49 | |
| 50 | Name & |
| 51 | appendComp(const Bytes &comp); |
| 52 | |
| 53 | Name & |
| 54 | appendComp(const string &compStr); |
| 55 | |
| 56 | int |
| 57 | size() const {return m_comps.size();} |
| 58 | |
| 59 | Bytes |
| 60 | getComp(int index) const; |
| 61 | |
| 62 | // return string format of the comp |
| 63 | // if all characters are printable, simply returns the string |
| 64 | // if not, print the bytes in hex string format |
| 65 | string |
| 66 | getCompAsString(int index) const; |
| 67 | |
| 68 | Name |
Zhenkai Zhu | cb2d0dd | 2013-01-03 14:10:48 -0800 | [diff] [blame] | 69 | getPartialName(int start, int n = -1) const; |
Zhenkai Zhu | f47109b | 2013-01-02 19:41:34 -0800 | [diff] [blame] | 70 | |
Zhenkai Zhu | cb2d0dd | 2013-01-03 14:10:48 -0800 | [diff] [blame] | 71 | string |
| 72 | toString() const; |
| 73 | |
| 74 | Name & |
| 75 | operator=(const Name &other); |
| 76 | |
| 77 | bool |
Zhenkai Zhu | 3b82d43 | 2013-01-03 22:48:40 -0800 | [diff] [blame] | 78 | operator==(const string &str) const; |
Zhenkai Zhu | cb2d0dd | 2013-01-03 14:10:48 -0800 | [diff] [blame] | 79 | |
| 80 | bool |
Zhenkai Zhu | 3b82d43 | 2013-01-03 22:48:40 -0800 | [diff] [blame] | 81 | operator!=(const string &str) const; |
Zhenkai Zhu | cb2d0dd | 2013-01-03 14:10:48 -0800 | [diff] [blame] | 82 | |
| 83 | friend Name |
| 84 | operator+(const Name &n1, const Name &n2); |
Zhenkai Zhu | f47109b | 2013-01-02 19:41:34 -0800 | [diff] [blame] | 85 | |
| 86 | protected: |
| 87 | vector<Bytes> m_comps; |
| 88 | }; |
| 89 | |
| 90 | ostream& |
| 91 | operator <<(ostream &os, const Name &name); |
| 92 | |
Zhenkai Zhu | cb2d0dd | 2013-01-03 14:10:48 -0800 | [diff] [blame] | 93 | bool |
| 94 | operator ==(const Name &n1, const Name &n2); |
| 95 | |
| 96 | bool |
| 97 | operator !=(const Name &n1, const Name &n2); |
| 98 | |
| 99 | bool |
| 100 | operator <(const Name &n1, const Name &n2); |
| 101 | |
| 102 | |
Zhenkai Zhu | f47109b | 2013-01-02 19:41:34 -0800 | [diff] [blame] | 103 | struct InterestSelectorException: |
| 104 | virtual boost::exception, virtual exception {}; |
| 105 | |
| 106 | class Selectors |
| 107 | { |
| 108 | public: |
| 109 | Selectors(); |
| 110 | Selectors(const Selectors &other); |
| 111 | ~Selectors(){}; |
| 112 | |
| 113 | typedef enum |
| 114 | { |
| 115 | AOK_CS = 0x1, |
| 116 | AOK_NEW = 0x2, |
| 117 | AOK_DEFAULT = 0x3, // (AOK_CS | AOK_NEW) |
| 118 | AOK_STALE = 0x4, |
| 119 | AOK_EXPIRE = 0x10 |
| 120 | } AOK; |
| 121 | |
| 122 | typedef enum |
| 123 | { |
| 124 | LEFT = 0, |
| 125 | RIGHT = 1, |
| 126 | DEFAULT = 2 |
| 127 | } CHILD_SELECTOR; |
| 128 | |
| 129 | inline Selectors & |
| 130 | maxSuffixComps(int maxSCs) {m_maxSuffixComps = maxSCs; return *this;} |
| 131 | |
| 132 | inline Selectors & |
| 133 | minSuffixComps(int minSCs) {m_minSuffixComps = minSCs; return *this;} |
| 134 | |
| 135 | inline Selectors & |
| 136 | answerOriginKind(AOK kind) {m_answerOriginKind = kind; return *this;} |
| 137 | |
| 138 | inline Selectors & |
| 139 | interestLifetime(int lifetime) {m_interestLifetime = lifetime; return *this;} |
| 140 | |
| 141 | inline Selectors & |
| 142 | scope(int scope) {m_scope = scope; return *this;} |
| 143 | |
| 144 | inline Selectors & |
| 145 | childSelector(CHILD_SELECTOR child) {m_childSelector = child; return *this;} |
| 146 | |
| 147 | // this has no effect now |
| 148 | inline Selectors & |
| 149 | publisherPublicKeyDigest(const Bytes &digest) {m_publisherPublicKeyDigest = digest; return *this;} |
| 150 | |
| 151 | CcnxCharbufPtr |
Zhenkai Zhu | cb2d0dd | 2013-01-03 14:10:48 -0800 | [diff] [blame] | 152 | toCcnxCharbuf() const; |
| 153 | |
| 154 | bool |
| 155 | isEmpty() const; |
| 156 | |
| 157 | bool |
| 158 | operator==(const Selectors &other); |
Zhenkai Zhu | f47109b | 2013-01-02 19:41:34 -0800 | [diff] [blame] | 159 | |
| 160 | private: |
| 161 | int m_maxSuffixComps; |
| 162 | int m_minSuffixComps; |
| 163 | AOK m_answerOriginKind; |
| 164 | double m_interestLifetime; |
| 165 | int m_scope; |
| 166 | CHILD_SELECTOR m_childSelector; |
| 167 | // not used now |
| 168 | Bytes m_publisherPublicKeyDigest; |
| 169 | }; |
| 170 | |
| 171 | } // Ccnx |
| 172 | #endif |