Commit 1f7eaae7 authored by EXT Arnaud Clère's avatar EXT Arnaud Clère
Browse files

Isolated recursive Seq<Seq<...>> compile problem to QBind<_,Val<_>> recursive call (commented)

parent d143dd9c
......@@ -23,6 +23,8 @@ DEFINES += QT_DEPRECATED_WARNINGS
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
QMAKE_CXXFLAGS += -ftemplate-backtrace-limit=0
SOURCES += \
main.cpp
......
......@@ -90,18 +90,18 @@ template<class T_> class Seq
public:
Q_ENABLE_MOVE_DEFAULT(Seq)
// T_ can be either a TResult or any combination of nested Seq or Rec like T_ = Rec<Seq<TResult>
// T_ can be either a TResult or any combination of nested Seq or Rec like Rec<Seq<TResult>
using TResult = typename T_::TResult; //!< the start and end point of the traversal as well as the associated processing (see QJsonWriter for an example)
using TImpl = typename TResult::TImpl;
//static constexpr BindMode Mode = T_::Mode;
static constexpr BindMode Mode = TResult::Mode;
Seq(T_&& out) { std::swap(m_out, out); }
operator bool() { return m_out.operator bool(); } //!< to drive QBind<TResult,T>() traversal
TImpl* operator->() { return m_out.operator ->(); }
Val<Seq<T_>> item() { if (Q_LIKELY(m_out) && m_out->_item()) return Val<Seq<T_>>(std::move(*this)); return Seq<T_>(); }
T_ out() { if (Q_LIKELY(m_out) && m_out-> _out()) return std::move(m_out) ; return T_ (); }
Val<Seq<T_>> item() { if (Q_LIKELY(m_out) && m_out->_item()) return Val<Seq<T_>>(std::move(*this)); return Val<Seq<T_>>(); }
T_ out() { if (Q_LIKELY(m_out) && m_out-> _out()) return std::move(m_out) ; return T_ (); }
operator TResult() { return out(); /* recursively calls operator TResult() as mandated by T_ */ }
TResult result() { return operator TResult(); }
......@@ -135,11 +135,11 @@ public:
Val<TResult> value() { return Val<TResult>(std::move(*static_cast<TResult*>(this))); }
// Shortcuts
/**/ Seq<TResult> sequence() { return value().sequence(); } // if (Q_LIKELY(m) && m->_sequence()) return Seq<TResult>(std::move(*static_cast<TResult*>(this))); return Seq<TResult>(); }
/**/ TResult null() { return value(). null(); } // if (Q_LIKELY(m) && m-> _null()) return std::move(*static_cast<TResult*>(this)) ; return TResult (); }
template<typename T> TResult bind(const T& t) { return value(). bind(t); } // if (Q_LIKELY(m) && m-> _bind(t)) return std::move(*static_cast<TResult*>(this)) ; return TResult (); } // TODO only for readers ?
template<typename T> TResult bind( T& t) { return value(). bind(t); } // if (Q_LIKELY(m) && m-> _bind(t)) return std::move(*static_cast<TResult*>(this)) ; return TResult (); }
template<typename T> TResult bind( T&& t) { return value(). bind(t); } // if (Q_LIKELY(m) && m-> _bind(t)) return std::move(*static_cast<TResult*>(this)) ; return TResult (); }
/**/ Seq<TResult> sequence() { return value().sequence(); }
/**/ TResult null() { return value(). null(); }
template<typename T> TResult bind(const T& t) { return value(). bind(t); } // TODO only for readers ?
template<typename T> TResult bind( T& t) { return value(). bind(t); }
template<typename T> TResult bind( T&& t) { return value(). bind(t); }
protected:
QScopedResult(TImpl* result, bool owned) : m(result), m_owned(owned) {}
......@@ -168,11 +168,11 @@ public:
Val<TResult> value() { return Val<TResult>(std::move(*static_cast<TResult*>(this))); }
// Shortcuts
/**/ Seq<TResult> sequence() { return value().sequence(); } // if (static_cast<TImpl*>(this)->_sequence()) return Seq<TResult>(std::move(*static_cast<TResult*>(this))); return Seq<TResult>(); }
/**/ TResult null() { return value(). null(); } // if (static_cast<TImpl*>(this)-> _null()) return std::move(*static_cast<TResult*>(this)) ; return TResult (); }
template<typename T> TResult bind(const T& t) { return value(). bind(t); } // if (static_cast<TImpl*>(this)-> _bind(t)) return std::move(*static_cast<TResult*>(this)) ; return TResult (); } // TODO only for readers ?
template<typename T> TResult bind( T& t) { return value(). bind(t); } // if (static_cast<TImpl*>(this)-> _bind(t)) return std::move(*static_cast<TResult*>(this)) ; return TResult (); }
template<typename T> TResult bind( T&& t) { return value(). bind(t); } // if (static_cast<TImpl*>(this)-> _bind(t)) return std::move(*static_cast<TResult*>(this)) ; return TResult (); }
/**/ Seq<TResult> sequence() { return value().sequence(); }
/**/ TResult null() { return value(). null(); }
template<typename T> TResult bind(const T& t) { return value(). bind(t); } // TODO only for readers ?
template<typename T> TResult bind( T& t) { return value(). bind(t); }
template<typename T> TResult bind( T&& t) { return value(). bind(t); }
};
// //////////////////////////////////////////////////////////////////////////
......@@ -298,24 +298,25 @@ struct QBind<TResult, Val<TSource>> { static TResult bind(Val<TResult> dst, Val<
static_assert(TSource::Mode==Read ,"cannot read from TSource");
static_assert(TResult::Mode==Write,"cannot write to TResult");
auto srcNull(src.null());
if (srcNull)
if (!src || src.null())
return dst.null();
auto srcSequence(src.sequence());
Seq<TSource> srcSequence(src.sequence());
if (srcSequence) {
auto dsTValue(dst.sequence());
for (auto srcItem(srcSequence.item()); srcItem && dsTValue; srcItem=srcSequence.item()) {
dsTValue = dsTValue.bind(srcItem);
Seq<TResult> dstSequence(dst.sequence());
if (dstSequence) {
// for (auto srcItem=srcSequence.item(); srcItem /*&& dstSequence*/; srcItem=srcSequence.item()) {
// dstSequence = QBind<Seq<TResult>,Val<Seq<TSource>>>::bind(dstSequence.item(),srcItem);
// }
}
return dsTValue;
return dstSequence.out();
}
QString srcData; // TODO Use QBindDispatch to avoid losing native types
if (src.bind(srcData))
return dst.bind(srcData);
else
return dst.null();
return dst.null();
}};
// //////////////////////////////////////////////////////////////////////////
......
......@@ -325,11 +325,11 @@ int main()
CborWriter(&b).bind(p);
}
STOP("T>Cbor",QString::fromUtf8(b.buffer().toHex()))
//START {
// json.seek(0); b.buffer().clear();
// CborWriter(&b).bind(QJsonReader(&json).value());
//}
//STOP("Json>Cbor",QString::fromUtf8(b.buffer().toHex()))
START {
json.seek(0); b.seek(0); b.buffer().clear();
QCborWriter(&b).bind(QJsonReader(&json).value());
}
STOP("Json>Cbor",QString::fromUtf8(b.buffer().toHex()))
}
GROUP_STOP
return fclose(samples);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment