40 template <
class CC>
class Element;
54 typedef typename CC::ATOM_TYPE T;
81 const char * m_description;
86 return m_vDesc.m_type;
91 return m_vDesc.GetMin();
94 s32 GetDefault()
const
96 return m_vDesc.GetDefault();
101 return m_vDesc.GetMax();
106 return GetMax() - GetMin() + 1;
109 u32 MapValue(u32 max, s32 val)
const
111 val = CLAMP(GetMin(), GetMax(), val);
113 u32 zval = (u32) (val - GetMin());
115 return zval * max / GetRange();
120 bs.Printf(
"Parameter[%s](\"%s\",\"%s\",\"%s\",%d,%d,%d)",
121 VD::GetTypeName(this->GetType()),
130 void PrintValue(
ByteSink &bs,
const T & atom)
132 switch (this->GetType())
134 case VD::U32: bs.
Print(m_vDesc.GetValueU32<CC>(atom));
break;
135 case VD::S32: bs.
Print(m_vDesc.GetValueS32<CC>(atom));
break;
136 case VD::BOOL: bs.
Print(m_vDesc.GetValueBool<CC>(atom));
break;
137 case VD::UNARY: bs.
Print(m_vDesc.GetValueUnary<CC>(atom));
break;
138 default: FAIL(ILLEGAL_STATE);
142 virtual bool ReadValue(
ByteSource &bs, T & atom)
144 switch (this->GetType())
149 if (!bs.
Scan(val))
return false;
150 m_vDesc.SetValueU32<CC>(atom,val);
156 if (!bs.
Scan(val))
return false;
157 m_vDesc.SetValueS32<CC>(atom,val);
166 m_vDesc.SetValueBool<CC>(atom,
true);
168 else if (temp.
Equals(
"false"))
170 m_vDesc.SetValueBool<CC>(atom,
false);
181 if (!bs.
Scan(val))
return false;
182 m_vDesc.SetValueUnary<CC>(atom,val);
185 default: FAIL(ILLEGAL_STATE);
197 void SetBitsAsS32(T& atom,
const s32 val)
const
210 void SetBitsAsU64(T& atom,
const u64 val)
const
223 if (this->GetType()==VD::U32)
225 store = m_vDesc.GetValueU32<CC>(atom);
231 void StoreU32(T& atom,
const u32 val)
const
233 if (this->GetType()==VD::U32)
235 this->m_vDesc.SetValueU32(atom, val);
246 if (this->GetType()==VD::S32)
248 store = this->m_vDesc.GetValueS32(atom);
254 void StoreS32(T& atom,
const s32 val)
const
256 if (this->GetType()==VD::S32)
258 this->m_vDesc.SetValueS32(atom, val);
269 if (this->GetType()==VD::BOOL)
271 store = m_vDesc.GetValueBool<CC>(atom);
277 void StoreBool(T& atom,
const bool val)
const
279 if (this->GetType()==VD::BOOL)
281 this->m_vDesc.SetValueBool(atom, val);
292 if (this->GetType()==VD::UNARY)
294 store = this->m_vDesc.GetValueUnary(atom);
300 void StoreUnary(T& atom,
const u32 val)
const
302 if (this->GetType()==VD::UNARY)
304 this->m_vDesc.SetValueUnary(atom, val);
328 Parameter(
const VD & vd,
const char* tag,
const char* name,
const char* description) ;
330 const VD & GetVD()
const
365 return m_description;
372 template <
class CC>
class Parameters;
375 class ElementParameter :
public Parameter<CC>
377 typedef Parameter<CC> Super;
378 typedef typename CC::ATOM_TYPE T;
379 typedef typename CC::PARAM_CONFIG P;
381 friend class Parameters< ElementParameter<CC> >;
382 ElementParameter * m_next;
387 BPA = P::BITS_PER_ATOM,
389 START_POS = BPA - PARM_LENGTH,
391 LONG_PARM_LENGTH = 64,
392 LONG_START_POS = BPA - LONG_PARM_LENGTH
396 static const VD MakeVD(u32 type, s32 min, s32 vdef, s32 max)
398 VD::AssertValidType(type);
399 return VD(type, PARM_LENGTH, START_POS, min, vdef, max);
402 static const VD MakeLongVD(u64 vdef)
404 return VD(VD::BITS, LONG_PARM_LENGTH, LONG_START_POS, vdef);
409 typedef BitVector<BPA> BV;
410 typedef BitField<BV, VD::U32, PARM_LENGTH, START_POS> FieldU32;
411 typedef BitField<BV, VD::S32, PARM_LENGTH, START_POS> FieldS32;
412 typedef BitField<BV, VD::BOOL, PARM_LENGTH, START_POS> FieldBool;
413 typedef BitField<BV, VD::UNARY, PARM_LENGTH, START_POS> FieldUnary;
414 typedef BitField<BV, VD::BITS, LONG_PARM_LENGTH, LONG_START_POS> FieldBits;
416 const T & GetAtom()
const
426 void PrintValue(ByteSink &bs)
428 Super::PrintValue(bs, m_storage);
431 virtual bool ReadValue(ByteSource &bs)
433 return Super::ReadValue(bs, m_storage);
436 ElementParameter * GetNextParameter()
441 const ElementParameter * GetNextParameter()
const
446 ElementParameter(Element<CC> * elt, u32 type,
const char * tag,
447 const char * name,
const char * description,
448 s32 min, s32 vdef, s32 max) ;
450 ElementParameter(Element<CC> * elt, u32 type,
const char * tag,
451 const char * name,
const char * description,
462 void SetBitsAsS32(
const s32 val)
467 u64 GetBitsAsU64()
const
469 return GetBitsAsU64(m_storage);
472 void SetBitsAsU64(
const u64 val)
474 Parameter<CC>::SetBitsAsU64(m_storage, val);
479 if (this->GetVD().GetType()==VD::BITS)
481 this->SetBitsAsU64(this->GetVD().GetLongDefault());
485 this->SetBitsAsS32(this->GetVD().GetDefault());
494 return FieldU32::GetValue(m_storage);
497 void SetValueU32(
const u32 val)
499 FieldU32::SetValue(m_storage, val);
507 return FieldS32::GetValue(m_storage);
510 void SetValueS32(
const s32 val)
512 FieldS32::SetValue(m_storage, val);
520 return FieldBool::GetValue(m_storage);
523 void SetValueBool(
const bool val)
525 FieldBool::SetValue(m_storage, val);
533 return FieldUnary::GetValue(m_storage);
536 void SetValueUnary(
const u32 val)
const
538 FieldUnary::SetValue(m_storage, val);
547 FieldBits::Load(m_storage, val);
551 void SetValueBits(
const u64 val)
const
553 FieldBits::SetValue(m_storage, val);
562 const char * name,
const char * description,
563 u32 min, u32 vdef, u32 max) ;
568 void SetValue(u32 val)
570 return this->SetValueU32(val);
575 byteSink.Printf(
"%u", this->GetValue());
576 return ByteSerializable::SUCCESS;
582 if (byteSource.Scanf(
"%u", &val) != 1)
584 return ByteSerializable::FAILURE;
587 return ByteSerializable::SUCCESS;
597 const char * name,
const char * description,
598 s32 min, s32 vdef, s32 max) ;
603 void SetValue(s32 val)
605 return this->SetValueS32(val);
610 byteSink.Printf(
"%d", this->GetValue());
611 return ByteSerializable::SUCCESS;
617 if (byteSource.Scanf(
"%d", &val) != 1)
619 return ByteSerializable::FAILURE;
622 return ByteSerializable::SUCCESS;
632 const char * name,
const char * description,
634 bool GetValue()
const
638 void SetValue(
bool val)
640 return this->SetValueBool(val);
645 byteSink.Printf(
"%s", this->GetValue() ?
"true" :
"false");
646 return ByteSerializable::SUCCESS;
654 return ByteSerializable::FAILURE;
658 this->SetValue(
true);
659 return ByteSerializable::SUCCESS;
663 this->SetValue(
false);
664 return ByteSerializable::SUCCESS;
666 return ByteSerializable::FAILURE;
671 template <
class CC, u32 LENGTH>
674 typedef typename CC::ATOM_TYPE T;
675 typedef typename CC::PARAM_CONFIG P;
678 BPA = P::BITS_PER_ATOM,
679 START_POS = BPA - LENGTH
686 const char * name,
const char * description,
691 FieldBitsLength::Load(this->GetAtom(), val);
695 void SetValue(u64 val)
697 FieldBitsLength::SetValue(this->GetAtom(), val);
700 void ClearBit(u32 bitnum)
704 void SetBit(u32 bitnum)
708 bool GetBit(u32 bitnum)
const
714 template <
class CC, u32 SITES>
719 const char * name,
const char * description,
726 return PrintU64AsNeighborhood(byteSink, this->GetValue());
729 virtual ByteSerializable::Result PrintU64AsNeighborhood(
ByteSink & byteSink, u64 nghb)
732 bool firstOut =
false;
734 for (u32 i = 0; i <= SITES; ++i)
736 bool bitvalue =
false;
739 bitvalue = (nghb>>((SITES-1)-i))&1;
763 byteSink.
Print(start);
766 byteSink.Printf(
"-%d", i-1);
773 return ByteSerializable::SUCCESS;
779 ByteSerializable::Result res = ReadNeighborhoodAsU64(byteSource, ngb);
780 if (res == ByteSerializable::SUCCESS)
787 virtual ByteSerializable::Result ReadNeighborhoodAsU64(
ByteSource & byteSource, u64 & ngb)
789 const ByteSerializable::Result FAIL = ByteSerializable::FAILURE;
792 if (byteSource.
Read() !=
'[')
800 if (byteSource.
Read() ==
']')
803 return ByteSerializable::SUCCESS;
807 if (!byteSource.
Scan(start))
811 if (start < 0 || start >= (s32) SITES)
817 s32 delim = byteSource.
Read();
820 if (!byteSource.
Scan(end))
824 if (end < 0 || end >= (s32) SITES || end < start)
829 delim = byteSource.
Read();
831 for (s32 bit = start; bit <= end; ++bit)
833 val |= 1L<<((SITES-1)-bit);
849 bool ReadValue(ByteSource &bs)
851 return ReadFrom(bs) == ByteSerializable::SUCCESS;
857 class AtomicParameter :
public Parameter<CC>
859 typedef Parameter<CC> Super;
860 typedef typename CC::ATOM_TYPE T;
862 friend class Parameters< AtomicParameter<CC> >;
863 AtomicParameter * m_next;
868 return ByteSerializable::UNSUPPORTED;
873 return ByteSerializable::UNSUPPORTED;
881 const AtomicParameter * GetNextParameter()
const
886 virtual void Print(ByteSink & io)
893 virtual void Print(ByteSink & io,
const T & atom)
const = 0;
895 virtual void Reset(T & atom)
const = 0;
897 AtomicParameter<CC>(Element<CC> * pl,
const char * tag,
898 const char * name,
const char * description,
902 template <
class CC, VD::Type VT, u32 LEN, u32 POS>
906 typedef typename CC::ATOM_TYPE T;
907 typedef typename CC::PARAM_CONFIG P;
916 START = Field::START,
917 LENGTH = Field::LENGTH,
923 const VTYPE m_vdefault;
926 const char * name,
const char * description,
927 const VTYPE & vmin,
const VTYPE & vdefault,
const VTYPE & vmax) ;
929 VTYPE GetValue(
const T & atom)
const
931 return Field::GetValue(atom);
933 void SetValue(T & atom,
const VTYPE val)
const
935 Field::SetValue(atom,val);
938 virtual void Reset(T & atom)
const
940 SetValue(atom, m_vdefault);
943 virtual void Print(
ByteSink & io,
const T & atom)
const
950 template <
class PARM>
955 PARM* m_firstParameter;
972 PARM* p = m_firstParameter;
994 MFM_API_ASSERT_NONNULL(ap);
996 for (PARM * p = m_firstParameter; p; ++number, p = p->m_next)
1000 return (s32) number;
1018 MFM_API_ASSERT_NONNULL(tag);
1020 for (
const PARM* p = m_firstParameter; p; ++number, p = p->m_next)
1022 if (!strcmp(tag, p->GetTag()))
1024 return (s32) number;
1039 return m_firstParameter;
1057 PARM* p = m_firstParameter;
1058 s32 left = (s32) index;
1060 while (p && --left >= 0)
1067 FAIL(OUT_OF_BOUNDS);
1113 FAIL(ILLEGAL_ARGUMENT);
1116 PARM ** pPtr = &m_firstParameter;
1117 for (PARM * p = *pPtr; p; pPtr = &p->m_next, p = p->m_next)
1121 FAIL(DUPLICATE_ENTRY);
1130 class ElementParameters :
public Parameters< ElementParameter<CC> >
1148 class AtomicParameters :
public Parameters< AtomicParameter<CC> >
1151 typedef typename CC::ATOM_TYPE T;
1167 #include "Parameter.tcc"
bool GetValueBool() const
bool value
Definition: Parameter.h:518
Parameter(const VD &vd, const char *tag, const char *name, const char *description)
Definition: Parameter.tcc:8
const char * GetDescription() const
Definition: Parameter.h:363
s32 GetBitsAsS32() const
Un-type-checked access treating all bit fields as s32.
Definition: Parameter.h:457
bool LoadS32(const T &atom, s32 &store) const
s32 value
Definition: Parameter.h:244
Definition: Parameter.h:48
s32 GetParameterNumber(const PARM *ap) const
Definition: Parameter.h:992
void Unread()
Definition: ByteSource.h:87
Definition: Parameter.h:43
virtual ByteSerializable::Result PrintTo(ByteSink &byteSink, s32 argument=0)
Definition: Parameter.h:866
bool LoadUnary(const T &atom, u32 &store) const
unary value
Definition: Parameter.h:290
static void SetBit(BV &bv, u32 bitnum)
Definition: BitField.h:112
Definition: Parameter.h:628
u32 GetValueU32() const
u32 value
Definition: Parameter.h:492
s32 GetBitsAsS32(const typename CC::ATOM_TYPE &a) const
Definition: VD.tcc:43
virtual ByteSerializable::Result PrintTo(ByteSink &byteSink, s32 argument=0)
Definition: Parameter.h:608
PARM * GetParameter(u32 index)
Definition: Parameter.h:1085
virtual ByteSerializable::Result ReadFrom(ByteSource &byteSource, s32 argument=0)
Definition: Parameter.h:579
void SetBitsAsU64(typename CC::ATOM_TYPE &a, u64 val) const
Definition: VD.tcc:37
Definition: Parameter.h:903
virtual ByteSerializable::Result ReadFrom(ByteSource &byteSource, s32 argument=0)
Definition: Parameter.h:614
virtual ByteSerializable::Result PrintTo(ByteSink &byteSink, s32 argument=0)
Definition: Parameter.h:573
bool Equals(const char *str) const
Definition: OverflowableCharBufferByteSink.h:111
u64 GetBitsAsU64(const T &atom) const
Un-type-checked access treating all bit fields as u64.
Definition: Parameter.h:205
Definition: ByteSource.h:44
void SetBitsAsS32(typename CC::ATOM_TYPE &a, s32 val) const
Definition: VD.tcc:49
virtual ByteSerializable::Result ReadFrom(ByteSource &byteSource, s32 argument=0)
Definition: Parameter.h:776
Definition: Parameter.h:593
Definition: Parameter.h:558
virtual ByteSerializable::Result PrintTo(ByteSink &byteSink, s32 argument=0)
Definition: Parameter.h:724
void AddParameter(PARM *np)
Definition: Parameter.h:1104
Definition: ByteSink.h:47
const PARM * GetFirstParameter() const
Definition: Parameter.h:1037
static void ClearBit(BV &bv, u32 bitnum)
Definition: BitField.h:132
void Print(const char *str, s32 fieldWidth=-1, u8 padChar= ' ')
Definition: ByteSink.cpp:31
const char * GetTag() const
Definition: Parameter.h:341
u64 GetValueBits() const
bits value
Definition: Parameter.h:544
Definition: Parameter.h:47
s32 GetBitsAsS32(const T &atom) const
Un-type-checked access treating all bit fields as s32.
Definition: Parameter.h:192
bool ScanIdentifier(ByteSink &result)
Definition: ByteSource.h:271
s32 GetParameterNumberFromTag(const char *tag) const
Definition: Parameter.h:1016
virtual ByteSerializable::Result ReadFrom(ByteSource &byteSource, s32 argument=0)
Definition: Parameter.h:871
virtual ByteSerializable::Result ReadFrom(ByteSource &byteSource, s32 argument=0)
Definition: Parameter.h:649
void Reset(T &atom) const
Definition: Parameter.h:1157
bool LoadU32(const T &atom, u32 &store) const
Routines to (attempt to) apply this parameter to any given atom.
Definition: Parameter.h:221
u64 GetBitsAsU64(const typename CC::ATOM_TYPE &a) const
Definition: VD.tcc:31
Definition: Parameter.h:42
u32 GetValueUnary() const
unary value
Definition: Parameter.h:531
bool LoadBool(const T &atom, bool &store) const
bool value
Definition: Parameter.h:267
s32 Read()
Definition: ByteSource.h:66
Definition: Parameter.h:45
const PARM * GetParameter(u32 index) const
Definition: Parameter.h:1055
u32 GetParameterCount() const
Definition: Parameter.h:969
Definition: Parameter.h:51
void Reset()
Definition: Parameter.h:1137
virtual ByteSerializable::Result PrintTo(ByteSink &byteSink, s32 argument=0)
Definition: Parameter.h:643
const char * GetName() const
Definition: Parameter.h:352
bool Scan(u64 &result)
Definition: ByteSource.cpp:7
s32 GetValueS32() const
s32 value
Definition: Parameter.h:505
Definition: Parameter.h:672
static bool ReadBit(const BV &bv, u32 bitnum)
Definition: BitField.h:175
Definition: ByteSerializable.h:45
s32 SkipWhitespace()
Definition: ByteSource.h:348
Definition: Parameter.h:715