OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [host/] [tools/] [Utils/] [win32/] [FileName.h] - Blame information for rev 790

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
// ####ECOSHOSTGPLCOPYRIGHTBEGIN####                                        
2
// -------------------------------------------                              
3
// This file is part of the eCos host tools.                                
4
// Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.            
5
//
6
// This program is free software; you can redistribute it and/or modify     
7
// it under the terms of the GNU General Public License as published by     
8
// the Free Software Foundation; either version 2 or (at your option) any   
9
// later version.                                                           
10
//
11
// This program is distributed in the hope that it will be useful, but      
12
// 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 License        
17
// along with this program; if not, write to the                            
18
// Free Software Foundation, Inc., 51 Franklin Street,                      
19
// Fifth Floor, Boston, MA  02110-1301, USA.                                
20
// -------------------------------------------                              
21
// ####ECOSHOSTGPLCOPYRIGHTEND####                                          
22
//===========================================================================
23
//#####DESCRIPTIONBEGIN####
24
//
25
// Author(s):   sdf
26
// Contact(s):  sdf
27
// Date:                1998/09/11
28
// Version:             0.01
29
// Purpose:             Class to encapsulate filename operations (i.e. broadly on a file which probably do not involve opening
30
//              it).  Importantly, the + and += operators performs filename segment addition, making sure that only one '\\'
31
//                              comes between each piece.
32
// Description: Interface of a the filename class
33
// Requires:    
34
// Provides:    
35
// See also:    
36
// Known bugs:  
37
// Usage:       
38
//
39
//####DESCRIPTIONEND####
40
//
41
//===========================================================================
42
 
43
#ifndef _FILENAME_H
44
#define _FILENAME_H
45
#include <afxtempl.h>
46
class CFileName;
47
typedef CArray<CFileName,CFileName&> CFileNameArray;
48
class CFileName : public CString {
49
public:
50
        void ReplaceExtension (LPCTSTR pszNewExt);
51
 
52
  // previous directory is returned:
53
  static CFileName SetCurrentDirectory (LPCTSTR pszDir);
54
  const CString Root() const;
55
  const CString Extension() const;
56
  static CFileName GetTempPath();
57
  bool IsAbsolute() const;
58
 
59
  static const TCHAR cSep;        // The path separator ('\' on windows)
60
 
61
  // Standard ctors
62
  CFileName():CString(){}
63
  CFileName(const CFileName& stringSrc):CString(stringSrc){Normalize();}
64
  CFileName(const CString& stringSrc):CString(stringSrc){Normalize();}
65
  CFileName(TCHAR ch, int nRepeat = 1):CString(ch,nRepeat){Normalize();}
66
  CFileName(LPCSTR lpsz):CString(lpsz){Normalize();}
67
  CFileName(LPCWSTR lpsz):CString(lpsz){Normalize();}
68
  CFileName(LPCSTR lpch, int nLength):CString(lpch,nLength){Normalize();}
69
  CFileName(LPCWSTR lpch, int nLength):CString(lpch,nLength){Normalize();}
70
  CFileName(const unsigned char* psz):CString(psz){Normalize();}
71
 
72
  // Construct from path fragments
73
  CFileName(LPCTSTR,LPCTSTR);
74
  CFileName(LPCTSTR,LPCTSTR,LPCTSTR);
75
  CFileName(LPCTSTR,LPCTSTR,LPCTSTR,LPCTSTR);
76
  CFileName(LPCTSTR,LPCTSTR,LPCTSTR,LPCTSTR,LPCTSTR);
77
 
78
  // catenation operators: exactly one separator is placed between L and R
79
  const CFileName& operator+=(const CFileName& string);
80
  const CFileName& operator+=(TCHAR ch);
81
#ifdef _UNICODE
82
  const CFileName& operator+=(char ch);
83
#endif
84
  const CFileName& operator+=(LPCTSTR lpsz);
85
  friend CFileName AFXAPI operator+(const CFileName& string1,const CFileName& string2);
86
  friend CFileName AFXAPI operator+(const CFileName& string, TCHAR ch);
87
  friend CFileName AFXAPI operator+(TCHAR ch, const CFileName& string);
88
#ifdef _UNICODE
89
  friend CFileName AFXAPI operator+(const CFileName& string, char ch);
90
  friend CFileName AFXAPI operator+(char ch, const CFileName& string);
91
#endif
92
  friend CFileName AFXAPI operator+(const CFileName& string, LPCTSTR lpsz);
93
  friend CFileName AFXAPI operator+(LPCTSTR lpsz, const CFileName& string);
94
 
95
  // Textual append - no separator functionality
96
  const CFileName& Append (TCHAR ch);
97
  const CFileName& Append (LPCTSTR psz);
98
 
99
  // Utility functions
100
  const CFileName FullName() const;   // full path name
101
  const CFileName NoSpaceName() const;// sans spaces
102
  const CFileName ShortName() const;    // the type with ~s in it
103
  const CFileName Tail() const;       // file name sans directory part
104
  const CFileName Head() const;       // directory part
105
  const CFileName CygPath() const;    // path mangled for CygWin
106
 
107
  static CFileName GetCurrentDirectory();
108
  const CFileName& ExpandEnvironmentStrings();
109
  static CFileName ExpandEnvironmentStrings(LPCTSTR psz);
110
 
111
  // Form path name relative to given parameter (if NULL, current directory)
112
  const CFileName& MakeRelative(LPCTSTR pszRelativeTo=0);
113
  static CFileName Relative(LPCTSTR psz,LPCTSTR pszRelativeTo=0);
114
 
115
  bool SameFile (const CFileName &strOther) const;
116
  bool SetFileAttributes (DWORD dwFileAttributes) const;
117
 
118
  DWORD Attributes() const { return ::GetFileAttributes(*this); }
119
 
120
  bool Exists     () const {return 0xFFFFFFFF!=Attributes();}
121
  bool IsDir      () const {    DWORD a=Attributes(); return 0xFFFFFFFF!=a && (0!=(a&FILE_ATTRIBUTE_DIRECTORY));}
122
  bool IsFile     () const {    DWORD a=Attributes(); return 0xFFFFFFFF!=a && (0==(a&FILE_ATTRIBUTE_DIRECTORY));}
123
  bool IsReadOnly () const {    DWORD a=Attributes(); return 0xFFFFFFFF!=a && (0!=(a&FILE_ATTRIBUTE_READONLY ));}
124
  FILETIME LastModificationTime() const;
125
 
126
  bool RecursivelyDelete();
127
 
128
  bool CreateDirectory (bool bParentsToo=true,bool bFailIfAlreadyExists=false) const;
129
 
130
  static int FindFiles (LPCTSTR pszDir,CFileNameArray &ar,LPCTSTR pszPattern=_T("*.*"),bool bRecurse=true,DWORD dwExclude=FILE_ATTRIBUTE_DIRECTORY|FILE_ATTRIBUTE_HIDDEN);
131
 
132
protected:
133
  // Helpers for Relative():
134
  LPCTSTR *Chop ();
135
  static CFileName Drive(LPCTSTR psz);
136
 
137
  // Remove trailing '/' (helper for ctors)
138
  void Normalize();
139
 
140
  // Implementating catenation functionality:
141
  void ConcatInPlace(int nSrcLen, LPCTSTR lpszSrcData);
142
  void ConcatCopy(int nSrc1Len, LPCTSTR lpszSrc1Data,int nSrc2Len, LPCTSTR lpszSrc2Data);
143
};
144
 
145
class CSaveExcursion {
146
  const CFileName m_strPrevDir;
147
public:
148
  CSaveExcursion(LPCTSTR pszDir) : m_strPrevDir(CFileName::SetCurrentDirectory(pszDir)) {}
149
  ~CSaveExcursion() { ::SetCurrentDirectory(m_strPrevDir); }
150
  bool Ok() const { return !m_strPrevDir.IsEmpty(); }
151
};
152
 
153
#endif  

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.