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 private import mango.io.ConduitStyle; 00042 00043 /******************************************************************************* 00044 00045 Defines how a file should be opened. You can use the predefined 00046 instances, or create specializations for your own needs. 00047 00048 *******************************************************************************/ 00049 00050 class FileStyle : ConduitStyle 00051 { 00052 /*********************************************************************** 00053 00054 Instantiate some common styles 00055 00056 ***********************************************************************/ 00057 00058 static FileStyle ReadExisting, 00059 WriteTruncate, 00060 WriteAppending, 00061 ReadWriteCreate, 00062 ReadWriteExisting; 00063 00064 /*********************************************************************** 00065 00066 ***********************************************************************/ 00067 00068 enum Open { 00069 Exists=0, // must exist 00070 Create, // create always 00071 Truncate, // must exist 00072 Append, // create if necessary 00073 }; 00074 00075 /*********************************************************************** 00076 00077 ***********************************************************************/ 00078 00079 enum Share { 00080 Read=0, // shared reading 00081 Write, // shared writing 00082 ReadWrite, // both 00083 }; 00084 00085 /*********************************************************************** 00086 00087 ***********************************************************************/ 00088 00089 enum Cache { 00090 None = 0x00, // don't optimize 00091 Random = 0x01, // optimize for random 00092 Stream = 0x02, // optimize for stream 00093 WriteThru = 0x04, // backing-cache flag 00094 }; 00095 00096 /*********************************************************************** 00097 00098 ***********************************************************************/ 00099 00100 private Open m_open; 00101 private Share m_share; 00102 private Cache m_cache; 00103 00104 /*********************************************************************** 00105 00106 Construct a set of typical FileStyle instances. 00107 00108 ***********************************************************************/ 00109 00110 static this () 00111 { 00112 ReadExisting = new FileStyle (Access.Read, Open.Exists); 00113 WriteTruncate = new FileStyle (Access.Write, Open.Truncate); 00114 WriteAppending = new FileStyle (Access.Write, Open.Append); 00115 ReadWriteCreate = new FileStyle (Access.ReadWrite, Open.Create); 00116 ReadWriteExisting = new FileStyle (Access.ReadWrite, Open.Exists); 00117 } 00118 00119 /*********************************************************************** 00120 00121 Construct a FileStyle with the given properties. Defaults 00122 are set to indicate the file should exist, will be opened 00123 for read-only sharing, and should not be cache optimized 00124 in any special manner by the OS. 00125 00126 ***********************************************************************/ 00127 00128 this (Access access, 00129 Open open = Open.Exists, 00130 Share share = Share.Read, 00131 Cache cache = Cache.None) 00132 { 00133 super(access); 00134 m_open = open; 00135 m_share = share; 00136 m_cache = cache; 00137 } 00138 00139 /*********************************************************************** 00140 00141 Return the style of opening 00142 00143 ***********************************************************************/ 00144 00145 Open open() 00146 { 00147 return m_open; 00148 } 00149 00150 /*********************************************************************** 00151 00152 Return the style of sharing 00153 00154 ***********************************************************************/ 00155 00156 Share share() 00157 { 00158 return m_share; 00159 } 00160 00161 /*********************************************************************** 00162 00163 Return the style of caching 00164 00165 ***********************************************************************/ 00166 00167 Cache cache() 00168 { 00169 return m_cache; 00170 } 00171 }