Re: Properties with non standard C++ (REALLY SORRY ABOUT THAT)
Vincent RICHOMME wrote:
Vincent RICHOMME a ?crit :
Victor Bazarov a ?crit :
Vincent RICHOMME wrote:
Hi,
first I would like to apologize about my question because usually I
hate specific implementation but in this case I really would like
an answer. [..]
Is there any reason why you dind't post it to the newsgroup that
specifically caters to the needs of Visual Studio?
V
Yes and a good one : people here have better knowledge of C++ and are
more used to manipulate concept like template, OOP.
When I see people who can write boost class for instance, I must
admit I am impressed and you cannot find people like that on any
newsgroup.
But if you can give me a more standard approach I am curious.
The problem here is my class has lots of methods with different names
that almost do the same :
class foo
{
public:
...
LPCTSTR GetName();
void SetName(LPCTSTR Value);
A GetABC();
void SetABC(A Value);
A GetABC();
void SetDEF(B Value);
B GetDEF();
...
};
I don't know what to recommend you. There is no one "hard and fast"
solution that would be good for all. In many cases separating the
concepts (to reduce the individual number of "properties") is good
enough a way to go:
class hasName {
whatevertypeyoulike name;
public:
LPCTSTR GetName() const;
void SetName(LPCTSTR);
};
...
class foo : public hasName .... {
...
};
(yes
Essentially this employs the "policy" technique (see Alexandrescu,
"Modern C++ Design").
You can also create (and possibly pre-fill) a 'std::map' of all the
named values of your "properties". You then have a slightly smaller
set of functions:
class foo {
public:
boost::any GetProp(LPCTSTR) const;
void SetProp(LPCTSTR, boost::any);
};
There are plenty of other portable solutions, you just need to
search for them. Have you actually tried looking, say, on Google?
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask