24 #define AMProperty_log(...) printf(__VA_ARGS__) 26 #define AMProperty_log(...) 33 template<
typename T>
string to_string(
const T&);
34 template<
typename T>
string to_string(T&);
42 class AMPropertyRefBase;
66 const char*
what() const noexcept {
return "AMProperty: Use descendant of this exception to identify a problem.";}
102 const char*
what() const noexcept {
return "AMProperty: Detected deleted property. Member propertyXXX() show which property causes an exception. Run trace() to explain.";}
119 const char*
what() const noexcept {
return "AMProperty: Detected loop. Member propertyXXX() show which property causes an exception. Run trace() to explain.";}
135 const char*
what() const noexcept {
return "AMProperty: Detected too depth nesting. Member propertyXXX() show which property causes an exception. Run trace() to explain.";}
206 static const int TRACE_SIZE = 1024;
251 return ((static_cast<unsigned int>(m_state) & ~0xF ) == (static_cast<unsigned int>(AMPropertyState::DESTROYED_NORMAL)));
259 return (m_trace_iterator != m_trace_array);
298 void dump(
char* buffer =
nullptr,
int length = 0);
314 (*m_trace_iterator) = item;
318 void minusDepth() {
if (m_trace_iterator == m_trace_array) {
throw std::underflow_error(
"AMPropertyPool: Out of range");};m_trace_iterator--;}
341 unsigned long m_uint;
387 void setNoComputed(
bool noComputed) {m_uint = noComputed ? m_uint | 0x2 : m_uint & ~0x2;}
430 void setComputingFlag() {m_uint |= 0x1;}
431 void clearComputingFlag() {m_uint &= ~0x1;}
432 void clearComputingAndNocomputedFlag() {m_uint &= ~0x3;}
433 void setModified() {setNoComputedFlag();getPool().setModified();}
434 void plusDepthTraceItem(
AMPropertyBase* item) {getPool().plusDepthTraceItem(item);}
435 void minusDepth() {getPool().minusDepth();}
436 void setNext(
AMPropertyBase* newNext) { m_uint =
reinterpret_cast<unsigned long>(newNext) | (m_uint & 0x3); }
437 void setVariableName(
const void* ptr,
const char * prefix,
const char * delimiter,
const char * name)
const;
438 bool isEnabledVariableNames()
const;
439 std::string getVariableName(
const void* ptr)
const;
440 const char* getVariableNameCStr(
const void* ptr)
const;
443 template<
typename T,
typename TSubProperties,
typename TParent, T TParent::*po
inter_member>
444 class AMPropertyKernel
448 constexpr AMPropertyKernel(
AMPropertyPool& pool, T*
const valuePtr): m_memberPtr(valuePtr){};
449 TParent* getParentPointer() {
451 T TParent::*my_pointer_member = pointer_member;
454 return (TParent*)(((
void*)m_memberPtr) - offset);
456 TParent& getParent() {
return *getParentPointer();}
458 T& getT() {
return *(m_memberPtr);};
459 const T& getTconst()
const {
return *m_memberPtr;};
460 T*
const getTPointerConst()
const {
return m_memberPtr;}
461 T* getTPointer() {
return m_memberPtr;}
463 constexpr TSubProperties* getSubpropertiesPtr() {
return nullptr;}
464 constexpr T TParent::* getPointerToMember() {
return pointer_member;}
467 void setDescription(
const char * desc) {}
470 void to_string_valptr(std::ostringstream& os)
const {os<<
"val="<<((
reinterpret_cast<const unsigned long>(m_memberPtr) <=
sizeof(TSubProperties)) ? std::string(
"nullptr") :
std::to_string(*m_memberPtr))<<
", ptr="<<std::hex<<m_memberPtr;}
471 void to_string_subprops(std::ostringstream& os)
const {};
474 template<
typename T,
typename TSubProperties,
typename TParent, T TParent::*po
inter_member>
475 class AMPropertyKernelWithSub
478 TSubProperties m_subMembers;
480 constexpr AMPropertyKernelWithSub(
AMPropertyPool& pool, T*
const valuePtr): m_memberPtr(valuePtr), m_subMembers(pool, m_memberPtr){};
481 TParent* getParentPointer() {
483 T TParent::*my_pointer_member = pointer_member;
486 return (TParent*)(((
void*)m_memberPtr) - offset);
488 TParent& getParent() {
return *getParentPointer();}
490 T& getT() {
return *(m_memberPtr);};
491 const T& getTconst()
const {
return *m_memberPtr;};
492 T*
const getTPointerConst()
const {
return m_memberPtr;}
493 T* getTPointer() {
return m_memberPtr;}
496 constexpr TSubProperties* getSubpropertiesPtr() {
return &m_subMembers;}
497 constexpr T TParent::* getPointerToMember() {
return pointer_member;}
499 void compute() {m_subMembers.compute();}
500 void setDescription(
const char * desc) {m_subMembers.setDescription(desc);}
503 void to_string_valptr(std::ostringstream& os)
const {os<<
"val="<<((
reinterpret_cast<const unsigned long>(m_memberPtr) <=
sizeof(TSubProperties)) ? std::string(
"nullptr") :
std::to_string(*m_memberPtr))<<
", ptr="<<std::hex<<m_memberPtr;}
504 void to_string_subprops(std::ostringstream& os)
const {os<<m_subMembers.to_string();};
507 template<
typename T,
typename TSubProperties,
typename TParent, T TParent::*po
inter_member>
508 class AMPropertyKernelWithT
512 constexpr AMPropertyKernelWithT(
AMPropertyPool& pool, T*
const valuePtr): m_value(valuePtr ==
nullptr? T() : *valuePtr){};
513 TParent* getParentPointer(){
return nullptr;}
515 T& getT() {
return m_value;};
516 const T& getTconst()
const {
return m_value;};
517 T*
const getTPointerConst()
const {T& ref=
const_cast<T&
>(m_value);
return &ref;}
518 T* getTPointer() {
return &m_value;}
521 constexpr TSubProperties* getSubpropertiesPtr() {
return nullptr;}
522 constexpr T TParent::* getPointerToMember() {
return pointer_member;}
525 void setDescription(
const char * desc) {}
528 void to_string_valptr(std::ostringstream& os)
const {os<<
"val="<<
std::to_string(m_value);}
529 void to_string_subprops(std::ostringstream& os)
const {};
532 template<
typename T,
typename TSubProperties,
typename TParent, T TParent::*po
inter_member>
533 class AMPropertyKernelWithTWithSub
536 TSubProperties m_subMembers;
538 constexpr AMPropertyKernelWithTWithSub(
AMPropertyPool& pool, T*
const valuePtr): m_value(valuePtr ==
nullptr? T() : *valuePtr), m_subMembers(pool, &m_value){};
539 TParent* getParentPointer(){
return nullptr;}
541 T& getT() {
return m_value;};
542 const T& getTconst()
const {
return m_value;};
543 T*
const getTPointerConst()
const {T& ref=
const_cast<T&
>(m_value);
return &ref;}
544 T* getTPointer() {
return &m_value;}
546 constexpr TSubProperties* getSubpropertiesPtr() {
return &m_subMembers;}
547 constexpr T TParent::* getPointerToMember() {
return pointer_member;}
549 void compute() {m_subMembers.compute();}
550 void setDescription(
const char * desc) {m_subMembers.setDescription(desc);}
553 void to_string_valptr(std::ostringstream& os)
const {os<<
"val="<<
std::to_string(m_value);}
554 void to_string_subprops(std::ostringstream& os)
const {os<<m_subMembers.to_string();};
569 template<
typename T,
typename TSubProperties,
typename TParent, T TParent::*po
inter_member>
600 template<
typename T,
typename TSubProperties = T,
typename TParent = AMPropertyNonBase, T TParent::*po
inter_member =
nullptr>
612 typename std::conditional< pointer_member !=
nullptr,
613 typename std::conditional< std::is_same<T,TSubProperties>::value, AMPropertyKernel<T, TSubProperties, TParent, pointer_member>, AMPropertyKernelWithSub<T, TSubProperties, TParent, pointer_member> >::type ,
614 typename std::conditional< std::is_same<T,TSubProperties>::value, AMPropertyKernelWithT<T, TSubProperties, TParent, pointer_member>, AMPropertyKernelWithTWithSub<T, TSubProperties, TParent, pointer_member> >::type
627 static_assert(pointer_member !=
nullptr,
"This constructor is intended only for subproperties, do not use it.");
628 AMProperty_log(
"AMProperty(%p)::AMProperty(T* ptr=%p) %s\n",
this, ptr,
to_string().c_str());
637 static_assert(pointer_member ==
nullptr,
"This constructor is not intended for subproperties, do not use it.");
638 AMProperty_log(
"AMProperty(%p)::AMProperty() %s\n",
this,
to_string().c_str());
639 setVariableName(
this,
"",
"", name);
640 m_kernel.setDescription(name);
652 static_assert(pointer_member ==
nullptr,
"This constructor is not intended for subproperties, do not use it.");
653 AMProperty_log(
"AMProperty(%p)::AMProperty(T value=%s) %s\n",
this,
std::to_string(value).c_str(),
to_string().c_str());
654 setVariableName(
this,
"",
"", name);
655 m_kernel.setDescription(name);
667 static_assert(pointer_member ==
nullptr,
"This constructor is not intended for subproperties, do not use it.");
668 AMProperty_log(
"AMProperty(%p)::AMProperty(type_fn _f=%p) %s\n",&f,
this,
to_string().c_str());
669 setVariableName(
this,
"",
"", name);
670 m_kernel.setDescription(name);
678 static_assert(pointer_member ==
nullptr,
"This constructor is not intended for subproperties, do not use it.");
679 AMProperty_log(
"AMProperty(%p)::AMProperty(AMProperty& other)) %s\n",
this,other.
to_string().c_str());
680 const char* name = getVariableNameCStr(&other);
681 setVariableName(
this,
"",
"", name);
682 m_kernel.setDescription(name);
690 static_assert(pointer_member ==
nullptr,
"This constructor is not intended for subproperties, do not use it.");
691 AMProperty_log(
"AMProperty(%p)::AMProperty(AMProperty& other)) %s\n",
this,other.to_string().c_str());
692 const char* name = getVariableNameCStr(&other);
693 setVariableName(
this,
"",
"", name);
694 m_kernel.setDescription(name);
695 other.setPool(AMPropertyPool::defaultPool());
702 AMProperty_log(
"AMProperty(%p)::AMProperty(%x)",
this);
703 setPool(AMPropertyPool::defaultPool());
711 AMProperty_log(
"AMProperty(%p)::setValueFn(%p) %s\n",
this, &_f,
to_string().c_str());
721 AMProperty_log(
"AMProperty(%p)::setValueFn(%p) %s\n",
this, &_f,
to_string().c_str());
730 AMProperty_log(
"AMProperty(%p)::getValueFn() -> %p ---%s\n",
this, &m_f,
to_string().c_str());
739 AMPropertyBase::setPool(pool);
740 m_kernel.setPool(pool);
748 return m_kernel.getTconst();
756 AMProperty_log(
"AMProperty(%p)::setResult(%s) \n",
this,
std::to_string(m_kernel.getTconst()).c_str());
757 m_kernel.getT() = value;
766 return m_kernel.getSubpropertiesPtr();
773 return m_f ==
nullptr;
780 return pointer_member !=
nullptr;
790 AMProperty_log(
"AMProperty(%p)::const T& operator() const ->%s --- %s\n",(
const void *)
this,
std::to_string(m_kernel.getTconst()).c_str(),
to_string().c_str());
800 AMProperty_log(
"AMProperty(%p)::compute --- %s\n",(
const void *)
this,
to_string().c_str());
801 AMPropertyState state = getState(m_f ==
nullptr ? AMPropertyState::VALUEONLY : AMPropertyState::NORMAL);
803 case AMPropertyState::NORMAL:
805 case AMPropertyState::COMPUTING:
808 case AMPropertyState::NOCOMPUTED:
810 plusDepthTraceItem(
this);
813 clearComputingAndNocomputedFlag();
815 case AMPropertyState::NOCOMPUTED_COMPUTING:
818 case AMPropertyState::VALUEONLY:
820 case AMPropertyState::VALUEONLY_COMPUTING:
823 case AMPropertyState::VALUEONLY_NOCOMPUTED:
824 plusDepthTraceItem(
this);
828 case AMPropertyState::VALUEONLY_NOCOMPUTED_COMPUTING:
831 case AMPropertyState::MODIFIED:
833 plusDepthTraceItem(
this);
836 clearComputingAndNocomputedFlag();
838 case AMPropertyState::MODIFIED_COMPUTING:
841 case AMPropertyState::MODIFIED_NOCOMPUTED:
843 plusDepthTraceItem(
this);
846 clearComputingAndNocomputedFlag();
848 case AMPropertyState::MODIFIED_NOCOMPUTED_COMPUTING:
851 case AMPropertyState::MODIFIED_VALUEONLY:
852 plusDepthTraceItem(
this);
856 case AMPropertyState::MODIFIED_VALUEONLY_COMPUTING:
859 case AMPropertyState::MODIFIED_VALUEONLY_NOCOMPUTED:
860 plusDepthTraceItem(
this);
864 case AMPropertyState::MODIFIED_VALUEONLY_NOCOMPUTED_COMPUTING:
867 case AMPropertyState::DESTROYED_NORMAL:
868 case AMPropertyState::DESTROYED_COMPUTING:
869 case AMPropertyState::DESTROYED_NOCOMPUTED:
870 case AMPropertyState::DESTROYED_NOCOMPUTED_COMPUTING:
871 case AMPropertyState::DESTROYED_VALUEONLY:
872 case AMPropertyState::DESTROYED_VALUEONLY_COMPUTING:
873 case AMPropertyState::DESTROYED_VALUEONLY_NOCOMPUTED:
874 case AMPropertyState::DESTROYED_VALUEONLY_NOCOMPUTED_COMPUTING:
875 case AMPropertyState::DESTROYED_MODIFIED:
876 case AMPropertyState::DESTROYED_MODIFIED_COMPUTING:
877 case AMPropertyState::DESTROYED_MODIFIED_NOCOMPUTED:
878 case AMPropertyState::DESTROYED_MODIFIED_NOCOMPUTED_COMPUTING:
879 case AMPropertyState::DESTROYED_MODIFIED_VALUEONLY:
880 case AMPropertyState::DESTROYED_MODIFIED_VALUEONLY_COMPUTING:
881 case AMPropertyState::DESTROYED_MODIFIED_VALUEONLY_NOCOMPUTED:
882 case AMPropertyState::DESTROYED_MODIFIED_VALUEONLY_NOCOMPUTED_COMPUTING:
896 AMProperty_log(
"AMProperty(%p)::operator const T& () const ->%s --- %s\n",(
const void *)
this,
std::to_string(m_kernel.getTconst()).c_str(),
to_string().c_str());
905 const type_fn& operator = (
const type_fn& right) {
914 const type_fn& operator = (
const type_fn&& right) {
915 setValueFn(std::move(right));
924 const T& operator = (
const T& right) {
935 AMProperty_log(
"AMProperty(%p)::T* operator->() %s\n",
this,
to_string().c_str());
936 return m_kernel.getSubpropertiesPtr();
945 AMProperty_log(
"AMProperty(%p)::operator+(T&) %s --- %s\n",(
const void *)
this,
to_string().c_str(),
std::to_string(other));
947 T result = getResult();
948 result = result + other;
958 AMProperty_log(
"AMProperty(%p)::operator-(T&) %s --- %s\n",(
const void *)
this,
to_string().c_str(),
std::to_string(other));
960 T result = getResult();
961 result = result - other;
971 AMProperty_log(
"AMProperty(%p)::operator*(T&) %s --- %s\n",(
const void *)
this,
to_string().c_str(),
std::to_string(other));
973 T result = getResult();
974 result = result * other;
984 AMProperty_log(
"AMProperty(%p)::operator/(T&) %s --- %s\n",(
const void *)
this,
to_string().c_str(),
std::to_string(other));
986 T result = getResult();
987 result = result / other;
997 AMProperty_log(
"AMProperty(%p)::operator%(T&) %s --- %s\n",(
const void *)
this,
to_string().c_str(),
std::to_string(other));
999 T result = getResult();
1000 result = result % other;
1010 AMProperty_log(
"AMProperty(%p)::operator++() %s\n",(
const void *)
this,
to_string().c_str());
1012 T result = getResult();
1023 AMProperty_log(
"AMProperty(%p)::operator--() %s\n",(
const void *)
this,
to_string().c_str());
1025 T result = getResult();
1036 AMProperty_log(
"AMProperty(%p)::setDescritption(%s, %s) %s\n",
this,desc,suffix,
to_string().c_str());
1037 if (isEnabledVariableNames()) {
1038 std::string str = desc;
1040 setVariableName(
this,
"",
"",str.c_str());
1041 m_kernel.setDescription(str.c_str());
1048 std::ostringstream os;
1049 os << getVariableName(
this);
1051 m_kernel.to_string_valptr(os);
1057 m_kernel.to_string_subprops(os);
Definition: AMProperty.h:157
Definition: AMProperty.h:156
Smart property reference base class.
Definition: AMProperty.h:578
T operator%(const T &other)
operator % computes a value and add module by right side parameter.
Definition: AMProperty.h:996
Definition: AMProperty.h:167
T operator-(const T &other)
operator - computes a value and substract by right side parameter.
Definition: AMProperty.h:957
constexpr AMProperty(AMPropertyPool &pool, type_fn f, const char *name=nullptr)
"Functor" constructor. Every reading from property, returns result of this function. (i may be cached, ref: Smart properties)
Definition: AMProperty.h:665
Definition: AMProperty.h:171
Definition: AMProperty.h:165
Definition: AMProperty.h:155
T operator()()
returns a computed value. Freshly computed, or cached, in case of nothig is modified.
Definition: AMProperty.h:788
void resetState()
Reset state od property. This function is not intenden for use in common operation.
Definition: AMProperty.h:369
Definition: AMProperty.h:162
Definition: AMProperty.h:154
void setValueFn(const type_fn &_f)
Copy functor into property. Do not use it directly..
Definition: AMProperty.h:709
T operator+(const T &other)
operator + computes a value and add it to right side parameter.
Definition: AMProperty.h:944
void setModified()
Set state to modified. This state is signalized from AMProperty and holds this state untl next reset...
Definition: AMProperty.h:237
AMProperty(AMPropertyPool &pool, T *const ptr)
Constructor for subproperty. Do not use othervise. Suproperty has only reference to real type T...
Definition: AMProperty.h:625
Definition: AMProperty.h:170
T operator--()
operator – computes a value and decrement it.Value does not store back!
Definition: AMProperty.h:1022
bool isValueOnly() const
test, if property has a constant value (functor is empty)
Definition: AMProperty.h:771
std::string to_string() const
dumps a property info a std::string.
Definition: AMProperty.h:1047
Definition: AMProperty.h:161
Definition: AMProperty.h:151
Definition: AMProperty.h:32
constexpr bool hasSubproperties() const
test if proparty has subproperties.
Definition: AMProperty.h:778
Definition: AMProperty.h:163
const char * what() const noexcept
what
Definition: AMProperty.h:66
bool isDestroyed()
Test if Pool is in Destroyed state. Trace is, when state signalised Destroyed flag.
Definition: AMProperty.h:250
void setDescription(const char *desc, const char *suffix)
set description (variable names). Name consists from two equvalent parts. Reason for split is avoidin...
Definition: AMProperty.h:1035
Definition: AMProperty.h:166
Generic functor type for specified type of property.
Definition: AMProperty.h:57
void setValueFn(const type_fn &&_f)
Move functor into property. Do not use it directly..
Definition: AMProperty.h:719
void setResult(T value)
set last result. This function does not compute property. Consider use it directly. Stored value will be there until next recompution.
Definition: AMProperty.h:754
"NULL" type class. Used by AMSmartProperties::AMProperty, when parent class is not defined...
Definition: AMProperty.h:564
Definition: AMProperty.h:175
T operator/(const T &other)
operator / computes a value and add divide by right side parameter.
Definition: AMProperty.h:983
This exception is thrown when loop is detected.
Definition: AMProperty.h:111
type_fn & getValueFn()
Get functor from property.
Definition: AMProperty.h:728
This exception is thrown when too much properties was nested.
Definition: AMProperty.h:127
Definition: AMProperty.h:174
constexpr TSubProperties * operator->()
get subproperties.
Definition: AMProperty.h:933
AMProperty(AMPropertyPool &pool, T value, const char *name=nullptr)
"Value" constructor. Every reading from property, returns this value.
Definition: AMProperty.h:650
AMProperty(const AMProperty &other)
"Copy" constructor.
Definition: AMProperty.h:677
const char * what() const noexcept
what
Definition: AMProperty.h:135
void setPool(AMPropertyPool &pool)
Set Pool (AMSmartProperties::AMPropertyPool) You may reassign property to another pool(window)...
Definition: AMProperty.h:737
Definition: AMProperty.h:152
bool isInProgress()
Test if Pool is in progress.
Definition: AMProperty.h:258
AMPropertyBase * getNext() const
Do not use it directly!
Definition: AMProperty.h:364
constexpr TSubProperties * getSubProperties()
get subproperties. Consider use it directly.
Definition: AMProperty.h:763
This exception is thrown when compuded property depends on deleted property.
Definition: AMProperty.h:94
Definition: AMProperty.h:176
bool isNonComputed() const
Information about property.
Definition: AMProperty.h:375
Definition: AMProperty.h:178
Definition: AMProperty.h:164
Definition: AMProperty.h:160
Definition: AMProperty.h:172
bool getComputingFlag()
Information about property.
Definition: AMProperty.h:393
constexpr AMProperty(AMProperty &&other)
"Move" constructor. Smart roperty has not move constructor, due to composition. (All member are stora...
Definition: AMProperty.h:689
Definition: AMProperty.h:177
std::string to_string(const AMPropertyState &state)
Converts AMPropertyState to std::string.
~AMProperty()
Destructor.
Definition: AMProperty.h:700
const T & getResult() const
get last result. This function does not compute property. Consider use it directly.
Definition: AMProperty.h:746
Definition: AMProperty.h:150
Definition: AMProperty.h:169
AMFunction< T()> type_fn
Functor type for this property.
Definition: AMProperty.h:608
const char * what() const noexcept
what
Definition: AMProperty.h:102
Smart property class.
Definition: AMProperty.h:570
void setNoComputedFlag()
Information about property Set flag that property is not already computed.
Definition: AMProperty.h:381
Definition: AMFunction.h:16
void setPool(AMPropertyPool &newPool)
Move property from one pool to another.
Definition: AMProperty.h:358
void compute()
computes result. Consider use it directly.
Definition: AMProperty.h:798
Definition: AMProperty.h:179
AMPropertyState getPoolState()
Returns state.
Definition: AMProperty.h:231
const char * what() const noexcept
what
Definition: AMProperty.h:119
AMPropertyPool & getPool() const
Get the pool assigned to property.
Definition: AMProperty.h:352
AMSmartProperties::AMPropertyPool is a property pool for smart properties.
Definition: AMProperty.h:201
bool isInProgress()
Information about property.
Definition: AMProperty.h:399
T operator++()
operator ++ computes a value and add increment it. Value does not store back!
Definition: AMProperty.h:1009
AMPropertyState
Smart property state This is combined state for each property. Bits 3-4 are stored in AMSmartProperti...
Definition: AMProperty.h:146
void setNoComputed(bool noComputed)
Information about property.
Definition: AMProperty.h:387
AMProperty(AMPropertyPool &pool, const char *name=nullptr)
"Default" constructor.
Definition: AMProperty.h:635
Definition: AMProperty.h:153
Definition: AMProperty.h:159
Definition: AMProperty.h:148
T operator*(const T &other)
operator * computes a value and multiply by right side parameter.
Definition: AMProperty.h:970
Definition: AMProperty.h:168
Definition: AMProperty.h:158
AMPropertyState getState(AMPropertyState valueOnly) const
Get state (AMSmartProperties::AMPropertyState) of property. Bits 0,1 comes from this property...
Definition: AMProperty.h:421
Definition: AMProperty.h:149
Definition: AMProperty.h:173
Base interface and basic fuction for smart property. Most of these funcions can be used...
Definition: AMProperty.h:332