From ca9fa939a433a9ab34631190bc16b39a4e24696a Mon Sep 17 00:00:00 2001 From: Hamed Masafi Date: Wed, 12 Aug 2020 19:02:32 +0430 Subject: [PATCH] update doc --- doc/sharedpointer.md | 32 ++++++------- src/nut/config/nut_namespace.h | 87 ++++++++++++++++++---------------- 2 files changed, 62 insertions(+), 57 deletions(-) diff --git a/doc/sharedpointer.md b/doc/sharedpointer.md index 2287e27..0b27ae8 100644 --- a/doc/sharedpointer.md +++ b/doc/sharedpointer.md @@ -4,23 +4,23 @@ In *shared pointer* mode results of queries is QList> and in * Almost in every case shared pointer mode is better, But nut support regular mode for backward comptability. -To compiling in *shared pointer* define **NUT_SHARED_POINTER** macro +By default _Nut_ compiles in shared pointer mode, to switch to ols raw pointer mode you must define **NUT_RAW_POINTER** macro Nut has template alias ```cpp -#ifdef NUT_SHARED_POINTER - template - using RowList = QList>; - - template - using Row = QSharedPointer; -#else +#ifdef NUT_RAW_POINTER template using RowList = QList; template using Row = T*; +#else + template + using RowList = QList>; + + template + using Row = QSharedPointer; #endif ``` @@ -36,16 +36,16 @@ For the integration of your source, you can use these aliases. Ans also Nut::create() method are defined for two mode ```cpp -#ifdef NUT_SHARED_POINTER - template - inline Row create(QObject *parent) { - return QSharedPointer(new T(parent)); - } -#else +#ifdef NUT_RAW_POINTER template inline Row create() { return new T; } +#else + template + inline Row create(QObject *parent) { + return QSharedPointer(new T(parent)); + } #endif ``` @@ -54,6 +54,6 @@ So you can use the Nut::create function without considering in what way the libr auto post = Nut::create(); ``` -In above example if *NUT_SHARED_POINTER* is defined *post* is *QSharedPointer* else is *Post\** +In above example if *NUT_RAW_POINTER* is defined *post* is *Post\** else is *QSharedPointer* -I recommand use *NUT_SHARED_POINTER* always! +I recommand use shared pointer mode (default) always! diff --git a/src/nut/config/nut_namespace.h b/src/nut/config/nut_namespace.h index b87c38d..a64fc87 100644 --- a/src/nut/config/nut_namespace.h +++ b/src/nut/config/nut_namespace.h @@ -1,7 +1,12 @@ #ifndef NUT_NAMESPACE_H #define NUT_NAMESPACE_H -#include +#ifndef NUT_GLOBAL_H +# error "Do not include nut_namespace.h header directly!" +#endif + +//avoid ide warnings +#include #include #include @@ -79,57 +84,57 @@ inline bool nutClassInfoInt(const QMetaClassInfo &classInfo, } #ifdef NUT_RAW_POINTER -template -using RowList = QList; + template + using RowList = QList; -template -using RowSet = QSet; + template + using RowSet = QSet; -template -using Row = T*; + template + using Row = T*; -template -inline Row create() { - return new T; -} + template + inline Row create() { + return new T; + } -template -inline T *get(const Row row) { - return row; -} + template + inline T *get(const Row row) { + return row; + } -template -inline T *get(const QSharedPointer row) { - return row.data(); -} + template + inline T *get(const QSharedPointer row) { + return row.data(); + } #else -template -using RowList = QList>; + template + using RowList = QList>; -template -using RowSet = QSet>; + template + using RowSet = QSet>; -template -using Row = QSharedPointer; + template + using Row = QSharedPointer; -template -inline Row create() { - return QSharedPointer(new T); -} + template + inline Row create() { + return QSharedPointer(new T); + } -template -inline Row create(QObject *parent) { - return QSharedPointer(new T(parent)); -} + template + inline Row create(QObject *parent) { + return QSharedPointer(new T(parent)); + } -template -inline Row createFrom(T *row) { - return QSharedPointer(row); -} -template -inline Row createFrom(const QSharedPointer row) { - return row; -} + template + inline Row createFrom(T *row) { + return QSharedPointer(row); + } + template + inline Row createFrom(const QSharedPointer row) { + return row; + } #endif NUT_END_NAMESPACE