blob: 3b98fa7c627d4201dc3dd3e3f45d93d7444adf42 [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
Jeff Thompsone6063512013-07-01 15:11:28 -07007#include <sstream>
Jeff Thompson9c41dfe2013-06-27 12:10:25 -07008#include "Name.hpp"
9
10using namespace std;
11
12namespace ndn {
13
Jeff Thompson016ed642013-07-02 14:39:06 -070014void Name::get(struct ndn_Name &nameStruct)
Jeff Thompson48815112013-06-28 18:22:48 -070015{
Jeff Thompson016ed642013-07-02 14:39:06 -070016 if (nameStruct.maxComponents < components_.size())
17 throw runtime_error("nameStruct.maxComponents must be >= this name getNComponents()");
18
19 nameStruct.nComponents = components_.size();
20 for (unsigned int i = 0; i < nameStruct.nComponents; ++i)
21 components_[i].get(nameStruct.components[i]);
Jeff Thompson48815112013-06-28 18:22:48 -070022}
23
Jeff Thompsonb468c312013-07-01 17:50:14 -070024void Name::set(struct ndn_Name &nameStruct)
25{
26 clear();
Jeff Thompsonccb13c12013-07-01 18:16:00 -070027 for (unsigned int i = 0; i < nameStruct.nComponents; ++i)
Jeff Thompsonb468c312013-07-01 17:50:14 -070028 addComponent(nameStruct.components[i].value, nameStruct.components[i].valueLength);
29}
30
Jeff Thompsone6063512013-07-01 15:11:28 -070031std::string Name::to_uri()
32{
33 // TODO: implement fully.
34 ostringstream output;
Jeff Thompsonccb13c12013-07-01 18:16:00 -070035 for (unsigned int i = 0; i < components_.size(); ++i) {
Jeff Thompsone6063512013-07-01 15:11:28 -070036 output << "/";
Jeff Thompson016ed642013-07-02 14:39:06 -070037 for (unsigned int j = 0; j < components_[i].getValue().size(); ++j)
38 output << components_[i].getValue()[j];
Jeff Thompsone6063512013-07-01 15:11:28 -070039 }
40
41 return output.str();
42}
43
Jeff Thompson9c41dfe2013-06-27 12:10:25 -070044}