Skip to content

Commit

Permalink
prcpp: U4 sort funktioniert
Browse files Browse the repository at this point in the history
  • Loading branch information
platzhersh committed Jan 10, 2014
1 parent f24a7b7 commit 15935cc
Show file tree
Hide file tree
Showing 15 changed files with 305 additions and 92 deletions.
Binary file modified prcpp/RandomAccessFile.rar
Binary file not shown.
Binary file modified prcpp/RandomAccessFile.sdf
Binary file not shown.
Binary file modified prcpp/RandomAccessFile.v12.suo
Binary file not shown.
3 changes: 2 additions & 1 deletion prcpp/RandomAccessFile/PersistentVector.h
Expand Up @@ -46,9 +46,10 @@ template<class T> class PersistentVector {


VectorAccessor<T> operator[](int index) {
return VectorAccessor<T>(*this, index);
return VectorAccessor<T>(this, index);
}


bool isEmpty() {
return m_size == 0;
}
Expand Down
2 changes: 2 additions & 0 deletions prcpp/RandomAccessFile/RandomAccessFile.vcxproj
Expand Up @@ -81,7 +81,9 @@
<ClInclude Include="RandomAccessFile.h" />
<ClInclude Include="RandomAccessFile.hpp" />
<ClInclude Include="VectorAccessor.hpp" />
<ClInclude Include="VectorAccessor.hpp_old" />
<ClInclude Include="VectorIterator.hpp" />
<ClInclude Include="VectorIteratorAccessor.hpp" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp" />
Expand Down
6 changes: 6 additions & 0 deletions prcpp/RandomAccessFile/RandomAccessFile.vcxproj.filters
Expand Up @@ -35,6 +35,12 @@
<ClInclude Include="VectorIterator.hpp">
<Filter>Headerdateien</Filter>
</ClInclude>
<ClInclude Include="VectorIteratorAccessor.hpp">
<Filter>Headerdateien</Filter>
</ClInclude>
<ClInclude Include="VectorAccessor.hpp_old">
<Filter>Headerdateien</Filter>
</ClInclude>
<ClInclude Include="VectorAccessor.hpp">
<Filter>Headerdateien</Filter>
</ClInclude>
Expand Down
94 changes: 85 additions & 9 deletions prcpp/RandomAccessFile/RandomAccessFileTest/unittest1.cpp
Expand Up @@ -19,8 +19,8 @@ namespace RandomAccessFileTest

// todo
}


TEST_METHOD(WriteReadTestInt)
{

Expand Down Expand Up @@ -50,7 +50,7 @@ namespace RandomAccessFileTest
PersistentVector<int> pv("test.bin");
Assert::IsTrue(pv.isEmpty());
pv[0] = 13;
Assert::AreEqual(13, (int) pv[0]);
Assert::AreEqual(13, (int)pv[0]);
//Assert::AreEqual(99, pv[1]);
}

Expand All @@ -62,8 +62,8 @@ namespace RandomAccessFileTest
pv.push_back(99);
pv.push_back(77);

Assert::AreEqual(99, (int) pv[0]);
Assert::AreEqual(77, (int) pv[1]);
Assert::AreEqual(99, (int)pv[0]);
Assert::AreEqual(77, (int)pv[1]);
}

TEST_METHOD(IteratorSetGet)
Expand All @@ -77,14 +77,16 @@ namespace RandomAccessFileTest

PersistentVector<int>::iterator it = pv.begin();
PersistentVector<int>::iterator end = pv.end();

Assert::AreEqual(99, it.get());
Assert::AreEqual(55, (--end).get());

it.set(100);
Assert::AreEqual(100, it.get());
}
TEST_METHOD(IteratorOperators)
};
TEST_CLASS(VectorIteratorTest) {
TEST_METHOD(IteratorTestOperators)
{
remove("test.bin");
PersistentVector<int> pv("test.bin");
Expand Down Expand Up @@ -117,19 +119,93 @@ namespace RandomAccessFileTest
}
TEST_METHOD(Sort)
{
remove("test.bin");
PersistentVector<int> pv("test.bin");
Assert::AreEqual(pv.isEmpty(), true);
pv.push_back(3);
pv.push_back(1);
pv.push_back(9);
pv.push_back(2);
pv.push_back(30);
pv.push_back(42);
pv.push_back(4);

PersistentVector<int>::iterator a = pv.begin();
PersistentVector<int>::iterator z = pv.end();

sort(a, z);

Assert::IsTrue(a.get() == 1); a++;
Assert::IsTrue(a.get() == 2); a++;
Assert::IsTrue(a.get() == 3); a++;
Assert::IsTrue(a.get() == 4); a++;
Assert::IsTrue(a.get() == 9); a++;
Assert::IsTrue(a.get() == 30); a++;
Assert::IsTrue(a.get() == 42);

}
TEST_METHOD(IteratorTestDefault)
{
// default iterator criteria
Assert::IsTrue(is_copy_constructible<VectorIterator<int>>::value);
Assert::IsTrue(is_copy_assignable<VectorIterator<int>>::value);
Assert::IsTrue(is_destructible<VectorIterator<int>>::value);

// Can be incremented
remove("test.bin");
PersistentVector<int> pv("test.bin");
Assert::AreEqual(pv.isEmpty(), true);
pv.push_back(55);
pv.push_back(99);
pv.push_back(77);

PersistentVector<int>::iterator a = pv.begin();
a++;
PersistentVector<int>::iterator b = pv.begin();
++b;

Assert::AreEqual(77, a.get());
Assert::AreEqual(a.get(), b.get());
}
TEST_METHOD(IteratorTestForward)
{
//Assert::IsTrue(is_default_constructible<VectorIterator<int>>::value);

remove("test.bin");
PersistentVector<int> pv("test.bin");
Assert::AreEqual(pv.isEmpty(), true);
pv.push_back(55);
pv.push_back(88);

PersistentVector<int>::iterator a = pv.begin();
PersistentVector<int>::iterator b = pv.begin();
PersistentVector<int>::iterator z = pv.end();

//sort(a, z);
// Supports equality / inequality comparisons
Assert::IsTrue(a == b);
Assert::IsTrue(a != z);
a++; a++;
Assert::IsTrue(a == z);

// Can be dereferenced as an rvalue

// Can be dereferenced as an lvalue
// (only for mutable iterator types)
// Multi-pass: neither dereferencing nor incrementing affects dereferenceability
}
TEST_METHOD(IteratorTestBidirectional)
{
// bidirectional iterator criteria
// Can be decremented
}
TEST_METHOD(IteratorTestRandomAccess)
{

// random access iterator criteria
// Supports arithmetic operators + and -
// Supports inequality comparisons (<, >, <= and >=) between iterators
// Supports compound assignment operations += and -=
// Supports offset dereference operator ([])
}

};
}
56 changes: 34 additions & 22 deletions prcpp/RandomAccessFile/VectorAccessor.hpp
@@ -1,33 +1,45 @@
#pragma once

template<class T> class PersistentVector;
template<class Type> class PersistentVector;

template<class T> class VectorAccessor {
template<class Type> class VectorAccessor {
friend class PersistentVector<Type>;
friend class VectorIterator<Type>;

friend class PersistentVector<T>;
PersistentVector<Type> *m_vector;
size_t m_pos; // current iterator position
Type m_value; // current value

protected:

PersistentVector<T>& m_pv;
int m_pos;
VectorAccessor(PersistentVector<Type> *vector, size_t pos)
: m_vector(vector)
, m_pos(pos)
{}

public:

VectorAccessor(PersistentVector<T>& pv, int index) : m_pv(pv), m_pos(index) {}

PersistentVector<T>& operator=(int val) {
m_pv.write(m_pos, val);
return m_pv;
typedef const Type& const_reference;

VectorAccessor(const VectorAccessor& vh)
: m_vector(0)
, m_pos(-1)
, m_value(vh)
{}

VectorAccessor& operator=(const_reference val) {
if (m_vector)
m_vector->write(m_pos, val);
else
m_value = val;
return *this;
}

operator VectorIterator<T> const& () {
return VectorIterator<T> a(m_pv ,m_pos);
}
operator PersistentVector<T> const& () {
return m_pv;
}
operator T const () {
return m_pv.read(m_pos);
VectorAccessor& operator=(const VectorAccessor& vh) {
if (m_vector)
m_vector->write(m_pos, vh);
else
m_value = vh;
return *this;
}

};
operator Type() const { return (m_vector) ? m_vector->read(m_pos) : m_value; }
};

30 changes: 30 additions & 0 deletions prcpp/RandomAccessFile/VectorAccessor.hpp_old
@@ -0,0 +1,30 @@
#pragma once

template<class T> class PersistentVector;

template<class T> class VectorAccessor {

friend class PersistentVector<T>;

protected:

PersistentVector<T>& m_pv;
int m_pos;

public:

VectorAccessor(PersistentVector<T>& pv, int index) : m_pv(pv), m_pos(index) {}

PersistentVector<T>& operator=(T val) {
m_pv.write(m_pos, val);
return m_pv;
}

operator PersistentVector<T> const& () {
return m_pv;
}
operator T const () {
return m_pv.read(m_pos);
}

};

0 comments on commit 15935cc

Please sign in to comment.