Skip to content

Commit

Permalink
Update documentation
Browse files Browse the repository at this point in the history
fix line ending
  • Loading branch information
djmott committed Jul 26, 2016
1 parent a853547 commit 1807bfe
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 13 deletions.
9 changes: 7 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ add_library(XTL STATIC ${EVT_TRACE_SRC}
include/xtd/concurrent/rw_lock.hpp
include/xtd/concurrent/spin_lock.hpp
include/xtd/concurrent/recursive_spin_lock.hpp
include/xtd/btree.hpp
include/xtd/debug.hpp
include/xtd/dynamic_library.hpp
include/xtd/event_trace.hpp
Expand All @@ -165,10 +166,14 @@ add_library(XTL STATIC ${EVT_TRACE_SRC}
include/xtd/tuple.hpp
include/xtd/unique_id.hpp
include/xtd/var.hpp
include/xtd/xtd.hpp.in
include/xtd/windows/dbghelp.hpp
include/xtd/exception.inl
)
include/xtd/nlp/nlp.hpp
include/xtd/nlp/bag_of_words.hpp


include/xtd/xtd.hpp.in
)

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)

Expand Down
63 changes: 63 additions & 0 deletions docs/Hierarchy-Generation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
Hierarchy Generation
====================
This is a TMP pattern to generate a class hierarchy from a collection of policy classes. It permits arbitrarily mixing policies to generate rich components while avoiding multiple inheritance. It works by chaining together a series of policies in a linear class hierarchy through a couple controller templates.

The various policies are required to implement a parameterized super class idiom:
```{.cpp}
template <class _SuperT> class OnClick : _SuperT {
...
};
template <class _SuperT> class OnPaint : _SuperT {
...
};
template <class _SuperT> class OnResize : _SuperT {
...
};
template <class _SuperT> class OnTimer : _SuperT {
...
};
```
Each policy template is a self contained behavioral unit that describes an aspect of the larger whole. To maximize reuse they should be independent but it's possible to share information between them if care is taken.

The process of chaining the policies together is performed through a controller with the following declaration:

```{.cpp}
template <class _BaseT, template <class> class ... _PolicyList>
class HierarchyGenerator;
```

The parameters of the `HierarchyGenerator` are `_BaseT` and `_PolicyList`. The `_BaseT` parameter in this example is the super class of the entire hierarchy and will normally be a non-templated class. Policies are passed as parameters to the `HierarchyGenerator` in the `_PolicyList` parameter to successively declare a linear class hierarchy:

```{.cpp}
class Window{
...
};
using Button = HierarchyGenerator<Window, OnClick, OnPaint, OnResize>;
using Label = HierarchyGenerator<Window, OnPaint>;
using Sizer = HierarchyGenerator<Window, OnClick, OnPaint, OnResize, OnTimer>;
using Timer = HierarchyGenerator<Window, OnTimer>;
```
This results in linear class hierarchies composed of a mixture of policies. It equivalently declares the following:

```{.cpp}
using Button = OnClick<OnPaint<OnResize<Window>>>;
using Label = OnPaint<Window>;
using Sizer = OnClick<OnPaint<OnResize<OnTimer<Window>>>>;
using Timer = OnTimer<Window>;
```
The two forms are the same and the varation using the `HierarchyGenerator` is more verbose but the intent is clearer and more readable.

The 'magic' is done through a couple partial specializations of `HierarchyGenerator`:
```{.cpp}
template <typename _BaseT> class HierarchyGenerator<_BaseT> : public _BaseT{
template <typename ... _Args> HierarchyGenerator(_Args&&...oArgs) : _BaseT(std::forward<_Args>(oArgs)...){}
};
```
This is the final specialization in the recusive template instantation chain that makes `_BaseT` the base class of all the policies. The compiler selects this specialization when the `_PolicyList` has been depleted of items. Chaining together the items in the `_PolicyList` is performed with the following partial specialization:
```
template <typename _BaseT, template <class> class _PolicyT, template <class> class ... _PolicyList>
class HierarchyGenerator<_BaseT, _PolicyT, _PolicyList...> : public _PolicyT< HierarchyGenerator<_PolicyList...>> {
template <typename ... _Args> HierarchyGenerator(_Args&&...oArgs)
: _PolicyT< HierarchyGenerator<_PolicyList...>>(std::forward<_Args>(oArgs)...){}
};
```
2 changes: 1 addition & 1 deletion examples/example_nlp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
#include <xtd/xtd.hpp>

int main(){
INFO("Hello?");

return 0;
}
4 changes: 2 additions & 2 deletions include/xtd/btree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ namespace xtd{
using value_type = _ValueT;

bool insert(const key_type& key, const value_type& value){

return false;
}


};
}
}
8 changes: 0 additions & 8 deletions include/xtd/filesystem.inl

This file was deleted.

1 change: 1 addition & 0 deletions include/xtd/xtd.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ TODO("Remove cassert when XTD implementation is finished")
#include <xtd/event_trace.hpp>
#include <xtd/log.hpp>
#include <xtd/debug.hpp>
#include <xtd/btree.hpp>

#include <xtd/parse.hpp>
#include <xtd/process.hpp>
Expand Down

0 comments on commit 1807bfe

Please sign in to comment.