/usr/include/odil/pdu/Item.h is in libodil-dev 0.8.0-4build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 | /*************************************************************************
* odil - Copyright (C) Universite de Strasbourg
* Distributed under the terms of the CeCILL-B license, as published by
* the CEA-CNRS-INRIA. Refer to the LICENSE file or to
* http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
* for details.
************************************************************************/
#ifndef _1c7b57cc_79f5_497c_815c_920e0711a864
#define _1c7b57cc_79f5_497c_815c_920e0711a864
#include <cstdint>
#include <istream>
#include <ostream>
#include <string>
#include <utility>
#include <vector>
#include "odil/odil.h"
namespace odil
{
namespace pdu
{
/// @brief A sequence of fields forming a full PDU or a part of it.
class ODIL_API Item
{
public:
/// @brief Generic field.
class ODIL_API Field
{
public:
/// @brief Possible types stored in the field.
enum class Type
{
unsigned_int_8,
unsigned_int_16,
unsigned_int_32,
string,
items
};
/// @brief Constructor.
Field(uint8_t value);
/// @brief Constructor.
Field(uint16_t value);
/// @brief Constructor.
Field(uint32_t value);
/// @brief Constructor.
Field(std::string const & value);
/// @brief Constructor.
Field(std::vector<Item> const & value);
/// @brief Return the concrete type stored in the field.
Type get_type() const;
/**
* @brief Return the uint8_t stored in the field.
*
* If the field does not contain an uint8_t, a odil::Exception is raised.
*/
uint8_t as_unsigned_int_8() const;
/**
* @brief Return the uint8_t stored in the field.
*
* If the field does not contain an uint8_t, a odil::Exception is raised.
*/
uint8_t & as_unsigned_int_8();
/**
* @brief Return the uint16_t stored in the field.
*
* If the field does not contain an uint16_t, a odil::Exception is raised.
*/
uint16_t as_unsigned_int_16() const;
/**
* @brief Return the uint16_t stored in the field.
*
* If the field does not contain an uint16_t, a odil::Exception is raised.
*/
uint16_t & as_unsigned_int_16();
/**
* @brief Return the uint32_t stored in the field.
*
* If the field does not contain an uint32_t, a odil::Exception is raised.
*/
uint32_t as_unsigned_int_32() const;
/**
* @brief Return the uint32_t stored in the field.
*
* If the field does not contain an uint32_t, a odil::Exception is raised.
*/
uint32_t & as_unsigned_int_32();
/**
* @brief Return the string stored in the field.
*
* If the field does not contain an string, a odil::Exception is raised.
*/
std::string const & as_string() const;
/**
* @brief Return the string stored in the field.
*
* If the field does not contain an string, a odil::Exception is raised.
*/
std::string & as_string();
/**
* @brief Return the items stored in the field.
*
* If the field does not contain items, a odil::Exception is raised.
*/
std::vector<Item> const & as_items() const;
/**
* @brief Return the items stored in the field.
*
* If the field does not contain items, a odil::Exception is raised.
*/
std::vector<Item> & as_items();
private:
Type _type;
uint8_t _uint8;
uint16_t _uint16;
uint32_t _uint32;
std::string _string;
std::vector<Item> _items;
};
typedef std::vector<std::pair<std::string, Field>> Container;
/// @brief Create an empty PDU item.
Item();
/// @brief Create an initialized PDU item.
Item(std::vector<std::pair<std::string, Field>> const & fields);
/// @brief Add a new field to the PDU item.
Item & add(std::string const & name, Field const & field);
/// @brief Return the number of fields.
Container::size_type size() const;
/// @brief Test whether the container is empty.
bool empty() const;
/// @brief Test whether the PDU item contains a field with a given name.
bool has_field(std::string const & name) const;
/// @brief Return the named field. Raise an exception if no such field exists.
Field const & operator[](std::string const & name) const;
/// @brief Return the named field. Raise an exception if no such field exists.
Field & operator[](std::string const & name);
/**
* @brief Return the named field as an uint8_t.
*
* Raise an exception if no such field exists or if the field does not
* contain an uint8_t.
*/
uint8_t as_unsigned_int_8(std::string const & name) const;
/**
* @brief Return the named field as an uint8_t.
*
* Raise an exception if no such field exists or if the field does not
* contain an uint8_t.
*/
uint8_t & as_unsigned_int_8(std::string const & name);
/**
* @brief Return the named field as an uint16_t.
*
* Raise an exception if no such field exists or if the field does not
* contain an uint16_t.
*/
uint16_t as_unsigned_int_16(std::string const & name) const;
/**
* @brief Return the named field as an uint16_t.
*
* Raise an exception if no such field exists or if the field does not
* contain an uint16_t.
*/
uint16_t & as_unsigned_int_16(std::string const & name);
/**
* @brief Return the named field as an uint32_t.
*
* Raise an exception if no such field exists or if the field does not
* contain an uint32_t.
*/
uint32_t as_unsigned_int_32(std::string const & name) const;
/**
* @brief Return the named field as an uint32_t.
*
* Raise an exception if no such field exists or if the field does not
* contain an uint32_t.
*/
uint32_t & as_unsigned_int_32(std::string const & name);
/**
* @brief Return the named field as a string.
*
* Raise an exception if no such field exists or if the field does not
* contain a string.
*/
std::string const & as_string(std::string const & name) const;
/**
* @brief Return the named field as a sequence of items.
*
* Raise an exception if no such field exists or if the field does not
* contain a sequence of items.
*/
std::string & as_string(std::string const & name);
std::vector<Item> const & as_items(std::string const & name) const;
/**
* @brief Return the named field as a sequence of items.
*
* Raise an exception if no such field exists or if the field does not
* contain a sequence of items.
*/
std::vector<Item> & as_items(std::string const & name);
typedef Container::const_iterator const_iterator;
const_iterator begin() const;
const_iterator end() const;
/**
* @brief Read a field from a stream.
*
* The size parameter is ignored for non-string types.
*/
void read(
std::istream & stream,std::string const & name, Field::Type type,
std::streamsize size=0);
private:
std::vector<std::pair<std::string, Field>> _fields;
};
// No operator>> since we need explicit names and types.
ODIL_API
std::ostream &
operator<<(std::ostream & stream, Item const & item);
}
}
#endif // _1c7b57cc_79f5_497c_815c_920e0711a864
|