Hi,
How can I transform the following functions into templated version :
class foo
{
public:
Ret_t GetProfileCount( UShort_t& a_nCount ) typename Traits::> {
return Get( SM_PRIV_CMD_GET_PROFILE_COUNT,
0,
0,
( ULong_t ) sizeof( UShort_t ),
( MemPtr_t ) &a_nCount );
}
};
I tried this :
class foo
{
public:
template <class Type>
Ret_t GetProp1(Short_t a_cmdId, Type& a_argType)
{
return Get( a_cmdId,
0,
0,
( a_argType ) sizeof( a_argType ),
( MemPtr_t ) &a_argType );
}
typedef GetProp1<UShort_t> GetProfileCount;
};
but of course it doesn't work like that.
Some help is needed.
Is the correlation between SM_PRIV_CMD_GET_PROFILE_COUNT (and other
types) and the argument ?
Then, you need to couple these things somehow:
i.e.
struct ProfileCount
{
enum { cmd_id = SM_PRIV_CMD_GET_PROFILE_COUNT };
typedef ULong_t & param_t;
};
Now define a Get method
template <typename Traits>
Ret_t Get( typename Traits:

aram_t param )
{
return Get(
Traits::cmd_id, 0, 0, sizeof( param ),
reinterpret_cast<MemPtr_t>( & param )
);
}
Now you can write
if ( Get<ProfileCount>( val ) == OK )
So, now you need to ask yourself, did it make a difference to you -
probably not much.
val = Get<ProfileCount>();
That would be a bit better - maybe you can define another Get like
(and keep them both)
.... first add a few things here
struct ProfileCount
{
enum { cmd_id = SM_PRIV_CMD_GET_PROFILE_COUNT };
typedef ULong_t result_t;
typedef result_t & param_t;
};
template <typename Traits>
typename Traits::result_t Get()
{
typename Traits::result_t val;
Ret_t ret = Get(
Traits::cmd_id, 0, 0, sizeof( val ),
reinterpret_cast<MemPtr_t>( & val )
);
if ( ret != OK )
{
abort(); // if it is a programming error
throw Exception<ProfileCount>();
}
return val;
}
OK - now you have two ways to call these GET methods and one lump of
code.
Without knowing more about what it is exactly that you need to do, I
have no idea how to help.
As a guess, you can add some methods in your traits class depending on
the type you're dealing with.
Example: You wanted to return a vector and the Get called required an
array, then you need to provide a method of converting a reference to
a vector to a reference to an array which would work also for non
array types.
Do you need to do somthing like:
std::list<std::string> val = Get<Names>();
If so, you need to add some more stuff to your traits class so that it
works for all types.