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 | 9c41dfe | 2013-06-27 12:10:25 -0700 | [diff] [blame] | 8 | #include "Name.hpp" |
| 9 | |
| 10 | using namespace std; |
| 11 | |
| 12 | namespace ndn { |
| 13 | |
Jeff Thompson | 016ed64 | 2013-07-02 14:39:06 -0700 | [diff] [blame^] | 14 | void Name::get(struct ndn_Name &nameStruct) |
Jeff Thompson | 4881511 | 2013-06-28 18:22:48 -0700 | [diff] [blame] | 15 | { |
Jeff Thompson | 016ed64 | 2013-07-02 14:39:06 -0700 | [diff] [blame^] | 16 | 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 Thompson | 4881511 | 2013-06-28 18:22:48 -0700 | [diff] [blame] | 22 | } |
| 23 | |
Jeff Thompson | b468c31 | 2013-07-01 17:50:14 -0700 | [diff] [blame] | 24 | void Name::set(struct ndn_Name &nameStruct) |
| 25 | { |
| 26 | clear(); |
Jeff Thompson | ccb13c1 | 2013-07-01 18:16:00 -0700 | [diff] [blame] | 27 | for (unsigned int i = 0; i < nameStruct.nComponents; ++i) |
Jeff Thompson | b468c31 | 2013-07-01 17:50:14 -0700 | [diff] [blame] | 28 | addComponent(nameStruct.components[i].value, nameStruct.components[i].valueLength); |
| 29 | } |
| 30 | |
Jeff Thompson | e606351 | 2013-07-01 15:11:28 -0700 | [diff] [blame] | 31 | std::string Name::to_uri() |
| 32 | { |
| 33 | // TODO: implement fully. |
| 34 | ostringstream output; |
Jeff Thompson | ccb13c1 | 2013-07-01 18:16:00 -0700 | [diff] [blame] | 35 | for (unsigned int i = 0; i < components_.size(); ++i) { |
Jeff Thompson | e606351 | 2013-07-01 15:11:28 -0700 | [diff] [blame] | 36 | output << "/"; |
Jeff Thompson | 016ed64 | 2013-07-02 14:39:06 -0700 | [diff] [blame^] | 37 | for (unsigned int j = 0; j < components_[i].getValue().size(); ++j) |
| 38 | output << components_[i].getValue()[j]; |
Jeff Thompson | e606351 | 2013-07-01 15:11:28 -0700 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | return output.str(); |
| 42 | } |
| 43 | |
Jeff Thompson | 9c41dfe | 2013-06-27 12:10:25 -0700 | [diff] [blame] | 44 | } |