Bdb packages | Design docs | Source docs | Guidelines | Recent releases

Search | Site Map .

Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

/BdbClustering/BdbComponent.cc

Go to the documentation of this file.
00001 //------------------------------------------------------------------------------
00002 // File:
00003 //      BdbComponent.cc
00004 //
00005 // Description:
00006 //
00007 //      
00008 //
00009 // Environment:
00010 //      Software developed for the BaBar Detector at the SLAC B-Factory
00011 //
00012 // Author List:
00013 //      Jacek Becla                Original Author
00014 //
00015 // Copyright Information:
00016 //      Copyright (C) 1997      Stanford Linear Accelerator Center
00017 //
00018 //------------------------------------------------------------------------------
00019 
00020 // ----------------------
00021 // This Class's Header --
00022 // ----------------------
00023 #ifndef BDBCOMPONENT_HH
00024 #include "BdbClustering/BdbComponent.hh"
00025 #endif
00026 
00027 
00028 // ------------------------------
00029 // Collaborating Class Headers --
00030 // ------------------------------
00031 #ifndef BDBDEBUG_HH
00032 #include "BdbApplication/BdbDebug.hh"
00033 #endif
00034 
00035 #ifndef BDBCLUSTERINGERRORS_HH
00036 #include "BdbClustering/BdbClusteringErrors.hh"
00037 #endif
00038 
00039 // ------------
00040 // C Headers --
00041 // ------------
00042 
00043 extern "C" {
00044 #include <ctype.h>   /* isalnum, isupper, tolower */
00045 }
00046 
00047 // ----------------------------
00048 // Constructors / Destructor --
00049 // ----------------------------
00050 
00051 BdbComponent::BdbComponent()
00052 {
00053     _name = 0;
00054     _componentChanged = d_True;
00055 }
00056 
00057 
00058 BdbComponent::BdbComponent(BdbComponent& obj)
00059 {
00060     if ( obj._name == 0 )
00061         _name = 0;
00062     else
00063         {  _name = new char [ strlen(obj._name)+1 ];
00064         strcpy(_name, obj._name);
00065         }
00066 
00067     _componentChanged = obj._componentChanged;
00068 }
00069 
00070 
00071 BdbComponent::~BdbComponent()
00072 {
00073     reset();
00074 }
00075 
00076 
00077 
00078 // ------
00079 // Set --
00080 // ------
00081 
00082 BdbStatus 
00083 BdbComponent::setC(const char* name, d_Boolean applyRestr)
00084 {
00085     if ( name == 0 ) {
00086         return BdbSignal(BdbcUserError, BdbClusteringErrCompIsNul, 0, "BdbComponent::setC");
00087     }
00088 
00089     // note that the same verification is done during loading data from ASCII file
00090    
00091     int length = strlen(name);
00092     if ( length > 6 && applyRestr ) { 
00093         BdbSignal(BdbcUserError, BdbClusteringErrCompNameTooLong, 0, "BdbComponent::setC");
00094         length = 6;
00095     }
00096 
00097     reset();
00098     _name = new char [ length+1 ];
00099 
00100     d_Boolean issueWarning = d_False;
00101     for (int i=0 ; i<length ; i++) {
00102         char c = name[i];
00103         if ( ! isalnum(c) && applyRestr ) {
00104             issueWarning = d_True;
00105             _name[i] = '_';
00106         }
00107         else if ( isupper(c) && applyRestr ) {
00108             issueWarning = d_True;
00109             _name[i] = tolower(c);
00110         }
00111         else {
00112             _name[i] = c;
00113         }
00114     }
00115     _name[length] = '\0';
00116 
00117     if ( issueWarning ) {
00118         COUT1 << "Specified component name was not valid and has been changed to " << _name << endl;
00119         // BdbSignal(BdbcWarning, BdbClusteringErrCompNameAltered, 0, "BdbComponent::setC", _name);
00120     }
00121 
00122     setComponentChanged();
00123 
00124     return BdbcSuccess;
00125 }
00126 
00127 d_Boolean 
00128 BdbComponent::isIllegal(const char* name) const
00129 {  
00130     if ( name == 0 ) {
00131         return d_True;
00132     }
00133 
00134     return d_False;
00135 }
00136 
00137 d_Boolean 
00138 BdbComponent::isTheSameAs(const char* name) const
00139 {
00140     if ( name == 0 || _name == 0 ) {
00141         return d_False;
00142     }
00143 
00144     return strcmp(name, _name) == 0;
00145 }

 


BaBar Public Site | SLAC | News | Links | Who's Who | Contact Us

Page Owner: Jacek Becla
Last Update: October 04, 2002