blob: eacd420826684020e5864e8b66a6b207b143ae03 [file] [log] [blame]
Jeff Thompson9c41dfe2013-06-27 12:10:25 -07001/*
2 * Author: Jeff Thompson
3 *
4 * BSD license, See the LICENSE file for more information.
5 */
6
7#ifndef NDN_NAME_HPP
8#define NDN_NAME_HPP
9
10#include <vector>
11#include "common.h"
12#include "encoding/BinaryXMLWireFormat.hpp"
13
Jeff Thompsonb468c312013-07-01 17:50:14 -070014extern "C" { struct ndn_Name; }
15
Jeff Thompson9c41dfe2013-06-27 12:10:25 -070016namespace ndn {
17
18class Name {
19public:
20 Name();
21 Name(const char *uri);
22
23 void encode(std::vector<unsigned char> &output, WireFormat &wireFormat) {
24 wireFormat.encodeName(*this, output);
25 }
26 void encode(std::vector<unsigned char> &output) {
27 encode(output, BinaryXMLWireFormat::instance());
28 }
Jeff Thompson42380712013-06-28 10:59:33 -070029 void decode(const unsigned char *input, unsigned int inputLength, WireFormat &wireFormat) {
30 wireFormat.decodeName(*this, input, inputLength);
Jeff Thompson9c41dfe2013-06-27 12:10:25 -070031 }
Jeff Thompson42380712013-06-28 10:59:33 -070032 void decode(const unsigned char *input, unsigned int inputLength) {
33 decode(input, inputLength, BinaryXMLWireFormat::instance());
Jeff Thompson9c41dfe2013-06-27 12:10:25 -070034 }
35
Jeff Thompsone5f839b2013-06-28 12:50:38 -070036 /**
Jeff Thompsonb468c312013-07-01 17:50:14 -070037 * Clear the name, and set the components by copying from the name struct.
38 * @param name a C ndn_Name struct
39 */
40 void set(struct ndn_Name &nameStruct);
41
42 /**
Jeff Thompsone5f839b2013-06-28 12:50:38 -070043 * Add a new component, copying from value of length valueLength.
44 */
45 void addComponent(unsigned char *value, unsigned int valueLength) {
46 components_.push_back(std::vector<unsigned char>(value, value + valueLength));
47 }
48
49 /**
50 * Clear all the components.
51 */
52 void clear() {
53 components_.clear();
54 }
55
56 /**
57 * Get the number of components.
58 * @return the number of components
59 */
60 unsigned int getComponentCount() {
61 return components_.size();
62 }
63
Jeff Thompsone6063512013-07-01 15:11:28 -070064 /**
65 * Encode this name as a URI.
66 * @return the encoded URI.
67 */
68 std::string to_uri();
69
Jeff Thompson9c41dfe2013-06-27 12:10:25 -070070private:
71 std::vector<std::vector<unsigned char> > components_;
72};
73
74}
75
76#endif
77