// @(#)root/reflex:$Id: Scope.cxx 23671 2008-05-07 09:41:12Z axel $
// Author: Stefan Roiser 2004

// Copyright CERN, CH-1211 Geneva 23, 2004-2006, All rights reserved.
//
// Permission to use, copy, modify, and distribute this software for any
// purpose is hereby granted without fee, provided that this copyright and
// permissions notice appear in all copies and derivatives.
//
// This software is provided "as is" without express or implied warranty.

#ifndef REFLEX_BUILD
#define REFLEX_BUILD
#endif

#include "Reflex/Scope.h"

#include "Reflex/internal/ScopeBase.h"
#include "Reflex/Member.h"
#include "Reflex/Type.h"
#include "Reflex/TypeTemplate.h"
#include "Reflex/MemberTemplate.h"
#include "Reflex/Base.h"

#include "Reflex/Tools.h"
#include "Class.h"

//-------------------------------------------------------------------------------
Reflex::Scope & Reflex::Scope::__NIRVANA__() {
//-------------------------------------------------------------------------------
// static wraper around NIRVANA, the base of the top scope.
   static Scope s = Scope( new ScopeName( "@N@I@R@V@A@N@A@", 0 ));
   return s;
}


//-------------------------------------------------------------------------------
Reflex::Scope::operator Reflex::Type () const {
//-------------------------------------------------------------------------------
// Conversion operator to Type. If this scope is not a Type, returns the empty type.
   if ( * this ) return *(fScopeName->fScopeBase);
   return Dummy::Type();
}



//-------------------------------------------------------------------------------
Reflex::Base Reflex::Scope::BaseAt( size_t nth ) const {
//-------------------------------------------------------------------------------
// Return nth base class info.
   if ( * this ) return fScopeName->fScopeBase->BaseAt( nth );
   return Dummy::Base();
}


//-------------------------------------------------------------------------------
size_t Reflex::Scope::BaseSize() const {
//-------------------------------------------------------------------------------
// Return number of base classes.
   if ( * this ) return fScopeName->fScopeBase->BaseSize();
   return 0;
}


//-------------------------------------------------------------------------------
Reflex::Scope Reflex::Scope::ByName( const std::string & name ) {
//-------------------------------------------------------------------------------
// Lookup a Scope by it's fully qualified name.
   return ScopeName::ByName( name );
}


//-------------------------------------------------------------------------------
Reflex::Member Reflex::Scope::DataMemberAt( size_t nth ) const {
//-------------------------------------------------------------------------------
// Return the nth data member of this scope.
   if ( * this ) return fScopeName->fScopeBase->DataMemberAt( nth ); 
   return Dummy::Member();
}


//-------------------------------------------------------------------------------
Reflex::Member Reflex::Scope::DataMemberByName( const std::string & name ) const {
//-------------------------------------------------------------------------------
// Return a data member by it's name.
   if ( * this ) return fScopeName->fScopeBase->DataMemberByName( name ); 
   return Dummy::Member();
}


//-------------------------------------------------------------------------------
size_t Reflex::Scope::DataMemberSize() const {
//-------------------------------------------------------------------------------
// Return number of data mebers of this scope.
   if ( * this ) return fScopeName->fScopeBase->DataMemberSize(); 
   return 0;
}


//-------------------------------------------------------------------------------
Reflex::Member Reflex::Scope::FunctionMemberAt( size_t nth ) const {
//------------------------------------------------------------------------------- 
// Return nth function member of this socpe.
   if ( * this ) return fScopeName->fScopeBase->FunctionMemberAt(nth); 
   return Dummy::Member();
}


//-------------------------------------------------------------------------------
Reflex::Member Reflex::Scope::FunctionMemberByName( const std::string & name ) const {
//------------------------------------------------------------------------------- 
// Return a function member by it's name.
   if ( * this ) return fScopeName->fScopeBase->FunctionMemberByName( name, Type(), 0 ); 
   return Dummy::Member();
}


//-------------------------------------------------------------------------------
Reflex::Member Reflex::Scope::FunctionMemberByName( const std::string & name,
                                                    const Type & signature,
                                                    unsigned int modifiers_mask) const {
//------------------------------------------------------------------------------- 
// Return a function member by it's name, qualified by it's signature type.
   if ( * this ) return fScopeName->fScopeBase->FunctionMemberByName( name, signature, modifiers_mask ); 
   return Dummy::Member();
}


//-------------------------------------------------------------------------------
Reflex::Member Reflex::Scope::FunctionMemberByNameAndSignature( const std::string & name,
                                                                const Type & signature,
                                                                unsigned int modifiers_mask) const {
//------------------------------------------------------------------------------- 
// Return a function member by it's name, qualified by it's signature type.
   if ( * this ) return fScopeName->fScopeBase->FunctionMemberByNameAndSignature( name, signature, modifiers_mask ); 
   return Dummy::Member();
}


//-------------------------------------------------------------------------------
size_t Reflex::Scope::FunctionMemberSize() const {
//-------------------------------------------------------------------------------
// Return number of function members of this scope.
   if ( * this ) return fScopeName->fScopeBase->FunctionMemberSize(); 
   return 0;
}


//-------------------------------------------------------------------------------
Reflex::Member 
Reflex::Scope::LookupMember( const std::string & nam ) const {
//-------------------------------------------------------------------------------
// Lookup a member from this scope.
   if ( * this ) return fScopeName->fScopeBase->LookupMember( nam, *this );
   return Dummy::Member();
}


//-------------------------------------------------------------------------------
Reflex::Type
Reflex::Scope::LookupType( const std::string & nam ) const {
//-------------------------------------------------------------------------------
// Lookup a type from this scope.
   if ( * this ) return fScopeName->fScopeBase->LookupType( nam, *this );
   return Dummy::Type();
}


//-------------------------------------------------------------------------------
Reflex::Scope
Reflex::Scope::LookupScope( const std::string & nam ) const {
//-------------------------------------------------------------------------------
// Lookup a scope from this scope.
   if ( * this ) return fScopeName->fScopeBase->LookupScope( nam, *this );
   return Dummy::Scope();
}


//-------------------------------------------------------------------------------
Reflex::Member 
Reflex::Scope::MemberByName( const std::string & name ) const {
//-------------------------------------------------------------------------------
// Return a member from this scope, by name.
   if ( * this ) return fScopeName->fScopeBase->MemberByName(name, Type()); 
   return Dummy::Member();
}


//-------------------------------------------------------------------------------
Reflex::Member 
Reflex::Scope::MemberByName( const std::string & name,
                             const Type & signature ) const {
//-------------------------------------------------------------------------------
// Return a member in this scope, looked up by name and signature (for functions)
   if ( * this ) return fScopeName->fScopeBase->MemberByName(name, signature); 
   return Dummy::Member();
}


//-------------------------------------------------------------------------------
Reflex::Member_Iterator Reflex::Scope::Member_Begin() const {
//-------------------------------------------------------------------------------
// Return the begin iterator of member container.
   if ( * this ) return fScopeName->fScopeBase->Member_Begin();
   return Dummy::MemberCont().begin();
}


//-------------------------------------------------------------------------------
Reflex::Member_Iterator Reflex::Scope::Member_End() const {
//-------------------------------------------------------------------------------
// Return the end iterator of member container.
   if ( * this ) return fScopeName->fScopeBase->Member_End();
   return Dummy::MemberCont().end();
}


//-------------------------------------------------------------------------------
Reflex::Reverse_Member_Iterator Reflex::Scope::Member_RBegin() const {
//-------------------------------------------------------------------------------
// Return the rbegin iterator of member container.
   if ( * this ) return fScopeName->fScopeBase->Member_RBegin();
   return Dummy::MemberCont().rbegin();
}


//-------------------------------------------------------------------------------
Reflex::Reverse_Member_Iterator Reflex::Scope::Member_REnd() const {
//-------------------------------------------------------------------------------
// Return the rend iterator of member container.
   if ( * this ) return fScopeName->fScopeBase->Member_REnd();
   return Dummy::MemberCont().rend();
}


//-------------------------------------------------------------------------------
Reflex::Member Reflex::Scope::MemberAt( size_t nth ) const {
//-------------------------------------------------------------------------------
// Return the nth member of this scope.
   if ( * this ) return fScopeName->fScopeBase->MemberAt(nth); 
   return Dummy::Member();
}


//-------------------------------------------------------------------------------
Reflex::MemberTemplate Reflex::Scope::MemberTemplateAt( size_t nth ) const {
//-------------------------------------------------------------------------------
// Return the nth memer template in this scope.
   if ( * this ) return fScopeName->fScopeBase->MemberTemplateAt( nth );
   return Dummy::MemberTemplate();
}


//-------------------------------------------------------------------------------
size_t Reflex::Scope::MemberTemplateSize() const {
//-------------------------------------------------------------------------------
// Return the number of member templates in this scope.
   if ( * this ) return fScopeName->fScopeBase->MemberTemplateSize();
   return 0;
}


//-------------------------------------------------------------------------------
Reflex::MemberTemplate Reflex::Scope::MemberTemplateByName( const std::string & nam ) const {
//-------------------------------------------------------------------------------
// Look up a member template in this scope by name and return it.
   if ( * this ) return fScopeName->fScopeBase->MemberTemplateByName( nam );
   return Dummy::MemberTemplate();
}


//-------------------------------------------------------------------------------
std::string Reflex::Scope::Name( unsigned int mod ) const {
//-------------------------------------------------------------------------------
// Return the name of this scope, scoped if requested.
   if ( * this ) return fScopeName->fScopeBase->Name( mod );
   else if ( fScopeName ) {
      if ( 0 != ( mod & ( SCOPED | S ))) return fScopeName->Name();
      else                               return Tools::GetBaseName( fScopeName->Name());
   }
   else {
      return "";
   }
}


//-------------------------------------------------------------------------------
Reflex::Scope Reflex::Scope::ScopeAt( size_t nth ) {
//-------------------------------------------------------------------------------
// Return the nth scope in the Reflex database.
   return ScopeName::ScopeAt( nth );
}


//-------------------------------------------------------------------------------
size_t Reflex::Scope::ScopeSize() {
//-------------------------------------------------------------------------------
// Return the number of scopes defined.
   return ScopeName::ScopeSize();
}


//-------------------------------------------------------------------------------
Reflex::Type Reflex::Scope::SubTypeAt( size_t nth ) const {
//-------------------------------------------------------------------------------
// Return the nth sub type of this scope.
   if ( * this ) return fScopeName->fScopeBase->SubTypeAt( nth ); 
   return Dummy::Type();
}


//-------------------------------------------------------------------------------
size_t Reflex::Scope::SubTypeSize() const {
//-------------------------------------------------------------------------------
// Return the number of sub types.
   if ( * this ) return fScopeName->fScopeBase->SubTypeSize(); 
   return 0;
}


//-------------------------------------------------------------------------------
Reflex::Type Reflex::Scope::SubTypeByName( const std::string & nam ) const {
//-------------------------------------------------------------------------------
// Look up a sub type by name and return it.
   if ( * this ) return fScopeName->fScopeBase->SubTypeByName( nam );
   return Dummy::Type();
}


//-------------------------------------------------------------------------------
Reflex::Type Reflex::Scope::TemplateArgumentAt( size_t nth ) const {
//-------------------------------------------------------------------------------
// Return the nth template argument of this scope (ie. class).
   if ( * this ) return fScopeName->fScopeBase->TemplateArgumentAt( nth );
   return Dummy::Type();
}


//-------------------------------------------------------------------------------
Reflex::TypeTemplate Reflex::Scope::TemplateFamily() const {
//-------------------------------------------------------------------------------
// Return the template family related to this scope.
   if ( * this ) return fScopeName->fScopeBase->TemplateFamily();
   return Dummy::TypeTemplate();
}


//-------------------------------------------------------------------------------
Reflex::TypeTemplate Reflex::Scope::SubTypeTemplateAt( size_t nth ) const {
//-------------------------------------------------------------------------------
// Return the nth sub type template.
   if ( * this ) return fScopeName->fScopeBase->SubTypeTemplateAt( nth ); 
   return Dummy::TypeTemplate();
}


//-------------------------------------------------------------------------------
size_t Reflex::Scope::SubTypeTemplateSize() const {
//-------------------------------------------------------------------------------
// Return the number of type templates in this scope.
   if ( * this ) return fScopeName->fScopeBase->SubTypeTemplateSize();
   return 0;
}


//-------------------------------------------------------------------------------
Reflex::TypeTemplate Reflex::Scope::SubTypeTemplateByName( const std::string & nam ) const {
//-------------------------------------------------------------------------------
// Lookup a sub type template by string and return it.
   if ( * this ) return fScopeName->fScopeBase->SubTypeTemplateByName( nam );
   return Dummy::TypeTemplate();
}


//-------------------------------------------------------------------------------
void Reflex::Scope::AddDataMember( const Member & dm ) const {
//-------------------------------------------------------------------------------
// Add data member dm to this scope.
   if ( * this) fScopeName->fScopeBase->AddDataMember( dm );
}


//-------------------------------------------------------------------------------
void Reflex::Scope::AddDataMember( const char * name,
                                   const Type & type,
                                   size_t offset,
                                   unsigned int modifiers ) const {
//-------------------------------------------------------------------------------
// Add data member to this scope.
   if ( * this ) fScopeName->fScopeBase->AddDataMember( name, 
                                                        type, 
                                                        offset, 
                                                        modifiers );
}


//-------------------------------------------------------------------------------
void Reflex::Scope::RemoveDataMember( const Member & dm ) const {
//-------------------------------------------------------------------------------
// Remove data member dm from this scope.
   if ( * this) fScopeName->fScopeBase->RemoveDataMember( dm );
}


//-------------------------------------------------------------------------------
void Reflex::Scope::AddFunctionMember( const Member & fm ) const {
//-------------------------------------------------------------------------------
// Add function member fm to this scope.
   if ( * this) fScopeName->fScopeBase->AddFunctionMember( fm );
}


//-------------------------------------------------------------------------------
void Reflex::Scope::AddFunctionMember( const char * nam,
                                             const Type & typ,
                                             StubFunction stubFP,
                                             void * stubCtx,
                                             const char * params,
                                             unsigned int modifiers ) const {
//-------------------------------------------------------------------------------
// Add function member to this scope.
   if ( * this ) fScopeName->fScopeBase->AddFunctionMember( nam, 
                                                            typ, 
                                                            stubFP, 
                                                            stubCtx, 
                                                            params, 
                                                            modifiers );
}


//-------------------------------------------------------------------------------
void Reflex::Scope::RemoveFunctionMember( const Member & fm ) const {
//-------------------------------------------------------------------------------
// Remove function member fm from this scope.
   if ( * this) fScopeName->fScopeBase->RemoveFunctionMember( fm );
}


//-------------------------------------------------------------------------------
void Reflex::Scope::AddSubType( const Type & ty ) const {
//-------------------------------------------------------------------------------
// Add sub type ty to this scope.
   if ( * this) fScopeName->fScopeBase->AddSubType( ty );
}


//-------------------------------------------------------------------------------
void Reflex::Scope::AddSubType( const char * type,
                                size_t size,
                                TYPE typeType,
                                const std::type_info & typeInfo,
                                unsigned int modifiers ) const {
//-------------------------------------------------------------------------------
// Add sub type to this scope.
   if ( * this ) fScopeName->fScopeBase->AddSubType( type, 
                                                     size, 
                                                     typeType, 
                                                     typeInfo, 
                                                     modifiers );
}


//-------------------------------------------------------------------------------
void Reflex::Scope::RemoveSubType( const Type & ty ) const {
//-------------------------------------------------------------------------------
// Remove sub type ty from this scope.
   if ( * this) fScopeName->fScopeBase->RemoveSubType( ty );
}


//-------------------------------------------------------------------------------
void Reflex::Scope::AddMemberTemplate( const MemberTemplate & mt ) const {
//-------------------------------------------------------------------------------
// Add member template mt to this scope.
   if ( * this ) fScopeName->fScopeBase->AddMemberTemplate( mt );
}


//-------------------------------------------------------------------------------
void Reflex::Scope::RemoveMemberTemplate( const MemberTemplate & mt ) const {
//-------------------------------------------------------------------------------
// Remove member template mt from this scope.
   if ( * this ) fScopeName->fScopeBase->RemoveMemberTemplate( mt );
}


//-------------------------------------------------------------------------------
void Reflex::Scope::AddSubTypeTemplate( const TypeTemplate & tt ) const {
//-------------------------------------------------------------------------------
// Add type template tt to this scope.
   if ( * this ) fScopeName->fScopeBase->AddSubTypeTemplate( tt );
}


//-------------------------------------------------------------------------------
void Reflex::Scope::RemoveSubTypeTemplate( const TypeTemplate & tt ) const {
//-------------------------------------------------------------------------------
// Remove type template tt from this scope.
   if ( * this ) fScopeName->fScopeBase->RemoveSubTypeTemplate( tt );
}


//-------------------------------------------------------------------------------
void Reflex::Scope::GenerateDict( DictionaryGenerator & generator) const {
//-------------------------------------------------------------------------------
// Generate Dictionary information about itself.
   if ( * this ) fScopeName->fScopeBase->GenerateDict(generator);
}


//-------------------------------------------------------------------------------
void Reflex::Scope::Unload() const {
//-------------------------------------------------------------------------------
// Unload a scope, i.e. delete the ScopeName's ScopeBase object.
   if ( * this ) delete fScopeName->fScopeBase;
}


#ifdef REFLEX_CINT_MERGE
bool Reflex::Scope::operator&&(const Scope &right) const
{ return operator bool() && (bool)right; }
bool Reflex::Scope::operator&&(const Type &right) const 
{ return operator bool() && (bool)right; }
bool Reflex::Scope::operator&&(const Member &right) const 
{ return operator bool() && (bool)right; }
bool Reflex::Scope::operator||(const Scope &right) const 
{ return operator bool() && (bool)right; }
bool Reflex::Scope::operator||(const Type &right) const 
{ return operator bool() && (bool)right; }
bool Reflex::Scope::operator||(const Member &right) const 
{ return operator bool() || (bool)right; }
#endif

Last change: Wed Jun 25 08:31:18 2008
Last generated: 2008-06-25 08:31

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.