Jeff Thompson | 9c41dfe | 2013-06-27 12:10:25 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Author: Jeff Thompson |
| 3 | * |
| 4 | * BSD license, See the LICENSE file for more information. |
| 5 | */ |
| 6 | |
Jeff Thompson | e606351 | 2013-07-01 15:11:28 -0700 | [diff] [blame] | 7 | #include <sstream> |
Jeff Thompson | b468c31 | 2013-07-01 17:50:14 -0700 | [diff] [blame] | 8 | #include "c/Name.h" |
Jeff Thompson | 9c41dfe | 2013-06-27 12:10:25 -0700 | [diff] [blame] | 9 | #include "Name.hpp" |
| 10 | |
| 11 | using namespace std; |
| 12 | |
| 13 | namespace ndn { |
| 14 | |
Jeff Thompson | 4881511 | 2013-06-28 18:22:48 -0700 | [diff] [blame] | 15 | Name::Name() |
| 16 | { |
| 17 | } |
| 18 | |
Jeff Thompson | b468c31 | 2013-07-01 17:50:14 -0700 | [diff] [blame] | 19 | void Name::set(struct ndn_Name &nameStruct) |
| 20 | { |
| 21 | clear(); |
Jeff Thompson | ccb13c1 | 2013-07-01 18:16:00 -0700 | [diff] [blame^] | 22 | for (unsigned int i = 0; i < nameStruct.nComponents; ++i) |
Jeff Thompson | b468c31 | 2013-07-01 17:50:14 -0700 | [diff] [blame] | 23 | addComponent(nameStruct.components[i].value, nameStruct.components[i].valueLength); |
| 24 | } |
| 25 | |
Jeff Thompson | ccb13c1 | 2013-07-01 18:16:00 -0700 | [diff] [blame^] | 26 | void 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 Thompson | e606351 | 2013-07-01 15:11:28 -0700 | [diff] [blame] | 38 | std::string Name::to_uri() |
| 39 | { |
| 40 | // TODO: implement fully. |
| 41 | ostringstream output; |
Jeff Thompson | ccb13c1 | 2013-07-01 18:16:00 -0700 | [diff] [blame^] | 42 | for (unsigned int i = 0; i < components_.size(); ++i) { |
Jeff Thompson | e606351 | 2013-07-01 15:11:28 -0700 | [diff] [blame] | 43 | output << "/"; |
Jeff Thompson | ccb13c1 | 2013-07-01 18:16:00 -0700 | [diff] [blame^] | 44 | for (unsigned int j = 0; j < components_[i].size(); ++j) |
Jeff Thompson | e606351 | 2013-07-01 15:11:28 -0700 | [diff] [blame] | 45 | output << components_[i][j]; |
| 46 | } |
| 47 | |
| 48 | return output.str(); |
| 49 | } |
| 50 | |
Jeff Thompson | 9c41dfe | 2013-06-27 12:10:25 -0700 | [diff] [blame] | 51 | } |