|
// // Class BrDbPerson // // A rep of a BRAHMS Person both inside and outside database // // $Author: hagel $ // $Date: 2001/06/21 14:55:16 $ // $Copyright: Brahms collaboration // $Id: BrDbPerson.cxx,v 1.1.1.1 2001/06/21 14:55:16 hagel Exp $ #include <BrDbPerson.h> #ifndef BRAT_BrException #include "BrException.h" #endif #ifndef WIN32 #include <stdlib.h> #else #include <cstdlib> #endif ClassImp(BrDbPerson); //____________________________________________________________________ const Char_t* BrDbPerson::kTableName = PERSON_NAME; //____________________________________________________________________ BrDbPerson::BrDbPerson(const Char_t* lastname, const Char_t* firstnames, const Char_t* email, const Char_t* institute) { SetLastName(lastname); SetFirstNames(firstnames); SetEmail(email); SetInstitute(institute); } //____________________________________________________________________ BrDbPerson* BrDbPerson::SingleInstance(TSQLRow* row) { if (!row) return 0; BrDbPerson* pers = new BrDbPerson(row->GetField(1), row->GetField(2), row->GetField(3), row->GetField(4)); pers->SetDBID(strtol(row->GetField(0),NULL,0)); return pers; } //____________________________________________________________________ TObjArray* BrDbPerson::MultipleInstance(TSQLResult* res) { Int_t count = (res) ? res->GetRowCount() : 0; TObjArray* table = new TObjArray(count); for (Int_t i = 0; i < count; i++) table->Add(BrDbPerson::SingleInstance(res->Next())); return table; } //____________________________________________________________________ BrDbQuery* BrDbPerson::Create(void) { return BrDbQuery::Create(BrDbPerson::kTableName, "lastname VARCHAR(64) NOT NULL," "firstnames VARCHAR(64) NOT NULL," "email VARCHAR(64)," "institute VARCHAR(64)"); } //____________________________________________________________________ BrDbQuery* BrDbPerson::Insert(void) { return BrDbQuery::Insert(BrDbPerson::kTableName, Form("%d, '%s', '%s', '%s', '%s'", GetDBID(), fLastName, fFirstNames, fEmail, fInstitute)); } //____________________________________________________________________ void BrDbPerson::SetLastName(const Char_t* lastname) { if (strlen(lastname) > 63) { strncpy(fLastName, lastname, 63); fLastName[63] = '0'; } else strcpy(fLastName,lastname); } //____________________________________________________________________ void BrDbPerson::SetFirstNames(const Char_t* firstnames) { if (strlen(firstnames) > 63) { strncpy(fFirstNames, firstnames, 63); fFirstNames[63] = '0'; } else strcpy(fFirstNames,firstnames); } //____________________________________________________________________ void BrDbPerson::SetEmail(const Char_t* email) { if (strlen(email) > 63) { strncpy(fEmail, email, 63); fEmail[63] = '0'; } else strcpy(fEmail,email); } //____________________________________________________________________ void BrDbPerson::SetInstitute(const Char_t* institute) { if (strlen(institute) > 63) { strncpy(fInstitute, institute, 63); fInstitute[63] = '0'; } else strcpy(fInstitute,institute); } //____________________________________________________________________ void BrDbPerson::SplitName(const Char_t* name, Char_t* lastname, Char_t* firstnames) { // Static method. // Split name (1. arg) into last- (2.arg) and firstnames // (3.arg). 1. arg should be of the form "Doe, John", or "Jane Doe", // but no 't' (TABS) should occour in the string. if (!name) return; Int_t length = strlen(name); Int_t comma = strcspn(name, ","); if (comma != length) { strncpy(lastname, name, comma); lastname[comma] = '0'; Char_t* first = new Char_t(name[comma+1]); strncpy(firstnames, first, length-comma); } else { Char_t* last = strrchr(name, ' '); Int_t space = strlen(last); if (!last) strcpy(lastname, name); else { strcpy(lastname, last+1); } strncpy(firstnames, name, length-space); } } //____________________________________________________________________ ostream& operator<<(ostream& o, BrDbPerson& p) { o << p.GetLastName() << ", " << p.GetFirstNames() << "; " << p.GetEmail() << "; " << p.GetInstitute(); return o; } // // $Log: BrDbPerson.cxx,v $ // Revision 1.1.1.1 2001/06/21 14:55:16 hagel // Initial revision of brat2 // // Revision 1.5 2001/06/05 18:40:53 cholm // Removed BrDbInc.h an all references to it // // Revision 1.4 2001/03/22 20:44:52 cholm // Added protection for NULL TSqlRow in SingleInstance methods, and cleaned // up a bit of the stuff. // // Revision 1.3 2000/05/10 15:56:13 nbi // Added the classes BrRunsDb, BrGeometriesDb, changed some code, bug // corrections , and so on. It's almost there ;-) // // |
||||||
This page automatically generated by script docBrat by Christian Holm |
Copyright ; 2002 BRAHMS Collaboration
<brahmlib@rcf.rhic.bnl.gov>
|