ClassUtils              package:methods              R Documentation

_U_t_i_l_i_t_i_e_s _f_o_r _M_a_n_a_g_i_n_g _C_l_a_s_s _D_e_f_i_n_i_t_i_o_n_s

_D_e_s_c_r_i_p_t_i_o_n:

     These are various functions to support the definition and use of
     formal classes.  Most of them are rarely suitable to be called
     directly.

_U_s_a_g_e:

     testVirtual(properties, extends, prototype)

     makePrototypeFromClassDef(properties, prototype, extends)

     newEmptyObject()

     completeClassDefinition(Class, ClassDef)

     getFromClassDef(ClassDef, what)

     setInClassDef(ClassDef, what, value, synchronize=TRUE)

     synchronizeClassDef(ClassDef)

     getProperties(ClassDef)

     setProperties(ClassDef, value)

     getSlots(x, complete = TRUE)

     getExtends(ClassDef)

     getAccess(ClassDef)

     getAllSuperClasses(ClassDef)

     superClassDepth(ClassDef, soFar)

     setExtends(ClassDef, value)

     getPrototype(ClassDef)

     setPrototype(ClassDef, value)

     getVirtual(ClassDef)

     isVirtualClass(Class)

     setVirtual(ClassDef, value)

     getSubclasses(ClassDef)

     setSubclasses(ClassDef, value)

     getClassName(ClassDef)

     setClassName(ClassDef, value)

     assignClassDef(Class, def, where=.GlobalEnv)

     newClassEnvironment(name, properties, extends, prototype, subclasses,
                      virtual, validity, access)

     newBasic(Class, ..., .Force=FALSE)

     makeExtends(extends)

     reconcilePropertiesAndPrototype(name, properties, prototype, extends)

     tryNew(Class)

     empty.dump()

     showClass(Class, complete=TRUE, propertiesAreCalled="Properties")

     showExtends(ext, printTo = stdout())

     print.classRepEnvironment(x, ...)

     print.environment(x, ...)

     getFromClassMetaData(name)

     assignToClassMetaData(name, value)

     removeFromClassMetaData(name)

     extendsCoerce(fromClass, Class, formFunction)

     extendsReplace(objectClass, Class)

     findExtends(class1, class2)

     completeExtends(ClassDef, soFar)

     classMetaName(name)

     methodsMetaName(prefix, name)

     as.data.frame(x, row.names=NULL, optional=FALSE)

     requireMethods(functions, signature, message)

     checkSlotAssignment(obj, name, value)

     defaultPrototype()

     isClassDef(object)

     validSlotNames(names)

_S_u_m_m_a_r_y _o_f _F_u_n_c_t_i_o_n_s:

     `_t_e_s_t_V_i_r_t_u_a_l': Test for a Virtual Class. Figures out, as well as
          possible, whether the class with these properties, extension,
          and prototype is a virtual class. Can be forced to be virtual
          by extending "VIRTUAL".  

          Otherwise, a class is virtual only if it has no slots,
          extends no non-virtual classes, and has a `NULL' Prototype.


     `_m_a_k_e_P_r_o_t_o_t_y_p_e_F_r_o_m_C_l_a_s_s_D_e_f': Makes the prototype implied by the
          class definition.

          The following three rules are applied in this order.

          If the class has slots, then the prototype for each slot is
          used by default, but a corresponding element in the
          explicitly supplied prototype, if there is one, is used
          instead (but it must be coercible to the class of the slot).

          If there are no slots but a non-null prototype was specified,
          this is returned.

          If there is a single non-virtual superclass (a class in the
          extends list), then its prototype is used.

          If all three of the above fail, the prototype is `NULL'.


     `_n_e_w_E_m_p_t_y_O_b_j_e_c_t': Utility function to create an empty object into
          which slots can be set.

          Currently just creates an empty list with class `"NULL"'.

          Later version should create a special object reference that
          marks an object currently with no slots and no data.


     `_c_o_m_p_l_e_t_e_C_l_a_s_s_D_e_f_i_n_i_t_i_o_n': Completes the definition of `Class',
          relative to the current session.

          The completed definition is stored in the session's class
          metadata, to be retrieved the next time that getClass is
          called on this class, and is returned as the value of the
          call.

          If `ClassDef' is omitted, the initial definition is obtained
          from the first package having a meta-object for this class.


     `_g_e_t_F_r_o_m_C_l_a_s_s_D_e_f': Extracts one of the intrinsically defined class
          definition properties (".Properties", etc.)  Strictly a
          utility function.


     `_s_e_t_I_n_C_l_a_s_s_D_e_f': Set Property in Class Definition. Set one of the
          intrinsically defined class definition properties
          (".Properties", etc.)  Strictly a utility function.


     `_s_y_n_c_h_r_o_n_i_z_e_C_l_a_s_s_D_e_f': Does whatever is needed to synchronize
          information in the class definition.

          Basically computes derived information used to make object
          manipulations more efficient but that need to be revised if
          information changes.

          (Nothing at the moment)


     `_g_e_t_P_r_o_p_e_r_t_i_e_s': Extracts the class's Properties information from
          the class representation (only, not from the name of the
          class).


     `_s_e_t_P_r_o_p_e_r_t_i_e_s': Sets the class's Properties information given the
          class representation (only, not from the name of the class)


     `_g_e_t_S_l_o_t_s': Returns a named character vector.  The names are the
          names of the slots, the values are the classes of the
          corresponding slots.  If `complete' is `TRUE', all slots from
          all superclasses will be included.  The argument `x' can
          either be the name of a class or an object having that class.


     `_g_e_t_E_x_t_e_n_d_s': Extracts the class's Extends information from the
          class representation (only, not from the name of the class)

          Contrast with the `findExtends' and `is' functions, both of
          which use indirect information as well.


     `_g_e_t_A_l_l_S_u_p_e_r_C_l_a_s_s_e_s', `_s_u_p_e_r_C_l_a_s_s_D_e_p_t_h': Get the names of all the
          classes that this class definition extends.

          `getAllSuperClasses' is a utility function used to complete a
          class definition.  It returns all the superclasses reachable
          from this class, in breadth-first order (which is the order
          used for matching methods); that is, the first direct
          superclass followed by all its superclasses, then the next,
          etc.  (The order is relevant only in the case that some of
          the superclasses have multiple inheritance.)

          `superClassDepth', which is called from `getAllSuperClasses',
          returns the same information, but as a list with components
          `label' and `depth', the latter for the number of generations
          back each class is in the inheritance tree.  The argument
          `soFar' is used to avoid loops in the network of class
          relationships.


     `_s_e_t_E_x_t_e_n_d_s': set the class's Extends information given the class
          representation (only, not from the name of the class)


     `_g_e_t_P_r_o_t_o_t_y_p_e': extract the class's Prototype information from the
          class representation (only, not from the name of the class)


     `_g_e_t_A_c_c_e_s_s': extract the class's Access information from the class
          representation (only, not from the name of the class)


     `_s_e_t_P_r_o_t_o_t_y_p_e': set the class's Prototype information given the
          class representation (only, not from the name of the class)


     `_g_e_t_V_i_r_t_u_a_l': extract the class's Virtual information from the
          class representation (only, not from the name of the class)


     `_i_s_V_i_r_t_u_a_l_C_l_a_s_s': Is the named class a virtual class?  

          A class is virtual if explicitly declared to be, and also if
          the class is not formally defined.


     `_s_e_t_V_i_r_t_u_a_l': set the class's Virtual information given the class
          representation (only, not from the name of the class)


     `_g_e_t_S_u_b_c_l_a_s_s_e_s': extract the class's Subclasses information from
          the class representation (only, not from the name of the
          class)


     `_s_e_t_S_u_b_c_l_a_s_s_e_s': set the class's Subclasses information given the
          class representation (only, not from the name of the class)


     `_g_e_t_C_l_a_s_s_N_a_m_e': The internal property in the class definition for
          the class name.


     `_s_e_t_C_l_a_s_s_N_a_m_e': set the name of the class inside the class
          definition


     `_a_s_s_i_g_n_C_l_a_s_s_D_e_f': assign the definition of the class to the
          specially named object


     `_n_e_w_B_a_s_i_c': the implementation of the function `new' for basic
          classes that don't have a formal definition.  

          Any of these could have a formal definition, except for
          `Class="NULL"' (disallowed because `NULL' can't have
          attributes).  For all cases except `"NULL"', the class of the
          result will be set to `Class'.

          See `new' for the interpretation of the arguments.


     `_m_a_k_e_E_x_t_e_n_d_s': convert the argument to a list defining the
          extension mechanism.


     `_r_e_c_o_n_c_i_l_e_P_r_o_p_e_r_t_i_e_s_A_n_d_P_r_o_t_o_t_y_p_e': makes a list or a structure
          look like a prototype for the given class.

          Specifically, returns a structure with attributes
          corresponding to the slot names in properties and values
          taken from prototype if they exist there, from `new(classi)'
          for the class, `classi' of the slot if that succeeds, and
          `NULL' otherwise.

          The prototype may imply slots not in the properties list,
          since properties does not include inherited slots (these are
          left unresolved until the class is used in a session).


     `_t_r_y_N_e_w': Tries to generate a new element from this class, but if
          the attempt fails (as, e.g., when the class is undefined or
          virtual) just returns `NULL'. 

          This is inefficient and also not a good idea when actually
          generating objects, but is useful in the initial definition
          of classes.


     `_s_h_o_w_C_l_a_s_s': Print the information about a class definition.  

          If `complete' is `TRUE', include the indirect information
          about extensions.


     `_s_h_o_w_E_x_t_e_n_d_s': Print the elements of the list of extensions.  

          (Used also by `promptClass' to get the list of what and how
          for the extensions.)


     `_p_r_i_n_t._e_n_v_i_r_o_n_m_e_n_t', `_s_h_o_w_N_o_n_V_e_c_t_o_r': These routines provide a
          default printing mechanism for objects from non-vector
          classes, implemented as environments.  The
          `print.environment' function exists to intercept printing
          based on S3-style methods; it calls `showNonVector' to do the
          work.


     `_e_x_t_e_n_d_s_C_o_e_r_c_e', `_e_x_t_e_n_d_s_R_e_p_l_a_c_e': Returns the function to perform
          coercion or replacement, respectivelyl, based on the `is'
          relation between two classes.

          A method may be explicitly stored in the metadata or
          inferred.  If the latter, a function will always be
          constructed if explicit test and/or coerce methods (in a call
          to setIs) were encountered, or if `formFunction=TRUE'.  If
          `formFunction=FALSE', the purpose of the call is to determine
          if the relation is explicit or intrinsic (according to
          whether a function object is returned).


     `_f_i_n_d_E_x_t_e_n_d_s': Find the information that says whether class1
          extends class2, directly or indirectly.

          This can be either a logical value or an object containing
          various functions to test and/or coerce the relationship.


     `_c_o_m_p_l_e_t_e_E_x_t_e_n_d_s': complete the extends information in the class
          definition, by following transitive chains.

          Elements in the immediate extends list may be added and
          current elements may be replaced, either by replacing a
          conditional relation with an unconditional one, or by adding
          indirect relations.

          The resulting extends list is presented in depth-first order;
          that is, the first immediate superclass followed by all the
          indirect relations through it, then the next immediate
          superclass, etc.

          Depth first order is required for consistent elaboration of
          inherited methods during dispatch, because the method
          dispatcher stores the inherited method under the immediate
          class name.  Under rather obscure situations of multiple
          inheritance, the result could be ambiguous (depending on the
          order in which signatures are seen by the dispatcher for a
          particular generic function), unless searching is done depth
          first.

          Used recursively, with `soFar' defining what has been
          included in previous calls at this level.


     `_c_l_a_s_s_M_e_t_a_N_a_m_e': a name for the object storing this class's
          definition


     `_m_e_t_h_o_d_s_M_e_t_a_N_a_m_e': a name mangling device to simulate the
          meta-data in S4


     `_r_e_q_u_i_r_e_M_e_t_h_o_d_s': Require a subclass to implement methods for the
          generic functions, for this signature.

          For each generic, `setMethod' will be called to define a
          method that throws an error, with the supplied message.

          The `requireMethods' function allows virtual classes to
          require actual classes that extend them to implement methods
          for certain functions, in effect creating an API for the
          virtual class.

          Otherwise, default methods for the corresponding function
          would be called, resulting in less helpful error messages or
          (worse still) silently incorrect results.


     `_c_h_e_c_k_S_l_o_t_A_s_s_i_g_n_m_e_n_t': Check that the value provided is allowed
          for this slot, by consulting the definition of the class. 
          Called from the C code that assigns slots.

          For privileged slots (those that can only be set by accesor
          functions defined along with the class itself), the class
          designer may choose to improve efficiency by validating the
          value to be assigned in the accessor function and then
          calling `slot<-' with the argument `check=FALSE', to prevent
          the call to `checkSlotAssignment'.


     `_d_e_f_a_u_l_t_P_r_o_t_o_t_y_p_e': The prototype for a class which will have
          slots, is not a virtual  class, and does not extend one of
          the basic classes.  In future releases, this will likely be a
          non-vector R object type, but none of the current types (as
          of release 1.4) is suitable.


     `_S_e_s_s_i_o_n_C_l_a_s_s_M_e_t_a_D_a_t_a': Contains the name of the special table in
          which class information is cached during the session.


     `._I_n_i_t_B_a_s_i_c_C_l_a_s_s_e_s', `._I_n_i_t_M_e_t_h_o_d_s_L_i_s_t_C_l_a_s_s', `._s_e_t_C_o_e_r_c_e_G_e_n_e_r_i_c': These
          functions perform part of the initialization of classes and
          methods, and are called (only!) from `.First.lib'.


     `_i_s_C_l_a_s_s_D_e_f': Is `object' a representation of a class?


     `_v_a_l_i_d_S_l_o_t_N_a_m_e_s': Returns `names' unless one of the names is
          reserved, in which case there is an error.  (As of writing,
          `"class"' is the only reserved slot name.)


