New keywords

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • hari4063

    New keywords

    This is mostly for Borland Builder and new keyword "__property ". I try (this is not my original idea) to make class (template) that imitates __property. Basic idea was proposed by my friend, but I try to rewrite Borlands VCL without __property to ensure that only standard C++ is used.

    Is any work similary to this one.


    Greetz.

  • AirPete

    #2
    Re: New keywords

    hari4063 wrote:[color=blue]
    > This is mostly for Borland Builder and new keyword "__property ". I
    > try (this is not my original idea) to make class (template) that
    > imitates __property. Basic idea was proposed by my friend, but I try
    > to rewrite Borlands VCL without __property to ensure that only
    > standard C++ is used.
    >
    > Is any work similary to this one.
    >
    >
    > Greetz.[/color]

    Is something like this what you want (I don't know what borland's extensions
    do)?

    - Pete


    #include <iostream>
    #include <string>
    using namespace std;
    template <class T, class Modify>
    class property
    {
    protected:
    T var;
    Modify mod;
    public:
    property<T, Modify>(const T& init, const Modify& m)
    : mod(m), var(init)
    {}
    operator T()
    {
    return var;
    }
    property& operator =(const T& val)
    {
    if(!mod(val))
    throw invalid_argumen t("bad property argument.");
    var = val;
    return *this;
    }
    };
    template<class T>
    struct RangeValidation PropModified
    {
    string msg;
    T minval, maxval;
    public:
    RangeValidation PropModified<T> (string m, const T& minv, const T& maxv)
    : msg(m),
    minval(minv),
    maxval(maxv)
    {}
    bool operator() (const T& val)
    {
    if(val >= minval && val <= maxval)
    {
    cout << msg;
    return true;
    }
    else
    return false;
    }
    };
    int main(int argc, char* argv[])
    {
    property<int, RangeValidation PropModified<in t> >
    p(0, RangeValidation PropModified<in t>("the property is being modifed!\n", 0,
    100));
    cout << p << endl;
    p = 5;
    cout << p << endl;
    p = 10;
    cout << p << endl;
    try
    {
    p = -1;
    cout << p << endl;
    p = 1000;
    cout << p << endl;
    }
    catch(invalid_a rgument ex)
    {
    cout << ex.what() << endl;
    }
    return 0;
    }


    Comment

    Working...