CMS 3D CMS Logo

Public Types | Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes

FileInPath Class Reference

#include <FileInPath.h>

List of all members.

Public Types

typedef std::string String

Public Member Functions

 FileInPath (const String &ipath, const String &ifile)
 constructor
 FileInPath (const FileInPath &rh)
const Stringname () const
 return full name
std::ifstream * operator() ()
 return stream
FileInPathoperator= (const FileInPath &rh)
 and usual operator
 ~FileInPath ()
 destructor

Private Member Functions

void init (const String &ipath, const String &ifile)

Private Attributes

std::vector< Stringdirectories
String file
own_ptr< std::ifstream > in

Static Private Attributes

static const String semicolon

Detailed Description

open the first file found in a ":"-separated list of files (path)

Definition at line 14 of file FileInPath.h.


Member Typedef Documentation

typedef std::string FileInPath::String

Definition at line 16 of file FileInPath.h.


Constructor & Destructor Documentation

FileInPath::FileInPath ( const String ipath,
const String ifile 
)

constructor

Definition at line 8 of file FileInPath.cc.

References init().

                                                                       {
  init(ipath, ifile);
}
FileInPath::FileInPath ( const FileInPath rh)

Definition at line 25 of file FileInPath.cc.

References file, own_ptr< X, P >::get(), and in.

                                            : 
  directories(rh.directories), file(rh.file) {
  if (rh.in.get()) in = own_ptr<std::ifstream>(new std::ifstream(file.c_str()));
}
FileInPath::~FileInPath ( )

destructor

Definition at line 38 of file FileInPath.cc.

{}

Member Function Documentation

void FileInPath::init ( const String ipath,
const String ifile 
) [private]

Definition at line 12 of file FileInPath.cc.

References directories, file, compare_using_db::ifile, in, own_ptr< X, P >::release(), and semicolon.

Referenced by FileInPath().

                                                                      {
  if (ipath.empty()||ifile.empty()) return;

  directories = Tokenizer(semicolon,ipath);
  typedef std::vector<std::string>::const_iterator Itr;
  for (Itr d=directories.begin(); d!=directories.end(); d++) {
    file = *d; file += "/"; file += ifile;
    in = own_ptr<std::ifstream>(new std::ifstream(file.c_str()));
    if (in->good()) break;
  }
  if (!in->good()) { in.release(); file="";}
}
const String& FileInPath::name ( void  ) const [inline]

return full name

Definition at line 34 of file FileInPath.h.

References file.

Referenced by CSCGasCollisions::readCollisionTable().

{ return file;}
std::ifstream* FileInPath::operator() ( ) [inline]

return stream

Definition at line 31 of file FileInPath.h.

References own_ptr< X, P >::get(), and in.

{ return in.get();} 
FileInPath & FileInPath::operator= ( const FileInPath rh)

and usual operator

Definition at line 31 of file FileInPath.cc.

References directories, file, own_ptr< X, P >::get(), and in.

                                                        {
  directories = rh.directories; 
  file = rh.file;
  if (rh.in.get()&&(!file.empty())) in = own_ptr<std::ifstream>(new std::ifstream(file.c_str()));
  return *this;
}

Member Data Documentation

std::vector<String> FileInPath::directories [private]

Definition at line 41 of file FileInPath.h.

Referenced by init(), and operator=().

Definition at line 42 of file FileInPath.h.

Referenced by FileInPath(), init(), name(), and operator=().

own_ptr<std::ifstream> FileInPath::in [private]

Definition at line 43 of file FileInPath.h.

Referenced by FileInPath(), init(), operator()(), and operator=().

const std::string FileInPath::semicolon [static, private]

Definition at line 39 of file FileInPath.h.

Referenced by init().