00001 /* 00002 * resources.h 00003 * 00004 * Copyright 2002,2010,2011 Thomas A. Vaughan 00005 * All rights reserved. 00006 * 00007 * 00008 * Redistribution and use in source and binary forms, with or without 00009 * modification, are permitted provided that the following conditions are met: 00010 * * Redistributions of source code must retain the above copyright 00011 * notice, this list of conditions and the following disclaimer. 00012 * * Redistributions in binary form must reproduce the above copyright 00013 * notice, this list of conditions and the following disclaimer in the 00014 * documentation and/or other materials provided with the distribution. 00015 * * Neither the name of the <organization> nor the 00016 * names of its contributors may be used to endorse or promote products 00017 * derived from this software without specific prior written permission. 00018 * 00019 * THIS SOFTWARE IS PROVIDED BY THOMAS A. VAUGHAN ''AS IS'' AND ANY 00020 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00021 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00022 * DISCLAIMED. IN NO EVENT SHALL THOMAS A. VAUGHAN BE LIABLE FOR ANY 00023 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00024 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00025 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00026 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00027 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00028 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00029 * 00030 * Support for resources (strings, binary objects, etc.) built into the 00031 * executable. 00032 */ 00033 00034 #ifndef WAVEPACKET_RESOURCES_H__ 00035 #define WAVEPACKET_RESOURCES_H__ 00036 00037 00038 // includes -------------------------------------------------------------------- 00039 #include "common/common.h" 00040 00041 00042 //////////////////////////////////////////////////////////////////////////////// 00043 /// 00044 /// \ingroup common 00045 /// 00046 /// \defgroup common_resources Resource APIs 00047 /// 00048 /// These APIs support the ability to build resources (strings, binary 00049 /// objects, etc.) directly into the binary for later reference. 00050 /// 00051 /// - A "resource" is defined as the full contents of a specified file. 00052 /// 00053 /// - Resources are assumed to be opaque binary data. These could be image 00054 /// files used for textures, font files, etc. The point is that the 00055 /// resource library treats all resource objects the same. 00056 /// 00057 /// \n 00058 /// To use resources in your library or executable, you'll need to update the 00059 /// CMakeLists.txt file so that the resource files are built, compiled and 00060 /// linked. 00061 /// \code 00062 /// \endcode 00063 /// 00064 /// A namespace is just a string identifier, which should be reasonably unique 00065 /// so you won't have collisions with other libraries that are declaring their 00066 /// own resources. 00067 /// 00068 /// Notes on the \p resource entry: 00069 /// - \p file is a required tag 00070 /// - if no \p type is supplied, \p string is assumed. 00071 /// - if no \p name is supplied, it is assumed to be the same name as the 00072 /// \p file. 00073 /// 00074 /// \n 00075 /// This is a very low-level API to access resources. For a named-stream-based 00076 /// read-only interface, see \ref restream 00077 /// 00078 //////////////////////////////////////////////////////////////////////////////// 00079 /*@{*/ 00080 00081 00082 /// retrieve the number of resource namespaces 00083 int getResourceNamespaceCount(void) throw(); 00084 00085 00086 /// retrieve the indexed namespace name. Returns NULL on invalid input 00087 const char * getResourceNamespaceName(IN int index) throw(); 00088 00089 00090 /// retrieve the number of resources in the specified resource namespace 00091 int getResourceCount(IN const char * nameSpace) throw(); 00092 00093 00094 /// retrieve name of the indexed resource within the given resource namespace 00095 /// returns NULL if index is invalid. 00096 const char * getResourceName(IN const char * nameSpace, 00097 IN int index) throw(); 00098 00099 00100 /// retrieve information about a named resource in the given namespace 00101 /// returns 0 if name is not found 00102 int getResourceSize(IN const char * nameSpace, 00103 IN const char * name) throw(); 00104 00105 00106 /// retrieve resource data by name (returns NULL if not found). 00107 /// Caller is responsible for knowing the resource size ahead of 00108 /// time (don't rely on null terminator, etc.). 00109 const byte_t * getResourceData(IN const char * nameSpace, 00110 IN const char * name) throw(); 00111 00112 00113 /// register a new resource. Caller is responsible for ensuring that the 00114 /// resource value (raw byte buffer) is valid for the lifetime of the 00115 /// process. No copy is made. If there is a collision (a resource 00116 /// of the same name already exists), the old resource is quietly 00117 /// overwritten. Resources must be at least one byte. 00118 void registerResource(IN const char * nameSpace, 00119 IN const char * name, 00120 IN const byte_t * value, 00121 IN int bytes); 00122 00123 00124 #endif // WAVEPACKET_RESOURCES_H__ 00125