aboutsummaryrefslogtreecommitdiffstats
path: root/icnet/ccnx/icnet_ccnx_segment.cc
blob: 4215650a6948414d1af27bbce537da69b4238ead (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
 * Copyright (c) 2017 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "icnet_ccnx_segment.h"

namespace icnet {

namespace ccnx {

Segment::Segment(CCNxNameLabelType type, std::string &segment_value) : name_segment_(
    ccnxNameSegment_CreateTypeValueArray(type, segment_value.length(), segment_value.c_str())) {
}

Segment::Segment(CCNxNameSegmentStructure *segment) : name_segment_(ccnxNameSegment_Acquire(segment)) {
}

Segment::Segment(const Segment &segment) : name_segment_(ccnxNameSegment_Copy(segment.name_segment_)) {
}

Segment::Segment(Segment &&otherSegment) : name_segment_(ccnxNameSegment_Acquire(otherSegment.name_segment_)) {
}

Segment::~Segment() {
  ccnxNameSegment_Release(&name_segment_);
}

Segment &Segment::operator=(const Segment &segment) {
  ccnxNameSegment_Release(&name_segment_);
  this->name_segment_ = ccnxNameSegment_Copy(segment.name_segment_);
  return *this;
}

bool Segment::operator==(const Segment &segment) {
  return ccnxNameSegment_Equals(this->name_segment_, segment.name_segment_);
}

const std::string &Segment::toString() {
  char *str = ccnxNameSegment_ToString(name_segment_);
  name_segment_string_ = std::string(str);
  free(str);
  return name_segment_string_;
}

std::size_t Segment::getSize() {
  return ccnxNameSegment_Length(name_segment_);
}

CCNxNameLabelType Segment::getType() {
  return ccnxNameSegment_GetType(name_segment_);
}

CCNxNameSegmentStructure *Segment::getWrappedStructure() const {
  return this->name_segment_;
}

bool Segment::isSegment() const {
  return ccnxNameSegmentNumber_IsValid(name_segment_);
}

uint64_t Segment::toSegment() const {
  return ccnxNameSegmentNumber_Value(name_segment_);
}

} // end namespace ccnx

} // end namespace icnet