MFMv2.0.10
Movable Feast Machine Simulator 2.0.10
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Parameter.h
Go to the documentation of this file.
1 /* -*- mode:C++ -*- */
2 /*
3  Parameter.h A configurable parameter usable for Elements and Atoms
4  Copyright (C) 2014 The Regents of the University of New Mexico. All rights reserved.
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 2.1 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this library; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
19  USA
20 */
21 
29 #ifndef PARAMETER_H
30 #define PARAMETER_H
31 
32 #include "ByteSerializable.h"
34 #include "Util.h"
35 #include "VD.h"
36 #include "Atom.h"
37 
38 namespace MFM
39 {
40  template <class CC> class Element; // FORWARD
41 
42  template <class CC> class AtomicParameter; // FORWARD
43  template <class CC> class ElementParameter; // FORWARD
44 
45  template <class PARM> class Parameters; // FORWARD
46 
47  template <class CC> class AtomicParameters; // FORWARD
48  template <class CC> class ElementParameters; // FORWARD
49 
50  template <class CC>
51  class Parameter : public ByteSerializable
52  {
53  private:
54  typedef typename CC::ATOM_TYPE T;
55 
59  const VD m_vDesc;
60 
69  const char * m_tag;
70 
75  const char * m_name;
76 
81  const char * m_description;
82 
83  public:
84  u32 GetType() const
85  {
86  return m_vDesc.m_type;
87  }
88 
89  s32 GetMin() const
90  {
91  return m_vDesc.GetMin();
92  }
93 
94  s32 GetDefault() const
95  {
96  return m_vDesc.GetDefault();
97  }
98 
99  s32 GetMax() const
100  {
101  return m_vDesc.GetMax();
102  }
103 
104  u32 GetRange() const
105  {
106  return GetMax() - GetMin() + 1;
107  }
108 
109  u32 MapValue(u32 max, s32 val) const
110  {
111  val = CLAMP(GetMin(), GetMax(), val);
112 
113  u32 zval = (u32) (val - GetMin());
114 
115  return zval * max / GetRange();
116  }
117 
118  virtual void Print(ByteSink & bs)
119  {
120  bs.Printf("Parameter[%s](\"%s\",\"%s\",\"%s\",%d,%d,%d)",
121  VD::GetTypeName(this->GetType()),
122  this->GetName(),
123  this->GetTag(),
124  this->GetDescription(),
125  this->GetMin(),
126  this->GetDefault(),
127  this->GetMax());
128  }
129 
130  void PrintValue(ByteSink &bs, const T & atom)
131  {
132  switch (this->GetType())
133  {
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);
139  }
140  }
141 
142  virtual bool ReadValue(ByteSource &bs, T & atom)
143  {
144  switch (this->GetType())
145  {
146  case VD::U32:
147  {
148  u32 val;
149  if (!bs.Scan(val)) return false;
150  m_vDesc.SetValueU32<CC>(atom,val);
151  return true;
152  }
153  case VD::S32:
154  {
155  s32 val;
156  if (!bs.Scan(val)) return false;
157  m_vDesc.SetValueS32<CC>(atom,val);
158  return true;
159  }
160  case VD::BOOL:
161  {
162  OString16 temp;
163  if (!bs.ScanIdentifier(temp)) return false;
164  if (temp.Equals("true"))
165  {
166  m_vDesc.SetValueBool<CC>(atom,true);
167  }
168  else if (temp.Equals("false"))
169  {
170  m_vDesc.SetValueBool<CC>(atom,false);
171  }
172  else
173  {
174  return false;
175  }
176  return true;
177  }
178  case VD::UNARY:
179  {
180  u32 val;
181  if (!bs.Scan(val)) return false;
182  m_vDesc.SetValueUnary<CC>(atom,val);
183  return true;
184  }
185  default: FAIL(ILLEGAL_STATE);
186  }
187  }
188 
191 
192  s32 GetBitsAsS32(const T& atom) const
193  {
194  return m_vDesc.GetBitsAsS32<CC>(atom);
195  }
196 
197  void SetBitsAsS32(T& atom, const s32 val) const
198  {
199  m_vDesc.SetBitsAsS32<CC>(atom, val);
200  }
201 
204 
205  u64 GetBitsAsU64(const T& atom) const
206  {
207  return m_vDesc.GetBitsAsU64<CC>(atom);
208  }
209 
210  void SetBitsAsU64(T& atom, const u64 val) const
211  {
212  m_vDesc.SetBitsAsU64<CC>(atom, val);
213  }
214 
217 
220 
221  bool LoadU32(const T& atom, u32 & store) const
222  {
223  if (this->GetType()==VD::U32)
224  {
225  store = m_vDesc.GetValueU32<CC>(atom);
226  return true;
227  }
228  return false;
229  }
230 
231  void StoreU32(T& atom, const u32 val) const
232  {
233  if (this->GetType()==VD::U32)
234  {
235  this->m_vDesc.SetValueU32(atom, val);
236  return true;
237  }
238  return false;
239  }
240 
243 
244  bool LoadS32(const T& atom, s32 & store) const
245  {
246  if (this->GetType()==VD::S32)
247  {
248  store = this->m_vDesc.GetValueS32(atom);
249  return true;
250  }
251  return false;
252  }
253 
254  void StoreS32(T& atom, const s32 val) const
255  {
256  if (this->GetType()==VD::S32)
257  {
258  this->m_vDesc.SetValueS32(atom, val);
259  return true;
260  }
261  return false;
262  }
263 
266 
267  bool LoadBool(const T& atom, bool & store) const
268  {
269  if (this->GetType()==VD::BOOL)
270  {
271  store = m_vDesc.GetValueBool<CC>(atom);
272  return true;
273  }
274  return false;
275  }
276 
277  void StoreBool(T& atom, const bool val) const
278  {
279  if (this->GetType()==VD::BOOL)
280  {
281  this->m_vDesc.SetValueBool(atom, val);
282  return true;
283  }
284  return false;
285  }
286 
289 
290  bool LoadUnary(const T& atom, u32 & store) const
291  {
292  if (this->GetType()==VD::UNARY)
293  {
294  store = this->m_vDesc.GetValueUnary(atom);
295  return true;
296  }
297  return false;
298  }
299 
300  void StoreUnary(T& atom, const u32 val) const
301  {
302  if (this->GetType()==VD::UNARY)
303  {
304  this->m_vDesc.SetValueUnary(atom, val);
305  return true;
306  }
307  return false;
308  }
309 
328  Parameter(const VD & vd, const char* tag, const char* name, const char* description) ;
329 
330  const VD & GetVD() const
331  {
332  return m_vDesc;
333  }
334 
341  const char* GetTag() const
342  {
343  return m_tag;
344  }
345 
352  const char* GetName() const
353  {
354  return m_name;
355  }
356 
363  const char* GetDescription() const
364  {
365  return m_description;
366  }
367  };
368 }
369 
370 namespace MFM
371 {
372  template <class CC> class Parameters; // FORWARD
373 
374  template <class CC>
375  class ElementParameter : public Parameter<CC>
376  {
377  typedef Parameter<CC> Super;
378  typedef typename CC::ATOM_TYPE T;
379  typedef typename CC::PARAM_CONFIG P;
380 
381  friend class Parameters< ElementParameter<CC> >;
382  ElementParameter * m_next;
383 
384  T m_storage;
385 
386  enum {
387  BPA = P::BITS_PER_ATOM,
388  PARM_LENGTH = 32,
389  START_POS = BPA - PARM_LENGTH,
390 
391  LONG_PARM_LENGTH = 64,
392  LONG_START_POS = BPA - LONG_PARM_LENGTH
393 
394  };
395 
396  static const VD MakeVD(u32 type, s32 min, s32 vdef, s32 max)
397  {
398  VD::AssertValidType(type);
399  return VD(type, PARM_LENGTH, START_POS, min, vdef, max);
400  }
401 
402  static const VD MakeLongVD(u64 vdef)
403  {
404  return VD(VD::BITS, LONG_PARM_LENGTH, LONG_START_POS, vdef);
405  }
406 
407  public:
408  // Make BitFields for faster access to the element storage
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;
415 
416  const T & GetAtom() const
417  {
418  return m_storage;
419  }
420 
421  T & GetAtom()
422  {
423  return m_storage;
424  }
425 
426  void PrintValue(ByteSink &bs)
427  {
428  Super::PrintValue(bs, m_storage);
429  }
430 
431  virtual bool ReadValue(ByteSource &bs)
432  {
433  return Super::ReadValue(bs, m_storage);
434  }
435 
436  ElementParameter * GetNextParameter()
437  {
438  return m_next;
439  }
440 
441  const ElementParameter * GetNextParameter() const
442  {
443  return m_next;
444  }
445 
446  ElementParameter(Element<CC> * elt, u32 type, const char * tag,
447  const char * name, const char * description,
448  s32 min, s32 vdef, s32 max) ;
449 
450  ElementParameter(Element<CC> * elt, u32 type, const char * tag,
451  const char * name, const char * description,
452  u64 vdef) ;
453 
456 
457  s32 GetBitsAsS32() const
458  {
459  return GetBitsAsS32(m_storage);
460  }
461 
462  void SetBitsAsS32(const s32 val)
463  {
464  Parameter<CC>::SetBitsAsS32(m_storage, val);
465  }
466 
467  u64 GetBitsAsU64() const
468  {
469  return GetBitsAsU64(m_storage);
470  }
471 
472  void SetBitsAsU64(const u64 val)
473  {
474  Parameter<CC>::SetBitsAsU64(m_storage, val);
475  }
476 
477  virtual void Reset()
478  {
479  if (this->GetVD().GetType()==VD::BITS)
480  {
481  this->SetBitsAsU64(this->GetVD().GetLongDefault());
482  }
483  else
484  {
485  this->SetBitsAsS32(this->GetVD().GetDefault());
486  }
487  }
488 
491 
492  u32 GetValueU32() const
493  {
494  return FieldU32::GetValue(m_storage);
495  }
496 
497  void SetValueU32(const u32 val)
498  {
499  FieldU32::SetValue(m_storage, val);
500  }
501 
504 
505  s32 GetValueS32() const
506  {
507  return FieldS32::GetValue(m_storage);
508  }
509 
510  void SetValueS32(const s32 val)
511  {
512  FieldS32::SetValue(m_storage, val);
513  }
514 
517 
518  bool GetValueBool() const
519  {
520  return FieldBool::GetValue(m_storage);
521  }
522 
523  void SetValueBool(const bool val)
524  {
525  FieldBool::SetValue(m_storage, val);
526  }
527 
530 
531  u32 GetValueUnary() const
532  {
533  return FieldUnary::GetValue(m_storage);
534  }
535 
536  void SetValueUnary(const u32 val) const
537  {
538  FieldUnary::SetValue(m_storage, val);
539  }
540 
543 
544  u64 GetValueBits() const
545  {
546  u64 val;
547  FieldBits::Load(m_storage, val);
548  return val;
549  }
550 
551  void SetValueBits(const u64 val) const
552  {
553  FieldBits::SetValue(m_storage, val);
554  }
555  };
556 
557  template <class CC>
559  {
560  public:
561  ElementParameterU32(Element<CC> * elt, const char * tag,
562  const char * name, const char * description,
563  u32 min, u32 vdef, u32 max) ;
564  u32 GetValue() const
565  {
566  return this->GetValueU32();
567  }
568  void SetValue(u32 val)
569  {
570  return this->SetValueU32(val);
571  }
572 
573  virtual ByteSerializable::Result PrintTo(ByteSink & byteSink, s32 argument = 0)
574  {
575  byteSink.Printf("%u", this->GetValue());
576  return ByteSerializable::SUCCESS;
577  }
578 
579  virtual ByteSerializable::Result ReadFrom(ByteSource & byteSource, s32 argument = 0)
580  {
581  u32 val;
582  if (byteSource.Scanf("%u", &val) != 1)
583  {
584  return ByteSerializable::FAILURE;
585  }
586  this->SetValue(val);
587  return ByteSerializable::SUCCESS;
588  }
589 
590  };
591 
592  template <class CC>
594  {
595  public:
596  ElementParameterS32(Element<CC> * elt, const char * tag,
597  const char * name, const char * description,
598  s32 min, s32 vdef, s32 max) ;
599  s32 GetValue() const
600  {
601  return this->GetValueS32();
602  }
603  void SetValue(s32 val)
604  {
605  return this->SetValueS32(val);
606  }
607 
608  virtual ByteSerializable::Result PrintTo(ByteSink & byteSink, s32 argument = 0)
609  {
610  byteSink.Printf("%d", this->GetValue());
611  return ByteSerializable::SUCCESS;
612  }
613 
614  virtual ByteSerializable::Result ReadFrom(ByteSource & byteSource, s32 argument = 0)
615  {
616  u32 val;
617  if (byteSource.Scanf("%d", &val) != 1)
618  {
619  return ByteSerializable::FAILURE;
620  }
621  this->SetValue(val);
622  return ByteSerializable::SUCCESS;
623  }
624 
625  };
626 
627  template <class CC>
629  {
630  public:
631  ElementParameterBool(Element<CC> * elt, const char * tag,
632  const char * name, const char * description,
633  bool vdef) ;
634  bool GetValue() const
635  {
636  return this->GetValueBool();
637  }
638  void SetValue(bool val)
639  {
640  return this->SetValueBool(val);
641  }
642 
643  virtual ByteSerializable::Result PrintTo(ByteSink & byteSink, s32 argument = 0)
644  {
645  byteSink.Printf("%s", this->GetValue() ? "true" : "false");
646  return ByteSerializable::SUCCESS;
647  }
648 
649  virtual ByteSerializable::Result ReadFrom(ByteSource & byteSource, s32 argument = 0)
650  {
651  OString16 temp;
652  if (byteSource.ScanIdentifier(temp))
653  {
654  return ByteSerializable::FAILURE;
655  }
656  if (temp.Equals("true"))
657  {
658  this->SetValue(true);
659  return ByteSerializable::SUCCESS;
660  }
661  if (temp.Equals("false"))
662  {
663  this->SetValue(false);
664  return ByteSerializable::SUCCESS;
665  }
666  return ByteSerializable::FAILURE;
667  }
668 
669  };
670 
671  template <class CC, u32 LENGTH>
673  {
674  typedef typename CC::ATOM_TYPE T;
675  typedef typename CC::PARAM_CONFIG P;
676 
677  enum {
678  BPA = P::BITS_PER_ATOM,
679  START_POS = BPA - LENGTH
680  };
681  typedef BitVector<BPA> BV;
683 
684  public:
685  ElementParameterBits(Element<CC> * elt, const char * tag,
686  const char * name, const char * description,
687  u64 vdef) ;
688  u64 GetValue() const
689  {
690  u64 val;
691  FieldBitsLength::Load(this->GetAtom(), val);
692  return val;
693  }
694 
695  void SetValue(u64 val)
696  {
697  FieldBitsLength::SetValue(this->GetAtom(), val);
698  }
699 
700  void ClearBit(u32 bitnum)
701  {
702  FieldBitsLength::ClearBit(this->GetAtom(), bitnum);
703  }
704  void SetBit(u32 bitnum)
705  {
706  FieldBitsLength::SetBit(this->GetAtom(), bitnum);
707  }
708  bool GetBit(u32 bitnum) const
709  {
710  return FieldBitsLength::ReadBit(this->GetAtom(), bitnum);
711  }
712  };
713 
714  template <class CC, u32 SITES>
716  {
717  public:
718  ElementParameterNeighborhood(Element<CC> * elt, const char * tag,
719  const char * name, const char * description,
720  u64 vdef) :
721  ElementParameterBits<CC,SITES>(elt, tag, name, description, vdef)
722  { }
723 
724  virtual ByteSerializable::Result PrintTo(ByteSink & byteSink, s32 argument = 0)
725  {
726  return PrintU64AsNeighborhood(byteSink, this->GetValue());
727  }
728 
729  virtual ByteSerializable::Result PrintU64AsNeighborhood(ByteSink & byteSink, u64 nghb)
730  {
731  byteSink.Print("[");
732  bool firstOut = false;
733  u32 start = SITES;
734  for (u32 i = 0; i <= SITES; ++i) // '<=' for one extra loop at end
735  {
736  bool bitvalue = false;
737  if (i < SITES)
738  {
739  bitvalue = (nghb>>((SITES-1)-i))&1;
740  }
741 
742  if (bitvalue)
743  {
744  if (start == SITES)
745  {
746  // Starting a run
747  start = i;
748  }
749  }
750  else
751  {
752  if (start != SITES)
753  {
754  // Ending a run
755  if (firstOut)
756  {
757  byteSink.Print(",");
758  }
759  else
760  {
761  firstOut = true;
762  }
763  byteSink.Print(start);
764  if (start < i-1)
765  {
766  byteSink.Printf("-%d", i-1);
767  }
768  start = SITES;
769  }
770  }
771  }
772  byteSink.Print("]");
773  return ByteSerializable::SUCCESS;
774  }
775 
776  virtual ByteSerializable::Result ReadFrom(ByteSource & byteSource, s32 argument = 0)
777  {
778  u64 ngb;
779  ByteSerializable::Result res = ReadNeighborhoodAsU64(byteSource, ngb);
780  if (res == ByteSerializable::SUCCESS)
781  {
782  this->SetValue(ngb);
783  }
784  return res;
785  }
786 
787  virtual ByteSerializable::Result ReadNeighborhoodAsU64(ByteSource & byteSource, u64 & ngb)
788  {
789  const ByteSerializable::Result FAIL = ByteSerializable::FAILURE;
790 
791  byteSource.SkipWhitespace();
792  if (byteSource.Read() != '[')
793  {
794  return FAIL;
795  }
796  u64 val = 0;
797  while (true)
798  {
799  byteSource.SkipWhitespace();
800  if (byteSource.Read() == ']')
801  {
802  ngb = val;
803  return ByteSerializable::SUCCESS;
804  }
805  byteSource.Unread();
806  s32 start;
807  if (!byteSource.Scan(start))
808  {
809  return FAIL;
810  }
811  if (start < 0 || start >= (s32) SITES)
812  {
813  return FAIL;
814  }
815  s32 end = start;
816  byteSource.SkipWhitespace();
817  s32 delim = byteSource.Read();
818  if (delim == '-')
819  {
820  if (!byteSource.Scan(end))
821  {
822  return FAIL;
823  }
824  if (end < 0 || end >= (s32) SITES || end < start)
825  {
826  return FAIL;
827  }
828  byteSource.SkipWhitespace();
829  delim = byteSource.Read();
830  }
831  for (s32 bit = start; bit <= end; ++bit)
832  {
833  val |= 1L<<((SITES-1)-bit);
834  }
835  if (delim != ',')
836  {
837  if (delim == ']')
838  {
839  byteSource.Unread();
840  }
841  else
842  {
843  return FAIL;
844  }
845  } // else go around again
846  }
847  }
848 
849  bool ReadValue(ByteSource &bs)
850  {
851  return ReadFrom(bs) == ByteSerializable::SUCCESS;
852  }
853 
854  };
855 
856  template <class CC>
857  class AtomicParameter : public Parameter<CC>
858  {
859  typedef Parameter<CC> Super;
860  typedef typename CC::ATOM_TYPE T;
861 
862  friend class Parameters< AtomicParameter<CC> >;
863  AtomicParameter * m_next;
864 
865  public:
866  virtual ByteSerializable::Result PrintTo(ByteSink & byteSink, s32 argument = 0)
867  {
868  return ByteSerializable::UNSUPPORTED;
869  }
870 
871  virtual ByteSerializable::Result ReadFrom(ByteSource & byteSource, s32 argument = 0)
872  {
873  return ByteSerializable::UNSUPPORTED;
874  }
875 
876  AtomicParameter * GetNextParameter()
877  {
878  return m_next;
879  }
880 
881  const AtomicParameter * GetNextParameter() const
882  {
883  return m_next;
884  }
885 
886  virtual void Print(ByteSink & io)
887  {
888  io.Print("AP(");
889  Super::Print(io);
890  io.Print(")");
891  }
892 
893  virtual void Print(ByteSink & io, const T & atom) const = 0;
894 
895  virtual void Reset(T & atom) const = 0;
896 
897  AtomicParameter<CC>(Element<CC> * pl, const char * tag,
898  const char * name, const char * description,
899  const VD & vdesc) ;
900  };
901 
902  template <class CC, VD::Type VT, u32 LEN, u32 POS>
904  {
905  public:
906  typedef typename CC::ATOM_TYPE T;
907  typedef typename CC::PARAM_CONFIG P;
908 
911 
912  // Lift BitField properties (particularly END) up to parameter level
913  enum
914  {
915  BITS = Field::BITS,
916  START = Field::START,
917  LENGTH = Field::LENGTH,
918  END = Field::END
919  };
920 
921  typedef typename VTypeToType<VT>::TYPE VTYPE;
922 
923  const VTYPE m_vdefault; // public, but const, whatever
924 
925  AtomicParameterType(Element<CC> * pl, const char * tag,
926  const char * name, const char * description,
927  const VTYPE & vmin, const VTYPE & vdefault, const VTYPE & vmax) ;
928 
929  VTYPE GetValue(const T & atom) const
930  {
931  return Field::GetValue(atom);
932  }
933  void SetValue(T & atom, const VTYPE val) const
934  {
935  Field::SetValue(atom,val);
936  }
937 
938  virtual void Reset(T & atom) const
939  {
940  SetValue(atom, m_vdefault);
941  }
942 
943  virtual void Print(ByteSink & io, const T & atom) const
944  {
945  atom.Print(io);
946  }
947 
948  };
949 
950  template <class PARM>
951  class Parameters
952  {
953  protected:
954 
955  PARM* m_firstParameter;
956 
957  public:
958  Parameters() : m_firstParameter(0)
959  { }
960 
969  u32 GetParameterCount() const
970  {
971  u32 count = 0;
972  PARM* p = m_firstParameter;
973  while (p)
974  {
975  ++count;
976  p = p->m_next;
977  }
978  return count;
979  }
980 
992  s32 GetParameterNumber(const PARM * ap) const
993  {
994  MFM_API_ASSERT_NONNULL(ap);
995  u32 number = 0;
996  for (PARM * p = m_firstParameter; p; ++number, p = p->m_next)
997  {
998  if (p == ap)
999  {
1000  return (s32) number;
1001  }
1002  }
1003  return -1;
1004  }
1005 
1016  s32 GetParameterNumberFromTag(const char* tag) const
1017  {
1018  MFM_API_ASSERT_NONNULL(tag);
1019  u32 number = 0;
1020  for (const PARM* p = m_firstParameter; p; ++number, p = p->m_next)
1021  {
1022  if (!strcmp(tag, p->GetTag()))
1023  {
1024  return (s32) number;
1025  }
1026  }
1027  return -1;
1028  }
1029 
1037  const PARM* GetFirstParameter() const
1038  {
1039  return m_firstParameter;
1040  }
1041 
1055  const PARM* GetParameter(u32 index) const
1056  {
1057  PARM* p = m_firstParameter;
1058  s32 left = (s32) index;
1059 
1060  while (p && --left >= 0)
1061  {
1062  p = p->m_next;
1063  }
1064 
1065  if (!p)
1066  {
1067  FAIL(OUT_OF_BOUNDS);
1068  }
1069  return p;
1070  }
1071 
1085  PARM * GetParameter(u32 index)
1086  {
1087  // Safe. But, barf.
1088  return
1089  const_cast<PARM *>(static_cast<const Parameters*>(this)->GetParameter(index));
1090  }
1091 
1104  void AddParameter(PARM * np)
1105  {
1106  if (!np)
1107  {
1108  FAIL(NULL_POINTER);
1109  }
1110 
1111  if (np->m_next) // Already added somewhere
1112  {
1113  FAIL(ILLEGAL_ARGUMENT);
1114  }
1115 
1116  PARM ** pPtr = &m_firstParameter;
1117  for (PARM * p = *pPtr; p; pPtr = &p->m_next, p = p->m_next)
1118  {
1119  if (p == np)
1120  {
1121  FAIL(DUPLICATE_ENTRY);
1122  }
1123  }
1124 
1125  *pPtr = np;
1126  }
1127  };
1128 
1129  template<class CC>
1130  class ElementParameters : public Parameters< ElementParameter<CC> >
1131  {
1132  public:
1133 
1137  void Reset()
1138  {
1139  for (ElementParameter<CC> * p = this->m_firstParameter; p; p = p->m_next)
1140  {
1141  p->Reset();
1142  }
1143  }
1144 
1145  };
1146 
1147  template<class CC>
1148  class AtomicParameters : public Parameters< AtomicParameter<CC> >
1149  {
1150  public:
1151  typedef typename CC::ATOM_TYPE T;
1152 
1157  void Reset(T & atom) const
1158  {
1159  for (AtomicParameter<CC> * p = this->m_firstParameter; p; p = p->m_next)
1160  {
1161  p->Reset(atom);
1162  }
1163  }
1164  };
1165 }
1166 
1167 #include "Parameter.tcc"
1168 
1169 #endif /* PARAMETER_H */
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
Definition: VD.h:44
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
Definition: VD.h:278
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: Atom.h:45
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: P1Atom.h:50
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
Definition: Atom.h:43
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