473,385 Members | 2,274 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.

transform into templates

Hi,

How can I transform the following functions into templated version :

class foo
{
public:

Ret_t GetProfileCount( UShort_t& a_nCount )
{
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_tGetProfileCount;
};
but of course it doesn't work like that.

Some help is needed.

May 14 '07 #1
8 1601
Mosfet wrote:
Hi,

How can I transform the following functions into templated version :

class foo
{
public:

Ret_t GetProfileCount( UShort_t& a_nCount )
{
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 ),
Should probably be

(ULong_t) sizeof( a_argType ),

....
( MemPtr_t ) &a_argType );
}

typedef GetProp1<UShort_tGetProfileCount;
};
but of course it doesn't work like that.
Not sure what you mean by "doesn't work".

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
May 14 '07 #2
Victor Bazarov a écrit :
Mosfet wrote:
>Hi,

How can I transform the following functions into templated version :

class foo
{
public:

Ret_t GetProfileCount( UShort_t& a_nCount )
{
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 ),

Should probably be

(ULong_t) sizeof( a_argType ),

...
>( MemPtr_t ) &a_argType );
}

typedef GetProp1<UShort_tGetProfileCount;
};
but of course it doesn't work like that.

Not sure what you mean by "doesn't work".

V
error C2146: syntax error : missing ';' before identifier 'GetProfileCount'
error C4430: missing type specifier - int assumed. Note: C++ does not
support default-int
error C2365: 'CSyncClientSession::GetProp1' : redefinition; previous
definition was 'member function'
error C4430: missing type specifier - int assumed. Note: C++ does not
support default-int
May 14 '07 #3
Mosfet wrote:
Victor Bazarov a écrit :
>Mosfet wrote:
>>Hi,

How can I transform the following functions into templated version :

class foo
{
public:

Ret_t GetProfileCount( UShort_t& a_nCount )
{
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 ),

Should probably be

(ULong_t) sizeof( a_argType ),

...
>>( MemPtr_t ) &a_argType );
}

typedef GetProp1<UShort_tGetProfileCount;
};
but of course it doesn't work like that.

Not sure what you mean by "doesn't work".

V
error C2146: syntax error : missing ';' before identifier
'GetProfileCount' error C4430: missing type specifier - int assumed.
Note: C++ does not support default-int
error C2365: 'CSyncClientSession::GetProp1' : redefinition; previous
definition was 'member function'
error C4430: missing type specifier - int assumed. Note: C++ does not
support default-int
FAQ 5.8.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
May 14 '07 #4
Victor Bazarov a écrit :
Mosfet wrote:
>Victor Bazarov a écrit :
>>Mosfet wrote:
Hi,

How can I transform the following functions into templated version :

class foo
{
public:

Ret_t GetProfileCount( UShort_t& a_nCount )
{
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 ),
Should probably be

(ULong_t) sizeof( a_argType ),

...

( MemPtr_t ) &a_argType );
}

typedef GetProp1<UShort_tGetProfileCount;
};
but of course it doesn't work like that.
Not sure what you mean by "doesn't work".

V
error C2146: syntax error : missing ';' before identifier
'GetProfileCount' error C4430: missing type specifier - int assumed.
Note: C++ does not support default-int
error C2365: 'foo::GetProp1' : redefinition; previous
definition was 'member function'
error C4430: missing type specifier - int assumed. Note: C++ does not
support default-int

FAQ 5.8.

V
I am not sure it's MS specific. I think I made a mistake ...
May 14 '07 #5
Mosfet wrote:
Victor Bazarov a écrit :
>Mosfet wrote:
>>Victor Bazarov a écrit :
Mosfet wrote:
Hi,
>
How can I transform the following functions into templated
version : class foo
{
public:
>
Ret_t GetProfileCount( UShort_t& a_nCount )
{
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 ),
Should probably be

(ULong_t) sizeof( a_argType ),

...

( MemPtr_t ) &a_argType );
}
>
typedef GetProp1<UShort_tGetProfileCount;
};
>
>
but of course it doesn't work like that.
Not sure what you mean by "doesn't work".

V
error C2146: syntax error : missing ';' before identifier
'GetProfileCount' error C4430: missing type specifier - int assumed.
Note: C++ does not support default-int
error C2365: 'foo::GetProp1' : redefinition; previous
definition was 'member function'
error C4430: missing type specifier - int assumed. Note: C++ does
not support default-int

FAQ 5.8.

V
I am not sure it's MS specific. I think I made a mistake ...
Who said anything about MS specificity? I don't want to assume anything
about your 'ULong_t', 'Ret_t' and so on. Do you have them defined? Do
not make me guess. If you want help, provide enough information. And
do read the FAQ.

V
May 14 '07 #6
Victor Bazarov a écrit :
Mosfet wrote:
>Victor Bazarov a écrit :
>>Mosfet wrote:
Victor Bazarov a écrit :
Mosfet wrote:
>Hi,
>>
>How can I transform the following functions into templated
>version : class foo
>{
>public:
>>
>Ret_t GetProfileCount( UShort_t& a_nCount )
>{
>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 ),
Should probably be
>
(ULong_t) sizeof( a_argType ),
>
...
>
>( MemPtr_t ) &a_argType );
>}
>>
>typedef GetProp1<UShort_tGetProfileCount;
>};
>>
>>
>but of course it doesn't work like that.
Not sure what you mean by "doesn't work".
>
V
error C2146: syntax error : missing ';' before identifier
'GetProfileCount' error C4430: missing type specifier - int assumed.
Note: C++ does not support default-int
error C2365: 'foo::GetProp1' : redefinition; previous
definition was 'member function'
error C4430: missing type specifier - int assumed. Note: C++ does
not support default-int
FAQ 5.8.

V
I am not sure it's MS specific. I think I made a mistake ...

Who said anything about MS specificity? I don't want to assume anything
about your 'ULong_t', 'Ret_t' and so on. Do you have them defined? Do
not make me guess. If you want help, provide enough information. And
do read the FAQ.

V

Ok sorry.
Yes it's define like that

typedef short Short_t; // short integer, 16 Bytes
typedef long Long_t; // long integer, 32 Bytes
typedef char Char_t;
typedef unsigned short UShort_t; // unsigned short integer, 16 Bytes
typedef unsigned long ULong_t; // unsigned long integer, 32 Bytes
typedef char* String_t; // String pointer,
typedef unsigned char Byte_t; // a single byte
typedef Byte_t Boolean_t; // a boolean
typedef Short_t Ret_t; // Return Type of API Commands
typedef Long_t Length_t; // System dependent string length
typedef Short_t MemHandle_t; // Memory object Handle
typedef unsigned char* MemPtr_t; // Memory object Pointer
typedef void* VoidPtr_t; // Void Pointer
typedef Long_t MemSize_t; // System dependent memory object size
typedef unsigned char MemByte_t; // Memory element
typedef unsigned int Flag_t; // A generic flag type. This type is
used to
// declare variables in structures
wherever
// flags are used.

class foo
{
public:

foo();
virtual ~foo();

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<SM_PRIV_CMD_GET_PROFILE_COUNT, UShort_tGetProfileCount;
};
May 14 '07 #7
On May 15, 6:41 am, Mosfet <anonym...@free.frwrote:
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_tGetProfileCount;

};

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::param_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::stringval = Get<Names>();

If so, you need to add some more stuff to your traits class so that it
works for all types.

May 14 '07 #8
Mosfet wrote:
[..some senseless type renaming snipped..]
class foo
{
public:

foo();
virtual ~foo();

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<SM_PRIV_CMD_GET_PROFILE_COUNT, UShort_t>
'GetProp1' has only _one_ template argument.
GetProfileCount; };
'GetProp1' is a function template. I don't think you can use that
template-id to form a typedef-id. If you're trying to do what I
think you're trying to do, you'd be much better off with a simple
function that calls the template instance:

Ret_t GetProfileCount(UShort_t & arg) {
return GetProp1(SM_PRIV_CMD..., arg);
}

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
May 15 '07 #9

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

Similar topics

1
by: Barry Anderberg | last post by:
I have an XML document that I am trying to display in my ASP.NET page. I am using an XSL Transform to display repeating XML data in a specific format. It reads the data, and displays it on my...
6
by: Gary Huntress | last post by:
Hi, I'm having trouble with an xslt transform. I'm trying to transform a vector into an array of width N. For example here is my vector: <data> <x id="1">1.2</x> <x id="2">.2</x> <x...
0
by: Xiaolei Li | last post by:
first off, i'm a total newbie at this stuff so excuse any wrong usage of terminology or whatever else. i have a XSL to transform a Document such that all "text" nodes will have a "SPAN" inserted...
2
by: Peter Clifton | last post by:
Hello all, I am very new to this subject and learning by example. I have a small inconsistency in an XML file when transformed using different processors. I was wondering if someone could shed...
3
by: Jason S | last post by:
Hello Group, I am just about tearing my hair out with this one and thought someone may have some insight. I have a transform that wasn't working so I grabbed the nearest debugger (xselerator)...
3
by: Andy | last post by:
Hi all, I'm having a problem doing an Xslt transform in code. I've done it before, so I'm not really sure why its not working. The problem is that the result of the transform is an empty...
1
by: Gi | last post by:
Hi, Can anyone tell me you can I transform this kind of XML: <Cont ID='faqs'> <Conts ID=''> <Elements> <Data></Data> <Pergunta></Pergunta> <Resposta></Resposta> </Elements>
12
by: das | last post by:
Hello all, I am using .NET XSLT to transform an XML into another XML file. All this is fine with small files, but when tested with big files (30MB) it is taking between 1hr-2hrs to just transform...
7
by: Bilal | last post by:
Hello all, I came across this problem while working out the bugs in my identity trasnformation stylesheets but sidestepped it for later to see if there is an easier/better solution. This is...
4
by: David Schwartz | last post by:
Thanks for your help Martin. I'd like to explore this in steps if possible. So when I execute the following transform, I don't get any attributes. Any ideas as to why? Shouldn't I get all the nodes...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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: 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.