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) 2024
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 #include <UT/UT_String.h>
36 #include <UT/UT_StringArray.h>
37 #include <SYS/SYS_Types.h>
38 #include <time.h>
39 
40 namespace HDK_Sample {
41 
42 /// @file
43 /// This example shows how to add a custom file handler to Houdini. There are
44 /// three separate types of helpers that can be added. An FS_ReaderHelper is
45 /// used for reading files; an FS_WriterHelper is used for writing files; and
46 /// an FS_InfoHelper is used for getting file information and browsing
47 /// directories. In this example, we implement a subclass of each of these
48 /// classes to allow the user to specify a file name in the format
49 /// <tt>home:/foo/bar.hip</tt>. This file name will be reinterpreted by these
50 /// derived classes as if the user had entered <tt>$HOME/foo/bar.hip</tt>. This
51 /// example does not implement any subclasses of the FS_ReaderStream or
52 /// FS_WriterStream classes, but these classes can also be extended to provide
53 /// extra functionality (such as buffering of read and write operations).
54 /// @see FS_ReaderHelper, FS_InfoHelper, FS_WriterHelper
55 
56 /// @brief Class to open a file as a read stream. The class tests for a
57 /// "home:" prefix and replaces it with $HOME.
59 {
60 public:
62  ~FS_HomeReadHelper() override;
63 
64  /// If the filename starts with @c "home:", open an FS_ReaderStream
65  FS_ReaderStream *createStream(const char *source,
66  const UT_Options *options) override;
67 
68  /// Parse the source path into the index file path and the section name.
69  /// Please, see the base class for more documentation.
70  bool splitIndexFileSectionPath(const char *source_section_path,
71  UT_String &index_file_path,
72  UT_String &section_name) override;
73 
74  /// Utility function to combine index file name and section name into the
75  /// section path. Performs the reverse of splitIndexFileSectionPath().
76  /// Please, see the base class for more documentation.
78  UT_String &source_section_path,
79  const char *index_file_path,
80  const char *section_name) override;
81 };
82 
83 /// @brief Class to open a file as a write stream. The class tests for a
84 /// "home:" prefix and replaces it with $HOME.
86 {
87 public:
89  ~FS_HomeWriteHelper() override;
90 
91  /// If the filename begins with "home:" return a new write stream
92  FS_WriterStream *createStream(const char *source) override;
93 
94  /// Whether this helper supports the given source path for makeDirectory().
95  bool canMakeDirectory(const char *source) override;
96 
97  /// Make a directory and all the parent directories needed.
98  bool makeDirectory(const char *source,
99  mode_t mode = 0777,
100  bool ignore_umask = false) override;
101 };
102 
103 /// @brief Class to stat a file. The class tests for a "home:" prefix and
104 /// replaces it with $HOME.
106 {
107 public:
109  ~FS_HomeInfoHelper() override;
110 
111  bool canHandle(const char *source) override;
112  bool hasAccess(const char *source, int mode) override;
113  bool getIsDirectory(const char *source) override;
114  time_t getModTime(const char *source) override;
115  int64 getSize(const char *source) override;
116  UT_String getExtension(const char *source) override;
117  bool getContents(const char *source,
118  UT_StringArray &contents,
119  UT_StringArray *dirs) override;
120 };
121 
122 } // End HDK_Sample namespace
123 
124 #endif
125 
bool canHandle(const char *source) override
Determine whether this helper can process the filename.
bool makeDirectory(const char *source, mode_t mode=0777, bool ignore_umask=false) override
Make a directory and all the parent directories needed.
UT_String getExtension(const char *source) override
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.
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:85
time_t getModTime(const char *source) override
Get the modification timestamp (returns time_t)
bool canMakeDirectory(const char *source) override
Whether this helper supports the given source path for makeDirectory().
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:803
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.
GLenum mode
Definition: glcorearb.h:99
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:58
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