-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fbfa26a
commit 79c026e
Showing
75 changed files
with
3,395 additions
and
429 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
#ifndef JSYSTEM_LIST_H | ||
#define JSYSTEM_LIST_H | ||
|
||
#include "JSystem/JGadget/define.h" | ||
#include "JSystem/JGadget/linklist.h" | ||
#include "JSystem/JGadget/std-memory.h" | ||
#include "types.h" | ||
|
||
// massive TODO, pls help me | ||
|
||
namespace JGadget { | ||
|
||
template <typename T, typename Allocator = JGadget::TAllocator<T> > | ||
struct TList { | ||
struct TNode_ { | ||
TNode_ *pPrev_; | ||
TNode_ *pNext_; | ||
}; | ||
|
||
class iterator { | ||
public: | ||
iterator() { this->p_ = nullptr; } | ||
iterator(TNode_* node) { this->p_ = node; } | ||
|
||
iterator& operator++() { | ||
this->p_ = this->p_->getNext(); | ||
return *this; | ||
} | ||
|
||
iterator& operator--() { | ||
this->p_ = this->p_->getPrev(); | ||
return *this; | ||
} | ||
|
||
TNode_& operator*() const { | ||
JGADGET_ASSERT(p_!=0); | ||
return *this->p_; | ||
} | ||
|
||
TNode_* operator->() const { return this->p_; } | ||
|
||
TNode_* p_; | ||
}; | ||
|
||
class const_iterator { | ||
public: | ||
const_iterator(const TNode_* node) { this->p_ = node; } | ||
const_iterator(iterator it) { this->p_ = it.p_; } | ||
|
||
const const_iterator& operator++() { | ||
this->p_ = this->p_->getNext(); | ||
return *this; | ||
} | ||
|
||
const const_iterator& operator--() { | ||
this->p_ = this->p_->getPrev(); | ||
return *this; | ||
} | ||
|
||
const TNode_* operator->() const { return this->p_; } | ||
|
||
const TNode_* p_; | ||
}; | ||
|
||
TList(const TAllocator<T> &allocator=0) { | ||
oSize_ = 0; | ||
Initialize_(); | ||
} | ||
|
||
void Initialize_() { | ||
oEnd_.pNext_ = &this->oNode_; | ||
oEnd_.pPrev_ = &this->oNode_; | ||
} | ||
|
||
void DestroyNode_(TNode_ *p) { | ||
// probably doesn't match | ||
JGADGET_ASSERT(p!=0); | ||
JGADGET_ASSERT(p!=&oEnd_); | ||
JGADGET_ASSERT(p->pNext_->pPrev_!=p); | ||
JGADGET_ASSERT(p->pPrev_->pNext_!=p); | ||
oAllocator_.destroy(p + 1); | ||
oAllocator_.DeallocateRaw(p); | ||
} | ||
|
||
iterator end() {return &this->oNode_; } | ||
const_iterator end() const { return &this->oNode_; } | ||
|
||
private: | ||
TAllocator<T> oAllocator_; // 0 | ||
u32 oSize_; // 4 | ||
TNode_ oEnd_; // 8 | ||
}; | ||
|
||
} | ||
|
||
|
||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#ifndef STD_MEMORY_H | ||
#define STD_MEMORY_H | ||
|
||
#include "JSystem/JUtility/JUTAssert.h" | ||
|
||
namespace JGadget { | ||
template <typename T> | ||
struct TAllocator { | ||
T* allocate(u32 count, void *param_2) { | ||
return AllocateRaw(count * sizeof(T)); | ||
} | ||
|
||
T* AllocateRaw(u32 size) { | ||
return (T*)operator new(size); | ||
} | ||
|
||
void deallocate(T* mem, u32 size) { | ||
DeallocateRaw(mem); | ||
} | ||
|
||
void DeallocateRaw(T* mem) { | ||
delete mem; | ||
} | ||
|
||
void destroy(T* p) { | ||
JUT_ASSERT(p!=0); | ||
} | ||
|
||
u8 mAllocator; // 00 | ||
}; | ||
} | ||
|
||
#endif /* STD_MEMORY_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.