CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Types | Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
FileInPath Class Reference

#include <FileInPath.h>

Public Types

typedef std::string String
 

Public Member Functions

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

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().

8  {
9  init(ipath, ifile);
10 }
void init(const String &ipath, const String &ifile)
Definition: FileInPath.cc:12
FileInPath::FileInPath ( const FileInPath rh)

Definition at line 25 of file FileInPath.cc.

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

25  :
26  directories(rh.directories), file(rh.file) {
27  if (rh.in.get()) in = own_ptr<std::ifstream>(new std::ifstream(file.c_str()));
28 }
X * get() const
Definition: own_ptr.h:83
String file
Definition: FileInPath.h:42
own_ptr< std::ifstream > in
Definition: FileInPath.h:43
std::vector< String > directories
Definition: FileInPath.h:41
FileInPath::~FileInPath ( )

destructor

Definition at line 38 of file FileInPath.cc.

38 {}

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().

12  {
13  if (ipath.empty()||ifile.empty()) return;
14 
16  typedef std::vector<std::string>::const_iterator Itr;
17  for (Itr d=directories.begin(); d!=directories.end(); d++) {
18  file = *d; file += "/"; file += ifile;
19  in = own_ptr<std::ifstream>(new std::ifstream(file.c_str()));
20  if (in->good()) break;
21  }
22  if (!in->good()) { in.release(); file="";}
23 }
String file
Definition: FileInPath.h:42
X * release() const
Definition: own_ptr.h:85
own_ptr< std::ifstream > in
Definition: FileInPath.h:43
static const String semicolon
Definition: FileInPath.h:39
std::vector< String > directories
Definition: FileInPath.h:41
Providers::iterator Itr
const String& FileInPath::name ( void  ) const
inline
std::ifstream* FileInPath::operator() ( )
inline

return stream

Definition at line 31 of file FileInPath.h.

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

31 { return in.get();}
X * get() const
Definition: own_ptr.h:83
own_ptr< std::ifstream > in
Definition: FileInPath.h:43
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.

31  {
33  file = rh.file;
34  if (rh.in.get()&&(!file.empty())) in = own_ptr<std::ifstream>(new std::ifstream(file.c_str()));
35  return *this;
36 }
X * get() const
Definition: own_ptr.h:83
String file
Definition: FileInPath.h:42
own_ptr< std::ifstream > in
Definition: FileInPath.h:43
std::vector< String > directories
Definition: FileInPath.h:41

Member Data Documentation

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

Definition at line 41 of file FileInPath.h.

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

String FileInPath::file
private

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
staticprivate

Definition at line 39 of file FileInPath.h.

Referenced by init().