AMSmartProperties  201
Core library
AMProperty.h
Go to the documentation of this file.
1 
8 #ifndef AMPROPERTY_H
9 #define AMPROPERTY_H
10 
16 #include <exception>
17 
18 #include <string>
19 #include <sstream>
20 
21 #ifdef DEBUG
22 #include <stdio.h>
23 #include <cstring>
24 #define AMProperty_log(...) printf(__VA_ARGS__)
25 #else
26 #define AMProperty_log(...)
27 #endif
28 
29 
31 
32 namespace std{
33  template<typename T> string to_string(const T&);
34  template<typename T> string to_string(T&);
35 };
36 
37 
38 namespace AMSmartProperties {
39 
40 
41 class AMPropertyBase;
42 class AMPropertyRefBase;
43 class AMPropertyPool;
44 
57 struct AMPropertyGeneralException : std::exception {
58 
59  AMPropertyPool &m_pool;
60 public:
66  const char* what() const noexcept {return "AMProperty: Use descendant of this exception to identify a problem.";}
67  //const char* what() const noexcept {return "";}
74  AMPropertyBase* propertyEntered() const noexcept;
79  AMPropertyBase* propertyCaused() const noexcept;
86  std::string trace();
87 };
88 
95 
96 
102  const char* what() const noexcept {return "AMProperty: Detected deleted property. Member propertyXXX() show which property causes an exception. Run trace() to explain.";}
103 };
104 
105 
112 
113 
119  const char* what() const noexcept {return "AMProperty: Detected loop. Member propertyXXX() show which property causes an exception. Run trace() to explain.";}
120 };
121 
128 
129 
135  const char* what() const noexcept {return "AMProperty: Detected too depth nesting. Member propertyXXX() show which property causes an exception. Run trace() to explain.";}
136 };
137 
138 
147 {
148  NORMAL = 0,
149  COMPUTING = 1,
152  VALUEONLY = 4,
156  MODIFIED = 8,
180 };
181 
187 std::string to_string(const AMPropertyState& state);
188 
189 
202 public:
206  static const int TRACE_SIZE = 1024;
207 
208 protected:
209  AMPropertyState m_state;
210  AMPropertyBase* m_firstChild;
211 
212  AMPropertyBase* m_trace_array[TRACE_SIZE];
213  AMPropertyBase** m_trace_iterator;
214  AMPropertyBase** m_trace_stop;
215 
216 public:
221  AMPropertyPool();
231  AMPropertyState getPoolState() {return m_state;}
237  void setModified() {m_state = (AMPropertyState)((unsigned int)m_state | 0x8);}
243  void reset();
250  bool isDestroyed() {
251  return ((static_cast<unsigned int>(m_state) & ~0xF ) == (static_cast<unsigned int>(AMPropertyState::DESTROYED_NORMAL)));
252  }
258  bool isInProgress() {
259  return (m_trace_iterator != m_trace_array);
260  }
265  void runLoop();
270  void runDeleted();
277  std::string trace();
283  void destroy();
291  static AMPropertyPool& defaultPool();
298  void dump(char* buffer = nullptr, int length = 0);
303  AMPropertyBase* getEnteringProperty();
308  AMPropertyBase* getLastCausedProperty();
309 
310  friend class AMPropertyBase;
311  friend class AMPropertyRefBase;
312 protected:
313  void plusDepthTraceItem(AMPropertyBase* item) {
314  (*m_trace_iterator) = item;
315  m_trace_iterator++;
316  if (m_trace_iterator == m_trace_array+TRACE_SIZE) {throw AMPropertyNestingException(*this);}
317  }
318  void minusDepth() {if (m_trace_iterator == m_trace_array) {throw std::underflow_error("AMPropertyPool: Out of range");};m_trace_iterator--;}
319  void addToPool(AMPropertyBase* property);
320  void removeFromPool(AMPropertyBase* property);
321 };
322 
323 
324 
333 {
334  friend class AMPropertyPool;
335 protected:
336 
337  AMPropertyPool* m_pool;
338  union {
339  AMPropertyBase* m_next;
340  AMPropertyState m_state;
341  unsigned long m_uint;
342  };
343 
344  AMPropertyBase(AMPropertyPool& pool): m_pool(&pool), m_uint((unsigned long)NOCOMPUTED) { m_pool->addToPool(this); }
345  ~AMPropertyBase() {m_pool->removeFromPool(this);}
346 public:
352  AMPropertyPool& getPool() const {return *m_pool;}
358  void setPool(AMPropertyPool& newPool) { m_pool->removeFromPool(this);m_pool = (&newPool);m_pool->addToPool(this); }
364  AMPropertyBase* getNext() const {return reinterpret_cast<AMPropertyBase*>(m_uint & ~0x3);}
369  void resetState() {m_uint &= ~0x3;m_uint |= 0x2;}
375  bool isNonComputed() const {return m_uint & 0x2;}
381  void setNoComputedFlag() {m_uint |= 0x2;}
387  void setNoComputed(bool noComputed) {m_uint = noComputed ? m_uint | 0x2 : m_uint & ~0x2;}
393  bool getComputingFlag() {return m_uint & 0x1;}
399  bool isInProgress() {return getPool().isInProgress();}
404  void runLoop();
405 
411  void runDeleted();
412 
421  AMPropertyState getState(AMPropertyState valueOnly) const {return static_cast<AMPropertyState>(static_cast<unsigned int>(getPool().getPoolState()) | (m_uint & 0x3) | static_cast<unsigned int>(valueOnly));}
427  std::string to_string() const;
428 
429 protected:
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;
441 };
442 
443 template<typename T, typename TSubProperties, typename TParent, T TParent::*pointer_member>
444 class AMPropertyKernel
445 {
446  T*const m_memberPtr;
447 public:
448  constexpr AMPropertyKernel(AMPropertyPool& pool, T*const valuePtr): m_memberPtr(valuePtr){};
449  TParent* getParentPointer() {
450  union {
451  T TParent::*my_pointer_member = pointer_member;
452  int offset;
453  };
454  return (TParent*)(((void*)m_memberPtr) - offset);
455  }
456  TParent& getParent() {return *getParentPointer();}
457 
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;}
462 
463  constexpr TSubProperties* getSubpropertiesPtr() {return nullptr;}
464  constexpr T TParent::* getPointerToMember() {return pointer_member;}
465 
466  void compute() {};
467  void setDescription(const char * desc) {}
468  void setPool(AMPropertyPool& pool) {}
469 
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 {};
472 };
473 
474 template<typename T, typename TSubProperties, typename TParent, T TParent::*pointer_member>
475 class AMPropertyKernelWithSub
476 {
477  T*const m_memberPtr;
478  TSubProperties m_subMembers;
479 public:
480  constexpr AMPropertyKernelWithSub(AMPropertyPool& pool, T*const valuePtr): m_memberPtr(valuePtr), m_subMembers(pool, m_memberPtr){};
481  TParent* getParentPointer() {
482  union {
483  T TParent::*my_pointer_member = pointer_member;
484  int offset;
485  };
486  return (TParent*)(((void*)m_memberPtr) - offset);
487  }
488  TParent& getParent() {return *getParentPointer();}
489 
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;}
494 
495 
496  constexpr TSubProperties* getSubpropertiesPtr() {return &m_subMembers;}
497  constexpr T TParent::* getPointerToMember() {return pointer_member;}
498 
499  void compute() {m_subMembers.compute();}
500  void setDescription(const char * desc) {m_subMembers.setDescription(desc);}
501  void setPool(AMPropertyPool& pool) {m_subMembers.setPool(pool);}
502 
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();};
505 };
506 
507 template<typename T, typename TSubProperties, typename TParent, T TParent::*pointer_member>
508 class AMPropertyKernelWithT
509 {
510  T m_value;
511 public:
512  constexpr AMPropertyKernelWithT(AMPropertyPool& pool, T*const valuePtr): m_value(valuePtr == nullptr? T() : *valuePtr){};
513  TParent* getParentPointer(){return nullptr;}
514 
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;}
519 
520 
521  constexpr TSubProperties* getSubpropertiesPtr() {return nullptr;}
522  constexpr T TParent::* getPointerToMember() {return pointer_member;}
523 
524  void compute() {}
525  void setDescription(const char * desc) {}
526  void setPool(AMPropertyPool& pool) {}
527 
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 {};
530 };
531 
532 template<typename T, typename TSubProperties, typename TParent, T TParent::*pointer_member>
533 class AMPropertyKernelWithTWithSub
534 {
535  T m_value;
536  TSubProperties m_subMembers;
537 public:
538  constexpr AMPropertyKernelWithTWithSub(AMPropertyPool& pool, T*const valuePtr): m_value(valuePtr == nullptr? T() : *valuePtr), m_subMembers(pool, &m_value){};
539  TParent* getParentPointer(){return nullptr;}
540 
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;}
545 
546  constexpr TSubProperties* getSubpropertiesPtr() {return &m_subMembers;}
547  constexpr T TParent::* getPointerToMember() {return pointer_member;}
548 
549  void compute() {m_subMembers.compute();}
550  void setDescription(const char * desc) {m_subMembers.setDescription(desc);}
551  void setPool(AMPropertyPool& pool) {m_subMembers.setPool(pool);}
552 
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();};
555 };
556 
557 
565 {
566 };
567 
568 
569 template<typename T, typename TSubProperties, typename TParent, T TParent::*pointer_member>
571 
572 
579 {
580  friend class AMPropertyPool;
581 
582 protected:
583  AMPropertyBase* m_target;
584  AMPropertyRefBase(AMPropertyBase* target) : m_target(target) {}
585  ~AMPropertyRefBase() {}
586  AMPropertyBase* getTarget() {return m_target;}
587  void setTarget(AMPropertyBase* target) {m_target = target;}
588 };
589 
590 
600 template<typename T, typename TSubProperties = T, typename TParent = AMPropertyNonBase, T TParent::*pointer_member = nullptr>
601 class AMProperty: public AMPropertyBase
602 {
603 
604 public:
608  typedef AMFunction<T()> type_fn;
609 protected:
610  type_fn m_f;
611 
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
615  >::type m_kernel;
616 
617 
618 public:
625  AMProperty(AMPropertyPool& pool, T*const ptr): AMPropertyBase(pool), m_f(nullptr), m_kernel(pool, ptr)
626  {
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());
629  }
635  AMProperty(AMPropertyPool& pool, const char* name = nullptr): AMPropertyBase(pool), m_f(nullptr), m_kernel(pool, nullptr)
636  {
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);
641 
642  };
650  AMProperty(AMPropertyPool& pool, T value, const char* name = nullptr): AMPropertyBase(pool), m_f(nullptr), m_kernel(pool, &value)
651  {
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);
656 
657  };
665  constexpr AMProperty(AMPropertyPool& pool, type_fn f, const char* name = nullptr): AMPropertyBase(pool), m_f(f), m_kernel(pool, nullptr)
666  {
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);
671 
672  };
677  AMProperty(const AMProperty& other) : AMPropertyBase(other.getPool()), m_f(other.m_f), m_kernel(other.getPool(), other.m_kernel.getTPointerConst()){
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);
683  }
689  constexpr AMProperty(AMProperty&& other) : AMPropertyBase(other.getPool()), m_f(std::move(other.m_f)), m_kernel(other.getPool(), other.m_kernel.getTPointer()){
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());
696  }
701  {
702  AMProperty_log("AMProperty(%p)::AMProperty(%x)",this);
703  setPool(AMPropertyPool::defaultPool());
704  };
709  void setValueFn(const type_fn& _f)
710  {
711  AMProperty_log("AMProperty(%p)::setValueFn(%p) %s\n",this, &_f,to_string().c_str());
712  setModified();
713  m_f=_f;
714  };
719  void setValueFn(const type_fn&& _f)
720  {
721  AMProperty_log("AMProperty(%p)::setValueFn(%p) %s\n",this, &_f,to_string().c_str());
722  setModified();
723  m_f=std::move(_f);
724  };
728  type_fn& getValueFn()
729  {
730  AMProperty_log("AMProperty(%p)::getValueFn() -> %p ---%s\n",this, &m_f,to_string().c_str());
731  return m_f;
732  };
738  {
739  AMPropertyBase::setPool(pool);
740  m_kernel.setPool(pool);
741  }
746  const T& getResult() const
747  {
748  return m_kernel.getTconst();
749  }
754  void setResult(T value)
755  {
756  AMProperty_log("AMProperty(%p)::setResult(%s) \n",this, std::to_string(m_kernel.getTconst()).c_str());
757  m_kernel.getT() = value;
758  }
763  constexpr TSubProperties* getSubProperties()
764  {
765  /*AMProperty_log("AMProperty(%p)::T* operator->() %s\n",this,to_string().c_str());*/
766  return m_kernel.getSubpropertiesPtr();
767  }
771  bool isValueOnly() const
772  {
773  return m_f == nullptr;
774  }
778  constexpr bool hasSubproperties() const
779  {
780  return pointer_member != nullptr;
781  }
789  {
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());
791  compute();
792  return getResult();
793  }
798  void compute()
799  {
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);
802  switch(state) {
803  case AMPropertyState::NORMAL:
804  break;
805  case AMPropertyState::COMPUTING:
806  runLoop();
807  break;
808  case AMPropertyState::NOCOMPUTED:
809  setComputingFlag();
810  plusDepthTraceItem(this);
811  setResult(m_f());
812  minusDepth();
813  clearComputingAndNocomputedFlag();
814  break;
815  case AMPropertyState::NOCOMPUTED_COMPUTING:
816  runLoop();
817  break;
818  case AMPropertyState::VALUEONLY:
819  break;
820  case AMPropertyState::VALUEONLY_COMPUTING:
821  runLoop();
822  break;
823  case AMPropertyState::VALUEONLY_NOCOMPUTED:
824  plusDepthTraceItem(this);
825  m_kernel.compute();
826  minusDepth();
827  break;
828  case AMPropertyState::VALUEONLY_NOCOMPUTED_COMPUTING:
829  runLoop();
830  break;
831  case AMPropertyState::MODIFIED:
832  setComputingFlag();
833  plusDepthTraceItem(this);
834  setResult(m_f());
835  minusDepth();
836  clearComputingAndNocomputedFlag();
837  break;
838  case AMPropertyState::MODIFIED_COMPUTING:
839  runLoop();
840  break;
841  case AMPropertyState::MODIFIED_NOCOMPUTED:
842  setComputingFlag();
843  plusDepthTraceItem(this);
844  setResult(m_f());
845  minusDepth();
846  clearComputingAndNocomputedFlag();
847  break;
848  case AMPropertyState::MODIFIED_NOCOMPUTED_COMPUTING:
849  runLoop();
850  break;
851  case AMPropertyState::MODIFIED_VALUEONLY:
852  plusDepthTraceItem(this);
853  m_kernel.compute();
854  minusDepth();
855  break;
856  case AMPropertyState::MODIFIED_VALUEONLY_COMPUTING:
857  runLoop();
858  break;
859  case AMPropertyState::MODIFIED_VALUEONLY_NOCOMPUTED:
860  plusDepthTraceItem(this);
861  m_kernel.compute();
862  minusDepth();
863  break;
864  case AMPropertyState::MODIFIED_VALUEONLY_NOCOMPUTED_COMPUTING:
865  runLoop();
866  break;
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:
883  runDeleted();
884  break;
885  default: break;
886  }
887  }
894  operator const T& ()
895  {
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());
897  compute();
898  return getResult();
899  }
905  const type_fn& operator = (const type_fn& right) {
906  setValueFn(right);
907  return getValueFn();
908  }
914  const type_fn& operator = (const type_fn&& right) {
915  setValueFn(std::move(right));
916  return getValueFn();
917  }
924  const T& operator = (const T& right) {
925  setValueFn(nullptr);
926  setResult(right);
927  setModified();
928  return right;
929  }
933  constexpr TSubProperties* operator->()
934  {
935  AMProperty_log("AMProperty(%p)::T* operator->() %s\n",this,to_string().c_str());
936  return m_kernel.getSubpropertiesPtr();
937  }
944  T operator+(const T& other) {
945  AMProperty_log("AMProperty(%p)::operator+(T&) %s --- %s\n",(const void *)this, to_string().c_str(), std::to_string(other));
946  compute();
947  T result = getResult();
948  result = result + other;
949  return result;
950  }
957  T operator-(const T& other) {
958  AMProperty_log("AMProperty(%p)::operator-(T&) %s --- %s\n",(const void *)this, to_string().c_str(), std::to_string(other));
959  compute();
960  T result = getResult();
961  result = result - other;
962  return result;
963  }
970  T operator*(const T& other) {
971  AMProperty_log("AMProperty(%p)::operator*(T&) %s --- %s\n",(const void *)this, to_string().c_str(), std::to_string(other));
972  compute();
973  T result = getResult();
974  result = result * other;
975  return result;
976  }
983  T operator/(const T& other) {
984  AMProperty_log("AMProperty(%p)::operator/(T&) %s --- %s\n",(const void *)this, to_string().c_str(), std::to_string(other));
985  compute();
986  T result = getResult();
987  result = result / other;
988  return result;
989  }
996  T operator%(const T& other) {
997  AMProperty_log("AMProperty(%p)::operator%(T&) %s --- %s\n",(const void *)this, to_string().c_str(), std::to_string(other));
998  compute();
999  T result = getResult();
1000  result = result % other;
1001  return result;
1002  }
1010  AMProperty_log("AMProperty(%p)::operator++() %s\n",(const void *)this, to_string().c_str());
1011  compute();
1012  T result = getResult();
1013  result = result++;
1014  return result;
1015  }
1023  AMProperty_log("AMProperty(%p)::operator--() %s\n",(const void *)this, to_string().c_str());
1024  compute();
1025  T result = getResult();
1026  result = result--;
1027  return result;
1028  }
1035  void setDescription(const char * desc, const char * suffix) {
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;
1039  str += suffix;
1040  setVariableName(this, "", "",str.c_str());
1041  m_kernel.setDescription(str.c_str());
1042  }
1043  }
1047  std::string to_string() const{
1048  std::ostringstream os;
1049  os << getVariableName(this);
1050  os << ", ";
1051  m_kernel.to_string_valptr(os);
1052  os << ", st=";
1053  os << AMSmartProperties::to_string(getState(m_f == nullptr ? AMPropertyState::VALUEONLY : AMPropertyState::NORMAL));
1054  os << ", fn=";
1055  os << &m_f;
1056  os << "{";
1057  m_kernel.to_string_subprops(os);
1058  os << "}]";
1059  return os.str();
1060  }
1061 
1062 };
1063 
1064 }//namespace
1065 
1067 #endif /* AMPROPERTY_H */
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
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:165
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: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
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:151
Definition: AMProperty.h:32
constexpr bool hasSubproperties() const
test if proparty has subproperties.
Definition: AMProperty.h:778
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
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
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
bool isNonComputed() const
Information about property.
Definition: AMProperty.h:375
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
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
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
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: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
Base interface and basic fuction for smart property. Most of these funcions can be used...
Definition: AMProperty.h:332