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) 2018
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  virtual ~FS_HomeReadHelper();
59 
60  /// If the filename starts with @c "home:", open an FS_ReaderStream
61  virtual FS_ReaderStream *createStream(const char *source,
62  const UT_Options *options);
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  virtual bool splitIndexFileSectionPath(const char *source_section_path,
67  UT_String &index_file_path,
68  UT_String &section_name);
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.
73  virtual bool combineIndexFileSectionPath(
74  UT_String &source_section_path,
75  const char *index_file_path,
76  const char *section_name);
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  virtual ~FS_HomeWriteHelper();
86 
87  /// If the filename begins with "home:" return a new write stream
88  virtual FS_WriterStream *createStream(const char *source);
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  virtual ~FS_HomeInfoHelper();
98 
99  virtual bool canHandle(const char *source);
100  virtual bool hasAccess(const char *source, int mode);
101  virtual bool getIsDirectory(const char *source);
102  virtual int getModTime(const char *source);
103  virtual int64 getSize(const char *source);
104  virtual UT_String getExtension(const char *source);
105  virtual bool getContents(const char *source,
106  UT_StringArray &contents,
107  UT_StringArray *dirs);
108 };
109 
110 } // End HDK_Sample namespace
111 
112 #endif
113 
virtual bool splitIndexFileSectionPath(const char *source_section_path, UT_String &index_file_path, UT_String &section_name)
virtual bool getIsDirectory(const char *source)
Return whether the filename is a directory.
virtual FS_ReaderStream * createStream(const char *source, const UT_Options *options)
If the filename starts with "home:", open an FS_ReaderStream.
virtual UT_String getExtension(const char *source)
virtual bool canHandle(const char *source)
Determine whether this helper can process the filename.
virtual bool getContents(const char *source, UT_StringArray &contents, UT_StringArray *dirs)
virtual bool hasAccess(const char *source, int mode)
virtual int64 getSize(const char *source)
Get the file size in bytes.
long long int64
Definition: SYS_Types.h:107
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
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:802
virtual int getModTime(const char *source)
Get the modification timestamp (returns time_t)
Class to stat a file. The class tests for a "home:" prefix and replaces it with $HOME.
Definition: FS_HomeHelper.h:93
virtual FS_WriterStream * createStream(const char *source)
If the filename begins with "home:" return a new write stream.
GLenum mode
Definition: glcorearb.h:98
A map of string to various well defined value types.
Definition: UT_Options.h:42
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
virtual bool combineIndexFileSectionPath(UT_String &source_section_path, const char *index_file_path, const char *section_name)