Fellow REBOLers,


I have created a C++ REBOL value class to load and save a small sub-set of REBOL
formatted values.  In my project I am using it to read and write configuration
files.  One of these config files is a plug-in database upon which I run
another REBOL script to genterate an HTML listing of the current plug-ins.

The code and associated HTML documentation are in an archive at
http://members.home.com/krobillard/rvalue.tar.gz.  This version is released
under the MIT License (it will also be release under the GPL with my project).

Here is part of the RValue class declaration:

----------------------------------------------------
typedef unsigned long RTuple;
 
 
class RValue
{
public:
 
    enum eType
    {
        kNull,
        kBlock,
        kDecimal,
        kInteger,
        kLogic,
        kString,
        kTuple,
    };
 
    static RValue* parse( const char* buffer, const char** pos = 0 );
    static const char* typeName( RValue::eType );
 
    RValue();
    RValue( const char* n );
    RValue( const char* n, const char* str );
    RValue( const char* n, int i );
    RValue( const char* n, float d );
    RValue( const char* n, RTuple t );
 
    ~RValue();
 
    RValue::eType type() const { return _type; }
 
    const char* name() const { return _name; }
    void setName( const char* );
 
    RValue* find( const char* ) const;
    RValue* find( const char*, RValue::eType checkType ) const;
 
    void write( FILE*, int nest = -1 ) const;
 
    void assign( RValue* );
 
    void setDecimal( float );
    void setInteger( int );
    void setLogic( bool );
    void setString( const char* );
    void setTuple( RTuple );
    void setTuple( RTuple a, RTuple b, RTuple c, RTuple d = 0 );
 
    bool isBlock() const { return _type == kBlock; }
    bool isDecimal() const { return _type == kDecimal; }
    bool isInteger() const { return _type == kInteger; }
    bool isLogic() const { return _type == kLogic; }
    bool isString() const { return _type == kString; }
    bool isTuple() const { return _type == kTuple; }

    // These are valid only if type() is appropriate.
 
    const char* string() const { return _string; }
 
    float decimal() const { return _decimal; }
 
    int integer() const { return _integer; }
 
    bool logic() const { return _logic; }
 
    RTuple tuple() const { return _tuple; }
    unsigned char tuple0() const { return _tuple & 0xff; }
    unsigned char tuple1() const { return (_tuple >> 8) & 0xff; }
    unsigned char tuple2() const { return (_tuple >> 16) & 0xff; }
    unsigned char tuple3() const { return (_tuple >> 24) & 0xff; }
 
    void append( RValue* );
    RValue* remove( RValue* );
    void clear();
 
    class iterator
    {
    public:
        iterator() {}
        iterator( RValue* p ) : v(p) {}
        iterator( const iterator& it ) : v(it.v) {}
        RValue* operator*() { return v; }
        iterator& operator=( const iterator it ) { v = it.v; return *this; }
        bool operator==( const iterator it ) { return v == it.v; }
        bool operator!=( const iterator it ) { return v != it.v; }
        iterator operator++() { v = v->_next; return *this; }
    private:
        RValue* v;
    };
 
    iterator begin() const { return _block; }
    iterator end() const { return 0; }

private:
    // ...more here
};
----------------------------------------------------

I hope someone finds this useful.  Still eagerly awaiting Rebol/Command...


Cheers,
-Karl Robillard

Reply via email to