ref.hpp
ftxui/screen/string.hpp
memory
string
variant
vector
include/ftxui/component/component.hpp
include/ftxui/component/component_options.hpp
include/ftxui/dom/elements.hpp
src/ftxui/component/button.cpp
src/ftxui/component/checkbox.cpp
src/ftxui/component/collapsible.cpp
src/ftxui/component/dropdown.cpp
src/ftxui/component/input.cpp
src/ftxui/component/menu.cpp
src/ftxui/component/radiobox.cpp
src/ftxui/component/resizable_split.cpp
src/ftxui/component/slider.cpp
src/ftxui/dom/canvas.cpp
ftxui/screen/string.hpp
include/ftxui/util/ref.hpp
memory
string
variant
vector
include/ftxui/component/component.hpp
include/ftxui/component/component_base.hpp
include/ftxui/component/component_options.hpp
include/ftxui/component/loop.hpp
include/ftxui/dom/elements.hpp
include/ftxui/dom/table.hpp
include/ftxui/util/ref.hpp
src/ftxui/component/button.cpp
src/ftxui/component/catch_event.cpp
src/ftxui/component/checkbox.cpp
src/ftxui/component/collapsible.cpp
src/ftxui/component/component.cpp
src/ftxui/component/component_fuzzer.cpp
src/ftxui/component/component_options.cpp
src/ftxui/component/container.cpp
src/ftxui/component/dropdown.cpp
src/ftxui/component/hoverable.cpp
src/ftxui/component/input.cpp
src/ftxui/component/loop.cpp
src/ftxui/component/maybe.cpp
src/ftxui/component/menu.cpp
src/ftxui/component/modal.cpp
src/ftxui/component/radiobox.cpp
src/ftxui/component/renderer.cpp
src/ftxui/component/resizable_split.cpp
src/ftxui/component/screen_interactive.cpp
src/ftxui/component/slider.cpp
src/ftxui/component/util.cpp
src/ftxui/component/window.cpp
src/ftxui/dom/automerge.cpp
src/ftxui/dom/blink.cpp
src/ftxui/dom/bold.cpp
src/ftxui/dom/border.cpp
src/ftxui/dom/canvas.cpp
src/ftxui/dom/clear_under.cpp
src/ftxui/dom/color.cpp
src/ftxui/dom/composite_decorator.cpp
src/ftxui/dom/dbox.cpp
src/ftxui/dom/dim.cpp
src/ftxui/dom/flex.cpp
src/ftxui/dom/flexbox.cpp
src/ftxui/dom/focus.cpp
src/ftxui/dom/frame.cpp
src/ftxui/dom/gauge.cpp
src/ftxui/dom/graph.cpp
src/ftxui/dom/gridbox.cpp
src/ftxui/dom/hbox.cpp
src/ftxui/dom/hyperlink.cpp
src/ftxui/dom/inverted.cpp
src/ftxui/dom/italic.cpp
src/ftxui/dom/linear_gradient.cpp
src/ftxui/dom/node_decorator.cpp
src/ftxui/dom/node_decorator.hpp
src/ftxui/dom/paragraph.cpp
src/ftxui/dom/reflect.cpp
src/ftxui/dom/scroll_indicator.cpp
src/ftxui/dom/selection.cpp
src/ftxui/dom/selection_style.cpp
src/ftxui/dom/separator.cpp
src/ftxui/dom/size.cpp
src/ftxui/dom/spinner.cpp
src/ftxui/dom/strikethrough.cpp
src/ftxui/dom/table.cpp
src/ftxui/dom/text.cpp
src/ftxui/dom/underlined.cpp
src/ftxui/dom/underlined_double.cpp
src/ftxui/dom/util.cpp
src/ftxui/dom/vbox.cpp
ftxui::ConstRef
ftxui::Ref
ftxui::StringRef
ftxui::ConstStringRef
ftxui::ConstStringListRef
ftxui::ConstStringListRef::Adapter
ftxui::ConstStringListRef::SizeVisitor
ftxui::ConstStringListRef::IndexedGetter
ftxui

    //Copyright2020ArthurSonzogni.Allrightsreserved.
    //UseofthissourcecodeisgovernedbytheMITlicensethatcanbefoundin
    //theLICENSEfile.
    #ifndefFTXUI_UTIL_REF_HPP
    #defineFTXUI_UTIL_REF_HPP

    #include<ftxui/screen/string.hpp>
    #include<memory>
    #include<string>
    #include<variant>
    #include<vector>

    namespaceftxui{

    ///@briefAnadapter.Ownorreferenceanimmutableobject.
    template<typenameT>
    classConstRef{
    public:
    ConstRef()=default;
    ConstRef(Tt):variant_(std::move(t)){}//NOLINT
    ConstRef(constT*t):variant_(t){}//NOLINT
    ConstRef&operator=(ConstRef&&)noexcept=default;
    ConstRef(constConstRef<T>&)=default;
    ConstRef(ConstRef<T>&&)noexcept=default;
    ~ConstRef()=default;

    //Makea"reseatable"reference
    ConstRef<T>&operator=(constConstRef<T>&)=default;

    //Accessors:
    constT&operator()()const{return*Address();}
    constT&operator*()const{return*Address();}
    constT*operator->()const{returnAddress();}

    private:
    std::variant<T,constT*>variant_=T{};

    constT*Address()const{
    returnstd::holds_alternative<T>(variant_)?&std::get<T>(variant_)
    :std::get<constT*>(variant_);
    }
    };

    ///@briefAnadapter.Ownorreferenceanmutableobject.
    template<typenameT>
    classRef{
    public:
    Ref()=default;
    Ref(Tt):variant_(std::move(t)){}//NOLINT
    Ref(T*t):variant_(t){}//NOLINT
    ~Ref()=default;
    Ref&operator=(Ref&&)noexcept=default;
    Ref(constRef<T>&)=default;
    Ref(Ref<T>&&)noexcept=default;

    //Makea"reseatable"reference.
    Ref<T>&operator=(constRef<T>&)=default;

    //Accessors:
    T&operator()(){return*Address();}
    T&operator*(){return*Address();}
    T*operator->(){returnAddress();}
    constT&operator()()const{return*Address();}
    constT&operator*()const{return*Address();}
    constT*operator->()const{returnAddress();}

    private:
    std::variant<T,T*>variant_=T{};

    constT*Address()const{
    returnstd::holds_alternative<T>(variant_)?&std::get<T>(variant_)
    :std::get<T*>(variant_);
    }
    T*Address(){
    returnstd::holds_alternative<T>(variant_)?&std::get<T>(variant_)
    :std::get<T*>(variant_);
    }
    };

    ///@briefAnadapter.Ownorreferenceaconstantstring.Forconvenience,this
    ///classconvertmultiplemutablestringtowardasharedrepresentation.
    classStringRef:publicRef<std::string>{
    public:
    usingRef<std::string>::Ref;

    StringRef(constwchar_t*ref)//NOLINT
    :StringRef(to_string(std::wstring(ref))){}
    StringRef(constchar*ref)//NOLINT
    :StringRef(std::string(ref)){}
    };

    ///@briefAnadapter.Ownorreferenceaconstantstring.Forconvenience,this
    ///classconvertmultipleimmutablestringtowardasharedrepresentation.
    classConstStringRef:publicConstRef<std::string>{
    public:
    usingConstRef<std::string>::ConstRef;

    ConstStringRef(conststd::wstring*ref)//NOLINT
    :ConstStringRef(to_string(*ref)){}
    ConstStringRef(conststd::wstringref)//NOLINT
    :ConstStringRef(to_string(ref)){}
    ConstStringRef(constwchar_t*ref)//NOLINT
    :ConstStringRef(to_string(std::wstring(ref))){}
    ConstStringRef(constchar*ref)//NOLINT
    :ConstStringRef(std::string(ref)){}
    };

    ///@briefAnadapter.Referencealistofstrings.
    ///
    ///Supportedinput:
    ///-`std::vector<std::string>`
    ///-`std::vector<std::string>*`
    ///-`std::vector<std::wstring>*`
    ///-`Adapter*`
    ///-`std::unique_ptr<Adapter>`
    classConstStringListRef{
    public:
    //Bringyourownadapter:
    classAdapter{
    public:
    Adapter()=default;
    Adapter(constAdapter&)=default;
    Adapter&operator=(constAdapter&)=default;
    Adapter(Adapter&&)=default;
    Adapter&operator=(Adapter&&)=default;
    virtual~Adapter()=default;
    virtualsize_tsize()const=0;
    virtualstd::stringoperator[](size_ti)const=0;
    };
    usingVariant=std::variant<conststd::vector<std::string>,//
    conststd::vector<std::string>*,//
    conststd::vector<std::wstring>*,//
    Adapter*,//
    std::unique_ptr<Adapter>//
    >;

    ConstStringListRef()=default;
    ~ConstStringListRef()=default;
    ConstStringListRef&operator=(constConstStringListRef&)=default;
    ConstStringListRef&operator=(ConstStringListRef&&)=default;
    ConstStringListRef(ConstStringListRef&&)=default;
    ConstStringListRef(constConstStringListRef&)=default;

    ConstStringListRef(std::vector<std::string>value)//NOLINT
    {
    variant_=std::make_shared<Variant>(value);
    }
    ConstStringListRef(conststd::vector<std::string>*value)//NOLINT
    {
    variant_=std::make_shared<Variant>(value);
    }
    ConstStringListRef(conststd::vector<std::wstring>*value)//NOLINT
    {
    variant_=std::make_shared<Variant>(value);
    }
    ConstStringListRef(Adapter*adapter)//NOLINT
    {
    variant_=std::make_shared<Variant>(adapter);
    }
    template<typenameAdapterType>
    ConstStringListRef(std::unique_ptr<AdapterType>adapter)//NOLINT
    {
    variant_=std::make_shared<Variant>(
    static_cast<std::unique_ptr<Adapter>>(std::move(adapter)));
    }

    size_tsize()const{
    returnvariant_?std::visit(SizeVisitor(),*variant_):0;
    }

    std::stringoperator[](size_ti)const{
    returnvariant_?std::visit(IndexedGetter(i),*variant_):"";
    }

    private:
    structSizeVisitor{
    size_toperator()(conststd::vector<std::string>&v)const{
    returnv.size();
    }
    size_toperator()(conststd::vector<std::string>*v)const{
    returnv->size();
    }
    size_toperator()(conststd::vector<std::wstring>*v)const{
    returnv->size();
    }
    size_toperator()(constAdapter*v)const{returnv->size();}
    size_toperator()(conststd::unique_ptr<Adapter>&v)const{
    returnv->size();
    }
    };

    structIndexedGetter{
    IndexedGetter(size_tindex)//NOLINT
    :index_(index){}
    size_tindex_;
    std::stringoperator()(conststd::vector<std::string>&v)const{
    returnv[index_];
    }
    std::stringoperator()(conststd::vector<std::string>*v)const{
    return(*v)[index_];
    }
    std::stringoperator()(conststd::vector<std::wstring>*v)const{
    returnto_string((*v)[index_]);
    }
    std::stringoperator()(constAdapter*v)const{return(*v)[index_];}
    std::stringoperator()(conststd::unique_ptr<Adapter>&v)const{
    return(*v)[index_];
    }
    };

    std::shared_ptr<Variant>variant_;
    };

    }//namespaceftxui

    #endif/*endofincludeguard:FTXUI_UTIL_REF_HPP*/