| 39 | }; |
| 40 | |
| 41 | struct StringRepositoryItemRequest |
| 42 | { |
| 43 | //The text is supposed to be utf8 encoded |
| 44 | StringRepositoryItemRequest(const char* text, unsigned int hash, unsigned short length) : m_hash(hash) |
| 45 | , m_length(length) |
| 46 | , m_text(text) |
| 47 | { |
| 48 | } |
| 49 | |
| 50 | enum { |
| 51 | AverageSize = 10 //This should be the approximate average size of an Item |
| 52 | }; |
| 53 | |
| 54 | using HashType = unsigned int; |
| 55 | |
| 56 | //Should return the hash-value associated with this request(For example the hash of a string) |
| 57 | HashType hash() const |
| 58 | { |
| 59 | return m_hash; |
| 60 | } |
| 61 | |
| 62 | //Should return the size of an item created with createItem |
| 63 | uint itemSize() const |
| 64 | { |
| 65 | return sizeof(StringData) + m_length; |
| 66 | } |
| 67 | //Should create an item where the information of the requested item is permanently stored. The pointer |
| 68 | //@param item equals an allocated range with the size of itemSize(). |
| 69 | void createItem(StringData* item) const |
| 70 | { |
| 71 | item->length = m_length; |
| 72 | void* itemText = reinterpret_cast<void*>(item + 1); |
| 73 | memcpy(itemText, m_text, m_length); |
| 74 | } |
| 75 | |
| 76 | static void destroy(StringData*, KDevelop::AbstractItemRepository&) |
| 77 | { |
| 78 | } |
| 79 | |
| 80 | static bool persistent(const StringData*) |
| 81 | { |
| 82 | //Reference-counting not supported in the normal string repository |
| 83 | return true; |
| 84 | } |
| 85 | |
| 86 | //Should return whether the here requested item equals the given item |
| 87 | bool equals(const StringData* item) const |
| 88 | { |
| 89 | return item->length == m_length && (memcmp(++item, m_text, m_length) == 0); |
| 90 | } |
| 91 | unsigned int m_hash; |
| 92 | unsigned short m_length; |
| 93 | const char* m_text; |
| 94 | }; |
| 95 | |
| 96 | using StringRepository = ItemRepository<StringData, StringRepositoryItemRequest, false>; |
| 97 | |