GTIRB
v2.2.0
GrammaTech Intermediate Representation for Binaries: C++ API
|
Go to the documentation of this file.
15 #ifndef GTIRB_DataBlock_H
16 #define GTIRB_DataBlock_H
34 template <
class T>
class ErrorOr;
47 :
Node(C, Kind::DataBlock, U), Size(
S) {}
82 uint64_t getOffset()
const;
87 std::optional<Addr> getAddress()
const;
98 Observer->sizeChange(
this,
S, Size);
100 "recovering from rejected size change is not implemented yet");
120 template <
typename T>
126 template <
typename T>
137 assert(Parent &&
"Block has no byte interval!");
138 return bytes_begin<T>(Parent->getBoostEndianOrder());
151 template <
typename T>
154 boost::endian::order OutputOrder = boost::endian::order::native) {
155 assert(Parent &&
"Block has no byte interval!");
156 return Parent->bytes_begin<T>(InputOrder, OutputOrder) + getOffset();
167 assert(Parent &&
"Block has no byte interval!");
168 return bytes_end<T>(Parent->getBoostEndianOrder());
181 template <
typename T>
184 boost::endian::order OutputOrder = boost::endian::order::native) {
185 assert(Parent &&
"Block has no byte interval!");
186 return Parent->bytes_begin<T>(InputOrder, OutputOrder) + getOffset() + Size;
197 assert(Parent &&
"Block has no byte interval!");
198 return bytes<T>(Parent->getBoostEndianOrder());
211 template <
typename T>
213 bytes(boost::endian::order InputOrder,
214 boost::endian::order OutputOrder = boost::endian::order::native) {
215 assert(Parent &&
"Block has no byte interval!");
217 bytes_end<T>(InputOrder, OutputOrder));
228 assert(Parent &&
"Block has no byte interval!");
229 return bytes_begin<T>(Parent->getBoostEndianOrder());
242 template <
typename T>
244 boost::endian::order InputOrder,
245 boost::endian::order OutputOrder = boost::endian::order::native)
const {
246 assert(Parent &&
"Block has no byte interval!");
247 return Parent->bytes_begin<T>(InputOrder, OutputOrder) + getOffset();
258 assert(Parent &&
"Block has no byte interval!");
259 return bytes_end<T>(Parent->getBoostEndianOrder());
272 template <
typename T>
274 boost::endian::order InputOrder,
275 boost::endian::order OutputOrder = boost::endian::order::native)
const {
276 assert(Parent &&
"Block has no byte interval!");
277 return Parent->bytes_begin<T>(InputOrder, OutputOrder) + getOffset() + Size;
288 assert(Parent &&
"Block has no byte interval!");
289 return bytes<T>(Parent->getBoostEndianOrder());
302 template <
typename T>
304 bytes(boost::endian::order InputOrder,
305 boost::endian::order OutputOrder = boost::endian::order::native)
const {
306 assert(Parent &&
"Block has no byte interval!");
308 bytes_end<T>(InputOrder, OutputOrder));
327 assert(Parent &&
"Block has no byte interval!");
328 return reinterpret_cast<T*
>(Parent->rawBytes<uint8_t>() + getOffset());
347 assert(Parent &&
"Block has no byte interval!");
348 return reinterpret_cast<const T*
>(Parent->rawBytes<uint8_t>() +
353 static bool classof(
const Node* N) {
return N->getKind() == Kind::DataBlock; }
357 ByteInterval* Parent{
nullptr};
358 DataBlockObserver* Observer{
nullptr};
361 void setParent(ByteInterval* BI, DataBlockObserver* O) {
367 using MessageType = proto::DataBlock;
374 void toProtobuf(MessageType* Message)
const;
382 static ErrorOr<DataBlock*> fromProtobuf(Context& C,
383 const MessageType& Message);
386 void save(std::ostream& Out)
const;
389 static DataBlock* load(Context& C, std::istream& In);
393 friend class SerializationTestHarness;
397 #endif // GTIRB_DataBlock_H
ByteInterval::const_bytes_iterator< T > const_bytes_iterator
Const iterator over bytes in this block.
Definition: DataBlock.hpp:121
BytesBaseIterator< ByteInterval, T > bytes_iterator
Iterator over bytes.
Definition: ByteInterval.hpp:1769
NodeTy * Create(Args &&... TheArgs)
Create an object of type T.
Definition: Context.hpp:126
Represents the base of the Node class hierarchy.
Definition: Node.hpp:39
static DataBlock * Create(Context &C)
Create an unitialized DataBlock object.
Definition: DataBlock.hpp:58
bytes_iterator< T > bytes_end(boost::endian::order InputOrder, boost::endian::order OutputOrder=boost::endian::order::native)
Get an iterator past the last byte in this block.
Definition: DataBlock.hpp:183
boost::uuids::uuid UUID
Represents a universally unique identifier used to identify Node objects across serialization boundar...
Definition: Context.hpp:36
bytes_range< T > bytes()
Get a range of the bytes in this block.
Definition: DataBlock.hpp:196
bytes_iterator< T > bytes_begin()
Get an iterator to the first byte in this block.
Definition: DataBlock.hpp:136
const_bytes_range< T > bytes(boost::endian::order InputOrder, boost::endian::order OutputOrder=boost::endian::order::native) const
Get a range of the bytes in this block.
Definition: DataBlock.hpp:304
Represents a data object, possibly symbolic.
Definition: DataBlock.hpp:44
T * rawBytes()
Return the raw data underlying this block's byte vector.
Definition: DataBlock.hpp:326
The context under which GTIRB operations occur.
Definition: Context.hpp:63
ByteInterval::bytes_range< T > bytes_range
Range over bytes in this block.
Definition: DataBlock.hpp:115
boost::iterator_range< bytes_iterator< T > > bytes_range
Range over bytes.
Definition: ByteInterval.hpp:1775
ByteInterval::const_bytes_range< T > const_bytes_range
Const range over bytes in this block.
Definition: DataBlock.hpp:127
const_bytes_iterator< T > bytes_end(boost::endian::order InputOrder, boost::endian::order OutputOrder=boost::endian::order::native) const
Get an iterator past the last byte in this block.
Definition: DataBlock.hpp:273
ByteInterval::bytes_iterator< T > bytes_iterator
Iterator over bytes in this block.
Definition: DataBlock.hpp:110
const_bytes_iterator< T > bytes_begin(boost::endian::order InputOrder, boost::endian::order OutputOrder=boost::endian::order::native) const
Get an iterator to the first byte in this block.
Definition: DataBlock.hpp:243
#define GTIRB_EXPORT_API
This macro controls the visibility of exported symbols (i.e. classes) in shared libraries....
Definition: Export.hpp:52
Main namespace for the GTIRB API.
Definition: Addr.hpp:28
Class gtirb::ByteInterval.
const_bytes_iterator< T > bytes_end() const
Get an iterator past the last byte in this block.
Definition: DataBlock.hpp:257
BytesBaseIterator< const ByteInterval, T > const_bytes_iterator
Const iterator over bytes.
Definition: ByteInterval.hpp:1781
const ByteInterval * getByteInterval() const
Get the ByteInterval this block belongs to.
Definition: DataBlock.hpp:72
bytes_range< T > bytes(boost::endian::order InputOrder, boost::endian::order OutputOrder=boost::endian::order::native)
Get a range of the bytes in this block.
Definition: DataBlock.hpp:213
uint64_t getSize() const
Get the size of a DataBlock.
Definition: DataBlock.hpp:78
bytes_iterator< T > bytes_end()
Get an iterator past the last byte in this block.
Definition: DataBlock.hpp:166
bytes_iterator< T > bytes_begin(boost::endian::order InputOrder, boost::endian::order OutputOrder=boost::endian::order::native)
Get an iterator to the first byte in this block.
Definition: DataBlock.hpp:153
const T * rawBytes() const
Return the raw data underlying this block's byte vector.
Definition: DataBlock.hpp:346
ByteInterval * getByteInterval()
Get the ByteInterval this block belongs to.
Definition: DataBlock.hpp:70
void setSize(uint64_t S)
Set the size of this block.
Definition: DataBlock.hpp:94
const_bytes_range< T > bytes() const
Get a range of the bytes in this block.
Definition: DataBlock.hpp:287
A contiguous region of bytes in a binary.
Definition: ByteInterval.hpp:124
boost::iterator_range< const_bytes_iterator< T > > const_bytes_range
Const range over bytes.
Definition: ByteInterval.hpp:1787
static DataBlock * Create(Context &C, uint64_t Size)
Create a DataBlock object.
Definition: DataBlock.hpp:65
const_bytes_iterator< T > bytes_begin() const
Get an iterator to the first byte in this block.
Definition: DataBlock.hpp:227
Class gtirb::Addr and related functions.
ChangeStatus
Definition: Observer.hpp:19