gwnavruntime/base/fileopener.h Source File

fileopener.h
Go to the documentation of this file.
1 /*
2 * Copyright 2015 Autodesk, Inc. All rights reserved.
3 * Use of this software is subject to the terms of the Autodesk license agreement and any attachments or Appendices thereto provided at the time of installation or download,
4 * or which otherwise accompanies this software in either electronic or hard copy form, or which is signed by you and accepted by Autodesk.
5 */
6 
7 
8 // primary contact: JAPA - secondary contact: GUAL
9 
10 // ***** FileOpenerBase
11 
12 // A callback interface that is used for opening files.
13 // Must return either an open file or 0 value for failure.
14 // The caller of the function is responsible for Releasing
15 // the File interface.
16 
17 #ifndef Navigation_FileOpener_H
18 #define Navigation_FileOpener_H
19 
23 
24 namespace Kaim
25 {
26 
29 {
32 };
33 
35 class FileOpenerBase : public NewOverrideBase<Stat_Default_Mem>
36 {
37 public:
38  virtual ~FileOpenerBase() {}
39 
40  int GetFlagsFromMode(FileOpenerMode mode)
41  {
42  if (mode == OpenMode_Read)
43  return FileConstants::Open_Read | FileConstants::Open_Buffered;
44 
45  else if (mode == OpenMode_Write)
46  return FileConstants::Open_Write | FileConstants::Open_Truncate | FileConstants::Open_Create | FileConstants::Open_Buffered;
47 
48  else
49  return 0;
50  }
51 
53  virtual Ptr<File> OpenFile(const char* filename, FileOpenerMode mode) = 0;
54 };
55 
56 
58 class DefaultFileOpener : public FileOpenerBase
59 {
60 public:
63  virtual Ptr<File> OpenFile(const char* filename, FileOpenerMode mode)
64  {
65  Ptr<File> file = *KY_NEW Kaim::SysFile(filename, GetFlagsFromMode(mode), FileConstants::Mode_ReadWrite);
66  if (file->IsValid() == false)
67  return NULL;
68  return file;
69  }
70 };
71 
72 }
73 
74 #endif //Navigation_FileOpener_H
Base interface for a class that opens a file on disk.
Definition: fileopener.h:35
virtual Ptr< File > OpenFile(const char *filename, FileOpenerMode mode)=0
Override to open a file using user-defined function and/or File class.
virtual Ptr< File > OpenFile(const char *filename, FileOpenerMode mode)
Override to open a file using user-defined function and/or File class.
Definition: fileopener.h:66
Opens the file for writing.
Definition: fileopener.h:31
FileOpenerMode
Enumerates the possible modes for opening a file with a class that derives from FileOpenerBase.
Definition: fileopener.h:28
Opens the file for reading only.
Definition: fileopener.h:30
Definition: gamekitcrowddispersion.h:20
Simple default implementation of an object that opens a file on disk.
Definition: fileopener.h:59