Index

NAME

IndexSet_prm  -  parameters  for  initialization  of the IndexSet
hierarchy


INCLUDE

include "IndexSet_prm.h"

SYNTAX

 //-----------------------------------------------------------------------------
 class IndexSet_prm : public HandleId
 //-----------------------------------------------------------------------------
 {
 protected:
   StringList subclasses;  // name of all subclasses in the IndexSet hier.
   static Handle(IndexSet_prm) master;
   virtual IndexSet_prm* clone () { return new IndexSet_prm(); }
   IndexSet_prm ();

 public:

   static   IndexSet_prm* construct ();
   virtual ~IndexSet_prm () {}

   String index_set_storage; // index set type
   int  nsd;                 // number of space dimensions
   String index_set_string;  // index set description

   bool ok () const;
   bool operator != (const IndexSet_prm& indprm);
   void operator = (const IndexSet_prm& indprm);

   static  void defineStatic  (MenuSystem& menu, int level = MAIN);
   void define        (MenuSystem& menu, int level = MAIN)
   { defineStatic (menu, level); }
   void scan          (MenuSystem& menu);

   void scan  (Is is);
   void print (Os os) const;

   friend  Os& operator << (Os& os, const IndexSet_prm& indprm);
   friend  Is& operator >> (Is& is, IndexSet_prm& indprm);


   virtual IndexSet* create () const;
           const StringList& hier () const    { return subclasses; }
   static  const StringList& hierStatic ()    { return master->hier(); }
   static  void   registerPrmSubclass (IndexSet_prm& sc) { master.rebind (sc); }
   static  void unregisterPrmSubclass () { master.rebind (new IndexSet_prm()); }
 };


KEYWORDS

initialization, IndexSet, base class


DESCRIPTION

The class contains a collection of all the parameters that may be
needed  when the base class IndexSet is used to construct derived
objects.

The constructor without arguments is protected and can hence  not
be used.  Instead, parameter objects are created by the construct
function, e.g.,


Handle(IndexSet_prm) pm = IndexSet_prm::construct();
// illegal: IndexSet_prm pm;

Parameter classes have a static member master which is defined in
IndexSet_prm.cpp  to  point to a IndexSet_prm object with default
values.  Users can develop new subclasses in the IndexSet hierar­
chy  and  then  derive  a subclass IndexSet2_prm of IndexSet_prm.
With the registerPrmSubclass function, they can register the  new
subclass  IndexSet2_prm  with  the  result that the master handle
points to a IndexSet2_prm object.  The Diffpack libraries  always
use  handles  to IndexSet_prm objects, created by the static con­
struct function. Since construct asks the master object to  clone
itself  (cf.  clone), every Handle(IndexSet_prm) declaration will
lead to a handle pointing to the  registered  type  of  parameter
object. This means that the libraries can "see" subclasses in new
modules created by users, without the need to adjust  or  compile
the libraries (!).

To  write  a subclass IndexSet2_prm of IndexSet_prm, just add the
new class names in the IndexSet hierarchy  in  the  IndexSet2_prm
constructor,  redefine  clone  to  take  a new IndexSet2_prm, and
redefine create:

IndexSet* IndexSet2_prm:: create () const {
  IndexSet* ptr = NULL;
  if (subclass_name == "MySpecialClass")
    ptr = new MySpecialClass();
  else if (subclass_name == "MySpecialClass2")
    ptr = new MySpecialClass2();
  else // not among the classes managed by this create function
    ptr = IndexSet_prm::create();
  return ptr;



MEMBER FUNCTIONS

ok  - returns true if the parameters are consistent.

operator !=  - checks for equality member by member.  If  one  or
more items differ, the value true is returned.

operator =  - assigns values from the specified parameter object,
member by member.

defineStatic  and  define  - builds a submenu for  initialization
of  the  parameters  and  links  it  to  the specified MenuSystem
object.

scan  - read input from an Is or form a MenuSystem  and  initial­
izes the object. An operator>> is also available.

print   -  prints the contents of the object to an Os.  An opera­
tor<< is also available.

create - creates a subclass object in the IndexSet hierarchy with
name  specified by the string subclass_name.  Can be redefined in
subclasses of IndexSet_prm if the IndexSet hierarchy is  extended
in a new module.

hier - returns a list with the names of all the subclasses in the
IndexSet hierarchy.

hierStatic - a version of hier that can be called without  having
a  IndexSet_prm object. Useful in defineStatic functions for pro­
viding a list of all the possible choices of a subclass names.

registerPrmSubclass - allows a user to register his own  subclass
of  IndexSet_prm  as  the  version of the parameter class for the
IndexSet hierarchy to be used by the Diffpack libraries.

unregisterPrmSubclass - resets the version of the parameter class
for the IndexSet hierarchy, to be used by the Diffpack libraries,
back to the default choice IndexSet_prm.




EXAMPLE

Here is a typical use of a parameter class:

// Have some Handle(X) x that we want to rebind to some
// user-chosen subclass object in the X hierarchy.
// The name of the subclass, plus all paramters necessary
// to create the subclass object, are contained in an
// X_prm object.

// a menu item related to the name of the subclass of X:
menu.addItem (level, "X class", "X_class", "sublcass object in  X
hier.",
              "Y", validationString(X_prm::hierStatic()));

// declare an X_prm object:
Handle(X_prm) xpm = X_prm::construct()
or Handle(X_prm) xpm; xpm.rebind (X_prm::construct());

// load menu answer:
xpm->scan(menu);

// create subclass:
x.rebind (xpm->create());

// if we have the subclass name as a string name, we can  shorten
the code:
Handle(X_prm) xpm = X_prm::construct()
xpm->subclass_name = name;
x.rebind (xpm->create());

Notice that we do not use new X_prm, but X_prm::construct instead
(many  of  the  parameter classes in Diffpack have protected con­
structors, forcing programmers to use construct).

The set of statements above will work even if the user makes  his
own  module, adds an X2_prm class, derived from X_prm, and regis­
ters X2_prm (the construct, hierStatic, and create functions will
then work with all the X_prm items and the X2_prm items).


SEE ALSO

class IndexSet


DEVELOPED BY

Numerical Objects AS


AUTHOR

Are Magnus Bruaset, Numerical Objects AS