2
// Copyright � 1997 - 2001, Paul C. Gregory
4
// Contact: pgregory@aqsis.com
6
// This library is free software; you can redistribute it and/or
7
// modify it under the terms of the GNU General Public
8
// License as published by the Free Software Foundation; either
9
// version 2 of the License, or (at your option) any later version.
11
// This library is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
// General Public License for more details.
16
// You should have received a copy of the GNU General Public
17
// License along with this library; if not, write to the Free Software
18
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
\brief Declares the CqFile class for handling files with RenderMan searchpath option support.
23
\author Paul C. Gregory (pgregory@aqsis.com)
26
//? Is .h included already?
27
#ifndef FILE_H_INCLUDED
28
#define FILE_H_INCLUDED 1
37
START_NAMESPACE( Aqsis )
39
// This should'nt really be in here, but for now it will do
40
#ifdef AQSIS_SYSTEM_WIN32
46
//----------------------------------------------------------------------
48
* \brief Standard handling of all file types utilising the searchpath options.
53
/** Default constructor
55
CqFile() : m_pStream( 0 ), m_bInternal( TqFalse )
57
/** Constructor taking an open stream pointer and a name.
58
* \param Stream a pointer to an already opened input stream to attach this object to.
59
* \param strRealName the name of the file associated with this stream.
61
CqFile( std::istream* Stream, const char* strRealName ) :
62
m_pStream( Stream ), m_strRealName( strRealName ), m_bInternal( TqFalse )
64
CqFile( const char* strFilename, const char* strSearchPathOption = "" );
65
/** Dectructor. Takes care of closing the stream if the constructor opened it.
69
if ( m_pStream != NULL && m_bInternal ) delete( m_pStream );
72
void Open( const char* strFilename, const char* strSearchPathOption = "", std::ios::openmode mode = std::ios::in );
73
/** Close any opened stream associated with this object.
77
if ( m_pStream != NULL ) delete( m_pStream ); m_pStream = NULL;
79
/** Find out if the stream associated with this object is valid.
80
* \return boolean indicating validity.
82
TqBool IsValid() const
84
return ( m_pStream != NULL );
86
/** Get the name asociated with this file object.
87
* \return a read only reference to the string object.
89
const CqString& strRealName() const
91
return ( m_strRealName );
94
/** Cast to a stream reference.
96
operator std::istream&()
98
return ( *m_pStream );
100
/** Cast to a stream pointer.
102
operator std::istream*()
104
return ( m_pStream );
107
/** Get the current position within the stream if appropriate.
108
* \return long integer indicating the offest from the start.
112
return ( m_pStream->tellg() );
114
/** Get the length of the stream if a file.
115
* \return the lenght as a long integer.
119
/// \todo Should check if it is a file here.
120
long pos = Position();
121
m_pStream->seekg( 0, std::ios::end );
122
long len = Position();
123
m_pStream->seekg( pos, std::ios::beg );
127
CqString FixupPath(CqString& strPath);
129
static std::list<CqString*> Glob( const CqString& strFileGlob );
130
static CqString GetSystemSetting( const CqString& strAsset );
133
std::istream* m_pStream; ///< a poimter to the stream associated with this file object.
134
CqString m_strRealName; ///< the name of this file object, usually the filename.
135
TqBool m_bInternal; ///< a flag indicating whether the stream originated internally, or was externally created and passed in.
139
//-----------------------------------------------------------------------
141
END_NAMESPACE( Aqsis )
143
#endif // !FILE_H_INCLUDED