mirror of
https://github.com/OpenCMT/uLib.git
synced 2025-12-06 15:31:31 +01:00
[uLib Geometry]
+ adds ClassCompound pattern
This commit is contained in:
@@ -24,133 +24,23 @@
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
//#include "boost/preprocessor.hpp"
|
||||
//#include "boost/preprocessor/repetition.hpp"
|
||||
|
||||
#include "Core/MplSequenceCombiner.h"
|
||||
|
||||
#include "Core/ClassCompound.h"
|
||||
|
||||
#include "Core/ClassFactory.h"
|
||||
#include "Core/Serializable.h"
|
||||
|
||||
|
||||
|
||||
#include "testing-prototype.h"
|
||||
|
||||
using namespace uLib;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//namespace {
|
||||
class Base {
|
||||
public:
|
||||
Base() {}
|
||||
Base(const Base ©) {}
|
||||
|
||||
virtual void Go() {}
|
||||
};
|
||||
|
||||
class Derived : public Base {
|
||||
public:
|
||||
void Go() { std::cout << "Derived Go\n"; }
|
||||
};
|
||||
|
||||
class Derived2 : public Base {
|
||||
public:
|
||||
void Go() { std::cout << "Derived2 Go\n"; }
|
||||
};
|
||||
|
||||
class Derived3 : public Base {
|
||||
public:
|
||||
void Go() { std::cout << "Derived3 Go\n"; }
|
||||
};
|
||||
|
||||
class Derived4 : public Base {
|
||||
public:
|
||||
void Go() { std::cout << "Derived4 Go\n"; }
|
||||
};
|
||||
|
||||
|
||||
template <
|
||||
class A1,
|
||||
class A2
|
||||
>
|
||||
class AlgHolder : public Base {
|
||||
A1 m_a1;
|
||||
A2 m_a2;
|
||||
public:
|
||||
void Go() {
|
||||
std::cout << "AlgHolder Go: \n";
|
||||
std::cout << " A1 -> "; m_a1.Go();
|
||||
std::cout << " A2 -> "; m_a2.Go();
|
||||
}
|
||||
};
|
||||
|
||||
//}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
typedef mpl::vector< Derived, Derived2, Derived3, Derived4 > seq;
|
||||
|
||||
|
||||
class ProgrammableAlgHolder {
|
||||
public:
|
||||
ProgrammableAlgHolder() : m_id1(0), m_id2(0)
|
||||
{ m_base = m_factory.Create(0,0); }
|
||||
|
||||
template < typename T >
|
||||
void SetA1(const T *alg = NULL) {
|
||||
int id = m_factory.FindS1<T>();
|
||||
Base * newbase = m_factory.Create(id,m_id2);
|
||||
*newbase = *m_base;
|
||||
delete m_base;
|
||||
m_base = newbase;
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
void SetA2(const T *alg = NULL) {
|
||||
int id = m_factory.FindS2<T>();
|
||||
Base * newbase = m_factory.Create(m_id1,id);
|
||||
*newbase = *m_base;
|
||||
delete m_base;
|
||||
m_base = newbase;
|
||||
}
|
||||
|
||||
Base * operator -> () { return m_base; }
|
||||
|
||||
private:
|
||||
RegisteredClassFactory2<Base, AlgHolder, seq, seq> m_factory;
|
||||
int m_id1, m_id2;
|
||||
Base * m_base;
|
||||
};
|
||||
|
||||
|
||||
|
||||
//int main() {
|
||||
// ProgrammableAlgHolder ah;
|
||||
// ah.SetA1<Derived4>();
|
||||
// ah->Go();
|
||||
|
||||
// return 0;
|
||||
//}
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// WORKING EXAMPLE //
|
||||
|
||||
@@ -190,7 +80,7 @@ private:
|
||||
class VoxCount {
|
||||
public:
|
||||
template < class T >
|
||||
int Count(const Vector<T> &ref ) {
|
||||
int Count(const Vector<T> &ref ) const {
|
||||
return ref.size();
|
||||
}
|
||||
};
|
||||
@@ -200,7 +90,7 @@ public:
|
||||
VoxCountOver() : m_threshold(0) {}
|
||||
|
||||
template < class T >
|
||||
int Count(const Vector<T> &ref ) {
|
||||
int Count(const Vector<T> &ref ) const {
|
||||
int count = 0 ;
|
||||
foreach (const T &el, ref) {
|
||||
if( el.Get() >= m_threshold ) ++count;
|
||||
@@ -236,6 +126,16 @@ template < class VoxType,
|
||||
class CounterType >
|
||||
class VoxelVector : public VoxelVectorBase {
|
||||
public:
|
||||
|
||||
VoxelVector() {} // remove?
|
||||
VoxelVector( const VoxType *A1, const CounterType *A2 ) {
|
||||
(void) A1;
|
||||
SetA2(A2);
|
||||
}
|
||||
|
||||
void * GetA2() { return &m_counter; }
|
||||
void SetA2(const void *A2) { m_counter = *A2; }
|
||||
|
||||
float Get(int id) const { return m_data[id].Get(); }
|
||||
void Set(int id, float data) {
|
||||
if(id >= Size()) m_data.resize(id+1);
|
||||
@@ -250,11 +150,18 @@ private:
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
class VoxelVectorFactory {
|
||||
public:
|
||||
VoxelVectorFactory() : m_id1(0), m_id2(0) { m_base = m_factory.Create(0,0); }
|
||||
VoxelVectorFactory() :
|
||||
m_id1(0), m_id2(0)
|
||||
{
|
||||
m_base = m_factory.Create(0,0);
|
||||
}
|
||||
|
||||
~VoxelVectorFactory() {
|
||||
delete m_base;
|
||||
}
|
||||
|
||||
VoxelVectorBase * operator -> () const { return m_base; }
|
||||
|
||||
template < typename T >
|
||||
@@ -262,6 +169,9 @@ public:
|
||||
int id = m_factory.FindS1<T>();
|
||||
VoxelVectorBase * newbase = m_factory.Create(id,m_id2);
|
||||
Test::copy(m_base,newbase); // *newbase = *m_base;
|
||||
|
||||
//
|
||||
|
||||
delete m_base;
|
||||
m_base = newbase;
|
||||
}
|
||||
@@ -271,7 +181,9 @@ public:
|
||||
int id = m_factory.FindS2<T>();
|
||||
VoxelVectorBase * newbase = m_factory.Create(m_id1,id);
|
||||
Test::copy(m_base,newbase); // *newbase = *m_base;
|
||||
// ????? come copiare i membri ???? ////
|
||||
|
||||
//
|
||||
|
||||
delete m_base;
|
||||
m_base = newbase;
|
||||
}
|
||||
@@ -289,22 +201,41 @@ private:
|
||||
|
||||
|
||||
|
||||
|
||||
struct B1 {
|
||||
B1() : m_b1(1) {}
|
||||
int m_b1;
|
||||
};
|
||||
|
||||
struct B2 {
|
||||
B2() : m_b2(2) {}
|
||||
int m_b2;
|
||||
};
|
||||
|
||||
struct B3 {
|
||||
B3() : m_b3(3) {}
|
||||
int m_b3;
|
||||
};
|
||||
|
||||
struct B3b {
|
||||
B3b() : m_b3(3) {}
|
||||
int m_b3; // learn to handle ambiguity ..
|
||||
};
|
||||
|
||||
|
||||
int main() {
|
||||
Test::VoxelVectorFactory factory;
|
||||
|
||||
for(int i=0; i<10; ++i)
|
||||
factory->Set(i,i);
|
||||
|
||||
factory.SetVoxel<Test::VoxelVal>();
|
||||
|
||||
for(int i=0; i<10; ++i)
|
||||
std::cout << factory->Get(i) << " ";
|
||||
std::cout << "\n";
|
||||
|
||||
std::cout << "vox count = " << factory->Count() << "\n";
|
||||
ClassCompound< B1, B2 > h1;
|
||||
ClassCompound< B2, B3, B1 > h2;
|
||||
|
||||
|
||||
h1.A0::m_b1 = 111;
|
||||
h1.A1::m_b2 = 222;
|
||||
|
||||
h2 = h1;
|
||||
|
||||
std::cout << "h1: " << h1.A0::m_b1 << " " << h1.A1::m_b2 << "\n";
|
||||
std::cout << "h2: " << h2.A0::m_b2 << " " << h2.A1::m_b3 << "\n";
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user