Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > New keywords

Reply
Thread Tools

New keywords

 
 
hari4063
Guest
Posts: n/a
 
      02-05-2004
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.

 
Reply With Quote
 
 
 
 
AirPete
Guest
Posts: n/a
 
      02-05-2004
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;
}


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
new keywords for (C++)++ Gernot Frisch C++ 11 06-16-2005 05:02 PM
Firefox 0.9.3 Smart Keywords disable? Michael Volland Firefox 0 10-09-2004 06:25 PM
Firefox 0.9.3 Smart Keywords disable? Michael Volland Firefox 0 10-09-2004 06:01 PM
Creating Smart Keywords for Mozilla Firebird (using Quick Searches) Who Firefox 1 12-06-2003 01:37 AM
Creating Smart Keywords for Firebird Nick Firefox 0 08-06-2003 12:01 AM



Advertisments