HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FS_HomeHelper.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021
3  * Side Effects Software Inc. All rights reserved.
4  *
5  * Redistribution and use of Houdini Development Kit samples in source and
6  * binary forms, with or without modification, are permitted provided that the
7  * following conditions are met:
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * 2. The name of Side Effects Software may not be used to endorse or
11  * promote products derived from this software without specific prior
12  * written permission.
13  *
14  * THIS SOFTWARE IS PROVIDED BY SIDE EFFECTS SOFTWARE `AS IS' AND ANY EXPRESS
15  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
17  * NO EVENT SHALL SIDE EFFECTS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
18  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
19  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
20  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
21  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
22  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
23  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  *
25  *----------------------------------------------------------------------------
26  */
27 
28 #ifndef __FS_HomeHelper__
29 #define __FS_HomeHelper__
30 
31 #include <FS/FS_Reader.h>
32 #include <FS/FS_Writer.h>
33 #include <FS/FS_Info.h>
34 #include <FS/FS_Utils.h>
35 
36 namespace HDK_Sample {
37 
38 /// @file
39 /// This example shows how to add a custom file handler to Houdini. There are
40 /// three separate types of helpers that can be added. An FS_ReaderHelper is
41 /// used for reading files; an FS_WriterHelper is used for writing files; and
42 /// an FS_InfoHelper is used for getting file information and browsing
43 /// directories. In this example, we implement a subclass of each of these
44 /// classes to allow the user to specify a file name in the format
45 /// <tt>home:/foo/bar.hip</tt>. This file name will be reinterpreted by these
46 /// derived classes as if the user had entered <tt>$HOME/foo/bar.hip</tt>. This
47 /// example does not implement any subclasses of the FS_ReaderStream or
48 /// FS_WriterStream classes, but these classes can also be extended to provide
49 /// extra functionality (such as buffering of read and write operations).
50 /// @see FS_ReaderHelper, FS_InfoHelper, FS_WriterHelper
51 
52 /// @brief Class to open a file as a read stream. The class tests for a
53 /// "home:" prefix and replaces it with $HOME.
55 {
56 public:
58  ~FS_HomeReadHelper() override;
59 
60  /// If the filename starts with @c "home:", open an FS_ReaderStream
61  FS_ReaderStream *createStream(const char *source,
62  const UT_Options *options) override;
63 
64  /// Parse the source path into the index file path and the section name.
65  /// Please, see the base class for more documentation.
66  bool splitIndexFileSectionPath(const char *source_section_path,
67  UT_String &index_file_path,
68  UT_String &section_name) override;
69 
70  /// Utility function to combine index file name and section name into the
71  /// section path. Performs the reverse of splitIndexFileSectionPath().
72  /// Please, see the base class for more documentation.
74  UT_String &source_section_path,
75  const char *index_file_path,
76  const char *section_name) override;
77 };
78 
79 /// @brief Class to open a file as a write stream. The class tests for a
80 /// "home:" prefix and replaces it with $HOME.
82 {
83 public:
85  ~FS_HomeWriteHelper() override;
86 
87  /// If the filename begins with "home:" return a new write stream
88  FS_WriterStream *createStream(const char *source) override;
89 };
90 
91 /// @brief Class to stat a file. The class tests for a "home:" prefix and
92 /// replaces it with $HOME.
94 {
95 public:
97  ~FS_HomeInfoHelper() override;
98 
99  bool canHandle(const char *source) override;
100  bool hasAccess(const char *source, int mode) override;
101  bool getIsDirectory(const char *source) override;
102  int getModTime(const char *source) override;
103  int64 getSize(const char *source) override;
104  UT_String getExtension(const char *source) override;
105  bool getContents(const char *source,
106  UT_StringArray &contents,
107  UT_StringArray *dirs) override;
108 };
109 
110 } // End HDK_Sample namespace
111 
112 #endif
113 
bool canHandle(const char *source) override
Determine whether this helper can process the filename.
int getModTime(const char *source) override
Get the modification timestamp (returns time_t)
UT_String getExtension(const char *source) override
GLenum mode
Definition: glew.h:2163
bool splitIndexFileSectionPath(const char *source_section_path, UT_String &index_file_path, UT_String &section_name) override
bool getIsDirectory(const char *source) override
Return whether the filename is a directory.
FS_ReaderStream * createStream(const char *source, const UT_Options *options) override
If the filename starts with "home:", open an FS_ReaderStream.
GLsizei GLsizei GLchar * source
Definition: glew.h:1832
bool combineIndexFileSectionPath(UT_String &source_section_path, const char *index_file_path, const char *section_name) override
Class to open a file as a write stream. The class tests for a "home:" prefix and replaces it with $HO...
Definition: FS_HomeHelper.h:81
long long int64
Definition: SYS_Types.h:116
Class to stat a file. The class tests for a "home:" prefix and replaces it with $HOME.
Definition: FS_HomeHelper.h:93
int64 getSize(const char *source) override
Get the file size in bytes.
bool hasAccess(const char *source, int mode) override
A map of string to various well defined value types.
Definition: UT_Options.h:84
Class to open a file as a read stream. The class tests for a "home:" prefix and replaces it with $HOM...
Definition: FS_HomeHelper.h:54
FS_WriterStream * createStream(const char *source) override
If the filename begins with "home:" return a new write stream.
bool getContents(const char *source, UT_StringArray &contents, UT_StringArray *dirs) override