language/duchain
KDevelop::ItemRepository< Item, ItemRequest, markForReferenceCounting, threadSafe, fixedItemSize, targetBucketHashSize > Class Template Reference
#include <itemrepository.h>

Public Types | |
| typedef DynamicItem< Item, markForReferenceCounting > | MyDynamicItem |
Public Member Functions | |
| ItemRepository (QString repositoryName, ItemRepositoryRegistry *registry=&globalItemRepositoryRegistry(), uint repositoryVersion=1, AbstractRepositoryManager *manager=0) | |
| void | deleteItem (unsigned int index) |
| template<class Action > | |
| void | dynamicAction (unsigned int index, Action &action) |
| MyDynamicItem | dynamicItemFromIndex (unsigned int index) |
| Item * | dynamicItemFromIndexSimple (unsigned int index) |
| unsigned int | findIndex (const ItemRequest &request) |
| unsigned int | index (const ItemRequest &request) |
| const Item * | itemFromIndex (unsigned int index) const |
| QMutex * | mutex () const |
| QString | printStatistics () const |
| virtual QString | repositoryName () const |
| void | setMutex (QMutex *mutex) |
| void | setUnloadingEnabled (bool enabled) |
| Statistics | statistics () const |
| virtual void | store () |
| uint | usedMemory () const |
| template<class Visitor > | |
| void | visitAllItems (Visitor &visitor, bool onlyInMemory=false) const |
| template<class Visitor > | |
| void | visitItemsWithHash (Visitor &visitor, uint hash) const |
Detailed Description
template<class Item, class ItemRequest, bool markForReferenceCounting = true, bool threadSafe = true, uint fixedItemSize = 0, unsigned int targetBucketHashSize = 524288*2>
class KDevelop::ItemRepository< Item, ItemRequest, markForReferenceCounting, threadSafe, fixedItemSize, targetBucketHashSize >
- Parameters:
-
Item
- See also:
- ExampleItem
- Parameters:
-
ItemRequest
- See also:
- ExampleReqestItem
- Parameters:
-
fixedItemSize When this is true, all inserted items must have the same size. This greatly simplifies and speeds up the task of managing free items within the buckets. markForReferenceCounting Whether the data within the repository should be marked for reference-counting. This costs a bit of performance, but must be enabled if there may be data in the repository that does on-disk reference counting, like IndexedString, IndexedIdentifier, etc. threadSafe Whether class access should be thread-safe. Disabling this is dangerous when you do multi-threading. You have to make sure that mutex() is locked whenever the repository is accessed.
Definition at line 1283 of file itemrepository.h.
Member Typedef Documentation
| typedef DynamicItem<Item, markForReferenceCounting> KDevelop::ItemRepository< Item, ItemRequest, markForReferenceCounting, threadSafe, fixedItemSize, targetBucketHashSize >::MyDynamicItem |
This returns an editable version of the item.
- Warning:
- : Never change an entry that affects the hash, or the equals(..) function. That would completely destroy the consistency.
- Parameters:
-
index The index. It must be valid(match an existing item), and nonzero.
- Warning:
- If you use this, make sure you lock mutex() before calling, and hold it until you're ready using/changing the data..
Definition at line 1763 of file itemrepository.h.
Constructor & Destructor Documentation
| KDevelop::ItemRepository< Item, ItemRequest, markForReferenceCounting, threadSafe, fixedItemSize, targetBucketHashSize >::ItemRepository | ( | QString | repositoryName, | |
| ItemRepositoryRegistry * | registry = &globalItemRepositoryRegistry(), |
|||
| uint | repositoryVersion = 1, |
|||
| AbstractRepositoryManager * | manager = 0 | |||
| ) | [inline] |
- Parameters:
-
registry May be zero, then the repository will not be registered at all. Else, the repository will register itself to that registry. If this is zero, you have to care about storing the data using store() and/or close() by yourself. It does not happen automatically. For the global standard registry, the storing/loading is triggered from within duchain, so you don't need to care about it.
Definition at line 1303 of file itemrepository.h.
Member Function Documentation
| void KDevelop::ItemRepository< Item, ItemRequest, markForReferenceCounting, threadSafe, fixedItemSize, targetBucketHashSize >::deleteItem | ( | unsigned int | index | ) | [inline] |
Deletes the item from the repository.
Now check whether the link previousBucketNumber -> bucket is still needed.
- Todo:
- Clear the nextBucketForHash links when not needed any more, by doing setNextBucketForHash(hash, 0);
Debug: Check for infinite recursion
Debug: Check for infinite recursion
Definition at line 1626 of file itemrepository.h.
| void KDevelop::ItemRepository< Item, ItemRequest, markForReferenceCounting, threadSafe, fixedItemSize, targetBucketHashSize >::dynamicAction | ( | unsigned int | index, | |
| Action & | action | |||
| ) | [inline] |
- Parameters:
-
Action Must be an object that has an "operator()(Item&)" function. That function is allowed to do any action on the item, except for anything that changes its identity/hash-value
Definition at line 1813 of file itemrepository.h.
| Item* KDevelop::ItemRepository< Item, ItemRequest, markForReferenceCounting, threadSafe, fixedItemSize, targetBucketHashSize >::dynamicItemFromIndexSimple | ( | unsigned int | index | ) | [inline] |
This returns an editable version of the item.
- Warning:
- : Never change an entry that affects the hash, or the equals(..) function. That would completely destroy the consistency.
- Parameters:
-
index The index. It must be valid(match an existing item), and nonzero.
- Warning:
- If you use this, make sure you lock mutex() before calling, and hold it until you're ready using/changing the data..
- If you change contained complex items that depend on reference-counting, you must use dynamicItemFromIndex(..) instead of dynamicItemFromIndexSimple(..)
Definition at line 1791 of file itemrepository.h.
| unsigned int KDevelop::ItemRepository< Item, ItemRequest, markForReferenceCounting, threadSafe, fixedItemSize, targetBucketHashSize >::findIndex | ( | const ItemRequest & | request | ) | [inline] |
Returns zero if the item is not in the repository yet.
Definition at line 1589 of file itemrepository.h.
| unsigned int KDevelop::ItemRepository< Item, ItemRequest, markForReferenceCounting, threadSafe, fixedItemSize, targetBucketHashSize >::index | ( | const ItemRequest & | request | ) | [inline] |
Returns the index for the given item.
If the item is not in the repository yet, it is inserted. The index can never be zero. Zero is reserved for your own usage as invalid
- Parameters:
-
dynamic will be applied to the dynamic data of the found item
- Todo:
- Move this compound statement into an own function
Step one: Search whether we can merge multiple empty buckets in the free-list into one monster-bucket
We can merge these buckets into one monster-bucket that can hold the data
Debug: Detect infinite recursion
Definition at line 1337 of file itemrepository.h.
| const Item* KDevelop::ItemRepository< Item, ItemRequest, markForReferenceCounting, threadSafe, fixedItemSize, targetBucketHashSize >::itemFromIndex | ( | unsigned int | index | ) | const [inline] |
- Parameters:
-
index The index. It must be valid(match an existing item), and nonzero. dynamic will be applied to the item.
Definition at line 1841 of file itemrepository.h.
| QMutex* KDevelop::ItemRepository< Item, ItemRequest, markForReferenceCounting, threadSafe, fixedItemSize, targetBucketHashSize >::mutex | ( | ) | const [inline] |
This mutex is used for the thread-safe locking when threadSafe is true.
Even if threadSafe is false, it is always locked before storing to or loading from disk.
- Warning:
- If threadSafe is false, and you sometimes call store() from within another thread(As happens in duchain), you must always make sure that this mutex is locked before you access this repository. Else you will get crashes and inconsistencies. In KDevelop This means: Make sure you _always_ lock this mutex before accessing the repository.
Definition at line 2159 of file itemrepository.h.
| void KDevelop::ItemRepository< Item, ItemRequest, markForReferenceCounting, threadSafe, fixedItemSize, targetBucketHashSize >::setMutex | ( | QMutex * | mutex | ) | [inline] |
With this, you can replace the internal mutex with another one.
Definition at line 2164 of file itemrepository.h.
| void KDevelop::ItemRepository< Item, ItemRequest, markForReferenceCounting, threadSafe, fixedItemSize, targetBucketHashSize >::setUnloadingEnabled | ( | bool | enabled | ) | [inline] |
Unloading of buckets is enabled by default.
Use this to disable it. When unloading is enabled, the data gotten from must only itemFromIndex must not be used for a long time.
Definition at line 1330 of file itemrepository.h.
| virtual void KDevelop::ItemRepository< Item, ItemRequest, markForReferenceCounting, threadSafe, fixedItemSize, targetBucketHashSize >::store | ( | ) | [inline, virtual] |
Synchronizes the state on disk to the one in memory, and does some memory-management.
Should be called on a regular basis. Can be called centrally from the global item repository registry.
Definition at line 2065 of file itemrepository.h.
| void KDevelop::ItemRepository< Item, ItemRequest, markForReferenceCounting, threadSafe, fixedItemSize, targetBucketHashSize >::visitAllItems | ( | Visitor & | visitor, | |
| bool | onlyInMemory = false | |||
| ) | const [inline] |
This can be used to safely iterate through all items in the repository.
- Parameters:
-
visitor Should be an instance of a class that has a bool operator()(const Item*) member function, that returns whether more items are wanted. onlyInMemory If this is true, only items are visited that are currently in memory.
Definition at line 2029 of file itemrepository.h.
| void KDevelop::ItemRepository< Item, ItemRequest, markForReferenceCounting, threadSafe, fixedItemSize, targetBucketHashSize >::visitItemsWithHash | ( | Visitor & | visitor, | |
| uint | hash | |||
| ) | const [inline] |
Visits all items that have the given hash-value, plus an arbitrary count of other items with a clashing hash.
- Parameters:
-
visitor Should be an instance of a class that has a bool operator()(const Item*, uint index) member function, that returns whether more items are wanted.
Definition at line 2043 of file itemrepository.h.
The documentation for this class was generated from the following file:
KDE 4.4 API Reference