New keywords

Discussion in 'C++' started by hari4063, Feb 5, 2004.

  1. hari4063

    hari4063 Guest

    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.
    hari4063, Feb 5, 2004
    #1
    1. Advertising

  2. hari4063

    AirPete Guest

    hari4063 wrote:
    > 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.


    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_argument("bad property argument.");
    var = val;
    return *this;
    }
    };
    template<class T>
    struct RangeValidationPropModified
    {
    string msg;
    T minval, maxval;
    public:
    RangeValidationPropModified<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, RangeValidationPropModified<int> >
    p(0, RangeValidationPropModified<int>("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_argument ex)
    {
    cout << ex.what() << endl;
    }
    return 0;
    }
    AirPete, Feb 5, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bruce
    Replies:
    0
    Views:
    687
    Bruce
    Aug 13, 2004
  2. valentin tihomirov

    Advantages of denying keywords as identifiers

    valentin tihomirov, Dec 17, 2004, in forum: VHDL
    Replies:
    8
    Views:
    511
    Mike Treseler
    Dec 28, 2004
  3. dw

    Friend & Protected keywords

    dw, May 15, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    4,851
  4. Gernot Frisch

    new keywords for (C++)++

    Gernot Frisch, Jun 15, 2005, in forum: C++
    Replies:
    11
    Views:
    2,790
    Arkadiy
    Jun 16, 2005
  5. Replies:
    2
    Views:
    448
    Thomas 'PointedEars' Lahn
    Mar 11, 2008
Loading...

Share This Page