[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Gnash-dev] Implementation: Doc vs. Code P.S.
From: |
Michael Meier |
Subject: |
Re: [Gnash-dev] Implementation: Doc vs. Code P.S. |
Date: |
Sun, 19 Nov 2006 19:37:06 +0100 |
User-agent: |
Debian Thunderbird 1.0.2 (X11/20060926) |
> As I don't know an other place to post this to, I attached Boolean.h and
> Boolean.cpp! Feedback welcome!
Of course I forgot to attach them!
Here they are...
//
// Copyright (C) 2005, 2006 Free Software Foundation, Inc.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
//
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "Boolean.h"
#include "as_object.h" // for inheritance
#include "log.h"
#include "fn_call.h"
#include "smart_ptr.h" // for boost intrusive_ptr
#include "builtin_function.h" // need builtin_function
namespace gnash {
void boolean_tostring(const fn_call& fn);
void boolean_valueof(const fn_call& fn);
void boolean_ctor(const fn_call& fn);
static void
attachBooleanInterface(as_object& o)
{
o.set_member("tostring", &boolean_tostring);
o.set_member("valueof", &boolean_valueof);
}
static as_object*
getBooleanInterface()
{
static boost::intrusive_ptr<as_object> o;
if ( ! o )
{
o = new as_object();
attachBooleanInterface(*o);
}
return o.get();
}
class boolean_as_object: public as_object
{
public:
boolean_as_object()
:
as_object(getBooleanInterface())
{}
boolean_as_object(bool _val)
:
as_object(getBooleanInterface())
{
val = _val;
}
// override from as_object ?
//const char* get_text_value() const { return "Boolean"; }
// override from as_object ?
//double get_numeric_value() const { return 0; }
bool val;
};
void boolean_tostring(const fn_call& fn) {
static char* strtrue = "true";
static char* strfalse = "false";
boolean_as_object* boolobj = (boolean_as_object*) (as_object*)
fn.this_ptr;
if (boolobj->val)
fn.result->set_string(strtrue);
else
fn.result->set_string(strfalse);
}
void boolean_valueof(const fn_call& fn) {
boolean_as_object* boolobj = (boolean_as_object*) (as_object*) fn.this_ptr;
fn.result->set_bool(boolobj->val);
}
void
boolean_ctor(const fn_call& fn)
{
bool val = false;
if (fn.nargs > 0)
{
val = fn.arg(0).to_bool();
}
boost::intrusive_ptr<as_object> obj = new boolean_as_object(val);
fn.result->set_as_object(obj.get()); // will keep alive
}
// extern (used by Global.cpp)
void boolean_class_init(as_object& global)
{
// This is going to be the global Boolean "class"/"function"
static boost::intrusive_ptr<builtin_function> cl;
if ( cl == NULL )
{
cl=new builtin_function(&boolean_ctor, getBooleanInterface());
// replicate all interface to class, to be able to access
// all methods as static functions
attachBooleanInterface(*cl);
}
// Register _global.Boolean
global.set_member("Boolean", cl.get());
}
} // end of gnash namespace
//
// Copyright (C) 2005, 2006 Free Software Foundation, Inc.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
//
#ifndef __GNASH_ASOBJ_BOOLEAN_H__
#define __GNASH_ASOBJ_BOOLEAN_H__
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <memory> // for auto_ptr
namespace gnash {
class as_object;
/// Initialize the global Boolean class
void boolean_class_init(as_object& global);
/// Return a Boolean instance (in case the core lib needs it)
//std::auto_ptr<as_object> init_boolean_instance();
} // end of gnash namespace
// __GNASH_ASOBJ_BOOLEAN_H__
#endif
- [Gnash-dev] Implementation: Doc vs. Code, Michael Meier, 2006/11/17
- Re: [Gnash-dev] Implementation: Doc vs. Code, strk, 2006/11/17
- Message not available
- Message not available
- Message not available
- Message not available
- Re: [Gnash-dev] Implementation: Doc vs. Code, Michael Meier, 2006/11/18
- Re: [Gnash-dev] Implementation: Doc vs. Code, strk, 2006/11/18
- Re: [Gnash-dev] Implementation: Doc vs. Code, strk, 2006/11/18
- Re: [Gnash-dev] Implementation: Doc vs. Code, Michael Meier, 2006/11/19
- Re: [Gnash-dev] Implementation: Doc vs. Code P.S.,
Michael Meier <=
- Re: [Gnash-dev] Implementation: Doc vs. Code, strk, 2006/11/20
- Re: [Gnash-dev] Implementation: Doc vs. Code, mark cox, 2006/11/21