DisplayEvaluation: draft evaluation invocation per track

...however, running into some type deduction problems...
This commit is contained in:
Fischlurch 2020-03-07 19:39:51 +01:00
parent 8d87029fd5
commit 4070cc0d83
5 changed files with 157 additions and 47 deletions

View file

@ -43,28 +43,40 @@
// 12/18 - investigate the trinomial random number algorithm from the C standard lib
// 04/19 - forwarding tuple element(s) to function invocation
// 06/19 - use a statefull counting filter in a treeExplorer pipeline
// 03/20 - investigate type deduction bug with PtrDerefIter
/** @file try.cpp
* How to pick a configurable prefix segment from an iterable sequence.
* Instead of using a classic indexed for loop, the same effect can be achieved
* through a statefull filter functor in a `treeExplore()`-pipeline; after full
* optimisation I'd expect even to get the same assembly as from an equivalent
* hand written for loop. (Caveat: debug builds will be bloated)
* Compiling a seemingly valid iterator pipeline failed, due to type deduction problems.
* As expected, they originate within PtrDerefIter, which I abused here to dereference
* an unique_ptr -- which might seem strange, yet is true to the spirit of generic programming.
* Since I consider this a valid usage, the fix is to add a further specialisation to my
* hand-written RemovePtr trait template in iter-adapter-ptr-deref.hpp (which also justifies
* in hindsight to use a hand-written trait right within this header, instead of some library).
*/
typedef unsigned int uint;
namespace std {
template <typename _Tp, typename _Dp>
class unique_ptr;
}
#include "lib/format-cout.hpp"
#include "lib/test/test-helper.hpp"
#include "lib/util.hpp"
#include "lib/iter-tree-explorer.hpp"
#include "lib/iter-adapter-ptr-deref.hpp"
#include "lib/iter-adapter-stl.hpp"
#include "lib/itertools.hpp"
#include <utility>
#include <string>
#include <vector>
#include <memory>
#include <type_traits>
using std::string;
using std::make_unique;
@ -73,37 +85,56 @@ using std::string;
#define SHOW_EXPR(_XX_) \
cout << "Probe " << STRINGIFY(_XX_) << " ? = " << _XX_ <<endl;
template<class IT>
auto
selectSeg(IT&& it, bool useFirst)
{
struct CountingFilter
{
int cnt;
bool useFirst;
bool
operator() (...)
{
bool isPrefixPart = 0 < cnt--;
return useFirst? isPrefixPart : not isPrefixPart;
}
};
return lib::treeExplore(std::forward<IT> (it))
.filter(CountingFilter{50, useFirst});
}
using PStr = std::unique_ptr<string>;
using Strs = std::vector<PStr>;
constexpr auto elems = [](auto& coll) { return lib::ptrDeref (lib::iter_stl::eachElm (coll)); };
namespace lib {
namespace {
template<typename T, typename D>
struct RemovePtr<std::unique_ptr<T,D>> { typedef T Type; };
}
}
namespace {
template<class IT>
inline auto
max (IT&& elms)
{
using Val = std::remove_reference_t<typename IT::value_type>;
Val res = std::numeric_limits<Val>::min();
for (auto& elm : std::forward<IT> (elms))
if (elm > res)
res = elm;
return res;
}
}
int
main (int, char**)
{
using VecN = std::vector<int>;
VecN numz{1,1,2,3,5,8,13,21};
Strs ss;
ss.emplace_back(new string{"li"});
ss.emplace_back(new string{"la"});
ss.emplace_back(new string{"lutsch"});
SHOW_EXPR (ss);
SHOW_EXPR (elems(ss));
using ITS = decltype(elems(ss));
SHOW_TYPE (ITS);
for (auto& elm : selectSeg(numz, false))
cout << elm<<"::";
for (auto& elm : selectSeg(numz, true))
cout << elm<<"::";
// using ITSR = typename ITS::reference;
// lib::test::TypeDebugger<ITSR> buggy;
auto dings = elems(ss);
int maxVSize = max (lib::transformIterator(dings,
[](string const& ding)
{
return ding.length();
}));
SHOW_EXPR (maxVSize);
cout << "\n.gulp.\n";
return 0;

View file

@ -152,6 +152,12 @@ namespace timeline {
}
int
ClipPresenter::determineRequiredVerticalExtension() const
{
UNIMPLEMENTED ("any details regarding clip presentation");
}
}}// namespace stage::timeline

View file

@ -98,6 +98,11 @@ namespace timeline {
virtual void buildMutator (lib::diff::TreeMutator::Handle) override;
/** find out the number of pixels necessary to render this clip properly,
* assuming its current presentation mode (abbreviated, full, expanded).
*/
int determineRequiredVerticalExtension() const;
private:/* ===== Internals ===== */
};

View file

@ -90,6 +90,9 @@
#include "stage/timeline/clip-presenter.hpp"
#include "stage/timeline/track-head-widget.hpp"
#include "stage/timeline/track-body.hpp"
#include "lib/iter-adapter-ptr-deref.hpp"
#include "lib/iter-adapter-stl.hpp"
#include "lib/itertools.hpp"
/////////////////////////////////////////////////////////////////////////////////////////////////////////////TICKET #1201 : test/code... remove this
#include "lib/format-cout.hpp"
/////////////////////////////////////////////////////////////////////////////////////////////////////////////TICKET #1201 : test/code... remove this
@ -113,6 +116,16 @@ namespace timeline {
using lib::diff::collection;
using std::make_unique;
using PFork = unique_ptr<TrackPresenter>;
using PClip = unique_ptr<ClipPresenter>;
using PMark = unique_ptr<MarkerWidget>;
using PRuler = unique_ptr<RulerTrack>;
namespace{
/** Helper: iterator to yield direct reference to collection members managed by (unique)pointer. */
constexpr auto elems = [](auto& coll) { return lib::ptrDeref (lib::iter_stl::eachElm (coll)); };
}
/**
* Reference frame to organise the presentation related to a specific Track in the Timeline-GUI.
@ -159,6 +172,9 @@ namespace timeline {
{
return body_.bindRulers();
}
template<class CLPS, class MRKS>
void establishExtension (CLPS, MRKS);
};
@ -171,9 +187,9 @@ namespace timeline {
{
DisplayFrame display_;
vector<unique_ptr<TrackPresenter>> subFork_;
vector<unique_ptr<MarkerWidget>> markers_;
vector<unique_ptr<ClipPresenter>> clips_;
vector<PFork> subFork_;
vector<PMark> markers_;
vector<PClip> clips_;
public:
@ -249,11 +265,6 @@ namespace timeline {
inline void
TrackPresenter::buildMutator (TreeMutator::Handle buffer)
{
using PFork = unique_ptr<TrackPresenter>;
using PClip = unique_ptr<ClipPresenter>;
using PMarker = unique_ptr<MarkerWidget>;
using PRuler = unique_ptr<RulerTrack>;
buffer.create (
TreeMutator::build()
.attach (collection(display_.bindRulers())
@ -280,15 +291,15 @@ namespace timeline {
{ // »Selector« : require object-like sub scope with type-field "Marker"
return TYPE_Marker == spec.data.recordType();
})
.matchElement ([&](GenNode const& spec, PMarker const& elm) -> bool
.matchElement ([&](GenNode const& spec, PMark const& elm) -> bool
{
return spec.idi == elm->getID();
})
.constructFrom ([&](GenNode const& spec) -> PMarker
.constructFrom ([&](GenNode const& spec) -> PMark
{
return make_unique<MarkerWidget> (spec.idi, this->uiBus_);
})
.buildChildMutator ([&](PMarker& target, GenNode::ID const& subID, TreeMutator::Handle buff) -> bool
.buildChildMutator ([&](PMark& target, GenNode::ID const& subID, TreeMutator::Handle buff) -> bool
{
if (subID != target->getID()) return false;
target->buildMutator (buff);
@ -343,9 +354,48 @@ namespace timeline {
inline void
TrackPresenter::establishLayout (DisplayEvaluation& displayEvaluation)
{
UNIMPLEMENTED ("respond to the DisplayEvaluation-Pass and pass on evaluation recursively");
display_.establishExtension (elems(clips_), elems(markers_));
for (auto& subTrack: subFork_)
subTrack->establishLayout (displayEvaluation);
}
namespace {
template<class IT>
inline auto
max (IT&& elms)
{
using Val = typename IT::value_type;
Val res = std::numeric_limits<Val>::min();
for (auto& elm : std::forward<IT> (elms))
if (elm > res)
res = elm;
return res;
}
}
/** */
template<class CLPS, class MRKS>
inline void
DisplayFrame::establishExtension (CLPS clips, MRKS markers)
{
// int maxVSize = max (lib::transformIterator(clips,
// [](ClipPresenter const& clip)
// {
// return clip.determineRequiredVerticalExtension();
// }));
int headSize = this->head_.get_height();
int bodySize = this->body_.calcHeight();
////////////////////TODO: was ist?
// typedef typename IT::value_type pointer;
// typedef typename RemovePtr<pointer>::Type value_type;
/// wobei IT = lib::RangeIter<__gnu_cxx::__normal_iterator<std::unique_ptr<stage::timeline::MarkerWidget>*, ...
}
}}// namespace stage::timeline
#endif /*STAGE_TIMELINE_TRACK_PRESENTER_H*/

View file

@ -21338,8 +21338,7 @@
</li>
</ul>
</body>
</html>
</richcontent>
</html></richcontent>
<linktarget COLOR="#db337d" DESTINATION="ID_815242494" ENDARROW="Default" ENDINCLINATION="-814;0;" ID="Arrow_ID_1920099327" SOURCE="ID_1528548638" STARTARROW="None" STARTINCLINATION="812;88;"/>
<icon BUILTIN="closed"/>
</node>
@ -21585,10 +21584,29 @@
<node CREATED="1583010115679" ID="ID_181195318" MODIFIED="1583010181687" TEXT="alle Tracks">
<node CREATED="1583010186970" ID="ID_1754142891" MODIFIED="1583010203965" TEXT="Ping-Pong auf DisplayFrame ausl&#xf6;sen">
<node CREATED="1583010212766" ID="ID_1377321766" MODIFIED="1583010221404" TEXT="Gr&#xf6;&#xdf;e vom Header"/>
<node CREATED="1583010223312" ID="ID_929067099" MODIFIED="1583010245037" TEXT="damit die Maximums-Berechnung auf dem Track-Inhalt ausl&#xf6;sen"/>
<node CREATED="1583010223312" ID="ID_929067099" MODIFIED="1583010245037" TEXT="damit die Maximums-Berechnung auf dem Track-Inhalt ausl&#xf6;sen">
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1583606375028" ID="ID_1922972295" MODIFIED="1583606379904" TEXT="funktionales Max">
<icon BUILTIN="flag-yellow"/>
<node COLOR="#338800" CREATED="1583606385337" ID="ID_1117598680" MODIFIED="1583626259305" TEXT="Type-deduction-Probleme">
<richcontent TYPE="NOTE"><html>
<head>
</head>
<body>
<p>
h&#228;ngen garnicht direkt damit zusammen, sondern wurden getriggert durch den &quot;unorthodoxen&quot; Gebrauch des PtrDerefIter
</p>
</body>
</html>
</richcontent>
<icon BUILTIN="button_ok"/>
</node>
</node>
</node>
<node CREATED="1583010246034" ID="ID_113344286" MODIFIED="1583010268212" TEXT="Resultat mit Wert vom Header vergleichen"/>
</node>
<node CREATED="1583010270152" ID="ID_689332581" MODIFIED="1583010283258" TEXT="depth-first-Suche und Aktion auf dem R&#xfc;ckweg">
<node COLOR="#338800" CREATED="1583010270152" ID="ID_689332581" MODIFIED="1583606371280" TEXT="depth-first-Suche und Aktion auf dem R&#xfc;ckweg">
<icon BUILTIN="button_ok"/>
<node CREATED="1583010287758" ID="ID_101138504" MODIFIED="1583010298353" TEXT="relative Reihenfolge der Sibling-Tracks ist egal"/>
</node>
</node>