blob: 59e34a56078eb8deb0af432efeebf6623a85b0d5 [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);
18 ~CcnxCharbuf();
19
20 // expose internal data structure, use with caution!!
21 ccn_charbuf *
22 getBuf() { return m_buf; }
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080023 static CcnxCharbufPtr Null;
Zhenkai Zhuf47109b2013-01-02 19:41:34 -080024
25protected:
26 ccn_charbuf *m_buf;
27};
28
Zhenkai Zhuf47109b2013-01-02 19:41:34 -080029
30struct NameException:
31 virtual boost::exception, virtual exception {};
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080032
Zhenkai Zhuf47109b2013-01-02 19:41:34 -080033class Name
34{
35public:
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 Zhucb2d0dd2013-01-03 14:10:48 -080065 getPartialName(int start, int n = -1) const;
Zhenkai Zhuf47109b2013-01-02 19:41:34 -080066
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080067 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 Zhuf47109b2013-01-02 19:41:34 -080081
82protected:
83 vector<Bytes> m_comps;
84};
85
86ostream&
87operator <<(ostream &os, const Name &name);
88
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080089bool
90operator ==(const Name &n1, const Name &n2);
91
92bool
93operator !=(const Name &n1, const Name &n2);
94
95bool
96operator <(const Name &n1, const Name &n2);
97
98
Zhenkai Zhuf47109b2013-01-02 19:41:34 -080099struct InterestSelectorException:
100 virtual boost::exception, virtual exception {};
101
102class Selectors
103{
104public:
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 Zhucb2d0dd2013-01-03 14:10:48 -0800148 toCcnxCharbuf() const;
149
150 bool
151 isEmpty() const;
152
153 bool
154 operator==(const Selectors &other);
Zhenkai Zhuf47109b2013-01-02 19:41:34 -0800155
156private:
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