IndexedIterable.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2005 Palmsource, Inc.
00003  * 
00004  * This software is licensed as described in the file LICENSE, which
00005  * you should have received as part of this distribution. The terms
00006  * are also available at http://www.openbinder.org/license.html.
00007  * 
00008  * This software consists of voluntary contributions made by many
00009  * individuals. For the exact contribution history, see the revision
00010  * history and logs, available at http://www.openbinder.org
00011  */
00012 
00013 #ifndef _STORAGE_INDEXEDITERABLE_H
00014 #define _STORAGE_INDEXEDITERABLE_H
00015 
00022 #include <storage/GenericIterable.h>
00023 
00024 #include <support/Vector.h>
00025 
00026 #if _SUPPORTS_NAMESPACE
00027 namespace palmos {
00028 namespace storage {
00029 #endif
00030 
00035 // ==========================================================================
00036 // ==========================================================================
00037 
00039 
00049 class BIndexedIterable : public BGenericIterable
00050 {
00051 public:
00052     // --------------------------------------------------------------
00056                                     BIndexedIterable();
00057                                     BIndexedIterable(const SContext& context);
00059 
00060     // ---------------------------------------------------------------------
00062 
00064 
00065     class IndexedIterator;
00066 
00068     virtual sptr<GenericIterator>   NewGenericIterator(const SValue& args);
00069 
00071 
00072     // ---------------------------------------------------------------------
00074 
00078 
00080 
00084     virtual status_t                EntryAtLocked(  const sptr<IndexedIterator>& it, size_t index,
00085                                                     uint32_t flags, SValue* key, SValue* entry) = 0;
00087 
00088     virtual status_t                RemoveEntryAtLocked(size_t index);
00090     virtual size_t                  CountEntriesLocked() const = 0;
00092 
00096     virtual void                    CreateSelectionLocked(SValue* inoutSelection, SValue* outCookie) const;
00098 
00103     virtual void                    CreateSortOrderLocked(SValue* inoutSortBy, SVector<ssize_t>* outOrder) const;
00104 
00106 
00109             void                    UpdateIteratorIndicesLocked(size_t index, ssize_t delta);
00110 
00112 
00113 protected:
00116     virtual                         ~BIndexedIterable();
00118 
00119 private:
00120                                     BIndexedIterable(const BIndexedIterable& copyFrom);
00121                                     BIndexedIterable& operator=(const BIndexedIterable& copyFrom);
00122 
00123     static  bool                    update_indices_func(    const sptr<BGenericIterable>& iterable,
00124                                                             const sptr<GenericIterator>& iterator,
00125                                                             void* cookie);
00126 };
00127 
00128 // --------------------------------------------------------------------------
00129 
00131 
00134 class BIndexedIterable::IndexedIterator : public BGenericIterable::GenericIterator
00135 {
00136 public:
00137     // --------------------------------------------------------------
00141                                 IndexedIterator(const SContext& context, const sptr<BGenericIterable>& owner);
00142 
00143 protected:
00144     virtual                     ~IndexedIterator();
00145 public:
00146 
00148     virtual SValue              Inspect(const sptr<IBinder>& caller, const SValue& which, uint32_t flags);
00149 
00151 
00152     // ---------------------------------------------------------------------
00154 
00156 
00158 
00160     virtual SValue              Options() const;
00161 
00163     virtual size_t              Count() const;
00165     virtual size_t              Position() const;
00167     virtual void                SetPosition(size_t p);
00168 
00170 
00171     // ---------------------------------------------------------------------
00173 
00175 
00177 
00179     virtual status_t            ParseArgs(const SValue& args);
00180 
00182     virtual status_t            NextLocked(uint32_t flags, SValue* key, SValue* entry);
00184     virtual status_t            RemoveLocked();
00185 
00187 
00188     // ---------------------------------------------------------------------
00190 
00193 
00195 
00196     inline  const SValue&       SelectArgsLocked() const { return m_selectArgs; }
00197 
00199 
00205             ssize_t             CurrentIndexLocked() const;
00207 
00209             ssize_t             MoveIndexLocked();
00211 
00212 private:
00213             friend class BIndexedIterable;
00214 
00215             void                update_indices_l(size_t index, ssize_t delta);
00216 
00217             size_t              m_count;
00218             SValue              m_selectArgs;
00219             SValue              m_selectCookie;
00220             SValue              m_orderArgs;
00221             SVector<ssize_t>    m_order;
00222             size_t              m_position;
00223 };
00224 
00225 // ==========================================================================
00226 // ==========================================================================
00227 
00230 #if _SUPPORTS_NAMESPACE
00231 } } // namespace palmos::storage
00232 #endif
00233 
00234 #endif // _STORAGE_INDEXEDITERABLE_H