예제 #1
0
void KVNameValueList::Merge(const KVNameValueList& other)
{
   // Merge other list into this one.
   // Any parameters in 'other' which do not exist in this one are added.
   // Any parameters which exist in both have their values summed.

   for (int i = 0; i < other.GetNpar(); ++i) {
      KVNamedParameter* np_other = other.GetParameter(i);
      AddValue(*np_other);
   }
}
예제 #2
0
void KVClassFactory::AddGetSetMethods(const KVNameValueList& nvl)
{
   // For each named parameter in the list, we add protected member variables and
   // public Get/Set methods with the name and type of the parameter.
   // Example: given a list containing NAME="some string" NUMBER=3 [integer]
   // PI=3.141592 [double], we generate the methods
   //   void SetNAME(const TString&);
   //   const TString& GetNAME() const;
   //   void SetNUMBER(Int_t);
   //   Int_t GetNUMBER() const;
   //   void SetPI(Double_t);
   //   Double_t GetPI() const;

   int npars = nvl.GetNpar();
   for(int i=0; i<npars; i++){
      KVNamedParameter* par = nvl.GetParameter(i);
      if(par->IsString()){
         KVClassMember* v = AddMember(par->GetName(),"TString","member automatically generated by KVClassFactory::AddGetSetMethods");
         KVClassMethod* m = AddMethod(Form("Set%s",par->GetName()), "void");
         m->AddArgument("const TString&");
         m->SetMethodBody(
Form("    // Method automatically generated by KVClassFactory::AddGetSetMethods\n"
"\n"
"    %s=arg1;", v->GetName())
         );
         m = AddMethod(Form("Get%s",par->GetName()), "const TString&", "public", kFALSE, kTRUE);
         m->SetMethodBody(
Form("    // Method automatically generated by KVClassFactory::AddGetSetMethods\n"
"\n"
"    return %s;", v->GetName())
                  );
         // make sure #include "TString.h" appears in header file
         if( ! fHeadInc.FindObject("TString.h") ) AddHeaderIncludeFile("TString.h");
      }
      else if(par->IsInt()){
         KVClassMember* v = AddMember(par->GetName(),"Int_t","member automatically generated by KVClassFactory::AddGetSetMethods");
         KVClassMethod* m = AddMethod(Form("Set%s",par->GetName()), "void");
         m->AddArgument("Int_t");
         m->SetMethodBody(
Form("    // Method automatically generated by KVClassFactory::AddGetSetMethods\n"
"\n"
"    %s=arg1;", v->GetName())
         );
         m = AddMethod(Form("Get%s",par->GetName()), "Int_t", "public", kFALSE, kTRUE);
         m->SetMethodBody(
Form("    // Method automatically generated by KVClassFactory::AddGetSetMethods\n"
"\n"
"    return %s;", v->GetName())
                  );
      }
      else if(par->IsDouble()){
         KVClassMember* v = AddMember(par->GetName(),"Double_t","member automatically generated by KVClassFactory::AddGetSetMethods");
         KVClassMethod* m = AddMethod(Form("Set%s",par->GetName()), "void");
         m->AddArgument("Double_t");
         m->SetMethodBody(
Form("    // Method automatically generated by KVClassFactory::AddGetSetMethods\n"
"\n"
"    %s=arg1;", v->GetName())
         );
         m = AddMethod(Form("Get%s",par->GetName()), "Double_t", "public", kFALSE, kTRUE);
         m->SetMethodBody(
Form("    // Method automatically generated by KVClassFactory::AddGetSetMethods\n"
"\n"
"    return %s;", v->GetName())
                  );
      }
   }
}