paramxx  1.0.7
ParFilename.h
1 #ifndef ParFilename_H
2 #define ParFilename_H
3 
4 // --8<--8<--8<--8<--
5 //
6 // Copyright (C) 2006 Smithsonian Astrophysical Observatory
7 //
8 // This file is part of paramxx
9 //
10 // paramxx is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU General Public License
12 // as published by the Free Software Foundation; either version 2
13 // of the License, or (at your option) any later version.
14 //
15 // paramxx is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with this program; if not, write to the
22 // Free Software Foundation, Inc.
23 // 51 Franklin Street, Fifth Floor
24 // Boston, MA 02110-1301, USA
25 //
26 // -->8-->8-->8-->8--
27 
28 #include <iostream>
29 #include <string>
30 #include <vector>
31 
32 #include "ParFileException.h"
33 
34 using namespace std;
35 
44 class ParFilename {
45 
49  friend ostream& operator << ( ostream& os, ParFilename& a ) {
50  a.print( os );
51  return os;
52  }
53 
57  friend ostream& operator << ( ostream& os, ParFilename* a ) {
58  os << *a;
59  return os;
60  }
61 
62  enum ParFileDelimit { pfiles_delimit = ':', dir_delimit = '/' };
63 
64 public:
65 
69  ~ParFilename( void ) { }
70 
74  ParFilename( ) { }
75 
79  ParFilename( int argc, char** argv, const char* file = NULL )
80  throw ( ParFileException );
81 
85  string get_filename( void ) { return filename; }
86 
90  void init_ParFilename( int argc, char** argv,
91  const char* file = NULL ) throw ( ParFileException );
92 
93  static vector< string > parse_string( string& str, char delimit );
94 
95  void print( ostream& os ) {
96  os << filename;
97  }
98 
99 private:
100 
104  string filename;
105 
106  int accessible( const char* str ) throw ( ParFileException );
107 
108  void copy_pfile( const char* str ) const throw ( ParFileException );
109 
117  void check_environment_variables( ) throw ( ParFileException );
118 
125  int find_pfile( const char* name ) throw ( ParFileException );
126 
127  const char* get_basename( const char* name ) const ;
128 
132  ParFilename( const ParFilename& pf );
133 
137  ParFilename& operator = ( const ParFilename& pf );
138 
139 };
140 
141 #define PFILE "pfile="
142 
143 #endif
Definition: ParFileException.h:33
STL namespace.
~ParFilename(void)
Definition: ParFilename.h:69
Definition: ParFilename.h:44
string get_filename(void)
Definition: ParFilename.h:85
ParFilename()
Definition: ParFilename.h:74