blob: d652008fe534ed6792bd3454980d92181201c33d [file] [log] [blame]
Zhenkai Zhuf47109b2013-01-02 19:41:34 -08001#ifndef CCNX_NAME_H
2#define CCNX_NAME_H
3#include <boost/shared_ptr.hpp>
4#include "ccnx-common.h"
5
6namespace Ccnx {
7
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -08008class CcnxCharbuf;
9typedef boost::shared_ptr<CcnxCharbuf> CcnxCharbufPtr;
10
Zhenkai Zhuf47109b2013-01-02 19:41:34 -080011// 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
13class CcnxCharbuf
14{
15public:
16 CcnxCharbuf();
17 CcnxCharbuf(ccn_charbuf *buf);
Zhenkai Zhub0adefe2013-01-04 21:56:38 -080018 CcnxCharbuf(const CcnxCharbuf &other);
Zhenkai Zhuf47109b2013-01-02 19:41:34 -080019 ~CcnxCharbuf();
20
21 // expose internal data structure, use with caution!!
22 ccn_charbuf *
23 getBuf() { return m_buf; }
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080024 static CcnxCharbufPtr Null;
Zhenkai Zhuf47109b2013-01-02 19:41:34 -080025
Zhenkai Zhub0adefe2013-01-04 21:56:38 -080026private:
27 void init(ccn_charbuf *buf);
28
Zhenkai Zhuf47109b2013-01-02 19:41:34 -080029protected:
30 ccn_charbuf *m_buf;
31};
32
Zhenkai Zhuf47109b2013-01-02 19:41:34 -080033
34struct NameException:
35 virtual boost::exception, virtual exception {};
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080036
Zhenkai Zhuf47109b2013-01-02 19:41:34 -080037class Name
38{
39public:
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 Zhucb2d0dd2013-01-03 14:10:48 -080069 getPartialName(int start, int n = -1) const;
Zhenkai Zhuf47109b2013-01-02 19:41:34 -080070
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080071 string
72 toString() const;
73
74 Name &
75 operator=(const Name &other);
76
77 bool
Zhenkai Zhu3b82d432013-01-03 22:48:40 -080078 operator==(const string &str) const;
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080079
80 bool
Zhenkai Zhu3b82d432013-01-03 22:48:40 -080081 operator!=(const string &str) const;
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080082
83 friend Name
84 operator+(const Name &n1, const Name &n2);
Zhenkai Zhuf47109b2013-01-02 19:41:34 -080085
86protected:
87 vector<Bytes> m_comps;
88};
89
90ostream&
91operator <<(ostream &os, const Name &name);
92
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080093bool
94operator ==(const Name &n1, const Name &n2);
95
96bool
97operator !=(const Name &n1, const Name &n2);
98
99bool
100operator <(const Name &n1, const Name &n2);
101
102
Zhenkai Zhuf47109b2013-01-02 19:41:34 -0800103struct InterestSelectorException:
104 virtual boost::exception, virtual exception {};
105
106class Selectors
107{
108public:
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 Zhucb2d0dd2013-01-03 14:10:48 -0800152 toCcnxCharbuf() const;
153
154 bool
155 isEmpty() const;
156
157 bool
158 operator==(const Selectors &other);
Zhenkai Zhuf47109b2013-01-02 19:41:34 -0800159
160private:
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