~ubuntu-branches/ubuntu/warty/aqsis/warty

« back to all changes in this revision

Viewing changes to libaqsistypes/file.h

  • Committer: Bazaar Package Importer
  • Author(s): LaMont Jones
  • Date: 2004-08-24 07:25:04 UTC
  • Revision ID: james.westby@ubuntu.com-20040824072504-zf993vnevvisdsvb
Tags: upstream-0.9.1
Import upstream version 0.9.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Aqsis
 
2
// Copyright � 1997 - 2001, Paul C. Gregory
 
3
//
 
4
// Contact: pgregory@aqsis.com
 
5
//
 
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.
 
10
//
 
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.
 
15
//
 
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
 
19
 
 
20
 
 
21
/** \file
 
22
                \brief Declares the CqFile class for handling files with RenderMan searchpath option support.
 
23
                \author Paul C. Gregory (pgregory@aqsis.com)
 
24
*/
 
25
 
 
26
//? Is .h included already?
 
27
#ifndef FILE_H_INCLUDED
 
28
#define FILE_H_INCLUDED 1
 
29
 
 
30
#include        <iostream>
 
31
#include        <list>
 
32
 
 
33
#include        "aqsis.h"
 
34
 
 
35
#include        "sstring.h"
 
36
 
 
37
START_NAMESPACE( Aqsis )
 
38
 
 
39
// This should'nt really be in here, but for now it will do
 
40
#ifdef AQSIS_SYSTEM_WIN32
 
41
#define DIRSEP "\\"
 
42
#else
 
43
#define DIRSEP "/"
 
44
#endif
 
45
 
 
46
//----------------------------------------------------------------------
 
47
/** \class CqFile
 
48
 *  \brief Standard handling of all file types utilising the searchpath options.
 
49
 */
 
50
class CqFile
 
51
{
 
52
public:
 
53
    /** Default constructor
 
54
     */
 
55
    CqFile() : m_pStream( 0 ), m_bInternal( TqFalse )
 
56
    {}
 
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.
 
60
     */
 
61
    CqFile( std::istream* Stream, const char* strRealName ) :
 
62
            m_pStream( Stream ), m_strRealName( strRealName ), m_bInternal( TqFalse )
 
63
    {}
 
64
    CqFile( const char* strFilename, const char* strSearchPathOption = "" );
 
65
    /** Dectructor. Takes care of closing the stream if the constructor opened it.
 
66
     */
 
67
    virtual     ~CqFile()
 
68
    {
 
69
        if ( m_pStream != NULL && m_bInternal ) delete( m_pStream );
 
70
    }
 
71
 
 
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.
 
74
     */
 
75
    void        Close()
 
76
    {
 
77
        if ( m_pStream != NULL ) delete( m_pStream ); m_pStream = NULL;
 
78
    }
 
79
    /** Find out if the stream associated with this object is valid.
 
80
     * \return boolean indicating validity.
 
81
     */
 
82
    TqBool      IsValid() const
 
83
    {
 
84
        return ( m_pStream != NULL );
 
85
    }
 
86
    /** Get the name asociated with this file object.
 
87
     * \return a read only reference to the string object.
 
88
     */
 
89
    const CqString&     strRealName() const
 
90
    {
 
91
        return ( m_strRealName );
 
92
    }
 
93
 
 
94
    /** Cast to a stream reference.
 
95
     */
 
96
    operator std::istream&()
 
97
    {
 
98
        return ( *m_pStream );
 
99
    }
 
100
    /** Cast to a stream pointer.
 
101
     */
 
102
    operator std::istream*()
 
103
    {
 
104
        return ( m_pStream );
 
105
    }
 
106
 
 
107
    /** Get the current position within the stream if appropriate.
 
108
     * \return long integer indicating the offest from the start.
 
109
     */
 
110
    TqLong      Position()
 
111
    {
 
112
        return ( m_pStream->tellg() );
 
113
    }
 
114
    /** Get the length of the stream if a file.
 
115
     * \return the lenght as a long integer.
 
116
     */
 
117
    TqLong      Length()
 
118
    {
 
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 );
 
124
        return ( len );
 
125
    }
 
126
 
 
127
    CqString FixupPath(CqString& strPath);
 
128
 
 
129
    static std::list<CqString*> Glob( const CqString& strFileGlob );
 
130
    static CqString GetSystemSetting( const CqString& strAsset );
 
131
 
 
132
private:
 
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.
 
136
}
 
137
;
 
138
 
 
139
//-----------------------------------------------------------------------
 
140
 
 
141
END_NAMESPACE( Aqsis )
 
142
 
 
143
#endif  // !FILE_H_INCLUDED