gwnavruntime/base/fileopener.h Source File

fileopener.h
Go to the documentation of this file.
1 /*
2 * Copyright 2016 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 // A callback interface that is used for opening files.
9 // Must return either an open file or 0 value for failure.
10 // The caller of the function is responsible for Releasing
11 // the File interface.
12 
13 #pragma once
14 
18 
19 namespace Kaim
20 {
21 
24 {
27 };
28 
30 class FileOpenerBase : public NewOverrideBase<Stat_Default_Mem>
31 {
32 public:
33  virtual ~FileOpenerBase() {}
34 
35  int GetFlagsFromMode(FileOpenerMode mode)
36  {
37  if (mode == OpenMode_Read)
38  return FileConstants::Open_Read | FileConstants::Open_Buffered;
39 
40  else if (mode == OpenMode_Write)
41  return FileConstants::Open_Write | FileConstants::Open_Truncate | FileConstants::Open_Create | FileConstants::Open_Buffered;
42 
43  else
44  return 0;
45  }
46 
48  virtual Ptr<File> OpenFile(const char* filename, FileOpenerMode mode) = 0;
49 };
50 
51 
56 {
57 public:
58  DefaultFileOpener(FileOpenerBase* primaryFileOpener = nullptr) : m_primaryFileOpener(primaryFileOpener) {}
59 
62  virtual Ptr<File> OpenFile(const char* filename, FileOpenerMode mode)
63  {
64  if (m_primaryFileOpener)
65  {
66  return m_primaryFileOpener->OpenFile(filename, mode);
67  }
68  else
69  {
70  Ptr<File> file = *KY_NEW Kaim::SysFile(filename, GetFlagsFromMode(mode), FileConstants::Mode_ReadWrite);
71  if (file->IsValid() == false)
72  return NULL;
73  return file;
74  }
75  }
76 
77 private:
78  FileOpenerBase* m_primaryFileOpener;
79 };
80 
81 
82 }
83 
Base interface for a class that opens a file on disk.
Definition: fileopener.h:30
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:62
Opens the file for writing.
Definition: fileopener.h:26
FileOpenerMode
Enumerates the possible modes for opening a file with a class that derives from FileOpenerBase.
Definition: fileopener.h:23
Opens the file for reading only.
Definition: fileopener.h:25
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
Simple default implementation of an object that opens a file on disk that is called when the primaryF...
Definition: fileopener.h:55