Rapicorn - Experimental UI Toolkit - Source Code
13.07.0
|
00001 // Licensed GNU LGPL v3 or later: http://www.gnu.org/licenses/lgpl.html 00002 #ifndef __RAPICORN_BLOBRES_HH__ 00003 #define __RAPICORN_BLOBRES_HH__ 00004 00005 #include <rcore/utilities.hh> 00006 #include <memory> 00007 00008 namespace Rapicorn { 00009 00010 // == Blob == 00011 class BlobResource; 00012 class Blob { 00013 std::shared_ptr<BlobResource> blob_; 00014 typedef size_t (Blob::*_UBool) () const; // unspecified-type-boolean for non-numeric operator bool() result 00015 static _UBool _ubool1 () { return &Blob::size; } // unspecified-type-boolean true value 00016 _UBool _bool () const { return blob_ && size() ? _ubool1() : 0; } 00017 explicit Blob (const std::shared_ptr<BlobResource> &initblob); 00018 public: 00019 explicit Blob (); 00020 String name () const; 00021 size_t size () const; 00022 const char* data () const; 00023 const uint8* bytes () const; 00024 String string () const; 00025 operator _UBool () const { return _bool(); } 00026 static Blob load (const String &res_path); 00027 static Blob from (const String &blob_string); 00028 }; 00029 00030 // == Resource Macros == 00031 00033 #define RAPICORN_STATIC_RESOURCE_DATA(IDENT) \ 00034 static const char __Rapicorn_static_resourceD__##IDENT[] __attribute__ ((__aligned__ (2 * sizeof (size_t)))) 00035 00037 #define RAPICORN_STATIC_RESOURCE_ENTRY(IDENT, PATH, ...) \ 00038 static const Rapicorn::ResourceEntry __Rapicorn_static_resourceE__##IDENT = { PATH, __Rapicorn_static_resourceD__##IDENT, __VA_ARGS__ }; 00039 00040 // == Internals == 00042 class ResourceEntry { 00043 ResourceEntry *next; 00044 const char *const name; 00045 const char *const pdata; 00046 const size_t psize, dsize; 00047 friend class Blob; 00048 static const ResourceEntry* find_entry (const String&); 00049 static void reg_add (ResourceEntry*); 00050 public: 00051 template <size_t N> ResourceEntry (const char *res, const char (&idata) [N], size_t data_size = 0) : 00052 next (NULL), name (res), pdata (idata), psize (N), dsize (data_size) 00053 { reg_add (this); } 00054 /*dtor*/ ~ResourceEntry(); 00055 }; 00057 00058 } // Rapicorn 00059 00060 #endif // __RAPICORN_BLOBRES_HH__