UI-Coordinates: implement indexed access
...under the assumption that the content is normalised, which means - leading NULL is changed to Symbol::EMPTY - missing elements in the middle are marked as "*" - trailing NULL in extension storage is handled by adjusting nominal extension size
This commit is contained in:
parent
ab391d3dfa
commit
1138898989
5 changed files with 34 additions and 8 deletions
|
|
@ -50,6 +50,7 @@
|
|||
#include "lib/symbol.hpp"
|
||||
#include "lib/iter-adapter.hpp"
|
||||
#include "lib/meta/variadic-helper.hpp"
|
||||
#include "lib/format-obj.hpp"
|
||||
#include "lib/util.hpp"
|
||||
|
||||
//#include <boost/noncopyable.hpp>
|
||||
|
|
@ -61,6 +62,7 @@
|
|||
|
||||
|
||||
namespace lib {
|
||||
namespace error = lumiera::error;
|
||||
|
||||
// using std::unique_ptr;
|
||||
using std::forward;
|
||||
|
|
@ -164,6 +166,13 @@ namespace lib {
|
|||
return storage_? size(unConst(this)->storage_)
|
||||
: 0;
|
||||
}
|
||||
|
||||
const char*
|
||||
operator[] (size_t idx) const
|
||||
{
|
||||
REQUIRE (storage_ and idx < size());
|
||||
return storage_[1+idx];
|
||||
}
|
||||
};
|
||||
}//(End)Implementation helper
|
||||
|
||||
|
|
@ -249,7 +258,7 @@ namespace lib {
|
|||
bool
|
||||
empty() const
|
||||
{
|
||||
UNIMPLEMENTED ("path implementation storage");
|
||||
return not elms_[0]; // normalise() ensures this holds only for empty paths
|
||||
}
|
||||
|
||||
operator string() const;
|
||||
|
|
@ -258,7 +267,18 @@ namespace lib {
|
|||
Literal
|
||||
operator[] (size_t idx)
|
||||
{
|
||||
UNIMPLEMENTED ("path implementation storage");
|
||||
Lit elm{0};
|
||||
if (idx < chunk_size)
|
||||
elm = elms_[idx];
|
||||
else
|
||||
if (idx-chunk_size < tail_.size())
|
||||
elm = tail_[idx-chunk_size];
|
||||
|
||||
if (not elm)
|
||||
throw error::Invalid ("Accessing index "+util::toString(idx)
|
||||
+" on PathArray of size "+ util::toString(size())
|
||||
,error::LUMIERA_ERROR_INDEX_BOUNDS);
|
||||
return elm;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -82,6 +82,7 @@ namespace lib {
|
|||
|
||||
|
||||
/* == predefined marker Symbols == */
|
||||
Symbol Symbol::EMPTY = "";
|
||||
Symbol Symbol::BOTTOM = "⟂";
|
||||
Symbol Symbol::FAILURE = "↯";
|
||||
|
||||
|
|
|
|||
|
|
@ -93,6 +93,7 @@ namespace lib {
|
|||
: public Literal
|
||||
{
|
||||
public:
|
||||
static Symbol EMPTY;
|
||||
static Symbol BOTTOM;
|
||||
static Symbol FAILURE;
|
||||
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ using std::string;
|
|||
//using lib::idi::EntryID;
|
||||
//using lib::diff::GenNode;
|
||||
//using util::isSameObject;
|
||||
using lib::Symbol;
|
||||
using util::isnil;
|
||||
using util::join;
|
||||
|
||||
|
|
@ -126,8 +127,8 @@ namespace test {
|
|||
|
||||
// representation is trimmed and filled
|
||||
CHECK ("UI:Θ.*.*/*/Φ" == string(uic));
|
||||
CHECK (NULL == uic[UIC_WINDOW]);
|
||||
CHECK (NULL == uic[UIC_PERSP]);
|
||||
CHECK (Symbol::EMPTY == uic[UIC_WINDOW]);
|
||||
CHECK (Symbol::EMPTY == uic[UIC_PERSP]);
|
||||
CHECK ("Θ" == uic[UIC_PANEL]);
|
||||
CHECK ("*" == uic[UIC_VIEW]);
|
||||
CHECK ("*" == uic[UIC_TAB]);
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ using std::string;
|
|||
//using lib::idi::EntryID;
|
||||
//using lib::diff::GenNode;
|
||||
//using util::isSameObject;
|
||||
using lib::Symbol;
|
||||
using util::isnil;
|
||||
using util::join;
|
||||
|
||||
|
|
@ -111,8 +112,8 @@ namespace test {
|
|||
|
||||
// representation is trimmed and filled
|
||||
CHECK ("Θ/*/*/*/Φ" == string(parr));
|
||||
CHECK (NULL == parr[0]);
|
||||
CHECK (NULL == parr[1]);
|
||||
CHECK (Symbol::EMPTY == parr[0]);
|
||||
CHECK (Symbol::EMPTY == parr[1]);
|
||||
CHECK ("Θ" == parr[2]);
|
||||
CHECK ("*" == parr[3]);
|
||||
CHECK ("*" == parr[4]);
|
||||
|
|
@ -158,8 +159,10 @@ namespace test {
|
|||
|
||||
// index numbering starts at absolute root
|
||||
CHECK ("Ω" == *parr.begin());
|
||||
CHECK (nullptr == parr[0]);
|
||||
CHECK ("Ω" == parr[15]);
|
||||
CHECK (Symbol::EMPTY == parr[0]);
|
||||
CHECK (Symbol::EMPTY == parr[1]);
|
||||
CHECK (Symbol::EMPTY == parr[2]);
|
||||
CHECK ("Ω" == parr[15]);
|
||||
VERIFY_ERROR (INDEX_BOUNDS, parr[16]);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue