00001 /******************************************************************************* 00002 00003 @file FileStyle.d 00004 00005 Copyright (c) 2004 Kris Bell 00006 00007 This software is provided 'as-is', without any express or implied 00008 warranty. In no event will the authors be held liable for damages 00009 of any kind arising from the use of this software. 00010 00011 Permission is hereby granted to anyone to use this software for any 00012 purpose, including commercial applications, and to alter it and/or 00013 redistribute it freely, subject to the following restrictions: 00014 00015 1. The origin of this software must not be misrepresented; you must 00016 not claim that you wrote the original software. If you use this 00017 software in a product, an acknowledgment within documentation of 00018 said product would be appreciated but is not required. 00019 00020 2. Altered source versions must be plainly marked as such, and must 00021 not be misrepresented as being the original software. 00022 00023 3. This notice may not be removed or altered from any distribution 00024 of the source. 00025 00026 4. Derivative works are permitted, but they must carry this notice 00027 in full and credit the original source. 00028 00029 00030 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 00031 00032 00033 @version Initial version, March 2004 00034 @author Kris 00035 00036 00037 *******************************************************************************/ 00038 00039 module mango.io.FileStyle; 00040 00041 pragma (msg, "FileStyle module deprecated -- please remove the import. Related constants are now in FileConduit"); 00042 00043 /+ 00044 private import mango.io.ConduitStyle; 00045 00046 /******************************************************************************* 00047 00048 Defines how a file should be opened. You can use the predefined 00049 instances, or create specializations for your own needs. 00050 00051 *******************************************************************************/ 00052 00053 class FileStyle : ConduitStyle 00054 { 00055 /*********************************************************************** 00056 00057 Instantiate some common styles 00058 00059 ***********************************************************************/ 00060 00061 static FileStyle ReadExisting, 00062 WriteTruncate, 00063 WriteAppending, 00064 ReadWriteCreate, 00065 ReadWriteExisting; 00066 00067 /*********************************************************************** 00068 00069 ***********************************************************************/ 00070 00071 enum Open { 00072 Exists=0, // must exist 00073 Create, // create always 00074 Truncate, // must exist 00075 Append, // create if necessary 00076 }; 00077 00078 /*********************************************************************** 00079 00080 ***********************************************************************/ 00081 00082 enum Share { 00083 Read=0, // shared reading 00084 Write, // shared writing 00085 ReadWrite, // both 00086 }; 00087 00088 /*********************************************************************** 00089 00090 ***********************************************************************/ 00091 00092 enum Cache { 00093 None = 0x00, // don't optimize 00094 Random = 0x01, // optimize for random 00095 Stream = 0x02, // optimize for stream 00096 WriteThru = 0x04, // backing-cache flag 00097 }; 00098 00099 /*********************************************************************** 00100 00101 ***********************************************************************/ 00102 00103 private Open m_open; 00104 private Share m_share; 00105 private Cache m_cache; 00106 00107 /*********************************************************************** 00108 00109 Construct a set of typical FileStyle instances. 00110 00111 ***********************************************************************/ 00112 00113 static this () 00114 { 00115 ReadExisting = new FileStyle (Access.Read, Open.Exists); 00116 WriteTruncate = new FileStyle (Access.Write, Open.Truncate); 00117 WriteAppending = new FileStyle (Access.Write, Open.Append); 00118 ReadWriteCreate = new FileStyle (Access.ReadWrite, Open.Create); 00119 ReadWriteExisting = new FileStyle (Access.ReadWrite, Open.Exists); 00120 } 00121 00122 /*********************************************************************** 00123 00124 Construct a FileStyle with the given properties. Defaults 00125 are set to indicate the file should exist, will be opened 00126 for read-only sharing, and should not be cache optimized 00127 in any special manner by the OS. 00128 00129 ***********************************************************************/ 00130 00131 this (Access access, 00132 Open open = Open.Exists, 00133 Share share = Share.Read, 00134 Cache cache = Cache.None) 00135 { 00136 super(access); 00137 m_open = open; 00138 m_share = share; 00139 m_cache = cache; 00140 } 00141 00142 /*********************************************************************** 00143 00144 Return the style of opening 00145 00146 ***********************************************************************/ 00147 00148 Open open() 00149 { 00150 return m_open; 00151 } 00152 00153 /*********************************************************************** 00154 00155 Return the style of sharing 00156 00157 ***********************************************************************/ 00158 00159 Share share() 00160 { 00161 return m_share; 00162 } 00163 00164 /*********************************************************************** 00165 00166 Return the style of caching 00167 00168 ***********************************************************************/ 00169 00170 Cache cache() 00171 { 00172 return m_cache; 00173 } 00174 } 00175 +/