M
mosfet
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<TCHAR> tstring;
#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 ?
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<TCHAR> tstring;
#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 ?