blob: c777ebe4a1cf74d1c6e36bf9087d1a3b6024996e [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 Thompsonb468c312013-07-01 17:50:14 -07008#include "c/Name.h"
Jeff Thompson9c41dfe2013-06-27 12:10:25 -07009#include "Name.hpp"
10
11using namespace std;
12
13namespace ndn {
14
Jeff Thompson48815112013-06-28 18:22:48 -070015Name::Name()
16{
17}
18
Jeff Thompsonb468c312013-07-01 17:50:14 -070019void Name::set(struct ndn_Name &nameStruct)
20{
21 clear();
Jeff Thompsonccb13c12013-07-01 18:16:00 -070022 for (unsigned int i = 0; i < nameStruct.nComponents; ++i)
Jeff Thompsonb468c312013-07-01 17:50:14 -070023 addComponent(nameStruct.components[i].value, nameStruct.components[i].valueLength);
24}
25
Jeff Thompsonccb13c12013-07-01 18:16:00 -070026void Name::get(struct ndn_Name &nameStruct)
27{
28 if (nameStruct.maxComponents < components_.size())
29 throw runtime_error("nameStruct.maxComponents must be >= this name getNComponents()");
30
31 nameStruct.nComponents = components_.size();
32 for (unsigned int i = 0; i < nameStruct.nComponents; ++i) {
33 nameStruct.components[i].value = &components_[i][0];
34 nameStruct.components[i].valueLength = components_[i].size();
35 }
36}
37
Jeff Thompsone6063512013-07-01 15:11:28 -070038std::string Name::to_uri()
39{
40 // TODO: implement fully.
41 ostringstream output;
Jeff Thompsonccb13c12013-07-01 18:16:00 -070042 for (unsigned int i = 0; i < components_.size(); ++i) {
Jeff Thompsone6063512013-07-01 15:11:28 -070043 output << "/";
Jeff Thompsonccb13c12013-07-01 18:16:00 -070044 for (unsigned int j = 0; j < components_[i].size(); ++j)
Jeff Thompsone6063512013-07-01 15:11:28 -070045 output << components_[i][j];
46 }
47
48 return output.str();
49}
50
Jeff Thompson9c41dfe2013-06-27 12:10:25 -070051}