close Warning: Can't use blame annotator:
No changeset 2313 in the repository

source: source/ariba/Name.h@ 12770

Last change on this file since 12770 was 9684, checked in by mies, 14 years ago

almost forgot to commit: doxygen modules :)

File size: 4.2 KB
RevLine 
1// [License]
2// The Ariba-Underlay Copyright
3//
4// Copyright (c) 2008-2009, Institute of Telematics, UniversitÀt Karlsruhe (TH)
5//
6// Institute of Telematics
7// UniversitÀt Karlsruhe (TH)
8// Zirkel 2, 76128 Karlsruhe
9// Germany
10//
11// Redistribution and use in source and binary forms, with or without
12// modification, are permitted provided that the following conditions are
13// met:
14//
15// 1. Redistributions of source code must retain the above copyright
16// notice, this list of conditions and the following disclaimer.
17// 2. Redistributions in binary form must reproduce the above copyright
18// notice, this list of conditions and the following disclaimer in the
19// documentation and/or other materials provided with the distribution.
20//
21// THIS SOFTWARE IS PROVIDED BY THE INSTITUTE OF TELEMATICS ``AS IS'' AND
22// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OF TELEMATICS OR
25// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32//
33// The views and conclusions contained in the software and documentation
34// are those of the authors and should not be interpreted as representing
35// official policies, either expressed or implied, of the Institute of
36// Telematics.
37// [License]
38
39#ifndef NAME_H_
40#define NAME_H_
41
42#include <iostream>
43#include <memory.h>
44#include <string>
45
46using std::string;
47
48// forward declaration
49namespace ariba { class Name; }
50
51std::ostream& operator<<( std::ostream&, const ariba::Name& );
52
53#include "Identifiers.h"
54
55namespace ariba {
56
57/**
58 * \addtogroup public
59 * @{
60 *
61 * This class is a wrapper for canonical names.
62 * Currently only human readable names are supported.
63 *
64 * @author Sebastian Mies <mies@tm.uka.de>
65 */
66class Name {
67 friend std::ostream& operator<<( std::ostream&, const ::ariba::Name& );
68public:
69 static const Name UNSPECIFIED;
70
71 /**
72 * Constructs a new, yet unspecified name.
73 */
74 Name();
75
76 /**
77 * Constructs a new name. If no length is specified, a human-readable
78 * name is assumed.
79 *
80 * @param name The name
81 * @param len The optional name length, if binary data is used as name
82 * @param copy A flag, whether the name's memory needs to be copied
83 */
84 Name(const char* name, int len = -1, bool copy = false);
85
86 /**
87 * Constructs a new name out of a human readable string.
88 *
89 * @param name A human readable name
90 */
91 Name(string name);
92
93 /**
94 * The copy constructor.
95 */
96 Name(const Name& name);
97
98 /**
99 * Destroys the name and releases underlying memory if this name is a copy.
100 */
101 virtual ~Name();
102
103 /**
104 * Returns the binary bytes of the name
105 *
106 * @return The binary data
107 */
108 const uint8_t* bytes() const;
109
110 /**
111 * Returns the length of the name in bytes.
112 *
113 * @return The length of the name
114 */
115 const size_t length() const;
116
117 /**
118 * The common assign operator
119 */
120 Name& operator=( const Name& name );
121
122 /**
123 * The common implementation of the "equal" operator.
124 */
125 bool operator==(const Name& name) const;
126
127 /**
128 * The common implementation of the "unequal" operator.
129 */
130 bool operator!=(const Name& name) const;
131
132 /**
133 * Returns true, if the name is yet unspecified
134 */
135 bool isUnspecified() const;
136
137 /**
138 * Returns a random name.
139 */
140 static Name random();
141
142 /**
143 * Returns a human-readable representation of this name
144 */
145 string toString() const;
146
147 // hack: to be changed!
148 NodeID toNodeId() const;
149
150 // hack: to be changed!
151 SpoVNetID toSpoVNetId() const;
152
153private:
154 uint8_t* _bytes; //< internal pointer
155 int _length; //< length of internal pointer
156 bool _copy; //< is the buffer a real copy
157 bool _hreadable; //< is the name human readable
158
159 void init(const char* name, int len, bool copy, bool hreadable);
160};
161
162} // namespace ariba
163
164/** @} */
165
166#endif /* NAME_H_ */
Note: See TracBrowser for help on using the repository browser.