Nut  0.1
defines.h
1 /**************************************************************************
2 **
3 ** This file is part of Nut project.
4 ** https://github.com/HamedMasafi/Nut
5 **
6 ** Nut is free software: you can redistribute it and/or modify
7 ** it under the terms of the GNU Lesser General Public License as published by
8 ** the Free Software Foundation, either version 3 of the License, or
9 ** (at your option) any later version.
10 **
11 ** Nut is distributed in the hope that it will be useful,
12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ** GNU Lesser General Public License for more details.
15 **
16 ** You should have received a copy of the GNU Lesser General Public License
17 ** along with Nut. If not, see <http://www.gnu.org/licenses/>.
18 **
19 **************************************************************************/
20 
21 #ifndef SYNTAX_DEFINES_H
22 #define SYNTAX_DEFINES_H
23 
24 #include "qglobal.h"
25 #include "defines_p.h"
26 
27 #define QT_NAMESPACE Nut
28 
29 #ifdef NUT_COMPILE_STATIC
30 # define NUT_EXPORT
31 #else
32 # define NUT_EXPORT Q_DECL_EXPORT
33 #endif
34 
35 // Database
36 #define NUT_DB_VERSION(major, minor) Q_CLASSINFO(QT_STRINGIFY(__nut_NAME_PERFIX __nut_DB_VERSION), QT_STRINGIFY(#major "." #minor))
37 
38 #define NUT_DECLARE_TABLE(type, name) \
39  Q_CLASSINFO(QT_STRINGIFY(__nut_NAME_PERFIX __nut_TABLE " " #type), #name) \
40  Q_PROPERTY(type* name READ name) \
41  Q_PROPERTY(TableSet<type> name##s READ name##s) \
42  type* m_##name; \
43  TableSet<type> *m_##name##s; \
44 public: \
45  static const type _##name; \
46  type* name() const{ return m_##name; } \
47  TableSet<type> *name##s() const { return m_##name##s; }
48 
49 //Table
50 #define NUT_DECLARE_FIELD(type, name, read, write) \
51  Q_PROPERTY(type name READ read WRITE write) \
52  Q_CLASSINFO(QT_STRINGIFY(__nut_NAME_PERFIX #name " " __nut_FIELD), #name) \
53  type m_##name; \
54 public: \
55  static FieldPhrase name##Field(){ \
56  static FieldPhrase f = FieldPhrase(staticMetaObject.className(), #name); \
57  return f; \
58  } \
59  type read() const{ \
60  return m_##name; \
61  } \
62  void write(type name){ \
63  m_##name = name; \
64  propertyChanged(#name); \
65  }
66 
67 #define NUT_FOREGION_KEY(type, keytype, name, read, write) \
68  Q_PROPERTY(type* name READ read WRITE write) \
69  NUT_DECLARE_FIELD(keytype, name##Id, read##Id, write##Id) \
70  Q_CLASSINFO(QT_STRINGIFY(__nut_NAME_PERFIX #name "Id " __nut_FOREGION_KEY), #type) \
71  type *m_##name; \
72 public: \
73  type *read() const { return m_##name ; } \
74  void write(type *name){ \
75  m_##name = name; \
76  }
77 
78 #define NUT_DECLARE_CHILD_TABLE(type, n) \
79  private: \
80  TableSet<type> *m_##n; \
81  public: \
82  static type *n##Table(){ \
83  static type *f = new type(); \
84  return f; \
85  } \
86  TableSet<type> *n(){ \
87  return m_##n; \
88  }
89 
90 
91 #define NUT_INDEX(name, field, order)
92 #define NUT_PRIMARY_KEY(x) Q_CLASSINFO(QT_STRINGIFY(__nut_NAME_PERFIX #x " " __nut_PRIMARY_KEY), #x)
93 #define NUT_AUTO_INCREMENT(x) Q_CLASSINFO(QT_STRINGIFY(__nut_NAME_PERFIX #x " " __nut_AUTO_INCREMENT), #x)
94 #define NUT_PRIMARY_AUTO_INCREMENT(x) NUT_PRIMARY_KEY(x) \
95  NUT_AUTO_INCREMENT(x)
96 #define NUT_UNIQUE(x) Q_CLASSINFO(QT_STRINGIFY(__nut_NAME_PERFIX #x " " __nut_UNIQUE), #x)
97 #define NUT_LEN(x, n) Q_CLASSINFO(QT_STRINGIFY(__nut_NAME_PERFIX #x " " __nut_LEN), #n)
98 #define NUT_DEFAULT_VALUE(x, n) Q_CLASSINFO(QT_STRINGIFY(__nut_NAME_PERFIX #x " " __nut_DEFAULT_VALUE), #n)
99 #define NUT_NOT_NULL(x) Q_CLASSINFO(QT_STRINGIFY(__nut_NAME_PERFIX #x " " __nut_NOT_NULL), "1")
100 
101 #ifndef NUT_NO_KEYWORDS
102 # define FROM(x) /*QScopedPointer<QueryBase*>*/(x->createQuery())
103 # define WHERE(x) ->setWhere(x)
104 # define JOIN(x) ->join(#x)
105 # define ORDERBY(x) ->orderBy(#x, "ASC");
106 # define ORDERBY_DESC(x) ->orderBy(#x, "DESC");
107 
108 # define SELECT() ->toList()
109 # define COUNT() ->count()
110 # define DELETE() ->remove()
111 # define FIRST() ->first()
112 #endif // NUT_NO_KEYWORDS
113 
114 
115 
116 #endif // SYNTAX_DEFINES_H