00001 /* 00002 * Copyright (c) 2012 00003 * Side Effects Software Inc. All rights reserved. 00004 * 00005 * Redistribution and use of Houdini Development Kit samples in source and 00006 * binary forms, with or without modification, are permitted provided that the 00007 * following conditions are met: 00008 * 1. Redistributions of source code must retain the above copyright notice, 00009 * this list of conditions and the following disclaimer. 00010 * 2. The name of Side Effects Software may not be used to endorse or 00011 * promote products derived from this software without specific prior 00012 * written permission. 00013 * 00014 * THIS SOFTWARE IS PROVIDED BY SIDE EFFECTS SOFTWARE `AS IS' AND ANY EXPRESS 00015 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00016 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 00017 * NO EVENT SHALL SIDE EFFECTS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, 00018 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00019 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 00020 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00021 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00022 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 00023 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00024 * 00025 *---------------------------------------------------------------------------- 00026 */ 00027 00028 #ifndef __FS_HomeHelper__ 00029 #define __FS_HomeHelper__ 00030 00031 #include <FS/FS_Reader.h> 00032 #include <FS/FS_Writer.h> 00033 #include <FS/FS_Info.h> 00034 #include <FS/FS_Utils.h> 00035 00036 namespace HDK_Sample { 00037 00038 /// @file 00039 /// This example shows how to add a custom file handler to Houdini. There are 00040 /// three separate types of helpers that can be added. An FS_ReaderHelper is 00041 /// used for reading files; an FS_WriterHelper is used for writing files; and 00042 /// an FS_InfoHelper is used for getting file information and browsing 00043 /// directories. In this example, we implement a subclass of each of these 00044 /// classes to allow the user to specify a file name in the format 00045 /// <tt>home:/foo/bar.hip</tt>. This file name will be reinterpreted by these 00046 /// derived classes as if the user had entered <tt>$HOME/foo/bar.hip</tt>. This 00047 /// example does not implement any subclasses of the FS_ReaderStream or 00048 /// FS_WriterStream classes, but these classes can also be extended to provide 00049 /// extra functionality (such as buffering of read and write operations). 00050 /// @see FS_ReaderHelper, FS_InfoHelper, FS_WriterHelper 00051 00052 /// @brief Class to open a file as a read stream. The class tests for a 00053 /// "home:" prefix and replaces it with $HOME. 00054 class FS_HomeReadHelper : public FS_ReaderHelper 00055 { 00056 public: 00057 FS_HomeReadHelper(); 00058 virtual ~FS_HomeReadHelper(); 00059 00060 /// If the filename starts with @c "home:", open an FS_ReaderStream 00061 virtual FS_ReaderStream *createStream(const char *source); 00062 }; 00063 00064 /// @brief Class to open a file as a write stream. The class tests for a 00065 /// "home:" prefix and replaces it with $HOME. 00066 class FS_HomeWriteHelper : public FS_WriterHelper 00067 { 00068 public: 00069 FS_HomeWriteHelper(); 00070 virtual ~FS_HomeWriteHelper(); 00071 00072 /// If the filename begins with "home:" return a new write stream 00073 virtual FS_WriterStream *createStream(const char *source); 00074 }; 00075 00076 /// @brief Class to stat a file. The class tests for a "home:" prefix and 00077 /// replaces it with $HOME. 00078 class FS_HomeInfoHelper : public FS_InfoHelper 00079 { 00080 public: 00081 FS_HomeInfoHelper(); 00082 virtual ~FS_HomeInfoHelper(); 00083 00084 virtual bool canHandle(const char *source); 00085 virtual bool hasAccess(const char *source, int mode); 00086 virtual bool getIsDirectory(const char *source); 00087 virtual int getModTime(const char *source); 00088 virtual int64 getSize (const char *source); 00089 virtual bool getContents(const char *source, 00090 UT_StringArray &contents, 00091 UT_StringArray *dirs); 00092 }; 00093 00094 } // End HDK_Sample namespace 00095 00096 #endif 00097
1.5.9