Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

FileStyle.d

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

Generated on Sun Nov 7 19:06:50 2004 for Mango by doxygen 1.3.6