//*-- Author : Valeriy Onuchin 11/09/2000 
//
//
////////////////////////////////////////////////////////////////////////////////
//
// rooModule class corresponds to d_Module class
//
// The class rooModule represents descriptors for modules in the schema of the
// federated database. An instance of rooModule is called a module descriptor.
// A module descriptor is both a descriptor and a scope. As a descriptor, 
// it provides information about a particular module, called its described 
// module. As a scope, it allows you to obtain descriptors for the entities 
// defined in the scope of the described module, either by looking up a 
// particular entity or by iterating through all entities in the module's 
// scope.
// 
//  You should never instantiate this class directly; instead:
//
//    Call the rooModule::top_level static member function to obtain a 
//    descriptor for the top-level module.
//
//    Call the resolve_module() member function of the top-level module's
//    descriptor to look up another module by name.
//
//    Call the named_modules_begin() member function of top-level module's
//    descriptor to get an iterator for all named modules.
//
////////////////////////////////////////////////////////////////////////////////
///
// d_Module is part of the ODMG standard.  It describes a domain of class
// descriptors in the database schema.  A d_Module in Objectivity can be
// the "default schema" (named "*") or a user-created "named schema."
//
// The top level module--that is, the default schema for the federated
// database--serves also as the name scope of the other modules, or named
// schemas.
//
// The function resolve_type() can be used to look up either name strings
// or type numbers, matching only entries which are types, casting the
// result in all cases to (const d_Type &).  The function resolve_class()
// can be used to look up either name strings or type numbers, matching
// only entries which are classes, and casting the result in all cases to
// (const d_Class &).  It takes an optional second integer argument which
// can be used to specify a particular version if the class was created
// using the Objectivity versioning feature.
//
// Looking up a name or type number in the top level module scope causes
// all other modules to be searched as well.
//
////////////////////////////////////////////////////////////////////////////////

#include "rooObjy.h"
#include <ooas.h>
#include <oo.h>

ClassImp(rooModule)

////////////////////////////////////////////////////////////////////////////////
rooModule* rooModule::fgTopLevel = 0;

//______________________________________________________________________________
 rooModule::rooModule()
{
   // default ctor. internal use only

   fImp = new d_Module();
}

//______________________________________________________________________________
 rooModule::~rooModule()
{
   // dtor. internal use only
   
   fImp = 0;
}

//______________________________________________________________________________
const rooModule & rooModule::top_level(ULong_t key)
{
   // Gets a descriptor for the top-level module in the federated database.
   //
   // The key with which the schema was last locked. This parameter can be
   // omitted if the schema is not currently locked.
   //
   // Returns: A module descriptor that provides information about the 
   //          top-level module. 
   //
   // If the federated database schema is currently locked, you must specify 
   // the appropriate key as the parameter to this member function. 
   // An AccessDenied error occurs if you attempt to access a locked schema 
   // without the correct key.
   //
   // Note that this member function returns a const object; if you want to 
   // call anynon-const member functions (for example, propose_new_class), 
   // you must cast the result to the type: d_Module &
   //
   // See also lock_schema()
   
   const d_Module& top = d_Module::top_level(key);
   if(!top) return 0;

   if(fgTopLevel) fgTopLevel->fImp=(void*)&top;
   else  fgTopLevel = new rooTopLevelModule((void*)&top);
   return *fgTopLevel;  
}

//______________________________________________________________________________
 rooTypeItr rooModule::defines_types_begin()
{
   // Gets an iterator for the types in the scope of the described module.
   //
   // Returns:
   //    A type iterator that finds all types in the scope of the described 
   //    module.
   //
   // If the described module is the top-level module, the returned iterator 
   // finds al classes and non-class types in the schema. If not, the returned
   // iterator finds all classes defined in the described module.
   //
   // See also: defines_types_end()

   rooTypeItr itr;
   if(!fImp) return itr;
   *((type_iterator*)itr.getImp()) =((d_Module*)fImp)->defines_types_begin();
   return itr;
}

//______________________________________________________________________________
 rooTypeItr rooModule::defines_types_end()
{
   // Gets an iterator representing the termination condition for iteration 
   // through the types defined in the described module's scope.
   //
   // You can compare the iterator returned by defines_types_begin with the 
   // one returned by this member function to test whether iteration has 
   // finished.
   
   rooTypeItr itr;
   if(!fImp) return itr;
   *((type_iterator*)itr.getImp()) =((d_Module*)fImp)->defines_types_end();
   return itr;
}

//______________________________________________________________________________
 UInt_t rooModule::id() const
{
   // Gets the unique ID that identifies the described module within its scope.

   return fImp ? ((d_Module*)fImp)->id() : 0;
}

//______________________________________________________________________________
 rooMetaObjectItr rooModule::defines_begin()
{
   // Gets an iterator for the entities in the scope of the described module.
   //
   // Returns:
   //      A descriptor iterator that finds all entities in the scope of the 
   //      described module.
   //
   // If the described module is the top-level module, the returned iterator 
   // finds all modules, classes, and non-class types in the schema. If not, 
   // the returned iterator finds all classes defined in the described module.
   // The returned iterator gets generic descriptors for each entity in the 
   // described module's scope. An alternative to calling this member 
   // function is to call more specific functions that find entities of some
   // particular kind.
   //
   // See also: defines_end() 
   
   rooMetaObjectItr itr;
   if(!fImp) return itr;
   *((meta_object_iterator*)itr.getImp()) = ((d_Module*)fImp)->defines_begin();
   return itr;
}

//______________________________________________________________________________
 rooMetaObjectItr rooModule::defines_end()
{
   // Gets an iterator representing the termination condition for iteration 
   // through the entities defined in the described module's scope.
   //
   // Returns:
   //    A descriptor iterator that is positioned after the last entity in 
   //    the described module's scope.
   //
   // You can compare the iterator returned by defines_begin() with the one 
   // returned by this member function to test whether iteration has finished.
   //
   
   rooMetaObjectItr itr;
   if(!fImp) return itr;
   *((meta_object_iterator*)itr.getImp()) = ((d_Module*)fImp)->defines_end();
   return itr;
}

//______________________________________________________________________________
const rooMetaObject & rooModule::resolve(const TString& mo,Int_t ver)
{
   // Looks up an entity in the described module's scope.
   // Parameters: 
   //          mo  - The name of the entity to be looked up.
   //          ver - The desired version of the entity named mo. 
   //                This optional parameter can be specified when looking up 
   //                a class that was created using the Objectivity/C++ 
   //                class-versioning feature.
   //
   // Returns:
   //          The descriptor for the entity in the described module's scope 
   //          with the specified name and version, or the null descriptor if 
   //          no such entity exists.
   //
   // If the described module is the top-level module, this member function can
   // look up any module, class, or non-class type in the schema. If not, it can
   // look up any class defined in the described module.
   // The returned generic descriptor can be cast to the appropriate descriptor
   // class (for example rooModule or rooClass). An alternative to calling this
   // member function is to call more specific functions that look up entities 
   // of a particular kind.
   //
   // See also: resolve_class(), resolve_module()
   //           resolve_proposed_class(), resolve_type()

   if(!fImp) return 0;
   d_Meta_Object& imd = ((d_Module*)fImp)->resolve(mo.Data(),ver);
   if(!imd) return 0;

   if(!fMetaObj) fMetaObj = new rooMetaObject((void*)&imd);
   else fMetaObj->setImp((void*)&imd);
   return *fMetaObj;
}

//______________________________________________________________________________
const rooType & rooModule::resolve_type(const TString& type)
{
   // Looks up a type in the described module's scope.
   // 
   // Returns: 
   //       The descriptor for the specified type in the described module's 
   //       scope, or the null descriptor if no such type exists.
   //
   // If the described module is the top-level module, this member function 
   // can look up any class or non-class type in the schema. If not, it can 
   // look up any class defined in the described module.
   // Typically this member function is used only to look up non-class types 
   // in the scope of the top-level module. The resolve_class member function 
   // is used instead of this member function to look up classes.
   //
   // See also:
   //          resolve()
   //          resolve_class()
   //          resolve_module()
   //          resolve_proposed_class()
      
   if(!fImp) return 0;
   d_Type& itp = ((d_Module*)fImp)->resolve_type(type.Data());
   if(!itp) return 0;

   if(!fType) fType = new rooType((void*)&itp);
   else fType->setImp((void*)&itp);
   return *fType;
}

//______________________________________________________________________________
const rooType & rooModule::resolve_type(Int_t type)
{
   // Looks up a type in the described module's scope.
   // 
   // Returns: 
   //       The descriptor for the specified type in the described module's 
   //       scope, or the null descriptor if no such type exists.
   //
   // If the described module is the top-level module, this member function 
   // can look up any class or non-class type in the schema. If not, it can 
   // look up any class defined in the described module.
   // Typically this member function is used only to look up non-class types 
   // in the scope of the top-level module. The resolve_class member function 
   // is used instead of this member function to look up classes.
   //
   // See also:
   //          resolve()
   //          resolve_class()
   //          resolve_module()
   //          resolve_proposed_class()
   
   if(!fImp) return 0;
   d_Type& itp = ((d_Module*)fImp)->resolve_type(type);
   if(!itp) return 0;

   if(!fType) fType = new rooType((void*)&itp);
   else fType->setImp((void*)&itp);
   return *fType;
}

//______________________________________________________________________________
const rooClass & rooModule::resolve_class(const TString& cl,Int_t ver) 
{
   // Looks up a class in the described module's scope.
   //
   // cl  - the class name to be looked up.
   // ver - the desired version of the class named cl. 
   // This optional parameter can be specified when looking up a class that 
   // was created using the Objectivity/C++ class-versioning feature.
   //
   // Returns:
   //       The descriptor for the specified class in the described module's
   //       scope, or the null descriptor if no such class exists.
   //
   // If the described module is the top-level module, this member function 
   // can look up any class in the schema. If not, it can look up any class 
   // defined in the described module.
   //
   // See also: 
   //          resolve()
   //          resolve_module()
   //          resolve_proposed_class()
   //          resolve_type()

   if(!fImp) return 0;
   const d_Class& rcl = ((d_Module*)fImp)->resolve_class(cl.Data(),ver);
   if(!rcl) return 0;

   if(!fClass) fClass = new rooClass((void*)&rcl);
   else fClass->setImp((void*)&rcl);
   return *fClass; 
}

//______________________________________________________________________________
const rooClass & rooModule::resolve_class(Int_t cl)
{
   // Looks up a class in the described module's scope.
   //
   // cl - the type number of the class to be looked up.
   //
   // Returns:
   //       The descriptor for the specified class in the described module's
   //       scope, or the null descriptor if no such class exists.
   //
   // If the described module is the top-level module, this member function 
   // can look up any class in the schema. If not, it can look up any class 
   // defined in the described module.
   //
   // See also: 
   //          resolve()
   //          resolve_module()
   //          resolve_proposed_class()
   //          resolve_type()

   if(!fImp) return 0;
   d_Class& icl = ((d_Module*)fImp)->resolve_class(cl);
   if(!icl) return 0;

   if(!fClass) fClass = new rooClass((void*)&icl);
   else fClass->setImp((void*)&icl);
   return *fClass;
}

//______________________________________________________________________________
const rooModule & rooModule::resolve_module(const TString& mod)
{
   // The function resolve_module() can be used to look up named schemas
   // (modules) in the scope of the top level module.  Lookup of any module
   // in the scope of a module other than the top level module will return
   // the null result.
   //
   // If the described module is the top-level module, this member function 
   // can look  up any module in the schema. If not, this member function 
   // returns the null descriptor (because named modules cannot contain other 
   // modules).
   //
   // See also: 
   //          resolve()
   //          resolve_class()
   //          resolve_proposed_class()
   //          resolve_type()
   
   if(!fImp) return 0;
   d_Module& imd = ((d_Module*)fImp)->resolve_module(mod.Data());
   if(!imd) return 0;

   if(!fModule) fModule = new rooModule((void*)&imd);
   else fModule->setImp((void*)&imd);
   return *fModule;
}

//______________________________________________________________________________
 rooModuleItr rooModule::named_modules_begin()
{
   // Gets an iterator for the modules defined in the described module's scope.
   //
   // Returns:
   //       A module iterator that finds all modules defined in the described 
   //       module.
   //
   // If the described module is the top-level module, the returned iterator 
   // finds all  other modules; otherwise, the returned iterator has an empty 
   // iteration set.
   //
   // See also: named_modules_end
   
   rooModuleItr itr;
   if(!fImp) return itr;
   *((module_iterator*)itr.getImp()) = ((d_Module*)fImp)->named_modules_begin();
   return itr;
}

//______________________________________________________________________________
 rooModuleItr rooModule::named_modules_end()
{
   // Gets an iterator representing the termination condition for iteration 
   // through the modules defined in the described module's scope.
   //
   // Returns:
   //       A module iterator that is positioned after the last module in 
   //       the described module's scope.
   //
   // You can compare the iterator returned by named_modules_begin with the
   // one returned by this member function to test whether iteration has 
   // finished.

   rooModuleItr itr;
   if(!fImp) return itr;
   *((module_iterator*)itr.getImp()) = ((d_Module*)fImp)->named_modules_end();
   return itr;
}

//______________________________________________________________________________
 Bool_t rooModule::is_module() const
{
   // Overrides the inherited member function. Indicates that this is a module
   // descriptor.

   return fImp ? ((d_Module*)fImp)->is_module() : 0;
}

//______________________________________________________________________________
 Bool_t rooModule::is_top_level() const
{
   // Tests whether the described module is the top-level module of the 
   // federated database.

   return  fImp ? ((d_Module*)fImp)->is_top_level() : 0;
}

//______________________________________________________________________________
 Int_t rooModule::schema_number() const
{
   // The type number that uniquely identifies this module within the 
   // federated database schema.

   return  fImp ? ((d_Module*)fImp)->schema_number() : 0;
}

//______________________________________________________________________________
 Int_t rooModule::next_type_number() const
{
   // Gets the next available type number for the described module.
   //
   // Returns: The next available type number for the described module.

   return  fImp ? ((d_Module*)fImp)->next_type_number() : 0;
}

//______________________________________________________________________________
 Int_t rooModule::next_assoc_number() const
{
   // Gets the next available association number for the described module.
   //
   // Returns:
   //       The next available association number for the described module.
   // 
   // The result is the association number to be assigned to the next 
   // relationship that is added to a class in the described module.
   //
   // See also: set_next_assoc_number()

   return  fImp ? ((d_Module*)fImp)->next_assoc_number() : 0;
}

//______________________________________________________________________________
 Bool_t rooModule::set_next_type_number(Int_t n)
{
   // Sets the next available type number for the described module.
   //
   // Parameters: 
   //          n - the new next available type number for the described module; 
   //             may not be less than the current next available type number 
   //             (which is returned by next_type_number).
   //
   // Returns: kTRUE on success; kFALSE if nis lower than the current next type 
   //          number.
   //
   // Most applications will not need to call this member function. 
   // It is provided to enable an application to recreate the exact state 
   // of another schema.
   //
   // See also: next_type_number

   return  fImp ? ((d_Module*)fImp)->set_next_type_number(n) : 0;
}

//______________________________________________________________________________
 Bool_t rooModule::set_next_assoc_number(Int_t n)
{
   //Sets the next available association number for the described module.
   //
   // Parameters:
   //          n - the new next available association number for the 
   //          described module; may not be less than the current next 
   //          available association number (which is returned by 
   //          next_assoc_number).
   //
   // Returns: kTRUE if successful; kFALSE if nis lower than the current next 
   //          association number.
   //
   // Most applications will not need to call this member function. 
   // It is provided to enable an application to recreate the exact state 
   // of another schema.
   //
   // See also: next_assoc_number()

   return  fImp ? ((d_Module*)fImp)->set_next_assoc_number(n) : 0;
}

//______________________________________________________________________________
 Bool_t rooModule::lock_schema(ULong_t key)
{
   // Locks the schema of the federated database.
   //
   // 1. static Bool_t lock_schema(ULong_t key);
   // 2. static Bool_t lock_schema(ULong_t key, ULong_t oldKey);
   //
   // Parameter the key with which the schema can be unlocked or accessed 
   // in the future. oldKey- the key with which the schema was locked
   // previously.
   //
   // Returns: kTRUE if successful; otherwise kFALSE.
   //
   //  The first variant locks the schema. If the schema is being locked for 
   /// the first time, key can be any key; if the schema was locked previously,
   // key must be the key with which the schema was last locked.
   //
   // The second variant relocks the schema and changes the key; 
   // oldKey must be the key with which the schema was last locked.
   //
   // See also: top_level() unlock_schema()

   return  d_Module::lock_schema(key);
}

//______________________________________________________________________________
 Bool_t rooModule::lock_schema(ULong_t key, ULong_t oldKey)
{
   // Locks the schema of the federated database.
   //
   // 1. static Bool_t lock_schema(ULong_t key);
   // 2. static Bool_t lock_schema(ULong_t key, ULong_t oldKey);
   //
   // Parameter the key with which the schema can be unlocked or accessed 
   // in the future. oldKey- the key with which the schema was locked
   // previously.
   //
   // Returns: kTRUE if successful; otherwise kFALSE.
   //
   //  The first variant locks the schema. If the schema is being locked for 
   /// the first time, key can be any key; if the schema was locked previously,
   // key must be the key with which the schema was last locked.
   //
   // The second variant relocks the schema and changes the key; 
   // oldKey must be the key with which the schema was last locked.
   //
   // See also: top_level() unlock_schema()

   return  d_Module::lock_schema(key,oldKey);
}

//______________________________________________________________________________
 Bool_t rooModule::unlock_schema(ULong_t key)
{
   // Unlocks the schema of the federated database.
   // The key with which the schema was locked.
   //
   // Returns: kTRUE if successful; otherwise kFASLE.
   //
   // Once the schema has been unlocked, it can be accessed by any process. 
   // The schema may be relocked, but only by a process that supplies key as 
   // the key with which it was last locked.
   //
   // See also lock_schema()

   return d_Module::unlock_schema(key);
}

//______________________________________________________________________________
 Bool_t rooModule::sanitize(rooTrans & tran)
{
   // Updates the federated database schema, restoring any class descriptions 
   // that may have become corrupted.
   //
   // trans - the current transaction.
   //
   // Returns: kTRUE if successful; otherwise kFALSE.
   //
   // This member function is a last resort for applications that experience 
   // inexplicable schema failure, such as a crash or inability to open or 
   // close a container in the system database. The system database, which 
   // contains the schema, has the identifier 1; the internal Objectivity/DB 
   // objects that represent class descriptions in the schema are stored in 
   // that database and, thus, have object identifiers of the form 1- n- n- n. 
   // A problem or failure in a different application can leave these
   // schema objects in a corrupted state in the federated database; when that
   // happens, your application may be unable to open or close the container 
   // for the corrupted objects. In that case, you can call this member 
   // function, which restores the class descriptions in the schema. This 
   // member function will fail if it is unable to obtain an update lock on 
   // the schema. If the current transaction is active, this member function 
   // repairs the federated database schema and commits the transaction. 
   // It then restarts the transaction using the same settings that were in 
   // effect when this member function was called. If the current transaction 
   // is not active, this member function starts the transaction
   // before attempting to repair the federated database schema and commits it 
   // after the schema has been modified.

   return d_Module::sanitize(*((ooTrans*)tran.fImp));
}


ROOT page - Class index - Top of the page

This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.