Overview   API Reference  

resource_manager.hpp

00001 #if !defined(__RESOURCE_MANAGER_HPP__)
00002 #define __RESOURCE_MANAGER_HPP__
00003 
00004 //
00005 // local includes
00006 //
00007 #include "core/common.hpp"
00008 
00012 struct resource_manager
00013 {
00014     //
00015     // range checker. defined here to specialize for 16 bit unsigned integer,
00016     //     which would otherwise produce an annoying warning.
00017     //
00018     template <typename IndexT, int NumberC>
00019     struct range_traits
00020     {
00021         static inline bool is_valid(const IndexT index)
00022         {
00023             static_assert(is_unsigned<IndexT>::conforms, "IndexT must be an unsigned integer");
00024             return (NumberC > integer_traits<IndexT>::const_max) || (index < NumberC);
00025         }
00026     };
00027 
00028     template <int NumberC>
00029     struct range_traits<uint16_t, NumberC>
00030     {
00031         static inline bool is_valid(const uint16_t index)
00032         {
00033             static_assert(NumberC > integer_traits<uint16_t>::const_max, "NumberC must be > 0xffff");
00034             return true;
00035         }
00036     };
00037 
00041     enum resource_flags_constants
00042     {
00043         /* internal flags */
00044 
00046         DONT_USE              = 0x0001,
00048         RESERVED_VIRTUAL      = 0x0002,
00050         RESERVED_PHYSICAL     = 0x0004,
00052         AVOID_USE             = 0x0008,
00054         AVAILABLE_FROM_OMEGA0 = 0x0010,
00056         ATTACHED              = 0x0020,
00057 
00058         /* usage flags */
00059 
00061         FIXED                 = 0x0100,
00063         VIRTUAL               = 0x0200,
00065         PHYSICAL              = 0x0400,
00066 
00067         /* masks */
00068 
00070         USE_MASK              = FIXED | VIRTUAL | PHYSICAL,
00072         ALL_MASK              = DONT_USE | RESERVED_VIRTUAL | RESERVED_PHYSICAL | AVOID_USE |
00073                                 AVAILABLE_FROM_OMEGA0 | ATTACHED | FIXED | VIRTUAL | PHYSICAL
00074     };
00075 
00079     struct resource_flags : public bitmask<uint_value_t<ALL_MASK>::least>
00080     {
00081         //
00082         // constructor
00083         //
00084         inline resource_flags(const word_type bits=word_type())
00085             : bitmask<word_type>(bits)
00086         {}
00087 
00088         //
00089         // query functions
00090         //
00094         inline bool is_attached(void) const
00095         {
00096             return is(ATTACHED);
00097         }
00098 
00102         inline bool is_fixed(void) const
00103         {
00104             return is(FIXED);
00105         }
00106 
00110         inline bool is_virtual(void) const
00111         {
00112             return is(VIRTUAL);
00113         }
00114 
00118         inline bool is_physical(void) const
00119         {
00120             return is(PHYSICAL);
00121         }
00122 
00127         inline bool is_used(void) const
00128         {
00129             return any(VIRTUAL | PHYSICAL);
00130         }
00131 
00136         inline bool is_valid_use(void) const
00137         {
00138             return is_virtual() ^ is_physical();
00139         }
00140 
00145         inline bool is_equal_use(const resource_flags use) const
00146         {
00147             return (bits & USE_MASK) == (use & USE_MASK);
00148         }
00149 
00153         inline bool is_usable(const resource_flags use) const
00154         {
00155             return !any(DONT_USE | VIRTUAL | PHYSICAL) &&
00156                        (!is(RESERVED_VIRTUAL) || use.is_virtual()) &&
00157                        (!is(RESERVED_PHYSICAL) || use.is_physical());
00158         }
00159     };
00160 
00161     static_assert(integer_traits<resource_flags::word_type>::const_max >= ALL_MASK,
00162                   "resource_flags's max value is too small");
00163 };
00164 
00165 #endif
00166 
00167 // ***** end of source ***** //
00168 

L4vmm Reference Manual, written by Mario Schwalbe  © 2006-2008