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