aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcathook <b01902109@csie.ntu.edu.tw>2014-05-02 01:29:33 +0800
committercathook <b01902109@csie.ntu.edu.tw>2014-05-02 01:29:33 +0800
commitd2d7a49563a8f04bd07264a4a989d5656313d375 (patch)
tree45812ca8bcc20b59e9f4f4e54bf052eb39a6c0be
parent395a4bceaac30588963dacb8e006e9ebbe2ca6dd (diff)
downloadmeow-d2d7a49563a8f04bd07264a4a989d5656313d375.tar
meow-d2d7a49563a8f04bd07264a4a989d5656313d375.tar.gz
meow-d2d7a49563a8f04bd07264a4a989d5656313d375.tar.bz2
meow-d2d7a49563a8f04bd07264a4a989d5656313d375.tar.lz
meow-d2d7a49563a8f04bd07264a4a989d5656313d375.tar.xz
meow-d2d7a49563a8f04bd07264a4a989d5656313d375.tar.zst
meow-d2d7a49563a8f04bd07264a4a989d5656313d375.zip
update test
-rw-r--r--README.asciidoc33
-rw-r--r--README.html77
-rw-r--r--_test/meowpp.cpp32
-rw-r--r--_test/meowpp.h55
-rw-r--r--_test/meowpp_BinaryIndexTree.cpp2
-rw-r--r--_test/meowpp_Colors.cpp2
-rw-r--r--_test/meowpp_DisjointSet.cpp2
-rw-r--r--_test/meowpp_KD_Tree.cpp2
-rw-r--r--_test/meowpp_Matrix.cpp2
-rw-r--r--_test/meowpp_MergeableHeap.cpp2
-rw-r--r--_test/meowpp_SegmentTree.cpp2
-rw-r--r--_test/meowpp_SplayTree.cpp2
-rw-r--r--_test/meowpp_SplayTree_Range.cpp2
-rw-r--r--_test/meowpp_VP_Tree.cpp2
-rw-r--r--header.asciidoc (renamed from description.asciidoc)0
-rw-r--r--meowpp/oo/ObjBase.h1
-rw-r--r--meowpp/oo/ObjSelector.h51
-rw-r--r--meowpp/oo/Properties.hpp2
-rw-r--r--meowpp/oo/Register_Implement.h55
-rw-r--r--meowpp/oo/Register_Implement.hpp36
20 files changed, 139 insertions, 223 deletions
diff --git a/README.asciidoc b/README.asciidoc
index 5ea6f5d..af84ff1 100644
--- a/README.asciidoc
+++ b/README.asciidoc
@@ -14,9 +14,7 @@
* *utility.h* some useful functions,
`stringPringf()` , `stringReplace()` , `cstringEndWith()` ,
- `debugPrintf()` , `messagePrintf()` , `constant PI` ,
- `noEPS()` , `normalize()` , `denormalize()` ,
- `ratioMapping()` , `inRange()` , `squ()` , `average()`
+ `debugPrintf()` , `messagePrintf()` , `filenameCompare()`
* *Usage.h* `class Usage`
* *colors/* Color splces and transformer
** *RGB.h* `class RGBi` , `class RGBf`
@@ -39,14 +37,19 @@
** *Vector2D.h* `Vector2D<Scalar>`
** *Vector3D.h* `Vector3D<Scalar>`
* *math/*
+** *utility.h* some useful functions,
+ `constant PI` ,
+ `noEPS()` , `normalize()` , `denormalize()` ,
+ `ratioMapping()` , `inRange()` , `squ()` , `average()`
** *LinearTransformation.h* `LinearTransformation<Scalar>`
** *LinearTransformations.h* `Rotation3D<Scalar>`
** *Matrix.h* `Matrix<Entry>`
** *Transformation.h* `Transformation<Scalar>`
** *Transformations.h* `BallProjection<Scalar>`, `PhotoProjection<Scalar>`
* *oo/*
-** *Register_Implement.h* `class RegisterInterface` ,
- `class ImplementInterface`
+** *ObjBase.h* `class ObjBase`
+** *ObjSelector.h* `class ObjBase<size_t id>`
+** *Properties.h* `class Properties`
== Structures/Classes/Functions
@@ -152,26 +155,6 @@ String const& value, String const& description)` +
'''
-=== meow:: *ImplementInterface/RegisterInterface* (C++ Class)
-==== Description
-Assume there is a problem which can be solved by different algorithms.
-Then you can write multiple classes to approach this problem. +
-Now if you want to decide which algorithm to use in runtime, you can just
-approach this case by a simple way:
-
-* Let all the problem-solving classes inherit from
-`class ImplementInterface<T>` , and call the constructure with giving
-`identify` (type `T` ) .
-* Create an class inherit from `RegisterInterface<T>` ,
-and register all your implement class to it by call
-`regImplement(pointer to the class)`.
-* Select which implement class you want by call
-`getImplement(identify)` , which will return the pointer
-to the corresponding class.
-
-'''
-
-
=== meow:: *DisjointSet* (C++ class)
==== Description
`DisjointSet` 是個*輕量級Data Dtructure*, 用來維護一堆互斥集的資訊.
diff --git a/README.html b/README.html
index aca9db5..f2f5c5c 100644
--- a/README.html
+++ b/README.html
@@ -715,9 +715,7 @@ asciidoc.install(2);
<p>
<strong>utility.h</strong> some useful functions,
<span class="monospaced">stringPringf()</span> , <span class="monospaced">stringReplace()</span> , <span class="monospaced">cstringEndWith()</span> ,
- <span class="monospaced">debugPrintf()</span> , <span class="monospaced">messagePrintf()</span> , <span class="monospaced">constant PI</span> ,
- <span class="monospaced">noEPS()</span> , <span class="monospaced">normalize()</span> , <span class="monospaced">denormalize()</span> ,
- <span class="monospaced">ratioMapping()</span> , <span class="monospaced">inRange()</span> , <span class="monospaced">squ()</span> , <span class="monospaced">average()</span>
+ <span class="monospaced">debugPrintf()</span> , <span class="monospaced">messagePrintf()</span> , <span class="monospaced">filenameCompare()</span>
</p>
</li>
<li>
@@ -826,6 +824,14 @@ asciidoc.install(2);
<div class="ulist"><ul>
<li>
<p>
+<strong>utility.h</strong> some useful functions,
+ <span class="monospaced">constant PI</span> ,
+ <span class="monospaced">noEPS()</span> , <span class="monospaced">normalize()</span> , <span class="monospaced">denormalize()</span> ,
+ <span class="monospaced">ratioMapping()</span> , <span class="monospaced">inRange()</span> , <span class="monospaced">squ()</span> , <span class="monospaced">average()</span>
+</p>
+</li>
+<li>
+<p>
<strong>LinearTransformation.h</strong> <span class="monospaced">LinearTransformation&lt;Scalar&gt;</span>
</p>
</li>
@@ -858,8 +864,17 @@ asciidoc.install(2);
<div class="ulist"><ul>
<li>
<p>
-<strong>Register_Implement.h</strong> <span class="monospaced">class RegisterInterface</span> ,
- <span class="monospaced">class ImplementInterface</span>
+<strong>ObjBase.h</strong> <span class="monospaced">class ObjBase</span>
+</p>
+</li>
+<li>
+<p>
+<strong>ObjSelector.h</strong> <span class="monospaced">class ObjBase&lt;size_t id&gt;</span>
+</p>
+</li>
+<li>
+<p>
+<strong>Properties.h</strong> <span class="monospaced">class Properties</span>
</p>
</li>
</ul></div>
@@ -1121,43 +1136,9 @@ String const&amp; value, String const&amp; description)</span><br>
</div>
</div>
<div class="sect2">
-<h3 id="_meow_strong_implementinterface_registerinterface_strong_c_class">meow:: <strong>ImplementInterface/RegisterInterface</strong> (C++ Class)</h3>
-<div class="sect3">
-<h4 id="_description_3">Description</h4>
-<div class="paragraph"><p>Assume there is a problem which can be solved by different algorithms.
-Then you can write multiple classes to approach this problem.<br>
-Now if you want to decide which algorithm to use in runtime, you can just
-approach this case by a simple way:</p></div>
-<div class="ulist"><ul>
-<li>
-<p>
-Let all the problem-solving classes inherit from
-<span class="monospaced">class ImplementInterface&lt;T&gt;</span> , and call the constructure with giving
-<span class="monospaced">identify</span> (type <span class="monospaced">T</span> ) .
-</p>
-</li>
-<li>
-<p>
-Create an class inherit from <span class="monospaced">RegisterInterface&lt;T&gt;</span> ,
-and register all your implement class to it by call
-<span class="monospaced">regImplement(pointer to the class)</span>.
-</p>
-</li>
-<li>
-<p>
-Select which implement class you want by call
-<span class="monospaced">getImplement(identify)</span> , which will return the pointer
-to the corresponding class.
-</p>
-</li>
-</ul></div>
-<hr>
-</div>
-</div>
-<div class="sect2">
<h3 id="_meow_strong_disjointset_strong_c_class">meow:: <strong>DisjointSet</strong> (C++ class)</h3>
<div class="sect3">
-<h4 id="_description_4">Description</h4>
+<h4 id="_description_3">Description</h4>
<div class="paragraph"><p><span class="monospaced">DisjointSet</span> 是個<strong>輕量級Data Dtructure</strong>, 用來維護一堆互斥集的資訊.
相關資料可參考
<a href="http://www.csie.ntnu.edu.tw/~u91029/DisjointSets.html">演算法筆記</a></p></div>
@@ -1249,7 +1230,7 @@ size_t <span class="monospaced">number2</span>)</p></td>
<div class="sect2">
<h3 id="_meow_strong_mergeableheap_lt_element_gt_strong_c_class">meow:: <strong>MergeableHeap&lt;Element&gt;</strong> (C++ class)</h3>
<div class="sect3">
-<h4 id="_description_5">Description</h4>
+<h4 id="_description_4">Description</h4>
<div class="paragraph"><p>一個用 <strong>左偏樹</strong> 實作的 <strong>Maximum-Heap</strong> , 除了原本heap有的功能外,
還支援 <span class="monospaced">merge</span>, <span class="monospaced">split</span> 等功能</p></div>
</div>
@@ -1419,7 +1400,7 @@ width:100%;
<div class="sect2">
<h3 id="_meow_strong_vp_tree_lt_vector_scalar_gt_strong_c_class">meow:: <strong>VP_Tree&lt;Vector, Scalar&gt;</strong> (C++ class)</h3>
<div class="sect3">
-<h4 id="_description_6">Description</h4>
+<h4 id="_description_5">Description</h4>
<div class="paragraph"><p><span class="monospaced">VP_Tree</span> 用來維護由 <strong>N個K維度向量所成的集合</strong>,
並可於該set中查找 <strong>前i個離給定向量最接近的向量</strong>.<br>
不像 <span class="monospaced">KD_Tree</span> 二分樹每次都選擇一個維度去分, 分成小的跟大的,
@@ -1674,7 +1655,7 @@ bool <span class="monospaced">cmp</span>)</p></td>
<div class="sect2">
<h3 id="_meow_strong_kd_tree_lt_vector_scalar_gt_strong_c_class">meow:: <strong>KD_Tree&lt;Vector, Scalar&gt;</strong> (C++ class)</h3>
<div class="sect3">
-<h4 id="_description_7">Description</h4>
+<h4 id="_description_6">Description</h4>
<div class="paragraph"><p><span class="monospaced">KD_Tree</span> 全名k-dimension tree, 用來維護由 <strong>N個K維度向量所成的集合</strong>,
並可於該set中查找 <strong>前i個離給定向量最接近的向量</strong></p></div>
</div>
@@ -1883,7 +1864,7 @@ bool <span class="monospaced">cmp</span>)</p></td>
<div class="sect2">
<h3 id="_meow_strong_splaytree_lt_key_value_gt_strong_c_class">meow:: <strong>SplayTree&lt;Key, Value&gt;</strong> (C++ class)</h3>
<div class="sect3">
-<h4 id="_description_8">Description</h4>
+<h4 id="_description_7">Description</h4>
<div class="paragraph"><p><span class="monospaced">SplayTree</span> 是一種神乎其技的資料結構, 維護一堆 Key&#8594;Value . 並且支援
一些 <span class="monospaced">std::map</span> 難以快速實踐的操作, 如 <span class="monospaced">split</span> , <span class="monospaced">merge</span> , <span class="monospaced">keyOffset</span></p></div>
</div>
@@ -2227,7 +2208,7 @@ SplayTree* <span class="monospaced">tree2</span>)</p></td>
<div class="sect2">
<h3 id="_meow_strong_segmenttree_lt_value_gt_strong_c_class">meow:: <strong>SegmentTree&lt;Value&gt;</strong> (C++ class)</h3>
<div class="sect3">
-<h4 id="_description_9">Description</h4>
+<h4 id="_description_8">Description</h4>
<div class="paragraph"><p>維護一個陣列, 並且讓user可以有區間查詢, 區間修改的小東東</p></div>
</div>
<div class="sect3">
@@ -2403,7 +2384,7 @@ Value const&amp; <span class="monospaced">delta</span>)</p></td>
<div class="sect2">
<h3 id="_meow_strong_splaytree_range_lt_key_value_gt_strong_c_class">meow:: <strong>SplayTree_Range&lt;Key, Value&gt;</strong> (C++ class)</h3>
<div class="sect3">
-<h4 id="_description_10">Description</h4>
+<h4 id="_description_9">Description</h4>
<div class="paragraph"><p><span class="monospaced">SplayTree_Range</span> 是一種神乎其技的資料結構, 維護一堆 Key&#8594;Value. 並且支援
一些 <span class="monospaced">std::map</span> 難以快速實踐的操作, 如 <span class="monospaced">split</span> , <span class="monospaced">merge</span> , <span class="monospaced">keyOffset</span></p></div>
</div>
@@ -2781,7 +2762,7 @@ SplayTree_Range* <span class="monospaced">tree2</span>)</p></td>
<div class="sect2">
<h3 id="_meow_strong_binaryindextree_lt_value_gt_strong_c_class">meow:: <strong>BinaryIndexTree&lt;Value&gt;</strong> (C++ class)</h3>
<div class="sect3">
-<h4 id="_description_11">Description</h4>
+<h4 id="_description_10">Description</h4>
<div class="paragraph"><p>極度簡化版的 <span class="monospaced">SegmentTree</span> 已無法區間操作, 區間詢問的區間開頭也一定要
在 <span class="monospaced">index=0</span> 的地方</p></div>
</div>
@@ -3090,7 +3071,7 @@ E-Mail: cat.hook31894 ~在~ gmail.com
<div id="footnotes"><hr></div>
<div id="footer">
<div id="footer-text">
-Last updated 2014-05-01 21:55:51 CST
+Last updated 2014-05-02 01:28:05 CST
</div>
</div>
</body>
diff --git a/_test/meowpp.cpp b/_test/meowpp.cpp
index e45a4c1..c380098 100644
--- a/_test/meowpp.cpp
+++ b/_test/meowpp.cpp
@@ -1,5 +1,6 @@
#include "meowpp.h"
+#include <vector>
#include <string>
#include <cstdlib>
#include <ctime>
@@ -9,11 +10,19 @@
////////////////////////////
meow::Usage usg("meowpp"), usg2;
int count = 0;
-TestFunctions tests;
////////////////////////
int main(int argc, char** argv){
- //srand(time(NULL));
+ std::vector<std::string> ids(meow::ObjSelector<0>::lst());
+ usg2.addOption('t', "Select which subject to test",
+ "<number>", "",
+ false);
+ for(size_t i = 0; i < ids.size(); i++){
+ TestFunction* tmp = (TestFunction*)meow::ObjSelector<0>::get(ids[i]);
+ usg2.addOptionValueAccept('t', ids[i], tmp->name() + ", " + tmp->description());
+ delete tmp;
+ }
+
usg.addOption('h', "Display this help document");
usg.addUsageBegin("<name> is a little test program to check whether"
"the data structures in the template is correct by"
@@ -32,21 +41,22 @@ int main(int argc, char** argv){
usg2.update(usg);
if(usg2.getOptionValuesCount('t') > 0){
for(int i = 0, I = usg2.getOptionValuesCount('t'); i < I; i++){
- int id = atoi(usg2.getOptionValue('t', i).c_str());
- TestFunction* f = (TestFunction*)tests.getImplement(id);
+ std::string wh = usg2.getOptionValue('t', i);
+ TestFunction* f = (TestFunction*)meow::ObjSelector<0>::get(wh);
if(f->run() == false){
printf("error occure on %s\n", f->name().c_str());
return 1;
}else{
printf("%s success\n", f->name().c_str());
}
+ delete f;
}
}else{
- std::vector<int> ids = tests.getIdentifys();
while(true){
for(int i = 0, I = ids.size(); i < I; i++){
- TestFunction* f = (TestFunction*)tests.getImplement(i);
- printf(" %d) %s\n", ids[i], f->name().c_str());
+ TestFunction* tmp = (TestFunction*)meow::ObjSelector<0>::get(ids[i]);
+ printf(" %s) %s\n", ids[i].c_str(), tmp->name().c_str());
+ delete tmp;
}
printf("please select(EOF to quit): ");
int id;
@@ -54,21 +64,21 @@ int main(int argc, char** argv){
break;
}
printf("\n");
- TestFunction* f = (TestFunction*)tests.getImplement(id);
+ TestFunction* f = (TestFunction*)meow::ObjSelector<0>::get(meow::stringPrintf("%d", id));
if(f == NULL){
printf("Bad value!\n\n");
continue;
}
if(f->run() == false){
- printf("error occure on %s\n\n", f->name().c_str());
+ printf("error occure on %s\n", f->name().c_str());
return 1;
}else{
- printf("%s success\n\n", f->name().c_str());
+ printf("%s success\n", f->name().c_str());
}
+ delete f;
}
printf("\n");
}
- return 0;
}
return 0;
}
diff --git a/_test/meowpp.h b/_test/meowpp.h
index 94ff3ec..8e6e181 100644
--- a/_test/meowpp.h
+++ b/_test/meowpp.h
@@ -5,51 +5,30 @@
#include "meowpp/geo/Vector3D.h"
#include "meowpp/Usage.h"
-#include "meowpp/oo/Register_Implement.h"
#include "meowpp/oo/Properties.h"
+#include "meowpp/oo/ObjBase.h"
+#include "meowpp/oo/ObjSelector.h"
-extern meow::Usage usg, usg2;
extern int count;
-//////////////////////////////////
-class TestFunctions: public meow::RegisterInterface<int>{
- public:
- TestFunctions(): RegisterInterface(){
- usg2.addOption('t',
- "Specify which part of the template to test",
- "name", "",
- false);
- }
- bool regImplement(meow::ImplementInterface<int>* imp,
- std::string const& str){
- usg2.addOptionValueAccept('t',
- meow::stringPrintf("%d", imp->identify()),
- str);
- return RegisterInterface::regImplement(imp);
- }
-};
-extern TestFunctions tests;
-////////////////////////
-class TestFunction: public meow::ImplementInterface<int>{
- private:
- std::string _name;
+
+class TestFunction: public meow::ObjBase{
public:
- TestFunction(std::string const& __name):
- ImplementInterface(count++), _name("testing code about " + __name){
- tests.regImplement(this, _name);
- }
- virtual ~TestFunction(){ }
+ virtual ~TestFunction(){ };
virtual bool run() = 0;
- std::string name() const{ return _name; }
+ virtual std::string name () const = 0;
+ virtual std::string description() const = 0;
};
-////////////////////////
-#define concat(a,b) a##b
-#define TEST(a) \
-class Test_##a: public TestFunction{ \
+#define TEST(__A,__B) \
+class Test##__A: public TestFunction{ \
public: \
- Test_##a(): TestFunction(#a){ } \
- bool run();\
-} __test_##a; bool Test_##a::run()
-
+ \
+ meow::ObjBase* create() const{ return new Test##__A(); } \
+ bool run(); \
+ std::string name() const{ return #__A; } \
+ std::string description() const{ return __B; } \
+}; \
+static meow::ObjSelector<0> _(meow::stringPrintf("%d", count++), new Test##__A()); \
+inline bool Test##__A::run()
#endif // __meowpp_h__
diff --git a/_test/meowpp_BinaryIndexTree.cpp b/_test/meowpp_BinaryIndexTree.cpp
index 3071839..0b81f10 100644
--- a/_test/meowpp_BinaryIndexTree.cpp
+++ b/_test/meowpp_BinaryIndexTree.cpp
@@ -19,7 +19,7 @@ inline int sum(int k){
static meow::BinaryIndexTree<int> bit;
-TEST(BinaryIndexTree){
+TEST(BinaryIndexTree, "Test with large data"){
size_t tMe = 0, tBi = 0, t0;
for(int z = 0; z < 10; z++){
meow::messagePrintf(1, "test %d", z);
diff --git a/_test/meowpp_Colors.cpp b/_test/meowpp_Colors.cpp
index ac740e0..3233cf6 100644
--- a/_test/meowpp_Colors.cpp
+++ b/_test/meowpp_Colors.cpp
@@ -6,7 +6,7 @@
#include "meowpp.h"
-TEST(Colors){
+TEST(Colors, "Transformations"){
meow::RGBf rgb, rgb2;
meow::YUVf yuv, yuv2;
meow::HSLf hsl, hsl2;
diff --git a/_test/meowpp_DisjointSet.cpp b/_test/meowpp_DisjointSet.cpp
index 484e146..41ca7d2 100644
--- a/_test/meowpp_DisjointSet.cpp
+++ b/_test/meowpp_DisjointSet.cpp
@@ -5,7 +5,7 @@
#include <vector>
-TEST(DisjointSet){
+TEST(DisjointSet, "..."){
int N = 10000000;
meow::DisjointSet dsj(N);
diff --git a/_test/meowpp_KD_Tree.cpp b/_test/meowpp_KD_Tree.cpp
index 6cb2e0c..25c18b0 100644
--- a/_test/meowpp_KD_Tree.cpp
+++ b/_test/meowpp_KD_Tree.cpp
@@ -116,7 +116,7 @@ struct Node{
bool operator<(Node const& n) const{ return (id < n.id); }
};
-TEST(KD_Tree){
+TEST(KD_Tree, "It is very slow"){
int t0, t1, t2;
diff --git a/_test/meowpp_Matrix.cpp b/_test/meowpp_Matrix.cpp
index dbcfcb1..6ef94b7 100644
--- a/_test/meowpp_Matrix.cpp
+++ b/_test/meowpp_Matrix.cpp
@@ -19,7 +19,7 @@ void print(Matrix<int> const& m){
}
}
-TEST(Matrix){
+TEST(Matrix, "Unfinished"){
Matrix<int> a(3, 4, 0);
Matrix<int> b(3, 4, 0);
Matrix<int> c(4, 5, 0);
diff --git a/_test/meowpp_MergeableHeap.cpp b/_test/meowpp_MergeableHeap.cpp
index 65fe2cc..78eed00 100644
--- a/_test/meowpp_MergeableHeap.cpp
+++ b/_test/meowpp_MergeableHeap.cpp
@@ -8,7 +8,7 @@
#include <cstdlib>
-TEST(MergeableHeap){
+TEST(MergeableHeap, "..."){
int N = 10;
std::vector<std::priority_queue<int> > nhp;
std::vector<meow::MergeableHeap<int> > mhp;
diff --git a/_test/meowpp_SegmentTree.cpp b/_test/meowpp_SegmentTree.cpp
index 05b1b51..f92f55f 100644
--- a/_test/meowpp_SegmentTree.cpp
+++ b/_test/meowpp_SegmentTree.cpp
@@ -80,7 +80,7 @@ void show(){
}
}
-TEST(SegmentTree){
+TEST(SegmentTree, "..."){
s_max.reset(N);
s_sum.reset(N);
s_max.override(0, N - 1, RangeMax(0));
diff --git a/_test/meowpp_SplayTree.cpp b/_test/meowpp_SplayTree.cpp
index 68ae58f..96c5807 100644
--- a/_test/meowpp_SplayTree.cpp
+++ b/_test/meowpp_SplayTree.cpp
@@ -312,7 +312,7 @@ static bool check(){
return true;
}
-TEST(SplayTree){
+TEST(SplayTree, "Seems buggy"){
detail_fg = false;
N = 5;
for(int i = 0; i < 10; i++){
diff --git a/_test/meowpp_SplayTree_Range.cpp b/_test/meowpp_SplayTree_Range.cpp
index 0233a49..7df650a 100644
--- a/_test/meowpp_SplayTree_Range.cpp
+++ b/_test/meowpp_SplayTree_Range.cpp
@@ -364,7 +364,7 @@ static bool check(){
return true;
}
-TEST(SplayTree_Range){
+TEST(SplayTree_Range, "..."){
detail_fg = false;
N = 5;
for(int i = 0; i < 10; i++){
diff --git a/_test/meowpp_VP_Tree.cpp b/_test/meowpp_VP_Tree.cpp
index c01db38..503cde6 100644
--- a/_test/meowpp_VP_Tree.cpp
+++ b/_test/meowpp_VP_Tree.cpp
@@ -110,7 +110,7 @@ static std::vector<MyVector> find(MyVector const& v, int k){
return ret;
}
-TEST(VP_Tree){
+TEST(VP_Tree, "A little bit slow"){
int t0, t1, t2;
meow::VP_Tree<MyVector, lnt> tree(D);
diff --git a/description.asciidoc b/header.asciidoc
index 6f4c2e1..6f4c2e1 100644
--- a/description.asciidoc
+++ b/header.asciidoc
diff --git a/meowpp/oo/ObjBase.h b/meowpp/oo/ObjBase.h
index 8bd0f1c..2c8cb70 100644
--- a/meowpp/oo/ObjBase.h
+++ b/meowpp/oo/ObjBase.h
@@ -11,6 +11,7 @@ namespace meow{
public:
virtual ~ObjBase(){ }
//
+ virtual ObjBase* create() const = 0;
virtual char const* ctype() const{
static char const* ptr = typeid(*this).name();
return ptr;
diff --git a/meowpp/oo/ObjSelector.h b/meowpp/oo/ObjSelector.h
new file mode 100644
index 0000000..e70c496
--- /dev/null
+++ b/meowpp/oo/ObjSelector.h
@@ -0,0 +1,51 @@
+#ifndef oo_ObjSelector_H__
+#define oo_ObjSelector_H__
+
+#include "ObjBase.h"
+
+#include <cstdlib>
+
+namespace meow{
+ template<size_t id>
+ class ObjSelector{
+ private:
+ typedef std::map <std::string, ObjBase*> Funcs;
+ typedef std::vector<std::string > Types;
+ //
+ static Funcs& funcs(){
+ static Funcs f;
+ return f;
+ }
+ //
+ std::string name;
+ ObjBase* ptr;
+ public:
+ ObjSelector( ObjBase* o){ add(name = o->type(), ptr = o); }
+ ObjSelector(std::string n, ObjBase* o){ add(name = n , ptr = o); }
+ ~ObjSelector(){ del(name); }
+ //
+ static void add(std::string n, ObjBase* b){
+ del(n);
+ funcs()[n] = b;
+ }
+ static void del(std::string s){
+ if(funcs().find(s) != funcs().end()){
+ delete funcs()[s];
+ funcs().erase(s);
+ }
+ }
+ static ObjBase* get(std::string s){
+ if(funcs().find(s) == funcs().end() || funcs()[s] == NULL)
+ return NULL;
+ return funcs()[s]->create();
+ }
+ static Types lst(){
+ Types ret;
+ for(Funcs::iterator it = funcs().begin(); it != funcs().end(); it++)
+ ret.push_back(it->first);
+ return ret;
+ }
+ };
+}
+
+#endif // oo_ObjSelector_H__
diff --git a/meowpp/oo/Properties.hpp b/meowpp/oo/Properties.hpp
index 90d9805..58be1b4 100644
--- a/meowpp/oo/Properties.hpp
+++ b/meowpp/oo/Properties.hpp
@@ -1,5 +1,7 @@
#include "Properties.h"
+#include "ObjBase.h"
+
#include <map>
#include <queue>
diff --git a/meowpp/oo/Register_Implement.h b/meowpp/oo/Register_Implement.h
deleted file mode 100644
index 910ee11..0000000
--- a/meowpp/oo/Register_Implement.h
+++ /dev/null
@@ -1,55 +0,0 @@
-#ifndef oo_Register_Implement_H__
-#define oo_Register_Implement_H__
-
-#include <map>
-#include <vector>
-
-namespace meow{
- template<class T>
- class ImplementInterface{
- private:
- T identify_;
- protected:
- ImplementInterface(T const& id): identify_(id) { }
- public:
- T const& identify() const { return identify_; }
- virtual ~ImplementInterface(){ }
- };
- //
- template<class T>
- class RegisterInterface{
- private:
- std::map<T, ImplementInterface<T>*> implements;
- protected:
- RegisterInterface();
- public:
- virtual bool regImplement(ImplementInterface<T>*imp);
- virtual ImplementInterface<T>* getImplement(T const& identify);
- virtual ~RegisterInterface(){ }
- std::vector<T> getIdentifys() const;
- };
- //#
- //# === meow:: *ImplementInterface/RegisterInterface* (C++ Class)
- //# ==== Description
- //# Assume there is a problem which can be solved by different algorithms.
- //# Then you can write multiple classes to approach this problem. +
- //# Now if you want to decide which algorithm to use in runtime, you can just
- //# approach this case by a simple way:
- //#
- //# * Let all the problem-solving classes inherit from
- //# `class ImplementInterface<T>` , and call the constructure with giving
- //# `identify` (type `T` ) .
- //# * Create an class inherit from `RegisterInterface<T>` ,
- //# and register all your implement class to it by call
- //# `regImplement(pointer to the class)`.
- //# * Select which implement class you want by call
- //# `getImplement(identify)` , which will return the pointer
- //# to the corresponding class.
- //#
- //# '''
- //#
-}
-
-#include "Register_Implement.hpp"
-
-#endif // oo_Register_Implement_H__
diff --git a/meowpp/oo/Register_Implement.hpp b/meowpp/oo/Register_Implement.hpp
deleted file mode 100644
index bee7f3e..0000000
--- a/meowpp/oo/Register_Implement.hpp
+++ /dev/null
@@ -1,36 +0,0 @@
-#include "Register_Implement.h"
-
-
-#include <map>
-#include <vector>
-
-namespace meow{
- template<class T>
- inline RegisterInterface<T>::RegisterInterface(){ }
- template<class T>
- inline bool RegisterInterface<T>::regImplement(ImplementInterface<T>* imp){
- if(implements.find(imp->identify()) != implements.end()){
- return false;
- }
- implements[imp->identify()] = imp;
- return true;
- }
- template<class T>
- inline ImplementInterface<T>*
- RegisterInterface<T>::getImplement(T const& identify){
- if(implements.find(identify) == implements.end()){
- return NULL;
- }
- return implements[identify];
- }
- template<class T>
- inline std::vector<T>
- RegisterInterface<T>::getIdentifys() const{
- std::vector<T> ret;
- for(typename std::map<T, ImplementInterface<T>*>::const_iterator
- it = implements.begin(); it != implements.end(); it++){
- ret.push_back(it->first);
- }
- return ret;
- }
-}