Alien-SmokeQt
view release on metacpan or search on metacpan
generator/parser/rpp/appendedlist.h view on Meta::CPAN
if(appendedListsDynamic()) { \
name ## NeedDynamicList(); \
KDevVarLengthArray<type, 10>& item( temporaryHash ## container ## name().getItem(name ## Data) ); \
item.clear(); \
const type* otherCurr = rhs.name(); \
const type* otherEnd = otherCurr + rhs.name ## Size(); \
for(; otherCurr < otherEnd; ++otherCurr) \
item.append(*otherCurr); \
}else{ \
Q_ASSERT(name ## Data == 0); /* It is dangerous to overwrite the contents of non-dynamic lists(Most probably a mistake) */ \
name ## Data = rhs.name ## Size(); \
type* curr = const_cast<type*>(name()); type* end = curr + name ## Size(); \
const type* otherCurr = rhs.name(); \
for(; curr < end; ++curr, ++otherCurr) \
new (curr) type(*otherCurr); /* Call the copy constructors */ \
}\
} \
void name ## NeedDynamicList() { Q_ASSERT(appendedListsDynamic()); if((name ## Data & KDevelop::DynamicAppendedListRevertMask) == 0) { name ## Data = temporaryHash ## container ## name().alloc(); Q_ASSERT(temporaryHash ## container ## name().ge...
void name ## Initialize(bool dynamic) { name ## Data = (dynamic ? KDevelop::DynamicAppendedListMask : 0); } \
void name ## Free() { if(appendedListsDynamic()) { if(name ## Data & KDevelop::DynamicAppendedListRevertMask) temporaryHash ## container ## name().free(name ## Data); } else { type* curr = const_cast<type*>(name()); type* end = curr + name ## ...
///@todo Make these things a bit faster(less recursion)
#define APPENDED_LIST_FIRST(container, type, name) APPENDED_LIST_COMMON(container, type, name) \
const type* name() const { if((name ## Data & KDevelop::DynamicAppendedListRevertMask) == 0) return 0; if(!appendedListsDynamic()) return (type*)(((char*)this) + classSize() + offsetBehindBase()); else r...
unsigned int name ## OffsetBehind() const { return name ## Size() * sizeof(type) + offsetBehindBase(); } \
template<class T> bool name ## ListChainEquals( const T& rhs ) const { return name ## Equals(rhs); } \
template<class T> void name ## CopyAllFrom( const T& rhs ) { name ## CopyFrom(rhs); } \
void name ## InitializeChain(bool dynamic) { name ## Initialize(dynamic); } \
void name ## FreeChain() { name ## Free(); }
#define APPENDED_LIST(container, type, name, predecessor) APPENDED_LIST_COMMON(container, type, name) \
const type* name() const {if((name ## Data & KDevelop::DynamicAppendedListRevertMask) == 0) return 0; if(!appendedListsDynamic()) return (type*)(((char*)this) + classSize() + predecessor ## OffsetBehind(...
unsigned int name ## OffsetBehind() const { return name ## Size() * sizeof(type) + predecessor ## OffsetBehind(); } \
template<class T> bool name ## ListChainEquals( const T& rhs ) const { return name ## Equals(rhs) && predecessor ## ListChainEquals(rhs); } \
template<class T> void name ## CopyAllFrom( const T& rhs ) { predecessor ## CopyAllFrom(rhs); name ## CopyFrom(rhs); } \
void name ## InitializeChain(bool dynamic) { name ## Initialize(dynamic); predecessor ## InitializeChain(dynamic); } \
void name ## FreeChain() { name ## Free(); predecessor ## FreeChain(); }
#define END_APPENDED_LISTS(container, predecessor) /* Returns the size of the object containing the appended lists, including them */ \
unsigned int completeSize() const { return classSize() + predecessor ## OffsetBehind(); } \
/* Compares all local appended lists(not from base classes) and returns true if they are equal */ \
template<class T> bool listsEqual(const T& rhs) const { return predecessor ## ListChainEquals(rhs); } \
/* Copies all the local appended lists(not from base classes) from the given item.*/ \
template<class T> void copyListsFrom(const T& rhs) { return predecessor ## CopyAllFrom(rhs); } \
void initializeAppendedLists(bool dynamic = appendedListDynamicDefault()) { predecessor ## Data = (dynamic ? KDevelop::DynamicAppendedListMask : 0); predecessor ## InitializeChain(dynamic); } \
void freeAppendedLists() { predecessor ## FreeChain(); } \
bool appendedListsDynamic() const { return predecessor ## Data & KDevelop::DynamicAppendedListMask; } \
unsigned int offsetBehindLastList() const { return predecessor ## OffsetBehind(); } \
size_t dynamicSize() const { return offsetBehindLastList() + classSize(); }
/**
* This is a class that allows you easily putting instances of your class into an ItemRepository as seen in itemrepository.h.
* All your class needs to do is:
* - Be implemented using the APPENDED_LIST macros.
* - Have a real copy-constructor that additionally takes a "bool dynamic = true" parameter, which should be given to initializeAppendedLists
* - Except for these appended lists, only contain directly copyable data like indices(no pointers, no virtual functions)
* - Implement operator==(..) which should compare everything, including the lists. @warning The default operator will not work!
* - Implement a hash() function. The hash should equal for two instances when operator==(..) returns true.
* - Should be completely functional without a constructor called, only the data copied
* - Implement a "bool persistent() const" function, that should check the reference-count or other information to decide whether the item should stay in the repository
* If those conditions are fulfilled, the data can easily be put into a repository using this request class.
* */
template<class Type, uint averageAppendedBytes = 8>
class AppendedListItemRequest {
public:
AppendedListItemRequest(const Type& item) : m_item(item) {
}
enum {
AverageSize = sizeof(Type) + averageAppendedBytes
};
unsigned int hash() const {
return m_item.hash();
}
size_t itemSize() const {
return m_item.dynamicSize();
}
void createItem(Type* item) const {
new (item) Type(m_item, false);
}
static void destroy(Type* item, KDevelop::AbstractItemRepository&) {
item->~Type();
}
static bool persistent(const Type* item) {
return item->persistent();
}
bool equals(const Type* item) const {
return m_item == *item;
}
const Type& m_item;
};
}
///This function is outside of the namespace, so it can always be found. It's used as default-parameter to initializeAppendedLists(..),
///and you can for example implement a function called like this in your local class hierarchy to override this default.
inline bool appendedListDynamicDefault() {
return true;
}
#endif
( run in 0.635 second using v1.01-cache-2.11-cpan-e1769b4cff6 )