Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 6, 2015, 2:51:14 PM (8 years ago)
Author:
landauf
Message:

no static functions anymore in ObjectList. you need to instantiate an ObjectList to use it.
this allows for prettier for-loop syntax when iterating over an ObjectList of a specific context: for (T* object : ObjectList<T>(context)) { … }

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/cpp11_v2/src/libraries/core/object/ObjectList.h

    r10774 r10920  
    7171            typedef ObjectListIterator<T> iterator;
    7272
    73             /// Returns the size of the list (for the root context)
    74             inline static size_t size()
    75             {   return size(Context::getRootContext());   }
     73            ObjectList() : ObjectList(Context::getRootContext()) {}
     74            ObjectList(Context* context) : ObjectList(context->getObjectList<T>()) {}
     75            ObjectList(ObjectListBase* list) : list_(list) {}
     76
    7677            /// Returns the size of the list
    77             inline static size_t size(Context* context)
    78             {
    79                 return context->getObjectList<T>()->size();
    80             }
     78            inline size_t size()
     79            {   return this->list_->size();   }
    8180
    82             /// Returns an Iterator to the first element in the list (for the root context).
    83             inline static ObjectListIterator<T> begin()
    84             {   return begin(Context::getRootContext());   }
    8581            /// Returns an Iterator to the first element in the list.
    86             inline static ObjectListIterator<T> begin(Context* context)
    87             {
    88                 ObjectListBase* list = context->getObjectList<T>();
    89                 return static_cast<ObjectListElement<T>*>(list->begin());
    90             }
     82            inline ObjectListIterator<T> begin()
     83            {   return static_cast<ObjectListElement<T>*>(this->list_->begin());   }
     84            /// Returns an Iterator to the element after the last element in the list.
     85            inline ObjectListIterator<T> end()
     86            {   return static_cast<ObjectListElement<T>*>(this->list_->end());   }
    9187
    92             /// Returns an Iterator to the element after the last element in the list (for the root context).
    93             inline static ObjectListIterator<T> end()
    94             {   return end(Context::getRootContext());   }
    95             /// Returns an Iterator to the element after the last element in the list.
    96             inline static ObjectListIterator<T> end(Context* context)
    97             {
    98                 ObjectListBase* list = context->getObjectList<T>();
    99                 return static_cast<ObjectListElement<T>*>(list->end());
    100             }
     88            /// Returns an Iterator to the last element in the list.
     89            inline ObjectListIterator<T> rbegin()
     90            {   return static_cast<ObjectListElement<T>*>(this->list_->rbegin());   }
     91            /// Returns an Iterator to the element before the first element in the list.
     92            inline ObjectListIterator<T> rend()
     93            {   return static_cast<ObjectListElement<T>*>(this->list_->rend());   }
    10194
    102             /// Returns an Iterator to the last element in the list (for the root context).
    103             inline static ObjectListIterator<T> rbegin()
    104             {   return rbegin(Context::getRootContext());   }
    105             /// Returns an Iterator to the last element in the list.
    106             inline static ObjectListIterator<T> rbegin(Context* context)
    107             {
    108                 ObjectListBase* list = context->getObjectList<T>();
    109                 return static_cast<ObjectListElement<T>*>(list->rbegin());
    110             }
    111 
    112             /// Returns an Iterator to the element before the first element in the list (for the root context).
    113             inline static ObjectListIterator<T> rend()
    114             {   return rend(Context::getRootContext());   }
    115             /// Returns an Iterator to the element before the first element in the list.
    116             inline static ObjectListIterator<T> rend(Context* context)
    117             {
    118                 ObjectListBase* list = context->getObjectList<T>();
    119                 return static_cast<ObjectListElement<T>*>(list->rend());
    120             }
     95        private:
     96            ObjectListBase* list_;
    12197    };
    12298}
Note: See TracChangeset for help on using the changeset viewer.