473,385 Members | 1,907 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Member function pointer, delegates

Hi,

In my project I am supposed to test if some HTTP headers belongs to a
know list of system headers so I wrote the following code.
I get a WebRequest class(ported from .net world) and a HttpWebRequest
deriving from it.
In my WebRequest I have some getters/setters defined like this
:

typedef std::basic_string<TCHARtstring;

#define DECL_GET_PROP( PropName, Type ) \
Type& get_##PropName() { return m_##PropName; }

#define DECL_SET_PROP( PropName, Type ) \
void set_##PropName(Type PropVal) { m_##PropName = PropVal; }

#define DECL_GETSET_PROP( PropName, Type ) \
DECL_GET_PROP(PropName, Type) \
DECL_SET_PROP(PropName, Type) \

class WebRequest
{
public:
....
// Properties
virtual DECL_GETSET_PROP(Accept, tstring);
virtual DECL_GETSET_PROP(Connection, tstring);
virtual DECL_GETSET_PROP(ConnectionGroupName, tstring);
virtual DECL_GETSET_PROP(ContentLength, long);
virtual DECL_GETSET_PROP(ContentType, tstring);
virtual DECL_GETSET_PROP(Headers, WebHeaderCollection);
virtual DECL_GETSET_PROP(Method, tstring);
virtual DECL_GETSET_PROP(PreAuthenticate, bool);
virtual DECL_GETSET_PROP(UserAgent, tstring);
virtual DECL_GETSET_PROP(Proxy, tstring);
....
};
I know macros are evil but in my case I find it useful, so the first
line for instance will be expanded as :
virtual tstring& get_Accept() { return m_Accept; }
virtual void set_Accept(tstring PropVal) {m_Accept = PropVal; }
class HttpWebRequest : public WebRequest
{
....
};

In my user class I would like

Ret_t CHttpAdapter::FilterHeader(BOOL a_fSpecific,
LPTSTR a_pHeader, LPTSTR a_pSpecificHeader, LPTSTR a_pValue )
{
Ret_t nRet = TP_ERR_OK;

typedef tstring& (HttpWebRequest::* get_Prop)(void);
typedef void (HttpWebRequest::* set_Prop)(tstring);

struct
{
const TCHAR* szHeader;
get_Prop pfnGet;
set_Prop pfnSet;
}
HdrFilter_t[] =
{
HdrFilter_t[] =
{
{_T("Accept"), &HttpWebRequest::get_Accept,
&HttpWebRequest::set_Accept },
{_T("Connection"), &HttpWebRequest::get_Connection,
&HttpWebRequest::set_Connection },
{_T("Content-Length"), &HttpWebRequest::get_ContentLength,
&HttpWebRequest::set_ContentLength },
{_T("Content-Type"), &HttpWebRequest::get_ContentType,
&HttpWebRequest::set_ContentType },

};

return nRet;
}

My goal is to test the parameters a_pHeader and if it correponds to one
of my struct array to call the member function pointer.
For instance if a_pHeader = "Accept" I would like to call
HttpWebRequest::setAccept( a_pHeader );

The problem is my get/set methods don't have the same signature, for
instance Accept takes a string while ContentLength takes a long.
My question is how to solve this ?
Should I use delegated instaead of member function pointers ?


Oct 4 '07 #1
4 1440
mosfet wrote:
Hi,

In my project I am supposed to test if some HTTP headers belongs to a
know list of system headers so I wrote the following code.
I get a WebRequest class(ported from .net world) and a HttpWebRequest
deriving from it.
In my WebRequest I have some getters/setters defined like this
:

typedef std::basic_string<TCHARtstring;
What's a TCHAR and isn't there an alternative standard type?
#define DECL_GET_PROP( PropName, Type ) \
Type& get_##PropName() { return m_##PropName; }
<snip>
>
class WebRequest
{
public:
....
// Properties
virtual DECL_GETSET_PROP(Accept, tstring);
<snip>
....
};
I know macros are evil but in my case I find it useful, so the first
line for instance will be expanded as :
virtual tstring& get_Accept() { return m_Accept; }
virtual void set_Accept(tstring PropVal) {m_Accept = PropVal; }
It's not the macros that would bother me, its the presence of all the
setter and getter methods, which tent to be indicative of a poor design.
The problem is my get/set methods don't have the same signature, for
instance Accept takes a string while ContentLength takes a long.
My question is how to solve this ?
Should I use delegated instaead of member function pointers ?
There you are, there is a problem with the design! You probably want to
look at the factory pattern, with a process object for each header item,
build a list of header objects for each message and process that.

--
Ian Collins.
Oct 4 '07 #2
Ian Collins a écrit :
mosfet wrote:
>Hi,

In my project I am supposed to test if some HTTP headers belongs to a
know list of system headers so I wrote the following code.
I get a WebRequest class(ported from .net world) and a HttpWebRequest
deriving from it.
In my WebRequest I have some getters/setters defined like this
:

typedef std::basic_string<TCHARtstring;
What's a TCHAR and isn't there an alternative standard type?
>#define DECL_GET_PROP( PropName, Type ) \
Type& get_##PropName() { return m_##PropName; }
<snip>
>class WebRequest
{
public:
....
// Properties
virtual DECL_GETSET_PROP(Accept, tstring);

<snip>
>....
};
I know macros are evil but in my case I find it useful, so the first
line for instance will be expanded as :
virtual tstring& get_Accept() { return m_Accept; }
virtual void set_Accept(tstring PropVal) {m_Accept = PropVal; }
It's not the macros that would bother me, its the presence of all the
setter and getter methods, which tent to be indicative of a poor design.
>The problem is my get/set methods don't have the same signature, for
instance Accept takes a string while ContentLength takes a long.
My question is how to solve this ?
Should I use delegated instaead of member function pointers ?
There you are, there is a problem with the design! You probably want to
look at the factory pattern, with a process object for each header item,
build a list of header objects for each message and process that.
It's not my design, tell Microsoft they have bad design in their .NET
languages.
Oct 4 '07 #3
mosfet a écrit :
>There you are, there is a problem with the design! You probably want to
look at the factory pattern, with a process object for each header item,
build a list of header objects for each message and process that.

It's not my design, tell Microsoft they have bad design in their .NET
languages.

I wanted to do something different but finally I think I am going to use
an old good
if (strcmp("Accept", a_pHeader) == 0)
m_Request->set_Accept(a_pHeader);
else if
....
Oct 4 '07 #4
On 2007-10-04 10:53, mosfet wrote:
Ian Collins a écrit :
>mosfet wrote:
>>Hi,

In my project I am supposed to test if some HTTP headers belongs to a
know list of system headers so I wrote the following code.
I get a WebRequest class(ported from .net world) and a HttpWebRequest
deriving from it.
In my WebRequest I have some getters/setters defined like this
:

typedef std::basic_string<TCHARtstring;
What's a TCHAR and isn't there an alternative standard type?
>>#define DECL_GET_PROP( PropName, Type ) \
Type& get_##PropName() { return m_##PropName; }
<snip>
>>class WebRequest
{
public:
....
// Properties
virtual DECL_GETSET_PROP(Accept, tstring);

<snip>
>>....
};
I know macros are evil but in my case I find it useful, so the first
line for instance will be expanded as :
virtual tstring& get_Accept() { return m_Accept; }
virtual void set_Accept(tstring PropVal) {m_Accept = PropVal; }
It's not the macros that would bother me, its the presence of all the
setter and getter methods, which tent to be indicative of a poor design.
>>The problem is my get/set methods don't have the same signature, for
instance Accept takes a string while ContentLength takes a long.
My question is how to solve this ?
Should I use delegated instaead of member function pointers ?
There you are, there is a problem with the design! You probably want to
look at the factory pattern, with a process object for each header item,
build a list of header objects for each message and process that.

It's not my design, tell Microsoft they have bad design in their .NET
languages.
If you are using the .Net Framework you should use C++/CLR, you will
probably never get it to work correctly with standard C++. For more help
with C++/CLR ask in one of the microsoft.public.* newsgroups or on
http://forums.microsoft.com/.

--
Erik Wikström
Oct 4 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

37
by: Ben | last post by:
Hi, there. Recently I was working on a problem where we want to save generic closures in a data structure (a vector). The closure should work for any data type and any method with pre-defined...
6
by: Peter Oliphant | last post by:
Here is a simplification of my code. Basically, I have a class (A) that can be constructed using a function pointer to a function that returns a bool with no parameters. I then want to create an...
10
by: ChrisB | last post by:
Coming from a C/C++ background, how would I pass a function pointer to a function? I want to write a function that handles certain thread spawning. Here's what I'm trying to invision: function(...
9
by: rellik | last post by:
Hi All, Is there a C# version of the C++ pointer (or reference) to member operator - ..* or ->* Basically I'd like to write a function that can take an object and an offset to a member of the...
4
by: Egbert Nierop \(MVP for IIS\) | last post by:
Hi, I have a CWindowImpl derived class , see below at ***, that needs to subclass simple controls like textboxes. like this...: m_MyControl.SubclassWindow(GetDlgItem(IDC_MyControl).m_hWnd); ...
0
by: Haxan | last post by:
Hi, I have an unmanaged application that converts a function pointer to a delegate and then pass this as a parameter(delegate) to a managed function which then invokes it. Currently Im able to...
6
by: smmk25 | last post by:
Before I state the problem, I just want to let the readers know, I am knew to C++\CLI and interop so please forgive any newbie questions. I have a huge C library which I want to be able to use in...
4
by: =?Utf-8?B?SnVhbiBEZW50?= | last post by:
Hi, I need the equivalent of a pointer to a member function (as used in C++) but in C# 2.0. I know it must be a special way of using delegates but don't know how to make the function associated...
6
by: jmDesktop | last post by:
In a function that takes another function (function pointer) as a argument, or the callback function, which is the one that "calls back"? I'm having a hard time understanding the language. Am I...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.