ROOT logo
// @(#)root/reflex:$Id: VariableBuilder.cxx 22729 2008-03-19 10:20:10Z pcanal $
// 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/Builder/VariableBuilder.h"

#include "Reflex/internal/OwnedMember.h"

#include "Namespace.h"
#include "DataMember.h"


//-------------------------------------------------------------------------------
Reflex::VariableBuilderImpl::VariableBuilderImpl( const char * nam,
                                                        const Type & typ,
                                                        size_t offs,
                                                        unsigned int modifiers ) 
   : fDataMember(Member()) {
//-------------------------------------------------------------------------------
// Construct the info for a variable.
   std::string declScope = "";
   std::string memName = std::string( nam );
   size_t pos = memName.rfind( "::" );
   if ( pos != std::string::npos ) {
      declScope = memName.substr( 0, pos );
      memName = memName.substr( pos + 2 );
   }

   Scope sc = Scope::ByName(declScope);
  
   if ( ! sc ) {
      sc = (new Namespace(declScope.c_str()))->ThisScope();
   }
  
   if ( ! sc.IsNamespace()) throw RuntimeError("Declaring At is not a namespace");

   sc.AddDataMember( memName.c_str(),
                     typ,
                     offs,
                     modifiers );
}


//-------------------------------------------------------------------------------
Reflex::VariableBuilderImpl::~VariableBuilderImpl() {
//-------------------------------------------------------------------------------
// Destructor.
   FireFunctionCallback( fDataMember );
}


//-------------------------------------------------------------------------------
void Reflex::VariableBuilderImpl::AddProperty( const char * key, 
                                                     const char * value ) {
//-------------------------------------------------------------------------------
// Attach a property to this variable as string.
   fDataMember.Properties().AddProperty( key , value );
}


//-------------------------------------------------------------------------------
void Reflex::VariableBuilderImpl::AddProperty( const char * key, 
                                                     Any value ) {
//-------------------------------------------------------------------------------
// Attach a property to this variable as Any object.
   fDataMember.Properties().AddProperty( key , value );
}


//-------------------------------------------------------------------------------
Reflex::Member Reflex::VariableBuilderImpl::ToMember() {
//-------------------------------------------------------------------------------
// Return the member currently being built.
   return fDataMember;
}


//-------------------------------------------------------------------------------
Reflex::VariableBuilder::VariableBuilder( const char * nam, 
                                                const Type & typ,
                                                size_t offs,
                                                unsigned int modifiers) 
   : fDataMember( Member()) {
//-------------------------------------------------------------------------------
// Construct the variable info.
   std::string declScope = Tools::GetScopeName(nam);
   std::string memName = Tools::GetBaseName(nam);
   
   Scope sc = Scope::ByName(declScope);
  
   if ( ! sc ) {
      sc = (new Namespace(declScope.c_str()))->ThisScope();
   }
  
   if ( ! sc.IsNamespace()) throw RuntimeError("Declaring scope is not a namespace");

   DataMember* dm = new DataMember( memName.c_str(),
                                    typ,
                                    offs,
                                    modifiers );
   sc.AddDataMember(Member(dm));
   fDataMember = Member(dm);
}


//-------------------------------------------------------------------------------
Reflex::VariableBuilder::~VariableBuilder() {
//-------------------------------------------------------------------------------
// Destructor.  
   FireFunctionCallback( fDataMember );
}


//-------------------------------------------------------------------------------
Reflex::VariableBuilder & 
Reflex::VariableBuilder::AddProperty( const char * key, 
                                            const char * value ) {
//-------------------------------------------------------------------------------
// Attach a property to this variable as a string.
   fDataMember.Properties().AddProperty( key , value );
   return * this;
}


//-------------------------------------------------------------------------------
Reflex::VariableBuilder & 
Reflex::VariableBuilder::AddProperty( const char * key, 
                                            Any value ) {
//-------------------------------------------------------------------------------
// Attach a property to this variable as Any object.
   fDataMember.Properties().AddProperty( key , value );
   return * this;
}


//-------------------------------------------------------------------------------
Reflex::Member Reflex::VariableBuilder::ToMember() {
//-------------------------------------------------------------------------------
// Return the member currently being built.
   return fDataMember;
}

 VariableBuilder.cxx:1
 VariableBuilder.cxx:2
 VariableBuilder.cxx:3
 VariableBuilder.cxx:4
 VariableBuilder.cxx:5
 VariableBuilder.cxx:6
 VariableBuilder.cxx:7
 VariableBuilder.cxx:8
 VariableBuilder.cxx:9
 VariableBuilder.cxx:10
 VariableBuilder.cxx:11
 VariableBuilder.cxx:12
 VariableBuilder.cxx:13
 VariableBuilder.cxx:14
 VariableBuilder.cxx:15
 VariableBuilder.cxx:16
 VariableBuilder.cxx:17
 VariableBuilder.cxx:18
 VariableBuilder.cxx:19
 VariableBuilder.cxx:20
 VariableBuilder.cxx:21
 VariableBuilder.cxx:22
 VariableBuilder.cxx:23
 VariableBuilder.cxx:24
 VariableBuilder.cxx:25
 VariableBuilder.cxx:26
 VariableBuilder.cxx:27
 VariableBuilder.cxx:28
 VariableBuilder.cxx:29
 VariableBuilder.cxx:30
 VariableBuilder.cxx:31
 VariableBuilder.cxx:32
 VariableBuilder.cxx:33
 VariableBuilder.cxx:34
 VariableBuilder.cxx:35
 VariableBuilder.cxx:36
 VariableBuilder.cxx:37
 VariableBuilder.cxx:38
 VariableBuilder.cxx:39
 VariableBuilder.cxx:40
 VariableBuilder.cxx:41
 VariableBuilder.cxx:42
 VariableBuilder.cxx:43
 VariableBuilder.cxx:44
 VariableBuilder.cxx:45
 VariableBuilder.cxx:46
 VariableBuilder.cxx:47
 VariableBuilder.cxx:48
 VariableBuilder.cxx:49
 VariableBuilder.cxx:50
 VariableBuilder.cxx:51
 VariableBuilder.cxx:52
 VariableBuilder.cxx:53
 VariableBuilder.cxx:54
 VariableBuilder.cxx:55
 VariableBuilder.cxx:56
 VariableBuilder.cxx:57
 VariableBuilder.cxx:58
 VariableBuilder.cxx:59
 VariableBuilder.cxx:60
 VariableBuilder.cxx:61
 VariableBuilder.cxx:62
 VariableBuilder.cxx:63
 VariableBuilder.cxx:64
 VariableBuilder.cxx:65
 VariableBuilder.cxx:66
 VariableBuilder.cxx:67
 VariableBuilder.cxx:68
 VariableBuilder.cxx:69
 VariableBuilder.cxx:70
 VariableBuilder.cxx:71
 VariableBuilder.cxx:72
 VariableBuilder.cxx:73
 VariableBuilder.cxx:74
 VariableBuilder.cxx:75
 VariableBuilder.cxx:76
 VariableBuilder.cxx:77
 VariableBuilder.cxx:78
 VariableBuilder.cxx:79
 VariableBuilder.cxx:80
 VariableBuilder.cxx:81
 VariableBuilder.cxx:82
 VariableBuilder.cxx:83
 VariableBuilder.cxx:84
 VariableBuilder.cxx:85
 VariableBuilder.cxx:86
 VariableBuilder.cxx:87
 VariableBuilder.cxx:88
 VariableBuilder.cxx:89
 VariableBuilder.cxx:90
 VariableBuilder.cxx:91
 VariableBuilder.cxx:92
 VariableBuilder.cxx:93
 VariableBuilder.cxx:94
 VariableBuilder.cxx:95
 VariableBuilder.cxx:96
 VariableBuilder.cxx:97
 VariableBuilder.cxx:98
 VariableBuilder.cxx:99
 VariableBuilder.cxx:100
 VariableBuilder.cxx:101
 VariableBuilder.cxx:102
 VariableBuilder.cxx:103
 VariableBuilder.cxx:104
 VariableBuilder.cxx:105
 VariableBuilder.cxx:106
 VariableBuilder.cxx:107
 VariableBuilder.cxx:108
 VariableBuilder.cxx:109
 VariableBuilder.cxx:110
 VariableBuilder.cxx:111
 VariableBuilder.cxx:112
 VariableBuilder.cxx:113
 VariableBuilder.cxx:114
 VariableBuilder.cxx:115
 VariableBuilder.cxx:116
 VariableBuilder.cxx:117
 VariableBuilder.cxx:118
 VariableBuilder.cxx:119
 VariableBuilder.cxx:120
 VariableBuilder.cxx:121
 VariableBuilder.cxx:122
 VariableBuilder.cxx:123
 VariableBuilder.cxx:124
 VariableBuilder.cxx:125
 VariableBuilder.cxx:126
 VariableBuilder.cxx:127
 VariableBuilder.cxx:128
 VariableBuilder.cxx:129
 VariableBuilder.cxx:130
 VariableBuilder.cxx:131
 VariableBuilder.cxx:132
 VariableBuilder.cxx:133
 VariableBuilder.cxx:134
 VariableBuilder.cxx:135
 VariableBuilder.cxx:136
 VariableBuilder.cxx:137
 VariableBuilder.cxx:138
 VariableBuilder.cxx:139
 VariableBuilder.cxx:140
 VariableBuilder.cxx:141
 VariableBuilder.cxx:142
 VariableBuilder.cxx:143
 VariableBuilder.cxx:144
 VariableBuilder.cxx:145
 VariableBuilder.cxx:146
 VariableBuilder.cxx:147
 VariableBuilder.cxx:148
 VariableBuilder.cxx:149
 VariableBuilder.cxx:150
 VariableBuilder.cxx:151
 VariableBuilder.cxx:152
 VariableBuilder.cxx:153