changed svn layout

git-svn-id: svn://ultimatepp.org/upp/trunk@281 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
mdelfede 2008-06-07 22:31:27 +00:00
commit d2b54f7989
2872 changed files with 670392 additions and 0 deletions

2
uppsrc/CbGen/AUTHORS Normal file
View file

@ -0,0 +1,2 @@
Mirek Fidler <cxl@ntllib.org>
Tomas Rylek <rylek@volny.cz>

30
uppsrc/CbGen/COPYING Normal file
View file

@ -0,0 +1,30 @@
Copyright (C) 2005 Mirek Fidler, Tomas Rylek and various contributors (see AUTHORS)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies of the Software and its Copyright notices. In addition publicly
documented acknowledgment must be given that this software has been used if no
source code of this software is made available publicly. This includes
acknowledgments in either Copyright notices, Manuals, Publicity and Marketing
documents or any documentation provided with any product containing this
software. This License does not apply to any software that links to the
libraries provided by this software (statically or dynamically), but only to
the software provided.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-----------
Please see the COPYING.PLAIN for a plain-english explanation of this notice
and it's intent.

View file

@ -0,0 +1,33 @@
Plain English Copyright Notice
This file is not intended to be the actual License. The reason this file
exists is that we here are programmers and engineers. We aren't lawyers. We
provide licenses that we THINK say the right things, but we have our own
intentions at heart. This is a plain-english explanation of what those
intentions are, and if you follow them you will be within the "spirit" of
the license.
The intent is for us to enjoy writing software that is useful to us (the
AUTHORS) and allow others to use it freely and also benefit from the work we
put into making it. We don't want to restrict others using it. They should
not *HAVE* to make the source code of the applications they write that
simply link to these libraries (be that statically or dynamically), or for
them to be limited as to what license they choose to use (be it open, closed
or anything else). But we would like to know you are using these libraries.
We simply would like to know that it has been useful to someone. This is why
we ask for acknowledgement of some sort.
You can do what you want with the source of this software - it doesn't
matter. We still have it here for ourselves and it is open and free to use
and download and play with. It can't be taken away. We don't really mind what
you do with the source to your software. We would simply like to know that
you are using it - especially if it makes it to a commerical product. If you
simply e-mail all the AUTHORS (see COPYING and AUTHORS files) telling us, and
then make sure you include a paragraph or page in the manual or in the "About.."
box for the product with the copyright notice and state that you used this
software, we will be very happy. If you want to contribute back modifications
and fixes you may have made we will welcome those too with open arms (generally).
If you want help with changes needed, ports needed or features to be added,
arrangements can be easily made with some dialogue.
Mirek Fidler <cxl@ntllib.org>

14
uppsrc/CbGen/CbGen.upp Normal file
View file

@ -0,0 +1,14 @@
description "Utility to generate (long and repetitive) callback C++ source files";
uses
Core;
file
CppGen.cpp,
Info readonly separator,
COPYING,
COPYING-PLAIN,
AUTHORS;
mainconfig
"Normal" = "";

373
uppsrc/CbGen/CppGen.cpp Normal file
View file

@ -0,0 +1,373 @@
#include <Core/Core.h>
using namespace Upp;
String If(String s, String txt)
{
return IsNull(s) ? String() : txt;
}
void CallbackGen(String name, String rettype, int n, String extension, String atest = Null)
{
LOG("// -----------------------------------------------------------");
String classdef, classlist, paramdef, paramlist;
for(int i = 1; i <= n; i++) {
if(i > 1) {
classdef << ", ";
classlist << ", ";
paramdef << ", ";
paramlist << ", ";
}
classdef << Format("class P%d", i);
classlist << Format("P%d", i);
paramdef << Format("P%d p%d", i, i);
paramlist << Format("p%d", i);
}
String cl_list = If(classlist, "<" + classlist + ">");
String cl_temp = String("template <class OBJECT, class METHOD") << If(classdef, ", " + classdef) << ">";
String return_ = rettype == "void" ? "" : "return ";
String name_cl = name + cl_list;
LOG("");
if(!IsNull(classdef))
LOG("template <" << classdef << ">");
LOG("struct " << name << "Action {");
LOGBEGIN();
LOG("Atomic count;");
LOG("");
LOG("virtual " << rettype << " Execute(" + paramdef + ") = 0;");
LOG("virtual bool IsValid() const { return true; }");
// LOG("virtual bool IsEqual(const " << name << "Action *other) const = 0;");
// LOG("virtual unsigned GetHashValue() const = 0;");
LOG("");
LOG(name << "Action() { count = 1; }");
LOG("virtual ~" << name << "Action() {}");
LOGEND();
LOG("};");
LOG("");
LOG(cl_temp);
LOG("struct " << name << "MethodActionPte : public " << name << "Action" << cl_list + " {");
LOGBEGIN();
LOG("Ptr<OBJECT> object;");
LOG("METHOD method;");
LOG("");
if(rettype == "void")
LOG(rettype << " Execute(" << paramdef << ") { if(object) (object->*method)(" << paramlist << "); }");
else
LOG(rettype << " Execute(" << paramdef << ") { return object ? (object->*method)(" << paramlist << ") : false; }");
LOG("bool IsValid() const { return object; }");
// LOG("bool IsEqual(const " << name << "Action" << cl_list << " *other) const {");
// LOGBEGIN();
// LOG("const " << name << "MethodActionPte *q = dynamic_cast<const " << name <<
// "MethodActionPte *>(other);");
// LOG("return q ? q->object == object && q->method == method : false;");
// LOGEND();
// LOG("}");
// LOG("unsigned GetHashValue() const {");
// LOG("\treturn (unsigned)(uintptr_t)~object ^ (unsigned)brutal_cast<uintptr_t>(method);");
// LOG("}");
LOG("");
LOG(name << "MethodActionPte(OBJECT *object, METHOD method) "
": object(object), method(method) {}");
LOGEND();
LOG("};");
LOG("");
LOG(cl_temp);
LOG("struct " << name << "MethodAction : public " << name << "Action" << cl_list + " {");
LOGBEGIN();
LOG("OBJECT *object;");
LOG("METHOD method;");
LOG("");
LOG(rettype << " Execute(" << paramdef << ") { " <<
return_ << "(object->*method)(" << paramlist << "); }");
/* LOG("bool IsEqual(const " << name << "Action" << cl_list << " *other) const {");
LOGBEGIN();
LOG("const " << name << "MethodAction *q = dynamic_cast<const " << name <<
"MethodAction *>(other);");
LOG("return q ? q->object == object && q->method == method : false;");
LOGEND();
LOG("}");
LOG("unsigned GetHashValue() const {");
LOG("\treturn (unsigned)(uintptr_t)object ^ (unsigned)brutal_cast<uintptr_t>(method);");
LOG("}");
*/ LOG("");
LOG(name << "MethodAction(OBJECT *object, METHOD method) "
": object(object), method(method) {}");
LOGEND();
LOG("};");
LOG("");
if(!IsNull(classdef))
LOG("template <" << classdef << ">");
LOG("struct " << name << "FnAction : public " << name << "Action" << cl_list << " {");
LOGBEGIN();
LOG(rettype << " (*fn)(" << paramdef << ");");
LOG("");
LOG(rettype << " Execute(" << paramdef << ") { " << return_ << "(*fn)(" <<
paramlist << "); }");
/* LOG("bool IsEqual(const " << name << "Action" << cl_list << " *other) const {");
LOGBEGIN();
LOG("const " << name << "FnAction *q = dynamic_cast<const " << name <<
"FnAction *>(other);");
LOG("return q ? q->fn == fn : false;");
LOGEND();
LOG("}");
LOG("unsigned GetHashValue() const {");
LOG("\treturn (unsigned)(uintptr_t)fn;");
LOG("}");
*/ LOG("");
LOG(name << "FnAction(" << rettype << " (*fn)(" << paramdef << ")) : fn(fn) {}");
LOGEND();
LOG("};");
LOG("");
if(!IsNull(classdef))
LOG("template <" << classdef << ">");
LOG("class " << name << " : Moveable< " << name_cl << " > {");
LOGBEGIN();
LOG(name << "Action" << cl_list << " *action;");
LOG("");
LOG("void Retain() const { if(action " << atest << ") AtomicInc(action->count); }");
LOG("void Release() { if(action " << atest << " && AtomicDec(action->count) == 0) delete action; }");
LOG("");
LOG("bool operator==(const " << name << "&);");
LOG("bool operator!=(const " << name << "&);");
LOG("");
LOGEND();
LOG("public:");
LOGBEGIN();
LOG("typedef " << name << " CLASSNAME;");
LOG("");
LOG(name << "& operator=(const " << name << "& c);");
LOG(name << "(const " << name << "& c);");
LOG("void Clear() { Release(); action = NULL; }");
LOG("");
// LOG("unsigned GetHashValue() const { return action->GetHashValue(); }");
LOG("");
LOG(extension);
LOG("");
LOG("explicit " << name << "(" << name << "Action " << cl_list <<
" *newaction) { action = newaction; }");
// LOG(name << "& operator=(" << name << "Action" << cl_list <<
// " *newaction) { action = newaction; return *this; }");
LOG(name << "() { action = NULL; }");
LOG(name << "(_CNULL) { action = NULL; }");
LOG("~" << name << "();");
LOG("");
LOG("static " << name << " Empty() { return CNULL; }");
LOG("");
// LOG("friend bool operator==(const " << name << "& a, const " << name << "& b)");
// LOG("\t{ return a.action ? a.action->IsEqual(b.action) : !b.action; }");
// LOG("friend bool operator!=(const " << name << "& a, const " << name << " & b)");
// LOG("\t{ return !(a == b); }");
LOGEND();
LOG("};");
LOG("");
LOG(cl_temp);
LOG(name_cl << " pteback(OBJECT *object, " << rettype <<
" (METHOD::*method)(" << paramdef << ")) {");
LOG("\treturn " << name_cl <<
"(new " << name << "MethodActionPte<OBJECT, " << rettype << " (METHOD::*)(" <<
paramdef << ")" << If(classlist, ", " + classlist) << ">(object, method));");
LOG("}");
LOG("");
LOG(cl_temp);
LOG(name_cl << " callback(OBJECT *object, " << rettype <<
" (METHOD::*method)(" << paramdef << ")) {");
LOG("\treturn " << name_cl <<
"(new " << name << "MethodAction<OBJECT, " << rettype << " (METHOD::*)(" <<
paramdef << ")" << If(classlist, ", " + classlist) << ">(object, method));");
LOG("}");
LOG("");
LOG(cl_temp);
LOG(name_cl << " callback(const OBJECT *object, " << rettype <<
" (METHOD::*method)(" << paramdef << ") const) {");
LOG("\treturn " << name_cl <<
"(new " << name << "MethodAction<const OBJECT, " << rettype << " (METHOD::*)("
<< paramdef << ") const" << If(classlist, ", " + classlist) << ">(object, method));");
LOG("}");
LOG("");
if(!IsNull(classdef))
LOG("template <" << classdef << ">");
LOG("inline " << name_cl << " callback(" << rettype << " (*fn)(" << paramdef << ")) {");
LOG("\treturn " << name_cl << "(new " << name << "FnAction " << cl_list << "(fn));");
LOG("}");
LOG("");
if(!IsNull(classdef))
LOG("template <" << classdef << ">");
LOG("struct " << name << "ForkAction : public " << name << "Action" << cl_list << " {");
LOGBEGIN();
LOG(name_cl << " cb1, cb2;");
LOG("");
LOG(rettype << " Execute(" << paramdef << ") { cb1(" << paramlist <<
"); " << return_ << "cb2(" << paramlist << "); }");
// LOG("bool IsEqual(const " << name << "Action " << cl_list << " *other) const {");
// LOG("\tconst " << name << "ForkAction *q = dynamic_cast<const " << name
// << "ForkAction *>(other);");
// LOG("\treturn q ? q->cb1 == cb1 && q->cb2 == cb2 : false;");
// LOG("}");
// LOG("unsigned GetHashValue() const {");
// LOG("\treturn ::GetHashValue(cb1) ^ ::GetHashValue(cb2);");
// LOG("}");
LOG("");
LOG(name << "ForkAction(" << name_cl << " cb1, " << name_cl << " cb2)"
"\n\t : cb1(cb1), cb2(cb2) {}");
LOGEND();
LOG("};");
LOG("");
if(!IsNull(classdef))
LOG("template <" << classdef << ">");
LOG("inline " << name_cl << " Proxy(" << name_cl << "& cb)");
LOG("{");
LOG("\treturn callback(&cb, &" << name_cl << "::Execute);");
LOG("}");
LOG("");
if(IsNull(classdef)) {
LOG(name_cl << " callback(" << name_cl << " cb1, " << name_cl << " cb2);");
LOG(name_cl << "& operator<<(" << name_cl << "& a, " << name_cl << " b);");
LOG("");
LOG("#endif");
LOG("#ifdef CPP_PART__");
LOG("");
}
if(!IsNull(classdef))
LOG("template <" << classdef << ">");
LOG(name_cl << " callback(" << name_cl << " cb1, " << name_cl << " cb2)");
LOG("{");
LOG("\treturn " << name_cl << "(new " << name << "ForkAction " << cl_list << "(cb1, cb2));");
LOG("}");
LOG("");
if(!IsNull(classdef))
LOG("template <" << classdef << ">");
LOG(name_cl << "& operator<<(" << name_cl << "& a, " << name_cl << " b)");
LOG("{");
LOG("\tif(a)");
LOG("\t\ta = callback(a, b);");
LOG("\telse");
LOG("\t\ta = b;");
LOG("\treturn a;");
LOG("}");
LOG("");
if(!IsNull(classdef))
LOG("template <" << classdef << ">");
LOG(name_cl << "& " << name_cl << "::operator=(const " << name << "& c)");
LOG("{");
LOG("\tc.Retain();");
LOG("\tRelease();");
LOG("\taction = c.action;");
LOG("\treturn *this;");
LOG("}");
LOG("");
if(!IsNull(classdef))
LOG("template <" << classdef << ">");
LOG(name_cl << "::" << name << "(const " << name << "& c)");
LOG("{");
LOG("\taction = c.action;");
LOG("\tRetain();");
LOG("}");
LOG("");
if(!IsNull(classdef))
LOG("template <" << classdef << ">");
LOG(name_cl << "::~" << name << "()");
LOG("{");
LOG("\tRelease();");
LOG("}");
LOG("");
if(IsNull(classdef)) {
LOG("#endif");
LOG("#ifndef CPP_PART__");
LOG("");
}
};
CONSOLE_APP_MAIN
{
LOG("#ifndef CPP_PART__");
LOG("");
CallbackGen("Callback", "void", 0,
"operator bool() const { return action && action->IsValid(); }\n"
"void Execute() const;\n"
"void operator()() const { Execute(); }"
);
CallbackGen("Callback1", "void", 1,
"operator bool() const { return action && action->IsValid(); }\n"
"void Execute(P1 p1) const { if(action) action->Execute(p1); }\n"
"void operator()(P1 p1) const { Execute(p1); }"
);
CallbackGen("Callback2", "void", 2,
"operator bool() const { return action && action->IsValid(); }\n"
"void Execute(P1 p1, P2 p2) const { if(action) action->Execute(p1, p2); }\n"
"void operator()(P1 p1, P2 p2) const { Execute(p1, p2); }"
);
CallbackGen("Callback3", "void", 3,
"operator bool() const { return action && action->IsValid(); }\n"
"void Execute(P1 p1, P2 p2, P3 p3) const { if(action) action->Execute(p1, p2, p3); }\n"
"void operator()(P1 p1, P2 p2, P3 p3) const { Execute(p1, p2, p3); }"
);
CallbackGen("Callback4", "void", 4,
"operator bool() const { return action && action->IsValid(); }\n"
"void Execute(P1 p1, P2 p2, P3 p3, P4 p4) const { if(action) action->Execute(p1, p2, p3, p4); }\n"
"void operator()(P1 p1, P2 p2, P3 p3, P4 p4) const { Execute(p1, p2, p3, p4); }"
);
CallbackGen("Gate", "bool", 0,
"operator bool() const { return (void *)action != (void *)1 && action && action->IsValid(); }\n"
"bool Execute() const;\n"
"bool operator()() const { return Execute(); }\n"
"void ClearTrue() { Clear(); action = (GateAction *)1; }\n"
"void ClearFalse() { Clear(); }\n\n"
"Gate(bool b) { action = (GateAction *)(int)b; }",
"&& (void *)action != (void *)1"
);
CallbackGen("Gate1", "bool", 1,
"operator bool() const { return (void *)action != (void *)1 && action && action->IsValid(); }\n"
"bool Execute(P1 p1) const;\n"
"bool operator()(P1 p1) const { return Execute(p1); }\n"
"void ClearTrue() { Clear(); action = (Gate1Action<P1> *)1; }\n"
"void ClearFalse() { Clear(); }\n\n"
"Gate1(bool b) { action = (Gate1Action<P1> *)(uintptr_t)b; }",
"&& (void *)action != (void *)1"
);
CallbackGen("Gate2", "bool", 2,
"operator bool() const { return (void *)action != (void *)1 && action && action->IsValid(); }\n"
"bool Execute(P1 p1, P2 p2) const;\n"
"bool operator()(P1 p1, P2 p2) const { return Execute(p1, p2); }\n"
"void ClearTrue() { Clear(); action = (Gate2Action<P1, P2> *)1; }\n"
"void ClearFalse() { Clear(); }\n\n"
"Gate2(bool b) { action = (Gate2Action<P1, P2> *)(uintptr_t)b; }",
"&& (void *)action != (void *)1"
);
CallbackGen("Gate3", "bool", 3,
"operator bool() const { return (void *)action != (void *)1 && action && action->IsValid(); }\n"
"bool Execute(P1 p1, P2 p2, P3 p3) const;\n"
"bool operator()(P1 p1, P2 p2, P3 p3) const { return Execute(p1, p2, p3); }\n"
"void ClearTrue() { Clear(); action = (Gate3Action<P1, P2, P3> *)1; }\n"
"void ClearFalse() { Clear(); }\n\n"
"Gate3(bool b) { action = (Gate3Action<P1, P2, P3> *)(uintptr_t)b; }",
"&& (void *)action != (void *)1"
);
CallbackGen("Gate4", "bool", 4,
"operator bool() const { return (void *)action != (void *)1 && action && action->IsValid(); }\n"
"bool Execute(P1 p1, P2 p2, P3 p3, P4 p4) const;\n"
"bool operator()(P1 p1, P2 p2, P3 p3, P4 p4) const { return Execute(p1, p2, p3, p4); }\n"
"void ClearTrue() { Clear(); action = (Gate4Action<P1, P2, P3, P4> *)1; }\n"
"void ClearFalse() { Clear(); }\n\n"
"Gate4(bool b) { action = (Gate4Action<P1, P2, P3, P4> *)(uintptr_t)b; }",
"&& (void *)action != (void *)1"
);
LOG("");
LOG("#endif");
}

2
uppsrc/CbGen/prj.aux Normal file
View file

@ -0,0 +1,2 @@
file
e:\out\upp/CppGen/CONSOLE-DEBUG-IA32-MAIN-MSC-ST-WIN32\CppGen.log;