Commit f212bae6 authored by thomas's avatar thomas
Browse files

no message


git-svn-id: https://svn.grrrr.org/ext/trunk@329 4d9ac71a-51e6-0310-8455-cad1006bcd31
parent f7570cb0
......@@ -148,6 +148,10 @@ SOURCE=.\source\flatom.cpp
# End Source File
# Begin Source File
SOURCE=.\source\flattr.cpp
# End Source File
# Begin Source File
SOURCE=.\source\flbase.cpp
# End Source File
# Begin Source File
......@@ -220,10 +224,6 @@ SOURCE=.\source\flthr.cpp
# End Source File
# Begin Source File
SOURCE=.\source\flthr.h
# End Source File
# Begin Source File
SOURCE=.\source\flutil.cpp
# End Source File
# Begin Source File
......
......@@ -48,15 +48,27 @@ void flext_base::AddAttrib(const char *attr,metharg tp,methfun gfun,methfun sfun
sprintf(tmp,"get%s",attr);
AddAttrItem(new attritem(MakeSymbol(attr),MakeSymbol(tmp),tp,gfun,sfun));
if(sfun)
AddMethod(0,attr,(methfun)cb_SetAttrib,a_any,a_null);
else
AddMethod(0,attr,(methfun)cb_NoSetAttrib,a_any,a_null);
AddMethod(0,attr,(methfun)cb_SetAttrib,a_any,a_null);
AddMethod(0,tmp,(methfun)cb_GetAttrib,a_any,a_null);
}
if(gfun)
AddMethod(0,tmp,(methfun)cb_GetAttrib,a_any,a_null);
else
AddMethod(0,tmp,(methfun)cb_NoGetAttrib,a_any,a_null);
bool flext_base::InitAttrib(int argc,const t_atom *argv)
{
if(procattr) {
int nxt = 0,cur = 0;
while(nxt < argc) {
// find next @symbol
cur = nxt;
if(nxt) ++nxt;
for(; nxt < argc; ++nxt)
if(IsString(argv[nxt]) && *GetString(argv[nxt]) == '@') break;
if(!cur) continue;
const t_symbol *tag = MakeSymbol(GetString(argv[cur])+1);
SetAttrib(tag,nxt-cur-1,argv+cur+1);
}
}
return true;
}
bool flext_base::ListAttrib()
......@@ -69,60 +81,52 @@ bool flext_base::ListAttrib()
return true;
}
bool flext_base::cb_NoGetAttrib(flext_base *c,const t_symbol *tag,int argc,const t_atom *argv)
{
post("%s - attribute %s has no get method",c->thisName(),GetString(tag));
return true;
}
bool flext_base::cb_NoSetAttrib(flext_base *c,const t_symbol *tag,int argc,const t_atom *argv)
{
post("%s - attribute %s has no set method",c->thisName(),GetString(tag));
return true;
}
bool flext_base::SetAttrib(const t_symbol *tag,int argc,const t_atom *argv)
{
attritem *a = attrhead;
for(; a && a->tag != tag; a = a->nxt) {}
if(a) {
bool ok = true;
AtomList la;
t_any any;
switch(a->argtp) {
case a_float:
if(argc == 1 && CanbeFloat(argv[0])) {
any.ft = GetAFloat(argv[0]);
if(a->sfun) {
bool ok = true;
AtomList la;
t_any any;
switch(a->argtp) {
case a_float:
if(argc == 1 && CanbeFloat(argv[0])) {
any.ft = GetAFloat(argv[0]);
((methfun_1)a->sfun)(this,any);
}
else ok = false;
break;
case a_int:
if(argc == 1 && CanbeInt(argv[0])) {
any.it = GetAInt(argv[0]);
((methfun_1)a->sfun)(this,any);
}
else ok = false;
break;
case a_symbol:
if(argc == 1 && IsSymbol(argv[0])) {
any.st = GetSymbol(argv[0]);
((methfun_1)a->sfun)(this,any);
}
else ok = false;
break;
case a_LIST:
any.vt = &(la(argc,argv));
((methfun_1)a->sfun)(this,any);
break;
default:
ERRINTERNAL();
}
else ok = false;
break;
case a_int:
if(argc == 1 && CanbeInt(argv[0])) {
any.it = GetAInt(argv[0]);
((methfun_1)a->sfun)(this,any);
}
else ok = false;
break;
case a_symbol:
if(argc == 1 && IsSymbol(argv[0])) {
any.st = GetSymbol(argv[0]);
((methfun_1)a->sfun)(this,any);
}
else ok = false;
break;
case a_LIST:
any.vt = &(la(argc,argv));
((methfun_1)a->sfun)(this,any);
break;
default:
ERRINTERNAL();
}
if(!ok)
post("%s - wrong arguments for attribute %s",thisName(),GetString(tag));
if(!ok)
post("%s - wrong arguments for attribute %s",thisName(),GetString(tag));
}
else
post("%s - attribute %s has no get method",thisName(),GetString(tag));
}
else
error("%s - %s: attribute not found",thisName(),tag);
......@@ -138,36 +142,40 @@ bool flext_base::GetAttrib(const t_symbol *tag,int argc,const t_atom *argv)
for(; a && a->gtag != tag; a = a->nxt) {}
if(a) {
AtomList la;
t_any any;
switch(a->argtp) {
case a_float: {
((methfun_1)a->gfun)(this,any);
la(1);
SetFloat(la[0],any.ft);
break;
}
case a_int: {
((methfun_1)a->gfun)(this,any);
la(1);
SetInt(la[0],any.it);
break;
}
case a_symbol: {
((methfun_1)a->gfun)(this,any);
la(1);
SetSymbol(la[0],any.st);
break;
}
case a_LIST: {
any.vt = &la;
((methfun_1)a->gfun)(this,any);
break;
}
default:
ERRINTERNAL();
if(a->gfun) {
AtomList la;
t_any any;
switch(a->argtp) {
case a_float: {
((methfun_1)a->gfun)(this,any);
la(1);
SetFloat(la[0],any.ft);
break;
}
case a_int: {
((methfun_1)a->gfun)(this,any);
la(1);
SetInt(la[0],any.it);
break;
}
case a_symbol: {
((methfun_1)a->gfun)(this,any);
la(1);
SetSymbol(la[0],any.st);
break;
}
case a_LIST: {
any.vt = &la;
((methfun_1)a->gfun)(this,any);
break;
}
default:
ERRINTERNAL();
}
ToOutAnything(outattr,a->tag,la.Count(),la.Atoms());
}
ToOutAnything(outattr,a->tag,la.Count(),la.Atoms());
else
post("%s - attribute %s has no set method",thisName(),GetString(tag));
}
else
error("%s - %s: attribute not found",thisName(),tag);
......
......@@ -129,7 +129,8 @@ class FLEXT_EXT flext_obj:
void InitProblem() { init_ok = false; }
virtual bool Init() { return true; }
// this also guarantees that there are no instances of flext_obj
virtual bool Init() = 0;
virtual void Exit() {}
// --- help -------------------------------------------------------
......
......@@ -50,6 +50,8 @@ class flext_base:
{
FLEXT_HEADER_S(flext_base,flext_obj,Setup)
friend class flext_obj;
public:
/*! \defgroup FLEXT_C_BASE Flext basic class functionality
......@@ -397,6 +399,11 @@ protected:
// inlets and outlets
/*! \brief Set up inlets and outlets
\return True on successful creation of all inlets and outlets
*/
virtual bool Init();
struct xlet {
enum type {
tp_none = 0,
......@@ -421,7 +428,7 @@ protected:
void AddAttrib(const char *attr,bool (*get)(flext_base *,float &),bool (*set)(flext_base *,float &)) { AddAttrib(attr,a_float,(methfun)get,(methfun)set); }
void AddAttrib(const char *attr,bool (*get)(flext_base *,int &),bool (*set)(flext_base *,int &)) { AddAttrib(attr,a_int,(methfun)get,(methfun)set); }
void AddAttrib(const char *attr,bool (*get)(flext_base *,t_symbol *&),bool (*set)(flext_base *,t_symbol *&)) { AddAttrib(attr,a_symbol,(methfun)get,(methfun)set); }
void AddAttrib(const char *attr,bool (*get)(flext_base *,AtomList &),bool (*set)(flext_base *,AtomList &)) { AddAttrib(attr,a_LIST,(methfun)get,(methfun)set); }
void AddAttrib(const char *attr,bool (*get)(flext_base *,AtomList *&),bool (*set)(flext_base *,AtomList *&)) { AddAttrib(attr,a_LIST,(methfun)get,(methfun)set); }
//! @}
......@@ -489,11 +496,6 @@ private:
void AddXlet(xlet::type tp,int mult,const char *desc,xlet *&root);
void DescXlet(int ix,const char *desc,xlet *&root);
/*! \brief Set up inlets and outlets
\return True on successful creation of all inlets and outlets
*/
virtual bool Init();
union t_any {
float ft;
int it;
......@@ -522,6 +524,8 @@ private:
void AddAttrib(const char *attr,metharg tp,methfun gfun,methfun sfun);
bool InitAttrib(int argc,const t_atom *argv);
bool ListAttrib();
bool GetAttrib(const t_symbol *s,int argc,const t_atom *argv);
bool SetAttrib(const t_symbol *s,int argc,const t_atom *argv);
......@@ -529,8 +533,6 @@ private:
static bool cb_ListAttrib(flext_base *c) { return c->ListAttrib(); }
static bool cb_GetAttrib(flext_base *c,const t_symbol *s,int argc,const t_atom *argv) { return c->GetAttrib(s,argc,argv); }
static bool cb_SetAttrib(flext_base *c,const t_symbol *s,int argc,const t_atom *argv) { return c->SetAttrib(s,argc,argv); }
static bool cb_NoGetAttrib(flext_base *c,const t_symbol *s,int argc,const t_atom *argv);
static bool cb_NoSetAttrib(flext_base *c,const t_symbol *s,int argc,const t_atom *argv);
#ifdef FLEXT_THREADS
bool shouldexit;
......@@ -550,7 +552,6 @@ private:
static void QTick(flext_base *th);
void Queue(qmsg *m);
class thr_entry;
thr_entry *thrhead,*thrtail;
ThrMutex tlmutex;
#endif
......
......@@ -871,16 +871,21 @@ static bool FLEXT_SET_PRE(VAR)(flext_base *c,TP &arg) \
static bool FLEXT_GET_PRE(VAR)(flext_base *c,TP &arg) \
{ arg = FLEXT_CAST<thisType *>(c)->VAR; return true; }
#define FLEXT_CALLSET_F(SFUN) FLEXT_CALLSET_(SFUN,float)
#define FLEXT_CALLSET_I(SFUN) FLEXT_CALLSET_(SFUN,int)
#define FLEXT_CALLSET_S(SFUN) FLEXT_CALLSET_(SFUN,t_symptr)
#define FLEXT_CALLSET_V(SFUN) FLEXT_CALLSET_(SFUN,AtomList)
#define FLEXT_CALLSET_V(FUN) \
static bool FLEXT_SET_PRE(FUN)(flext_base *c,AtomList *&arg) \
{ FLEXT_CAST<thisType *>(c)->FUN(*arg); return true; }
#define FLEXT_CALLGET_F(GFUN) FLEXT_CALLGET_(GFUN,float)
#define FLEXT_CALLGET_I(GFUN) FLEXT_CALLGET_(GFUN,int)
#define FLEXT_CALLGET_S(GFUN) FLEXT_CALLGET_(GFUN,t_symptr)
#define FLEXT_CALLGET_V(GFUN) FLEXT_CALLGET_(GFUN,AtomList)
#define FLEXT_CALLGET_V(FUN) \
static bool FLEXT_GET_PRE(FUN)(flext_base *c,AtomList *&arg) \
{ FLEXT_CAST<thisType *>(c)->FUN(*arg); return true; }
#define FLEXT_CALLXFER_F(GFUN,SFUN) FLEXT_CALLGET_F(GFUN) FLEXT_CALLSET_F(SFUN)
#define FLEXT_CALLXFER_I(GFUN,SFUN) FLEXT_CALLGET_I(GFUN) FLEXT_CALLSET_I(SFUN)
......@@ -890,12 +895,18 @@ static bool FLEXT_GET_PRE(VAR)(flext_base *c,TP &arg) \
#define FLEXT_ATTRSET_F(VAR) FLEXT_ATTRSET_(VAR,float)
#define FLEXT_ATTRSET_I(VAR) FLEXT_ATTRSET_(VAR,int)
#define FLEXT_ATTRSET_S(VAR) FLEXT_ATTRSET_(VAR,t_symptr)
#define FLEXT_ATTRSET_V(VAR) FLEXT_ATTRSET_(VAR,AtomList)
#define FLEXT_ATTRSET_V(VAR) \
static bool FLEXT_SET_PRE(VAR)(flext_base *c,AtomList *&arg) \
{ FLEXT_CAST<thisType *>(c)->VAR = *arg; return true; }
#define FLEXT_ATTRGET_F(VAR) FLEXT_ATTRGET_(VAR,float)
#define FLEXT_ATTRGET_I(VAR) FLEXT_ATTRGET_(VAR,int)
#define FLEXT_ATTRGET_S(VAR) FLEXT_ATTRGET_(VAR,t_symptr)
#define FLEXT_ATTRGET_V(VAR) FLEXT_ATTRGET_(VAR,AtomList)
#define FLEXT_ATTRGET_V(VAR) \
static bool FLEXT_GET_PRE(VAR)(flext_base *c,AtomList *&arg) \
{ *arg = FLEXT_CAST<thisType *>(c)->VAR; return true; }
#define FLEXT_ATTRXFER_F(VAR) FLEXT_ATTRGET_F(VAR) FLEXT_ATTRSET_F(VAR)
#define FLEXT_ATTRXFER_I(VAR) FLEXT_ATTRGET_I(VAR) FLEXT_ATTRSET_I(VAR)
......
......@@ -227,7 +227,7 @@ void flext_base::ToOutAnything(outlet *o,const t_symbol *s,int argc,const t_atom
bool flext_base::Init()
{
if(!flext_obj::Init()) return false;
// if(!flext_obj::Init()) return false;
bool ok = true;
......
......@@ -10,8 +10,7 @@ WARRANTIES, see the file, "license.txt," in this distribution.
// Code for handling of object creation functions
#include "flbase.h"
#include "flsupport.h"
#include "flext.h"
#include <stdarg.h>
#include <string.h>
......@@ -168,17 +167,20 @@ void flext_obj::lib_init(const char *name,void setupfun())
void flext_obj::obj_add(bool lib,bool dsp,const char *idname,const char *names,void setupfun(t_class *),flext_obj *(*newfun)(int,t_atom *),void (*freefun)(flext_hdr *),int argtp1,...)
{
// get first possible object name
const t_symbol *nsym = MakeSymbol(extract(names));
#ifdef _DEBUG
if(dsp) chktilde(idname);
if(dsp) chktilde(GetString(nsym));
#endif
// set dynamic class pointer
t_class **cl =
#ifdef MAXMSP
lib?&lib_class:
#endif
new t_class *;
const t_symbol *nsym = MakeSymbol(extract(names));
// register object class
#ifdef PD
*cl = ::class_new(
......@@ -308,23 +310,27 @@ flext_hdr *flext_obj::obj_new(const t_symbol *s,int argc,t_atom *argv)
flext_obj::m_holder = obj;
flext_obj::m_holdname = l->name;
// get actual flext object (newfun calls "new flext_obj()")
if(lo->argc >= 0)
// for interpreted arguments
obj->data = lo->newfun(lo->argc,args);
else
// for variable argument list
obj->data = lo->newfun(argc,argv);
argc = lo->argc,argv = args;
// get actual flext object (newfun calls "new flext_obj()")
obj->data = lo->newfun(argc,argv);
flext_obj::m_holder = NULL;
flext_obj::m_holdname = NULL;
if(!obj->data ||
bool ok = obj->data ||
// check constructor exit flag
!obj->data->InitOk() ||
// call virtual init function
!obj->data->Init())
{
obj->data->InitOk();
if(ok) // set cmdline attributes (this is a flext_base function!)
ok = ((flext_base *)obj->data)->InitAttrib(argc,argv);
if(ok) // call virtual init function
ok = obj->data->Init();
if(!ok) {
// there was some init error, free object
lo->freefun(obj);
obj = NULL;
......
Markdown is supported
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