Core: Ref, Sql: S_* refactored

git-svn-id: svn://ultimatepp.org/upp/trunk@6519 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2013-11-03 14:36:25 +00:00
parent 21d1af382d
commit cbea669aa4
14 changed files with 430 additions and 150 deletions

View file

@ -63,7 +63,7 @@ public:
bool operator==(const T&) const { NEVER(); return false; } bool operator==(const T&) const { NEVER(); return false; }
String ToString() const { return typeid(T).name(); } String ToString() const { return typeid(T).name(); }
operator ValueTypeRef(); // operator ValueTypeRef();
}; };
template <class T, dword type, class B = EmptyClass> // Backward compatiblity template <class T, dword type, class B = EmptyClass> // Backward compatiblity

View file

@ -333,9 +333,9 @@ inline const T& ValueTo(const Value& v, const T& dflt) { return v.Is<T>() ?
template <class T> // Deprecated (?) template <class T> // Deprecated (?)
struct RawRef : public RefManager { struct RawRef : public RefManager {
virtual void SetValue(void *p, const Value& v) { *(T *) p = RawValue<T>::Extract(v); } virtual void SetValue(void *p, const Value& v) const { *(T *) p = RawValue<T>::Extract(v); }
virtual Value GetValue(const void *p) { return RawValue<T>(*(const T *) p); } virtual Value GetValue(const void *p) const { return RawValue<T>(*(const T *) p); }
virtual int GetType() { return GetValueTypeNo<T>(); } virtual int GetType() const { return GetValueTypeNo<T>(); }
virtual ~RawRef() {} virtual ~RawRef() {}
}; };
@ -346,10 +346,10 @@ Ref RawAsRef(T& x) { // Deprecated (?)
template <class T> // Deprecated template <class T> // Deprecated
struct RichRef : public RawRef<T> { struct RichRef : public RawRef<T> {
virtual Value GetValue(const void *p) { return RichValue<T>(*(T *) p); } virtual Value GetValue(const void *p) const { return RichValue<T>(*(T *) p); }
virtual bool IsNull(const void *p) { return UPP::IsNull(*(T *) p); } virtual bool IsNull(const void *p) const { return UPP::IsNull(*(T *) p); }
virtual void SetValue(void *p, const Value& v) { *(T *) p = T(v); } virtual void SetValue(void *p, const Value& v) const { *(T *) p = T(v); }
virtual void SetNull(void *p) { UPP::SetNull(*(T *)p); } virtual void SetNull(void *p) const { UPP::SetNull(*(T *)p); }
}; };
template <class T> // Deprecated template <class T> // Deprecated

View file

@ -6,12 +6,13 @@ static String sAsString(const Vector<Value>& v);
#define LTIMING(x) // RTIMING(x) #define LTIMING(x) // RTIMING(x)
/*
struct Ref::ValueRef : public RefManager { struct Ref::ValueRef : public RefManager {
virtual int GetType() { return VALUE_V; } virtual int GetType() const { return VALUE_V; }
virtual Value GetValue(const void *ptr) { return *(Value *) ptr; } virtual Value GetValue(const void *ptr) const { return *(Value *) ptr; }
virtual bool IsNull(const void *ptr) { return UPP::IsNull(*(Value *) ptr); } virtual bool IsNull(const void *ptr) const { return UPP::IsNull(*(Value *) ptr); }
virtual void SetValue(void *ptr, const Value& v) { *(Value *) ptr = v; } virtual void SetValue(void *ptr, const Value& v) const { *(Value *) ptr = v; }
virtual void SetNull(void *ptr) { *(Value *) ptr = Null; } virtual void SetNull(void *ptr) const { *(Value *) ptr = Null; }
}; };
Ref::Ref(String& s) { ptr = &s; m = &Single< StdRef<String> >(); } Ref::Ref(String& s) { ptr = &s; m = &Single< StdRef<String> >(); }
@ -23,7 +24,7 @@ Ref::Ref(bool& b) { ptr = &b; m = &Single< StdRef<bool> >(); }
Ref::Ref(Date& d) { ptr = &d; m = &Single< StdRef<Date> >(); } Ref::Ref(Date& d) { ptr = &d; m = &Single< StdRef<Date> >(); }
Ref::Ref(Time& t) { ptr = &t; m = &Single< StdRef<Time> >(); } Ref::Ref(Time& t) { ptr = &t; m = &Single< StdRef<Time> >(); }
Ref::Ref(Value& v) { ptr = &v; m = &Single< ValueRef >(); } Ref::Ref(Value& v) { ptr = &v; m = &Single< ValueRef >(); }
*/
// ---------------------------------- // ----------------------------------
bool ValueArray::Data::IsNull() const bool ValueArray::Data::IsNull() const

View file

@ -80,27 +80,26 @@ public:
}; };
struct RefManager { struct RefManager {
virtual int GetType() = 0; virtual int GetType() const = 0;
virtual Value GetValue(const void *) { return Null; } virtual Value GetValue(const void *) const { return Null; }
virtual bool IsNull(const void *) { return false; } virtual bool IsNull(const void *) const { return false; }
virtual void SetValue(void *, const Value& v) { NEVER(); } virtual void SetValue(void *, const Value& v) const { NEVER(); }
virtual void SetNull(void *) { NEVER(); } virtual void SetNull(void *) const { NEVER(); }
virtual ~RefManager() {} virtual ~RefManager() {}
}; };
template <class T> template <class T>
struct StdRef : public RefManager { struct StdRef : public RefManager {
virtual void SetValue(void *p, const Value& v) { *(T *) p = (T)v; } virtual int GetType() const { return GetValueTypeNo<T>(); }
virtual Value GetValue(const void *p) { return *(const T *) p; } virtual Value GetValue(const void *p) const { return *(const T *) p; }
virtual int GetType() { return GetValueTypeNo<T>(); } virtual bool IsNull(const void *p) const { return UPP::IsNull(*(T *) p); }
virtual bool IsNull(const void *p) { return UPP::IsNull(*(T *) p); } virtual void SetValue(void *p, const Value& v) const { *(T *) p = (T)v; }
virtual void SetNull(void *p) { UPP::SetNull(*(T *)p); } virtual void SetNull(void *p) const { UPP::SetNull(*(T *)p); }
virtual ~StdRef() {}
}; };
class Ref : Moveable<Ref> { class Ref : Moveable<Ref> {
protected: protected:
RefManager *m; const RefManager *m;
void *ptr; void *ptr;
struct ValueRef; struct ValueRef;
@ -108,10 +107,11 @@ public:
dword GetType() const { return m ? m->GetType() : VOID_V; } dword GetType() const { return m ? m->GetType() : VOID_V; }
bool IsNull() const { return m ? m->IsNull(ptr) : true; } bool IsNull() const { return m ? m->IsNull(ptr) : true; }
void *GetVoidPtr() const { return ptr; } void *GetVoidPtr() const { return ptr; }
const RefManager *GetManager() const { return m; }
template <class T> template <class T>
bool Is() const { return GetType() == GetValueTypeNo<T>(); } // VALUE_V!!! bool Is() const { return GetType() == GetValueTypeNo<T>(); }
template <class T> template <class T>
T& Get() const { ASSERT(GetValueTypeNo<T>() == GetType()); return *(T *)GetVoidPtr(); } T& Get() const { ASSERT(GetValueTypeNo<T>() == GetType()); return *(T *)GetVoidPtr(); }
@ -121,8 +121,14 @@ public:
operator Value() const { return GetValue(); } operator Value() const { return GetValue(); }
Value operator~() const { return GetValue(); } Value operator~() const { return GetValue(); }
Ref& operator=(const Value& v) { SetValue(v); return *this; }
Ref& operator=(const Value& v) { SetValue(v); return *this; }
Ref& operator=(const Nuller&) { SetNull(); return *this; }
Ref& operator=(const char *s) { Get<String>() = s; return *this; }
template <class T>
Ref(T& x) { ptr = &x; m = &Single< StdRef<T> >(); }
/*
Ref(String& s); Ref(String& s);
Ref(WString& s); Ref(WString& s);
Ref(int& i); Ref(int& i);
@ -132,33 +138,34 @@ public:
Ref(Date& d); Ref(Date& d);
Ref(Time& t); Ref(Time& t);
Ref(Value& v); Ref(Value& v);
Ref(void *_ptr, RefManager *_m) { ptr = _ptr, m = _m; } */
Ref(const ValueTypeRef& r); Ref(void *_ptr, const RefManager *_m) { ptr = _ptr, m = _m; }
Ref() { ptr = m = NULL; } // Ref(const ValueTypeRef& r);
Ref() { ptr = NULL; m = NULL; }
}; };
template <class T> template <class T>
T& GetRef(Ref r, T *x = NULL) { T& GetRef(Ref r, T *x = NULL) { // Deprecated, use Ref::Get<T>
ASSERT(GetValueTypeNo<T>() == r.GetType()); ASSERT(GetValueTypeNo<T>() == r.GetType());
return *(T *) r.GetVoidPtr(); return *(T *) r.GetVoidPtr();
} }
inline String& RefString(Ref f) { return GetRef<String>(f); } inline String& RefString(Ref f) { return GetRef<String>(f); } // Deprecated, use Ref::Get<T>
inline WString& RefWString(Ref f) { return GetRef<WString>(f); } inline WString& RefWString(Ref f) { return GetRef<WString>(f); } // Deprecated, use Ref::Get<T>
inline int& RefInt(Ref f) { return GetRef<int>(f); } inline int& RefInt(Ref f) { return GetRef<int>(f); } // Deprecated, use Ref::Get<T>
inline int64& RefInt64(Ref f) { return GetRef<int64>(f); } inline int64& RefInt64(Ref f) { return GetRef<int64>(f); } // Deprecated, use Ref::Get<T>
inline double& RefDouble(Ref f) { return GetRef<double>(f); } inline double& RefDouble(Ref f) { return GetRef<double>(f); } // Deprecated, use Ref::Get<T>
inline bool& RefBool(Ref f) { return GetRef<bool>(f); } inline bool& RefBool(Ref f) { return GetRef<bool>(f); } // Deprecated, use Ref::Get<T>
inline Date& RefDate(Ref f) { return GetRef<Date>(f); } inline Date& RefDate(Ref f) { return GetRef<Date>(f); } // Deprecated, use Ref::Get<T>
inline Time& RefTime(Ref f) { return GetRef<Time>(f); } inline Time& RefTime(Ref f) { return GetRef<Time>(f); } // Deprecated, use Ref::Get<T>
inline Value& RefValue(Ref f) { ASSERT(f.GetType() == VALUE_V); inline Value& RefValue(Ref f) { ASSERT(f.GetType() == VALUE_V); // Deprecated, use Ref::Get<T>
return *(Value *)f.GetVoidPtr(); } return *(Value *)f.GetVoidPtr(); }
template <class T> template <class T>
Ref AsRef(T& x) { Ref AsRef(T& x) {
return Ref(&x, &Single< StdRef<T> >()); return Ref(&x, &Single< StdRef<T> >());
} }
/*
struct ValueTypeRef { struct ValueTypeRef {
RefManager *m; RefManager *m;
void *ptr; void *ptr;
@ -179,7 +186,7 @@ ValueType<T, type, B>::operator ValueTypeRef()
h.m = &Single< StdRef<T> >(); h.m = &Single< StdRef<T> >();
return h; return h;
} }
*/
#define E__Value(I) Value p##I #define E__Value(I) Value p##I
#define E__Ref(I) Ref p##I #define E__Ref(I) Ref p##I

View file

@ -81,11 +81,6 @@ onst]_[_^Value^ Value][@(0.0.255) `&]_[*@3 v])&]
[s2;%% Support for standard Value types and Value.&] [s2;%% Support for standard Value types and Value.&]
[s3;%% &] [s3;%% &]
[s4; &] [s4; &]
[s5;:Ref`:`:Ref`(const ValueTypeRef`&`): [* Ref]([@(0.0.255) const]_[_^ValueTypeRef^ ValueT
ypeRef][@(0.0.255) `&]_[*@3 r])&]
[s2;%% Support for rich Value types based on ValueType.&]
[s3;%% &]
[s4; &]
[s5;:Ref`:`:Ref`(`): [* Ref]()&] [s5;:Ref`:`:Ref`(`): [* Ref]()&]
[s2;%% Default constructor, constructs empty Ref (no variable referenced, [s2;%% Default constructor, constructs empty Ref (no variable referenced,
no value can be assigned).&] no value can be assigned).&]

View file

@ -35,7 +35,7 @@ void FontSysData::Init(Font font, int angle)
if(font.IsItalic() && !(FTFace(font)->style_flags & FT_STYLE_FLAG_ITALIC)) { if(font.IsItalic() && !(FTFace(font)->style_flags & FT_STYLE_FLAG_ITALIC)) {
cairo_matrix_t sheer[1]; cairo_matrix_t sheer[1];
cairo_matrix_init_identity(sheer); cairo_matrix_init_identity(sheer);
sheer->xy = -0.3; sheer->xy = -0.2;
cairo_matrix_multiply(font_matrix, font_matrix, sheer); cairo_matrix_multiply(font_matrix, font_matrix, sheer);
} }

View file

@ -87,10 +87,10 @@ GisCoords::Arg GisCoords::Arg::DropList(String& v, String ident, String name, St
struct GeomBoolRef : public RefManager struct GeomBoolRef : public RefManager
{ {
virtual int GetType() { return UNKNOWN_V; } virtual int GetType() const { return UNKNOWN_V; }
virtual Value GetValue(const void *x) { return *(const bool *)x ? 1 : 0; } virtual Value GetValue(const void *x) const { return *(const bool *)x ? 1 : 0; }
virtual void SetValue(void *x, const Value& v) { *(bool *)x = !UPP::IsNull(v) && (double)v; } virtual void SetValue(void *x, const Value& v) const { *(bool *)x = !UPP::IsNull(v) && (double)v; }
virtual void SetNull(void *x) { *(bool *)x = false; } virtual void SetNull(void *x) const { *(bool *)x = false; }
static RefManager *Manager() { static GeomBoolRef m; return &m; } static RefManager *Manager() { static GeomBoolRef m; return &m; }
}; };

87
uppsrc/Sql/S_info.cpp Normal file
View file

@ -0,0 +1,87 @@
#include "Sql.h"
NAMESPACE_UPP
void S_info_maker::Field(const char *name, Ref f)
{
info.column.Add(name, MakeTuple((byte *)f.GetVoidPtr() - (byte *)s, f.GetManager()));
}
Ref S_info::GetRef(const void *s, int i) const
{
return Ref((byte *)s + column[i].a, column[i].b);
}
Ref S_info::GetRef(const void *s, const SqlId& id) const
{
int q = column.Find(~id);
return q >= 0 ? GetRef(s, q) : Ref();
}
Value S_info::Get(const void *s, const SqlId& id) const
{
return ~GetRef(s, id);
}
Value S_info::Get(const void *s, int i) const
{
return ~GetRef(s, i);
}
ValueMap S_info::Get(const void *s) const
{
ValueMap m;
for(int i = 0; i < column.GetCount(); i++)
m.Add(column.GetKey(i), GetRef(s, i));
return m;
}
void S_info::Set(const void *s, int i, const Value& v) const
{
GetRef(s, i) = v;
}
void S_info::Set(const void *s, const SqlId& id, const Value& v) const
{
int q = column.Find(~id);
if(q >= 0)
Set(s, q, v);
}
void S_info::Set(const void *s, const ValueMap& m) const
{
for(int i = 0; i < m.GetCount(); i++) {
Value v = m.GetKey(i);
if(IsString(v))
Set(s, (String)v, m.GetValue(i));
}
}
SqlSet S_info::GetSet(const String& prefix) const
{
SqlSet set;
for(int i = 0; i < column.GetCount(); i++)
set << SqlId(prefix + column.GetKey(i));
return set;
}
SqlSet S_info::GetOf(const SqlId& table) const
{
SqlSet set;
for(int i = 0; i < ids.GetCount(); i++)
set << SqlId(ids[i].Of(table));
return set;
}
void S_info::Init()
{
column.Shrink();
ids.SetCount(column.GetCount());
for(int i = 0; i < column.GetCount(); i++) {
SqlId id(column.GetKey(i));
ids[i] = id;
set << id;
}
}
END_UPP_NAMESPACE

View file

@ -24,6 +24,7 @@ file
Schema readonly separator, Schema readonly separator,
SqlSchema.h, SqlSchema.h,
SqlSchema.cpp, SqlSchema.cpp,
S_info.cpp,
sch_model.h, sch_model.h,
sch_header.h, sch_header.h,
sch_source.h, sch_source.h,

View file

@ -130,3 +130,70 @@ String ExportIds(SqlSession& session, const String& database);
String ExportSch(const String& database); String ExportSch(const String& database);
String ExportIds(const String& database); String ExportIds(const String& database);
#endif #endif
struct S_info {
VectorMap< String, Tuple2<intptr_t, const RefManager *> > column;
SqlSet set;
Vector<SqlId> ids;
SqlId GetId(int i) const { return column.GetKey(i); }
int GetCount() const { return column.GetCount(); }
Ref GetRef(const void *s, int i) const;
Ref GetRef(const void *s, const SqlId& id) const;
Value Get(const void *s, const SqlId& id) const;
Value Get(const void *s, int i) const;
ValueMap Get(const void *s) const;
void Set(const void *s, int i, const Value& v) const;
void Set(const void *s, const SqlId& id, const Value& v) const;
void Set(const void *s, const ValueMap& m) const;
SqlSet GetSet(const String& prefix) const;
SqlSet GetOf(const SqlId& table) const;
void Init();
};
struct S_info_maker : FieldOperator {
S_info& info;
void *s;
virtual void Field(const char *name, Ref f);
S_info_maker(S_info& f, void *s) : info(f), s(s) {}
};
#if 0 // For documentation only, 'type' is a placeholder for the .sch TABLE or TYPE name
struct S_type {
static const char TableName[];
static const SqlSet& ColumnSet();
static SqlSet ColumnSet(const String& prefix);
static SqlSet Of(SqlId table);
static const Vector<SqlId>& GetColumnIds();
void Shrink();
void Clear();
void FieldLayoutRaw(FieldOperator& f, const String& prefix = String());
void FieldLayout(FieldOperator& f);
operator Fields();
bool operator==(const S_type& x) const;
bool operator!=(const S_type& x) const;
String ToString() const;
int GetCount() const;
SqlId GetId(int i) const;
Ref GetRef(int i);
Ref GetRef(const SqlId& id);
Value Get(const SqlId& id) const;
Value Get(int i) const;
ValueMap Get() const;
void Set(int i, const Value& v);
void Set(const SqlId& id, const Value& v);
void Set(const ValueMap& m);
S_type();
S_type(const ValueMap& m);
};
#endif

View file

@ -2,23 +2,36 @@
#define CODETYPE(Table, b) \ #define CODETYPE(Table, b) \
struct S_##Table b { \ struct S_##Table b { \
public:\ private: \
void Shrink(); \ S_##Table(int) {} \
void Clear(); \ static const S_info& GetInfo(); \
static const S_info *info; \
\
public: \
static const char TableName[]; \ static const char TableName[]; \
static const SqlSet& ColumnSet(); \ static const SqlSet& ColumnSet() { return GetInfo().set; } \
static SqlSet ColumnSet(const String& prefix); \ static SqlSet ColumnSet(const String& prefix) { return GetInfo().GetSet(prefix); } \
static SqlSet Of(SqlId table); \ static SqlSet Of(SqlId table) { return GetInfo().GetOf(table); } \
static const Vector<SqlId>& GetColumnIds(); \ static const Vector<SqlId>& GetColumnIds() { return GetInfo().ids; } \
void FieldLayoutRaw(FieldOperator& f, const String& prefix = String()); \ \
void FieldLayout(FieldOperator& f); \ void Clear(); \
operator Fields() { return callback(this, &S_##Table::FieldLayout); } \ void FieldLayout(FieldOperator& f); \
bool operator==(const S_##Table& x) const { return EqualFields(const_cast<S_##Table&>(*this), const_cast<S_##Table&>(x)); } \ operator Fields() { return callback(this, &S_##Table::FieldLayout); } \
bool operator!=(const S_##Table& x) const { return !EqualFields(const_cast<S_##Table&>(*this), const_cast<S_##Table&>(x)); } \ bool operator==(const S_##Table& x) const { return EqualFields(const_cast<S_##Table&>(*this), const_cast<S_##Table&>(x)); } \
String ToString() const { return AsString((Fields)const_cast<S_##Table&>(*this)); } \ bool operator!=(const S_##Table& x) const { return !operator==(x); } \
Value Get(SqlId column_id) const; \ String ToString() const { return AsString((Fields)const_cast<S_##Table&>(*this)); } \
ValueMap Get() const; \ int GetCount() const { return info->GetCount(); } \
S_##Table(); SqlId GetId(int i) const { return info->GetId(i); } \
Ref GetRef(int i) { return info->GetRef(this, i); } \
Ref GetRef(const SqlId& id) { return info->GetRef(this, id); } \
Value Get(const SqlId& id) const { return info->Get(this, id); } \
Value Get(int i) const { return info->Get(this, i); } \
ValueMap Get() const { return info->Get(this); } \
void Set(int i, const Value& v) { return info->Set(this, i, v); } \
void Set(const SqlId& id, const Value& v) { return info->Set(this, id, v); } \
void Set(const ValueMap& m) { return info->Set(this, m); } \
S_##Table(); \
S_##Table(const ValueMap& m);
#define TYPE(Table) CODETYPE(Table, __NIL) #define TYPE(Table) CODETYPE(Table, __NIL)
#define TYPE_I(Table, b) CODETYPE(Table, : public S_##b) #define TYPE_I(Table, b) CODETYPE(Table, : public S_##b)
@ -30,10 +43,14 @@ public:\
#define VAR(type, x) S_##type x; #define VAR(type, x) S_##type x;
#define COLUMN(type, ctype, name, width, prec) \ #define COLUMN(type, ctype, name, width, prec) \
enum { ADD_SCHEMA_PREFIX_CPP2(name,_WIDTH) = width, ADD_SCHEMA_PREFIX_CPP2(name,_PRECISION) = prec }; ctype ADD_SCHEMA_PREFIX_CPP(name); enum { ADD_SCHEMA_PREFIX_CPP2(name,_WIDTH) = width, ADD_SCHEMA_PREFIX_CPP2(name,_PRECISION) = prec }; \
ctype ADD_SCHEMA_PREFIX_CPP(name); \
static SqlId colid_##name;
#define COLUMN_ARRAY(type, ctype, name, width, prec, items) \ #define COLUMN_ARRAY(type, ctype, name, width, prec, items) \
enum { ADD_SCHEMA_PREFIX_CPP2(name,_WIDTH) = width, ADD_SCHEMA_PREFIX_CPP2(name,_PRECISION) = prec }; ctype ADD_SCHEMA_PREFIX_CPP(name)[items]; enum { ADD_SCHEMA_PREFIX_CPP2(name,_WIDTH) = width, ADD_SCHEMA_PREFIX_CPP2(name,_PRECISION) = prec }; \
ctype ADD_SCHEMA_PREFIX_CPP(name)[items]; \
static SqlId colid_##name;
#define END_TYPE }; #define END_TYPE };

View file

@ -7,59 +7,22 @@
// constructor // constructor
#define TYPE(x) S_##x::S_##x() { #define TYPE(x) const S_info *S_##x::info; S_##x::S_##x() { ONCELOCK { info = &GetInfo(); }
#define COLUMN(type, ctype, name, width, prec) SqlSchemaInitClear(ADD_SCHEMA_PREFIX_CPP(name)); #define COLUMN(type, ctype, name, width, prec) SqlSchemaInitClear(ADD_SCHEMA_PREFIX_CPP(name));
#define COLUMN_ARRAY(type, ctype, name, width, prec, items) SqlSchemaInitClear(ADD_SCHEMA_PREFIX_CPP(name), items); #define COLUMN_ARRAY(type, ctype, name, width, prec, items) SqlSchemaInitClear(ADD_SCHEMA_PREFIX_CPP(name), items);
#define END_TYPE } #define END_TYPE }
#include SCHEMADIALECT #include SCHEMADIALECT
// constructor, ColumnSet, TableName, SqlField // constructor from ValueMap
#define TYPECODE(x, y) \ #define TYPE(x) S_##x::S_##x(const ValueMap& m) { ONCELOCK { info = &GetInfo(); }
const char S_##x::TableName[] = #x; \ #define COLUMN(type, ctype, name, width, prec) SqlSchemaInitClear(ADD_SCHEMA_PREFIX_CPP(name));
const SqlSet& S_##x::ColumnSet() { \ #define COLUMN_ARRAY(type, ctype, name, width, prec, items) SqlSchemaInitClear(ADD_SCHEMA_PREFIX_CPP(name), items);
static SqlSet set = ColumnSet(""); \ #define END_TYPE Set(m); }
return set; \
} \
SqlSet S_##x::Of(SqlId id) { \
return ColumnSet(id.ToString() + '.'); \
} \
SqlSet S_##x::ColumnSet(const String& prefix) { \
SqlSet set; \
y \
#define TYPE(x) TYPECODE(x, __NIL)
#define BASECODE(b) \
set.Cat(S_##b::ColumnSet(prefix));
#define TYPE_I(x, b) TYPECODE(x, BASECODE(b))
#define BASE2CODE(b1, b2)\
set.Cat(S_##b1::ColumnSet(prefix)); \
set.Cat(S_##b2::ColumnSet(prefix));
#define TYPE_II(x, b1, b2) TYPECODE(x, BASE2CODE(b1, b2))
#define BASE3CODE(b1, b2, b3)\
set.Cat(S_##b1::ColumnSet(prefix)); \
set.Cat(S_##b2::ColumnSet(prefix)); \
set.Cat(S_##b3::ColumnSet(prefix));
#define TYPE_III(x, b1, b2, b3) TYPECODE(x, BASE3CODE(b1, b2, b3))
#define VAR(type, x) td_var(set, prefix, #x, &S_##type::ColumnSet);
#define COLUMN(type, ctype, name, width, prec) td_scalar(set, prefix, #name);
#define COLUMN_ARRAY(type, ctype, name, width, prec, items) td_array(set, prefix, #name, items);
#define END_TYPE return set; }
#include SCHEMADIALECT #include SCHEMADIALECT
#undef TYPECODE
#undef BASECODE
#undef BASE2CODE
#undef BASE3CODE
// Clear // Clear
#define TYPE(x)\ #define TYPE(x)\
@ -83,13 +46,28 @@ void S_##x::Clear() { S_##b1::Clear(); S_##b2::Clear(); S_##b3::Clear();
#include SCHEMADIALECT #include SCHEMADIALECT
// FieldLayout // TableName, FieldLayout and GetInfo
#define TYPE(x) \ #define TYPE(x) \
const char S_##x::TableName[] = #x; \
\
void S_##x::FieldLayout(FieldOperator& fo) {\ void S_##x::FieldLayout(FieldOperator& fo) {\
fo.Table(#x);\ fo.Table(#x);\
FieldLayoutRaw(fo);\ FieldLayoutRaw(fo);\
} } \
\
const S_info& S_##x::GetInfo() {\
static S_info *info; \
ONCELOCK { \
static S_info f; \
S_##x prot(0); \
S_info_maker m(f, &prot); \
prot.FieldLayoutRaw(m); \
f.Init(); \
info = &f; \
} \
return *info; \
} \
#include SCHEMADIALECT #include SCHEMADIALECT
@ -126,31 +104,6 @@ void S_##x::FieldLayoutRaw(FieldOperator& fo, const String& prefix) {\
#include SCHEMADIALECT #include SCHEMADIALECT
// S_*::Get(SqlId column_id) const
#define TYPE(x) Value S_##x::Get(SqlId column_id) const { String col = ~column_id;
#define COLUMN(type, ctype, name, width, prec) static String _x0_x_##name(#name); if(_x0_x_##name == col) return name;
#define END_TYPE return Value(); }
#include SCHEMADIALECT
// ValueMap S_*::Get() const
#define TYPE(x) ValueMap S_##x::Get() const { ValueMap vm;
#define COLUMN(type, ctype, name, width, prec) static String _x0_x_##name(#name); vm.Add(_x0_x_##name, name);
#define END_TYPE return vm; }
#include SCHEMADIALECT
// static const Vector<SqlId>& GetColumnIds();
#define TYPE(x) const Vector<SqlId>& S_##x::GetColumnIds() { static Vector<SqlId> cols; ONCELOCK {
#define COLUMN(type, ctype, name, width, prec) cols.Add(#name);
#define END_TYPE } return cols; }
#include SCHEMADIALECT
// Introspection // Introspection
#define TYPE(x) void SchDbInfo##x() { #define TYPE(x) void SchDbInfo##x() {

View file

@ -0,0 +1,152 @@
topic "";
[2 $$0,0#00000000000000000000000000000000:Default]
[i448;a25;kKO9;2 $$1,0#37138531426314131252341829483380:class]
[l288;2 $$2,2#27521748481378242620020725143825:desc]
[0 $$3,0#96390100711032703541132217272105:end]
[H6;0 $$4,0#05600065144404261032431302351956:begin]
[i448;a25;kKO9;2 $$5,0#37138531426314131252341829483370:item]
[l288;a4;*@5;1 $$6,6#70004532496200323422659154056402:requirement]
[l288;i1121;b17;O9;~~~.1408;2 $$7,0#10431211400427159095818037425705:param]
[i448;b42;O9;2 $$8,8#61672508125594000341940100500538:tparam]
[b42;2 $$9,9#13035079074754324216151401829390:normal]
[{_}%EN-US
[ {{10000@(113.42.0) [s0; [*@7;4 S`_][*/@7;4 type][*@7;4 structures]]}}&]
[s0;i448;a25;kKO9;:noref:@(0.0.255)%- &]
[s0; S`_[/ type] structures are generated (by multiincluding process)
from .sch files that describe the database schema. Each TABLE
or TYPE of .sch has correspending S`_[/ type] structure. This structure
has member variables corresponding to database columns, with
the same names and types. `'BOOL`' columns are represented as
CHAR(1) in database, but as `'bool`' C`+`+ type in S`_[/ type]).
ARRAY columns are represented as fixed C`+`+ arrays. If TABLE
or TYPE has any base TYPEs or TABLEs, S`_[/ type] structure contains
them as well.&]
[s0; &]
[ {{10000F(128)G(128)@1 [s0; [* Public Member List]]}}&]
[s3;%- &]
[s5;:S`_type`:`:TableName:%- [@(0.0.255) static]_[@(0.0.255) const]_[@(0.0.255) char]_[* Tabl
eName][@(0.0.255) `[`]]&]
[s2; The name of table or type.&]
[s3;%- &]
[s4;%- &]
[s5;:S`_type`:`:ColumnSet`(`):%- [@(0.0.255) static] [@(0.0.255) const]_[_^SqlSet^ SqlSet][@(0.0.255) `&
]_[* ColumnSet]()&]
[s2; The complete set of columns as SqlSet.&]
[s3;%- &]
[s4;%- &]
[s5;:S`_type`:`:ColumnSet`(const String`&`):%- [@(0.0.255) static]
[_^SqlSet^ SqlSet]_[* ColumnSet]([@(0.0.255) const]_[_^String^ String][@(0.0.255) `&]_[*@3 pr
efix])&]
[s2; The complete set of columns as SqlSet, all columns prefixed
with [%-*@3 prefix].&]
[s3; &]
[s4; &]
[s5;:S`_type`:`:Of`(SqlId`):%- [@(0.0.255) static] [_^SqlSet^ SqlSet]_[* Of]([_^SqlId^ SqlId]_
[*@3 table])&]
[s2; The complete set of columns as SqlSet, all columns expressed
as part of [%-*@3 table] (TABLE.COLUMN notation).&]
[s3; &]
[s4; &]
[s5;:S`_type`:`:GetColumnIds`(`):%- [@(0.0.255) static] [@(0.0.255) const]_[_^Vector^ Vecto
r]<[_^SqlId^ SqlId]>`&_[* GetColumnIds]()&]
[s2; Returns all columns.&]
[s3; &]
[s4; &]
[s5;:S`_type`:`:Clear`(`):%- [@(0.0.255) void]_[* Clear]()&]
[s2; Sets all member variables to Null.&]
[s3; &]
[s4; &]
[s5;:S`_type`:`:FieldLayout`(FieldOperator`&`):%- [@(0.0.255) void]_[* FieldLayout]([_^FieldOperator^ F
ieldOperator][@(0.0.255) `&]_[*@3 f])&]
[s2; Calls FieldOpertator`::Field(const char `*name, Ref f) and Table(const
char `*name) methods of [%-*@3 f] to provide a visitor pattern
for S`_[/ type].&]
[s3; &]
[s4; &]
[s5;:S`_type`:`:operator Fields`(`):%- [* operator_Fields]()&]
[s2; Returns callback(this, `&S`_##Table`::FieldLayout). This method
provides unified access to all S`_[/ type]s, which is then used
in Sql`::Fetch.&]
[s3; &]
[s4; &]
[s5;:S`_type`:`:operator`=`=`(const S`_type`&`)const:%- [@(0.0.255) bool]_[* operator`=`=
]([@(0.0.255) const]_[_^S`_type^ S`_][/_^S`_type^ type][@(0.0.255) `&]_[*@3 x])_[@(0.0.255) c
onst]&]
[s2; Returns true if all fields are the same.&]
[s3; &]
[s4; &]
[s5;:S`_type`:`:operator`!`=`(const S`_type`&`)const:%- [@(0.0.255) bool]_[* operator!`=](
[@(0.0.255) const]_[_^S`_type^ S`_][/_^S`_type^ type][@(0.0.255) `&]_[*@3 x])_[@(0.0.255) con
st]&]
[s2; Same as !operator`=`=(x).&]
[s3; &]
[s4; &]
[s5;:S`_type`:`:ToString`(`)const:%- [_^String^ String]_[* ToString]()_[@(0.0.255) const]&]
[s2; Converts S`_[/ type] to (multiline) text, mostly for debugging
purposes.&]
[s3; &]
[s4; &]
[s5;:S`_type`:`:GetCount`(`)const:%- [@(0.0.255) int]_[* GetCount]()_[@(0.0.255) const]&]
[s2; Returns a number of columns of this S`_[/ type].&]
[s3; &]
[s4; &]
[s5;:S`_type`:`:GetId`(int`)const:%- [_^SqlId^ SqlId]_[* GetId]([@(0.0.255) int]_[*@3 i])_[@(0.0.255) c
onst]&]
[s2; Returns a column ID for column at [%-*@3 i].&]
[s3; &]
[s4; &]
[s5;:S`_type`:`:GetRef`(int`):%- [_^Ref^ Ref]_[* GetRef]([@(0.0.255) int]_[*@3 i])&]
[s2; Returns a reference to column at [%-*@3 i].&]
[s3; &]
[s4; &]
[s5;:S`_type`:`:GetRef`(const SqlId`&`):%- [_^Ref^ Ref]_[* GetRef]([@(0.0.255) const]_[_^SqlId^ S
qlId][@(0.0.255) `&]_[*@3 id])&]
[s2; Returns a reference to column [%-*@3 id ]or void reference if
not in S`_[/ type].&]
[s3; &]
[s4; &]
[s5;:S`_type`:`:Get`(const SqlId`&`)const:%- [_^Value^ Value]_[* Get]([@(0.0.255) const]_[_^SqlId^ S
qlId][@(0.0.255) `&]_[*@3 id])_[@(0.0.255) const]&]
[s2; Returns a value of column [%-*@3 id] or void Value if not in S`_[/ type].&]
[s3; &]
[s4; &]
[s5;:S`_type`:`:Get`(int`)const:%- [_^Value^ Value]_[* Get]([@(0.0.255) int]_[*@3 i])_[@(0.0.255) c
onst]&]
[s2; Returns a value of column at [%-*@3 i].&]
[s3; &]
[s4; &]
[s5;:S`_type`:`:Get`(`)const:%- [_^ValueMap^ ValueMap]_[* Get]()_[@(0.0.255) const]&]
[s2; Returns a map of column names to column values.&]
[s3; &]
[s4; &]
[s5;:S`_type`:`:Set`(int`,const Value`&`):%- [@(0.0.255) void]_[* Set]([@(0.0.255) int]_[*@3 i
], [@(0.0.255) const]_[_^Value^ Value][@(0.0.255) `&]_[*@3 v])&]
[s2; Sets column at [%-*@3 i] to [%-*@3 v]. Type of [%-*@3 v] must be convertible
to the column.&]
[s3; &]
[s4; &]
[s5;:S`_type`:`:Set`(const SqlId`&`,const Value`&`):%- [@(0.0.255) void]_[* Set]([@(0.0.255) c
onst]_[_^SqlId^ SqlId][@(0.0.255) `&]_[*@3 id], [@(0.0.255) const]_[_^Value^ Value][@(0.0.255) `&
]_[*@3 v])&]
[s2; If [%-*@3 id] is in S`_[/ type], sets its value to [%-*@3 v], otherwise
does nothing.&]
[s3; &]
[s4; &]
[s5;:S`_type`:`:Set`(const ValueMap`&`):%- [@(0.0.255) void]_[* Set]([@(0.0.255) const]_[_^ValueMap^ V
alueMap][@(0.0.255) `&]_[*@3 m])&]
[s2; Keys in [%-*@3 m] found as column ids in S`_[/ type] as assigned
to respective values. Keys not found are ignored, columns not
present in [%-*@3 m] are left unchanged.&]
[s3; &]
[s4; &]
[s5;:S`_type`:`:S`_type`(`):%- [* S`_type]()&]
[s2; Sets all columns to Null.&]
[s3; &]
[s4; &]
[s5;:S`_type`:`:S`_type`(const ValueMap`&`):%- [* S`_type]([@(0.0.255) const]_[_^ValueMap^ V
alueMap][@(0.0.255) `&]_[*@3 m])&]
[s2; Keys in [%-*@3 m] found as column ids in S`_[/ type] as assigned
to respective values. Keys not found are ignored, columns not
present in [%-*@3 m] are set to Null. Overal effect is the same
as using the default constructor and then Set([%-*@3 m]).&]
[s3; ]]

View file

@ -127,10 +127,10 @@ bool FileFlush(FileStream& fstream);
struct BoolRef : public RefManager struct BoolRef : public RefManager
{ {
virtual int GetType() { return UNKNOWN_V; } virtual int GetType() const { return UNKNOWN_V; }
virtual Value GetValue(const void *x) { return *(const bool *)x ? 1 : 0; } virtual Value GetValue(const void *x) const { return *(const bool *)x ? 1 : 0; }
virtual void SetValue(void *x, const Value& v) { *(bool *)x = !UPP::IsNull(v) && (double)v; } virtual void SetValue(void *x, const Value& v) const { *(bool *)x = !UPP::IsNull(v) && (double)v; }
virtual void SetNull(void *x) { *(bool *)x = false; } virtual void SetNull(void *x) const { *(bool *)x = false; }
static RefManager *Manager() { static BoolRef m; return &m; } static RefManager *Manager() { static BoolRef m; return &m; }
}; };