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 | |
| 8 | // This class is mostly used in CcnxWrapper; users should not be directly using this class |
| 9 | // The main purpose of this class to is avoid manually create and destroy charbuf everytime |
| 10 | class CcnxCharbuf |
| 11 | { |
| 12 | public: |
| 13 | CcnxCharbuf(); |
| 14 | CcnxCharbuf(ccn_charbuf *buf); |
| 15 | ~CcnxCharbuf(); |
| 16 | |
| 17 | // expose internal data structure, use with caution!! |
| 18 | ccn_charbuf * |
| 19 | getBuf() { return m_buf; } |
| 20 | |
| 21 | protected: |
| 22 | ccn_charbuf *m_buf; |
| 23 | }; |
| 24 | |
| 25 | typedef boost::shared_ptr<CcnxCharbuf> CcnxCharbufPtr; |
| 26 | |
| 27 | struct NameException: |
| 28 | virtual boost::exception, virtual exception {}; |
| 29 | class Name |
| 30 | { |
| 31 | public: |
| 32 | Name(); |
| 33 | Name(const string &name); |
| 34 | Name(const vector<Bytes> &comps); |
| 35 | Name(const Name &other); |
| 36 | Name(const unsigned char *data, const ccn_indexbuf *comps); |
| 37 | virtual ~Name() {} |
| 38 | |
| 39 | CcnxCharbufPtr |
| 40 | toCcnxCharbuf() const; |
| 41 | |
| 42 | Name & |
| 43 | appendComp(const Bytes &comp); |
| 44 | |
| 45 | Name & |
| 46 | appendComp(const string &compStr); |
| 47 | |
| 48 | int |
| 49 | size() const {return m_comps.size();} |
| 50 | |
| 51 | Bytes |
| 52 | getComp(int index) const; |
| 53 | |
| 54 | // return string format of the comp |
| 55 | // if all characters are printable, simply returns the string |
| 56 | // if not, print the bytes in hex string format |
| 57 | string |
| 58 | getCompAsString(int index) const; |
| 59 | |
| 60 | Name |
| 61 | getPartialName(int start, int n) const; |
| 62 | |
| 63 | |
| 64 | protected: |
| 65 | vector<Bytes> m_comps; |
| 66 | }; |
| 67 | |
| 68 | ostream& |
| 69 | operator <<(ostream &os, const Name &name); |
| 70 | |
| 71 | struct InterestSelectorException: |
| 72 | virtual boost::exception, virtual exception {}; |
| 73 | |
| 74 | class Selectors |
| 75 | { |
| 76 | public: |
| 77 | Selectors(); |
| 78 | Selectors(const Selectors &other); |
| 79 | ~Selectors(){}; |
| 80 | |
| 81 | typedef enum |
| 82 | { |
| 83 | AOK_CS = 0x1, |
| 84 | AOK_NEW = 0x2, |
| 85 | AOK_DEFAULT = 0x3, // (AOK_CS | AOK_NEW) |
| 86 | AOK_STALE = 0x4, |
| 87 | AOK_EXPIRE = 0x10 |
| 88 | } AOK; |
| 89 | |
| 90 | typedef enum |
| 91 | { |
| 92 | LEFT = 0, |
| 93 | RIGHT = 1, |
| 94 | DEFAULT = 2 |
| 95 | } CHILD_SELECTOR; |
| 96 | |
| 97 | inline Selectors & |
| 98 | maxSuffixComps(int maxSCs) {m_maxSuffixComps = maxSCs; return *this;} |
| 99 | |
| 100 | inline Selectors & |
| 101 | minSuffixComps(int minSCs) {m_minSuffixComps = minSCs; return *this;} |
| 102 | |
| 103 | inline Selectors & |
| 104 | answerOriginKind(AOK kind) {m_answerOriginKind = kind; return *this;} |
| 105 | |
| 106 | inline Selectors & |
| 107 | interestLifetime(int lifetime) {m_interestLifetime = lifetime; return *this;} |
| 108 | |
| 109 | inline Selectors & |
| 110 | scope(int scope) {m_scope = scope; return *this;} |
| 111 | |
| 112 | inline Selectors & |
| 113 | childSelector(CHILD_SELECTOR child) {m_childSelector = child; return *this;} |
| 114 | |
| 115 | // this has no effect now |
| 116 | inline Selectors & |
| 117 | publisherPublicKeyDigest(const Bytes &digest) {m_publisherPublicKeyDigest = digest; return *this;} |
| 118 | |
| 119 | CcnxCharbufPtr |
| 120 | toCcnxCharbuf(); |
| 121 | |
| 122 | private: |
| 123 | int m_maxSuffixComps; |
| 124 | int m_minSuffixComps; |
| 125 | AOK m_answerOriginKind; |
| 126 | double m_interestLifetime; |
| 127 | int m_scope; |
| 128 | CHILD_SELECTOR m_childSelector; |
| 129 | // not used now |
| 130 | Bytes m_publisherPublicKeyDigest; |
| 131 | }; |
| 132 | |
| 133 | } // Ccnx |
| 134 | #endif |