Scanframe Modular Application 0.1.0
Loading...
Searching...
No Matches
ResultData.h
Go to the documentation of this file.
1#pragma once
7#include <misc/gen/pointer.h>
8
9namespace sf
10{
11
18 : public InformationBase
19 , public ResultDataTypes
20{
21 public:
25 static void initialize();
26
30 static void uninitialize();
31
36
43
49 explicit inline ResultData(id_type id, bool set_desired = false);
50
56 explicit inline ResultData(const std::string& definition, id_type id_ofs = 0);
57
63 explicit inline ResultData(const Definition& definition, id_type id_ofs = 0);
64
68 ~ResultData() override;
69
76 inline bool setup(const std::string& definition, id_type id_ofs = 0);
77
84 bool setup(const Definition& definition, id_type id_ofs);
85
91 inline bool setup(const ResultData& rd);
92
103 inline bool setup(id_type id, bool set_did = false);
104
109 [[nodiscard]] std::string getSetupString() const;
110
119 bool setAccessRange(const Range& rng, bool skip_self = false);
120
128 inline bool setAccessRange(Range::size_type stop, bool skip_self = false);
129
135
141 [[nodiscard]] const ResultDataHandler* getHandler() const
142 {
143 return _handler;
144 }
145
149 void makeOwner();
150
155
160 [[nodiscard]] bool isOwner() const;
161
166 inline void setUserData(void* data);
167
172 [[nodiscard]] inline void* getUserData() const;
173
178 [[nodiscard]] bool isValid() const;
179
184 [[nodiscard]] data_type getValueOffset() const;
185
190 [[nodiscard]] data_type getValueRange() const;
191
198 sdata_type getValue(const void* data) const;
199
205 data_type getValueU(const void* data) const;
206
213 sdata_type getValue(size_type idx, const void* data) const;
214
221 data_type getValueU(size_type idx, const void* data) const;
222
227 [[nodiscard]] id_type getId() const;
228
233 [[nodiscard]] inline id_type getDesiredId() const;
234
239 [[nodiscard]] id_type getSequenceId() const;
240
248 [[nodiscard]] std::string getName(int levels = 0) const;
249
254 [[nodiscard]] int getNameLevelCount() const;
255
260 [[nodiscard]] std::string getDescription() const;
261
266
273
278 template<typename T>
279 void setData(T data);
280
285 template<typename T = uint64_t>
286 [[nodiscard]] T getData() const;
287
292 [[nodiscard]] size_type getUsageCount() const;
293
299 [[nodiscard]] const FileMappedStorage& getDataStore() const;
300
306 [[nodiscard]] size_type getBufferSize(size_type blocks) const;
307
313 [[nodiscard]] inline size_type getBufferSize(const Range& rng) const;
314
319 [[nodiscard]] size_type getBlockSize() const;
320
325 [[nodiscard]] Range::size_type getBlockCount() const;
326
332
338
344
351
361 bool blockRead(Range::size_type ofs, Range::size_type sz, void* dest, bool force = false) const;
362
372 inline bool blockRead(const Range& rng, void* dest, bool force = false) const;
373
381 bool readIndexRange(Range::size_type ofs, Range& range) const;
382
389 bool readIndexRange(const Range& index, Range& range) const;
390
397 [[nodiscard]] bool isRangeValid(Range::size_type ofs, Range::size_type sz) const;
398
405 [[nodiscard]] bool isRangeValid(const Range& rng) const;
406
412 [[nodiscard]] bool isIndexRangeValid(const Range& rng) const;
413
419 [[nodiscard]] const Range& getAccessRange() const;
420
427 bool getRequests(Range::Vector& requests) const;
428
434 bool getSplitRequests(Range::Vector& req_list) const;
435
439 std::ostream& reportStatus(std::ostream& os) const;
440
445 [[nodiscard]] inline Range::id_type getTransId() const;
446
457 bool blockWrite(Range::size_type ofs, Range::size_type sz, const void* src, bool auto_reserve = false);
458
468 inline bool blockWrite(const Range& rng, const void* src, bool auto_reserve = false);
469
476 size_type commitValidations(bool skip_self = false);
477
486 bool setReservedBlockCount(Range::size_type sz, bool skip_self = false);
487
494 bool clearValidations(bool skip_self = false) const;
495
505
513 void validateRange(Range rng) const;
514
520 void validateRange(const Range::Vector& rl) const;
521
532
539 bool requestRange(const Range& rng);
540
547 bool requestIndexRange(const Range& rng);
548
553 void clearRequests() const;
554
560 [[nodiscard]] bool isFlag(int flag) const;
561
568 bool setFlag(int flag, bool skip_self);
569
576 bool unsetFlag(int flag, bool skip_self);
577
582 [[nodiscard]] std::string getCurFlagsString() const;
583
588 [[nodiscard]] std::string getFlagsString() const;
589
596 bool updateFlags(int flags, bool skip_self);
597
602 [[nodiscard]] flags_type getFlags() const;
603
608 [[nodiscard]] flags_type getCurFlags() const;
609
615 static EType getType(std::string_view type);
616
622 static std::string getType(EType type);
623
628 [[nodiscard]] EType getType() const;
629
636
641 [[nodiscard]] inline size_type getTypeSize() const;
642
647 [[nodiscard]] unsigned getSignificantBits() const;
648
655
662
669
673 static std::string getFieldName(int field);
674
681
690 static const ResultData& getInstanceById(id_type id, const PtrVector& list);
691
699 static const ResultData& getInstanceBySequenceId(id_type seq_id, const PtrVector& list);
700
706
715 static bool create(std::istream& is, PtrVector& list = null_ref<PtrVector>(), int& err_line = null_ref<int>());
716
724 bool writeUpdate(std::ostream& os) const;
725
734 static bool readUpdate(std::istream& is, bool skip_self, PtrVector& list = null_ref<PtrVector>());
735
742 static Definition getDefinition(const std::string& str);
743
749 static flags_type toFlags(const std::string& flags);
750
756 static std::string getFlagsString(flags_type flags);
757
764 inline ResultData& operator=(const ResultData& rd);
765
771 inline bool operator==(const ResultData& rd) const;
772
777 void operator delete(void*);// NOLINT(misc-new-delete-overloads)
778
779 private:
783 explicit ResultData(void*, void*);
784
792 bool createDataStore(ResultDataReference* ref, size_type segment_size, size_type block_size);
793
801 [[maybe_unused]] size_type emitLocalEvent(EEvent event, const Range& rng, bool skip_self = true) const;
802
810 [[maybe_unused]] size_type emitGlobalEvent(EEvent event, const Range& rng, bool skip_self = true) const;
811
820 bool emitEvent(EEvent event, const ResultData& caller, const Range& rng);
821
827 static ResultDataReference* getReferenceById(id_type id);
828
833 static void removeHandler(const ResultDataHandler* handler);
834
840 bool attachRef(ResultDataReference* ref);
841
846 size_type attachDesired() const;
847
853 bool recycleEnable(bool recycle);
854
858 ResultDataReference* _reference{nullptr};
862 ResultDataHandler* _handler{nullptr};
868 Range::id_type _transactionId{0};
872 id_type _desiredId{0};
876 void* _userData{nullptr};
880 uint64_t _data{0};
881
882 public:
887 void setDebug(bool debug) const;
892 [[nodiscard]] inline bool isDebug() const;
898 static std::string_view getEventName(EEvent event);
899
904 inline const ResultDataReference& getReference() const;
905
910 [[nodiscard]] const Range::Vector& getCommitList() const;
911
916 [[nodiscard]] const Range::Vector& getValidatedList() const;
917
922 [[nodiscard]] size_type getSegmentLocks() const;
923
932 size_type emitEvent(EEvent event, const Range& rng, bool skip_self = false);
933
934 friend class ResultDataHandler;
935
937
938 friend class ResultDataStatic;
939};
940
944_GII_FUNC std::ostream& operator<<(std::ostream& os, const ResultData&);
945
949_GII_FUNC std::istream& operator>>(std::istream& is, ResultData&);
950
951}// namespace sf
952
953// Include all inlined functions and template implementations.
954#include <gii/gen/ResultData.hpp>
This class provides storing of huge amounts of data using file mapping. Mapping only what is needed ...
Definition FileMappedStorage.h:55
uint64_t size_type
Type used for sizes of storage.
Definition FileMappedStorage.h:60
Base class for all generic information objects to be able to put them in a typed list together.
Definition InformationBase.h:13
uint64_t data_type
Type used for containing a single data element which is the largest integer.
Definition InformationBase.h:42
unsigned long long id_type
Type used for the identifying integer (64-bits).
Definition InformationBase.h:30
size_t size_type
Type used for size of vectors.
Definition InformationBase.h:38
int64_t sdata_type
Type used for containing a single data element which is the largest signed integer.
Definition InformationBase.h:46
int32_t flags_type
Type used for the flag integer.
Definition InformationBase.h:34
Type to contain and manipulate range lists.
Definition Range.h:67
Class to manage 64-bit integer ranges.
Definition Range.h:52
RANGE::size_type size_type
Integer type used for start and stop.
Definition Range.h:57
RANGE::id_type id_type
Integer type used for the ID.
Definition Range.h:61
Class used to give a ResultData instance access to virtual method of a derived class.
Definition ResultDataHandler.h:12
Base class of the sf::ResultData having all global static data members.
Definition ResultDataStatic.h:13
This base class contains all local types of used in the sf::ResultData class. Multiple inheritance m...
Definition ResultDataTypes.h:25
EEvent
Event enumerate values used in broadcasting where global events have a negative value.
Definition ResultDataTypes.h:46
EType
This enumerate is used to identify the type of data.
Definition ResultDataTypes.h:122
Class for creating and referencing global created data called result data. This class allows linking ...
Definition ResultData.h:20
Range::size_type getBlockCount() const
Gets the accessible block count which does not mean it is valid.
bool requestRange(const Range &rng)
Requests a range in blocks to validate.
bool requestRange(Range::size_type ofs, Range::size_type sz)
Requests a range using offset and size in blocks to validate. Emits event reGetRange to the owner whe...
ResultData(id_type id, bool set_desired=false)
Constructor for creating an instance that attaches to an existing reference by id.
~ResultData() override
Overridden destructor.
bool updateFlags(int flags, bool skip_self)
Sets a new set flags for this instance allowed by owners only.
void setUserData(void *data)
Sets the void pointer data member for general purposes to cast in a handler.
const FileMappedStorage & getDataStore() const
Returns reference to underlying multithreaded safe storage class. To access the data a local data sto...
static size_type getTotalReservedSize()
Gets the total amount of bytes reserved by all instances.
bool setup(const Definition &definition, id_type id_ofs)
Creates a new TResultDataReference from a structure for this instance.
bool blockRead(const Range &rng, void *dest, bool force=false) const
Reads a range of blocks from storage. This function also calls isRangeValid() to check the validity o...
ResultData(const Definition &definition, id_type id_ofs=0)
Creates a new result using the passed definition structure.
FileMappedStorage::size_type getReservedBlockCount() const
Get the amount of reserved blocks.
void setDebug(bool debug) const
Sets the debug flag for this instance reference.
static bool readUpdate(std::istream &is, bool skip_self, PtrVector &list=null_ref< PtrVector >())
Read new multiple current access range and current flags are read from stream. Used in communication ...
size_type getBufferSize(size_type blocks) const
Gets the size in bytes needed for buffers for reading or writing the amount of blocks.
ResultData()
Default constructor.
bool setAccessRange(const Range &rng, bool skip_self=false)
Sets the accessible range. When needed the method calls setReservedBlockCount() to match the given ra...
static const ResultData & getInstanceById(id_type id, const PtrVector &list)
Finds instance in the past vector having the passed id. When not found it te returns a reference to t...
std::string getSetupString() const
Gets the setup string for this instance.
sdata_type getValue(const void *data) const
Returns the value derived from a buffer data pointer mapped to the appropriate type and corrected wit...
size_type getUsageCount() const
Gets the usage count of this result reference.
void validateRange(const Range::Vector &rl) const
Like validateRange() but for a vector/list of ranges.
size_type commitValidations(bool skip_self=false)
Commits all validated ranges and to notifies assigned handlers. Emits the reCommitted event to all ha...
unsigned getSignificantBits() const
Gets the significant bits of the type used for this result.
size_type getTypeSize() const
Gets the byte size of this instance's type.
flags_type getFlags() const
Gets the set of flags at setup time.
void setData(T data)
Sets the data for this instance for user purposes.
T getData() const
Gets the data for this instance for user purposes Set with setData().
Range::id_type getTransId() const
Gets the transaction id used in requests of data.
bool blockRead(Range::size_type ofs, Range::size_type sz, void *dest, bool force=false) const
Reads blocks from the storage using an offset. This function also calls isRangeValid() to check the v...
static EType getType(std::string_view type)
Gets the type from the passed string name.
std::string getCurFlagsString() const
Gets the current flags as a string.
const Range::Vector & getCommitList() const
Gets a vector of ranges still to be committed.
id_type getDesiredId() const
Gets the desired id data member value.
static bool create(std::istream &is, PtrVector &list=null_ref< PtrVector >(), int &err_line=null_ref< int >())
Setup multiple instances from an input stream. Useful when reading a data file.
void setDesiredId()
Sets the desired id member variable to the current reference id.
static PtrVector getList()
Gets a list of owner instances available. Useful in populating a selection dialog.
bool setReservedBlockCount(Range::size_type sz, bool skip_self=false)
Sets the amount of blocks to reserve only for owners. This method is called underwater when 'auto_res...
ResultData(const ResultData &rd)
Copy constructor. Sets the reference as the passed instance.
void setHandler(ResultDataHandler *handler)
Sets an event handler for this instance.
size_type getSegmentLocks() const
Gets the accumulation of locks on segments.
size_type getBlockSize() const
Gets the block size in bytes.
static void initialize()
Must be called to initialize the statics which this class depends on.
static void uninitialize()
Called when terminating the application.
ResultData(const std::string &definition, id_type id_ofs=0)
Constructor for creating a completely new reference.
bool isIndexRangeValid(const Range &rng) const
Gets if the specified index range is valid.
bool writeUpdate(std::ostream &os) const
Writes id and current access range and current flags to the stream.
static size_type getInstanceCount()
Gets the amount of result data instances in the system.
const Range & getAccessRange() const
Gets the accessible block range where the stop value. Is the same as the result of calling 'getBlockC...
void setDesiredId(id_type id)
Sets the desired id member variable to the passed id. If the passed 'id' is zero the automatic attach...
flags_type getCurFlags() const
Gets the current flags of this instance.
bool setup(const ResultData &rd)
Sets reference as the reference in the past instance.
bool operator==(const ResultData &rd) const
Comparison operator.
bool getSplitRequests(Range::Vector &req_list) const
Returns the ranges which are bound by the segment bounds.
static std::string_view getEventName(EEvent event)
Gets the name of the passed EEvent number.
bool clearValidations(bool skip_self=false) const
Clears all the valid ranges of this instance. It generates an event reClear before it is actually cle...
data_type getValueU(const void *data) const
Same as getValue but no offset is added.
static std::string getFieldName(int field)
Gets the name of the passed field enumerate EField.
static flags_type toFlags(const std::string &flags)
Gets flags enumerate combination of the passed flags string.
FileMappedStorage::size_type getSegmentCount() const
Gets the accessible segment count.
bool getRequests(Range::Vector &requests) const
Returns a copy of the client requests that are out for data for only the owner. This list is already ...
void * getUserData() const
Gets the UserData void pointer data member.
FileMappedStorage::size_type getSegmentSize() const
Gets the segment size in blocks.
int getNameLevelCount() const
Gets the amount of levels of the fullname path.
FileMappedStorage::size_type getReservedSize() const
Returns the total reserved size in bytes for this instance. Taking recycling into account....
data_type getValueRange() const
Gets the value range (max) taking the significant bits into account.
bool blockWrite(const Range &rng, const void *src, bool auto_reserve=false)
For owners to writes data to storage in using a range in blocks.
void clearRequests() const
Clears the outstanding requests for only this instance. Enables making fresh start in events.
std::ostream & reportStatus(std::ostream &os) const
Reports the status as in the past 'std::ostream'.
bool isRangeValid(Range::size_type ofs, Range::size_type sz) const
Checks if the passed block range depicted by offset and size is valid to access/read.
std::string getName(int levels=0) const
Gets the result data name which is default the full result data path name. When levels is 'n' and lar...
static size_type getCount()
Gets the amount of references in the system. In fact the amount references in the system excluding th...
EType getType() const
Gets current type of the instance.
sdata_type getValue(size_type idx, const void *data) const
Same as getValue() but now from the instance at the passed index from the array of the results type.
const ResultDataReference & getReference() const
Gets the underlying reference class of this instance.
static const ResultData & getInstanceBySequenceId(id_type seq_id, const PtrVector &list)
Finds instance in passed vector. in vector with passed sequential ID and returns a reference to it....
bool setAccessRange(Range::size_type stop, bool skip_self=false)
Same as setAccessRange where the start value is default 0.
size_type getBufferSize(const Range &rng) const
Gets the size in bytes needed for buffers for reading or writing the range.
bool readIndexRange(Range::size_type ofs, Range &range) const
Reads a range when this instance holds indices. An index instance groups blocks together for processi...
bool setup(const std::string &definition, id_type id_ofs=0)
Creates a new reference from a setup string for this instance.
bool setFlag(int flag, bool skip_self)
Sets a flag or multiple flags allowed by owners only.
std::string getFlagsString() const
Gets the original setup flags as a string.
void validateRange(Range rng) const
Adds a validated range of blocks for committing later. Only available for owners. This method is usef...
data_type getValueOffset() const
Returns the correction offset for each value to get the real value.
bool blockWrite(Range::size_type ofs, Range::size_type sz, const void *src, bool auto_reserve=false)
For owners to writes data to storage in using an offset and size in blocks. Written data needs to be ...
static std::string getFlagsString(flags_type flags)
Gets flags string from the passed flags passed.
bool isDebug() const
Gets the debug flag of the instance reference.
bool isRangeValid(const Range &rng) const
Checks if the passed block range is valid to access/read.
ResultData & getOwner() const
Gets reference of the owning instance.
static Definition getDefinition(const std::string &str)
Fills a definition structure from a string. On failure the _valid field is set to false.
bool isOwner() const
Checks if this is the owner of this result.
id_type getId() const
Returns the result identifier.
size_type emitEvent(EEvent event, const Range &rng, bool skip_self=false)
Initiate event for all instances of this result. If skip_self is 'true' this instance is left out of ...
bool readIndexRange(const Range &index, Range &range) const
Reads a range when this instance holds indices.
void makeOwner()
Make this instance owner of this result.
data_type getValueU(size_type idx, const void *data) const
Same as getValue but no offset is added.
bool isValid() const
Gets the instance validity.
ResultData & operator=(const ResultData &rd)
Assigns the reference of the passed instance. Calls actually setup(const ResultData& rd).
bool unsetFlag(int flag, bool skip_self)
Unsets a flag or multiple flags allowed by owners only.
std::string getDescription() const
Gets the instance description.
bool isFlag(int flag) const
Check if a certain flag or flags (mask) are set.
void validateRange(Range::size_type ofs, Range::size_type sz) const
Adds a validated range of blocks for committing later. Only available for owners. This method is usef...
bool setup(id_type id, bool set_did=false)
Sets reference to other by id. The global list of references is searched for the passed id and refere...
const ResultDataHandler * getHandler() const
Gets the handler pointer of this instance set with setHandler().
Definition ResultData.h:141
id_type getSequenceId() const
Gets the sequential id of this instance.
static std::string getType(EType type)
Gets the string typename of the passed enumerate value.
bool requestIndexRange(const Range &rng)
Same as requestRange() but for when this instance is an index.
const Range::Vector & getValidatedList() const
Gets a vector of ranges that are validated.
static const ResultData & getInstanceById(id_type id)
Gets instance with the given id otherwise the zero instance.
static size_type getTypeSize(EType type)
Gets the size of the passed enumerate type value.
#define _GII_CLASS
Definition gii/global.h:38
#define _GII_FUNC
Definition gii/global.h:37
Definition Application.h:10
_GII_FUNC std::istream & operator>>(std::istream &is, ResultData &)
Stream operator for setting up this instance with a setup std::string.
_GII_FUNC std::ostream & operator<<(std::ostream &os, const ResultData &)
Stream operator for the setup std::string.
Definition ResultDataReference.h:13
Structure used to setup a result reference.
Definition ResultDataTypes.h:175