| 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 |
|
---|
| 46 | using std::string;
|
---|
| 47 |
|
---|
| 48 | // forward declaration
|
---|
| 49 | namespace ariba { class Name; }
|
---|
| 50 |
|
---|
| 51 | std::ostream& operator<<( std::ostream&, const ariba::Name& );
|
---|
| 52 |
|
---|
| 53 | #include "Identifiers.h"
|
---|
| 54 |
|
---|
| 55 | namespace ariba {
|
---|
| 56 |
|
---|
| 57 | /**
|
---|
| 58 | * This class is a wrapper for canonical names.
|
---|
| 59 | * Currently only human readable names are supported.
|
---|
| 60 | *
|
---|
| 61 | * @author Sebastian Mies <mies@tm.uka.de>
|
---|
| 62 | */
|
---|
| 63 | class Name {
|
---|
| 64 | friend std::ostream& operator<<( std::ostream&, const ::ariba::Name& );
|
---|
| 65 | public:
|
---|
| 66 | static const Name UNSPECIFIED;
|
---|
| 67 |
|
---|
| 68 | /**
|
---|
| 69 | * Constructs a new, yet unspecified name.
|
---|
| 70 | */
|
---|
| 71 | Name();
|
---|
| 72 |
|
---|
| 73 | /**
|
---|
| 74 | * Constructs a new name. If no length is specified, a human-readable
|
---|
| 75 | * name is assumed.
|
---|
| 76 | *
|
---|
| 77 | * @param name The name
|
---|
| 78 | * @param len The optional name length, if binary data is used as name
|
---|
| 79 | * @param copy A flag, whether the name's memory needs to be copied
|
---|
| 80 | */
|
---|
| 81 | Name(const char* name, int len = -1, bool copy = false);
|
---|
| 82 |
|
---|
| 83 | /**
|
---|
| 84 | * Constructs a new name out of a human readable string.
|
---|
| 85 | *
|
---|
| 86 | * @param name A human readable name
|
---|
| 87 | */
|
---|
| 88 | Name(string name);
|
---|
| 89 |
|
---|
| 90 | /**
|
---|
| 91 | * The copy constructor.
|
---|
| 92 | */
|
---|
| 93 | Name(const Name& name);
|
---|
| 94 |
|
---|
| 95 | /**
|
---|
| 96 | * Destroys the name and releases underlying memory if this name is a copy.
|
---|
| 97 | */
|
---|
| 98 | virtual ~Name();
|
---|
| 99 |
|
---|
| 100 | /**
|
---|
| 101 | * Returns the binary bytes of the name
|
---|
| 102 | *
|
---|
| 103 | * @return The binary data
|
---|
| 104 | */
|
---|
| 105 | const uint8_t* bytes() const;
|
---|
| 106 |
|
---|
| 107 | /**
|
---|
| 108 | * Returns the length of the name in bytes.
|
---|
| 109 | *
|
---|
| 110 | * @return The length of the name
|
---|
| 111 | */
|
---|
| 112 | const size_t length() const;
|
---|
| 113 |
|
---|
| 114 | /**
|
---|
| 115 | * The common assign operator
|
---|
| 116 | */
|
---|
| 117 | Name& operator=( const Name& name );
|
---|
| 118 |
|
---|
| 119 | /**
|
---|
| 120 | * The common implementation of the "equal" operator.
|
---|
| 121 | */
|
---|
| 122 | bool operator==(const Name& name) const;
|
---|
| 123 |
|
---|
| 124 | /**
|
---|
| 125 | * The common implementation of the "unequal" operator.
|
---|
| 126 | */
|
---|
| 127 | bool operator!=(const Name& name) const;
|
---|
| 128 |
|
---|
| 129 | /**
|
---|
| 130 | * Returns true, if the name is yet unspecified
|
---|
| 131 | */
|
---|
| 132 | bool isUnspecified() const;
|
---|
| 133 |
|
---|
| 134 | /**
|
---|
| 135 | * Returns a random name.
|
---|
| 136 | */
|
---|
| 137 | static Name random();
|
---|
| 138 |
|
---|
| 139 | /**
|
---|
| 140 | * Returns a human-readable representation of this name
|
---|
| 141 | */
|
---|
| 142 | string toString() const;
|
---|
| 143 |
|
---|
| 144 | // hack: to be changed!
|
---|
| 145 | NodeID toNodeId() const;
|
---|
| 146 |
|
---|
| 147 | // hack: to be changed!
|
---|
| 148 | SpoVNetID toSpoVNetId() const;
|
---|
| 149 |
|
---|
| 150 | private:
|
---|
| 151 | uint8_t* _bytes; //< internal pointer
|
---|
| 152 | int _length; //< length of internal pointer
|
---|
| 153 | bool _copy; //< is the buffer a real copy
|
---|
| 154 | bool _hreadable; //< is the name human readable
|
---|
| 155 |
|
---|
| 156 | void init(const char* name, int len, bool copy, bool hreadable);
|
---|
| 157 | };
|
---|
| 158 |
|
---|
| 159 | } // namespace ariba
|
---|
| 160 |
|
---|
| 161 | #endif /* NAME_H_ */
|
---|