471,599 Members | 1,835 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

A Complete ENUM++ (from Besser's CUJ article) Example

Hi,

Can anyone point me to a complete, compilable example
of Besser's ENUM++ mechanism? I downloaded it from
CUJ and gave it a try but got errors just trying to compile
the header enum.h.

--Randy Yates

Jan 6 '06 #1
10 3670
PS: Here's what I get. This is using gcc under fc3.

--RY
#include "enum.h"
int main(int argc, char **argv)
{
return 0;
}

cd /home/yates/modetest/host/app/modetest/
make -f enumpp.mak TARGET=native PLATFORM=linux
DSPROOT_DIR=/home/yates/modetest/ ATSIGN=
enumpp.mak:101: no file name for `include'
Building Component (enumpp) for Application enumpp
In file included from
/home/yates/modetest/host/app/modetest/enum.h:202,
from
/home/yates/modetest/host/app/modetest/enumpp.cpp:1:
/home/yates/modetest/host/app/modetest/StreamUDT.h: In function
`std::basic_ostream<_CharT, _Traits>&
KEA::stream_inserter(std::basic_ostream<_CharT, _Traits>&, const
UDT&)':
/home/yates/modetest/host/app/modetest/StreamUDT.h:96: error: expected
`;' before "prepost"
/home/yates/modetest/host/app/modetest/StreamUDT.h:97: error: `prepost'
undeclared (first use this function)
/home/yates/modetest/host/app/modetest/StreamUDT.h:97: error: (Each
undeclared identifier is reported only once for each function it
appears in.)
/home/yates/modetest/host/app/modetest/StreamUDT.h: In function
`std::basic_istream<_CharT, _Traits>&
KEA::stream_extractor(std::basic_istream<_CharT, _Traits>&, UDT&)':
/home/yates/modetest/host/app/modetest/StreamUDT.h:151: error: expected
`;' before "prepost"
/home/yates/modetest/host/app/modetest/StreamUDT.h:152: error:
`prepost' undeclared (first use this function)
In file included from
/home/yates/modetest/host/app/modetest/enumpp.cpp:1:
/home/yates/modetest/host/app/modetest/enum.h: At global scope:
/home/yates/modetest/host/app/modetest/enum.h:257: error: ISO C++
forbids declaration of `value_type' with no type
/home/yates/modetest/host/app/modetest/enum.h:257: error:
`::value_type' is not a valid declarator
/home/yates/modetest/host/app/modetest/enum.h:257: error: expected `;'
before "value_type"
/home/yates/modetest/host/app/modetest/enum.h:264: error: ISO C++
forbids declaration of `result_type' with no type
/home/yates/modetest/host/app/modetest/enum.h:264: error: expected `;'
before "operator"
/home/yates/modetest/host/app/modetest/enum.h:334: error: expected `;'
before '}' token
/home/yates/modetest/host/app/modetest/enum.h:338: error: ISO C++
forbids declaration of `result_type' with no type
/home/yates/modetest/host/app/modetest/enum.h:338: error: expected `;'
before "operator"
/home/yates/modetest/host/app/modetest/enum.h:344: error: expected `;'
before '}' token
/home/yates/modetest/host/app/modetest/enum.h:387: error: ISO C++
forbids declaration of `size_type' with no type
/home/yates/modetest/host/app/modetest/enum.h:387: error: `::size_type'
is not a valid declarator
/home/yates/modetest/host/app/modetest/enum.h:387: error: expected `;'
before "max_length"
/home/yates/modetest/host/app/modetest/enum.h:393: error: expected `;'
before "inline"
/home/yates/modetest/host/app/modetest/enum.h: In member function
`std::_Ios_Iostate KEA::_EnumSuper<_enumType, EnumSub,
N>::get_stream(std::basic_istream<_CharT2, _Traits2>&)':
/home/yates/modetest/host/app/modetest/enum.h:761: error: expected
primary-expression before "const"
/home/yates/modetest/host/app/modetest/enum.h:761: error: expected `;'
before "const"
/home/yates/modetest/host/app/modetest/enum.h:768: error:
`start_position' undeclared (first use this function)
/home/yates/modetest/host/app/modetest/enum.h: At global scope:
/home/yates/modetest/host/app/modetest/enum.h:789: error: expected
constructor, destructor, or type conversion before "_EnumSuper"
/home/yates/modetest/host/app/modetest/enum.h:789: error: expected `;'
before "_EnumSuper"
/home/yates/modetest/host/app/modetest/enum.h:805: error: expected
init-declarator before '&' token
/home/yates/modetest/host/app/modetest/enum.h:805: error: expected `;'
before '&' token
make: *** [/home/yates/modetest/host/app/modetest/nativelinux/enumpp.o]
Error 1

Compilation exited abnormally with code 2 at Fri Jan 6 11:41:16

Jan 6 '06 #2
PSS: I've also downloaded and installed boost.

--RY

Jan 6 '06 #3
More specificaly, here's what I got in trying to compile.

By the way, I have already downloaded and installed
boost. This is for gcc under fc3.

--RY

#include "enum.h"
int main(int argc, char **argv)
{
return 0;
}

cd /home/yates/modetest/host/app/modetest/
make -f enumpp.mak TARGET=native PLATFORM=linux
DSPROOT_DIR=/home/yates/modetest/ ATSIGN=
enumpp.mak:101: no file name for `include'
Building Component (enumpp) for Application enumpp
In file included from
/home/yates/modetest/host/app/modetest/enum.h:202,
from
/home/yates/modetest/host/app/modetest/enumpp.cpp:1:
/home/yates/modetest/host/app/modetest/StreamUDT.h: In function
`std::basic_ostream<_CharT, _Traits>&
KEA::stream_inserter(std::basic_ostream<_CharT, _Traits>&, const
UDT&)':
/home/yates/modetest/host/app/modetest/StreamUDT.h:96: error: expected
`;' before "prepost"
/home/yates/modetest/host/app/modetest/StreamUDT.h:97: error: `prepost'
undeclared (first use this function)
/home/yates/modetest/host/app/modetest/StreamUDT.h:97: error: (Each
undeclared identifier is reported only once for each function it
appears in.)
/home/yates/modetest/host/app/modetest/StreamUDT.h: In function
`std::basic_istream<_CharT, _Traits>&
KEA::stream_extractor(std::basic_istream<_CharT, _Traits>&, UDT&)':
/home/yates/modetest/host/app/modetest/StreamUDT.h:151: error: expected
`;' before "prepost"
/home/yates/modetest/host/app/modetest/StreamUDT.h:152: error:
`prepost' undeclared (first use this function)
In file included from
/home/yates/modetest/host/app/modetest/enumpp.cpp:1:
/home/yates/modetest/host/app/modetest/enum.h: At global scope:
/home/yates/modetest/host/app/modetest/enum.h:257: error: ISO C++
forbids declaration of `value_type' with no type
/home/yates/modetest/host/app/modetest/enum.h:257: error:
`::value_type' is not a valid declarator
/home/yates/modetest/host/app/modetest/enum.h:257: error: expected `;'
before "value_type"
/home/yates/modetest/host/app/modetest/enum.h:264: error: ISO C++
forbids declaration of `result_type' with no type
/home/yates/modetest/host/app/modetest/enum.h:264: error: expected `;'
before "operator"
/home/yates/modetest/host/app/modetest/enum.h:334: error: expected `;'
before '}' token
/home/yates/modetest/host/app/modetest/enum.h:338: error: ISO C++
forbids declaration of `result_type' with no type
/home/yates/modetest/host/app/modetest/enum.h:338: error: expected `;'
before "operator"
/home/yates/modetest/host/app/modetest/enum.h:344: error: expected `;'
before '}' token
/home/yates/modetest/host/app/modetest/enum.h:387: error: ISO C++
forbids declaration of `size_type' with no type
/home/yates/modetest/host/app/modetest/enum.h:387: error: `::size_type'
is not a valid declarator
/home/yates/modetest/host/app/modetest/enum.h:387: error: expected `;'
before "max_length"
/home/yates/modetest/host/app/modetest/enum.h:393: error: expected `;'
before "inline"
/home/yates/modetest/host/app/modetest/enum.h: In member function
`std::_Ios_Iostate KEA::_EnumSuper<_enumType, EnumSub,
N>::get_stream(std::basic_istream<_CharT2, _Traits2>&)':
/home/yates/modetest/host/app/modetest/enum.h:761: error: expected
primary-expression before "const"
/home/yates/modetest/host/app/modetest/enum.h:761: error: expected `;'
before "const"
/home/yates/modetest/host/app/modetest/enum.h:768: error:
`start_position' undeclared (first use this function)
/home/yates/modetest/host/app/modetest/enum.h: At global scope:
/home/yates/modetest/host/app/modetest/enum.h:789: error: expected
constructor, destructor, or type conversion before "_EnumSuper"
/home/yates/modetest/host/app/modetest/enum.h:789: error: expected `;'
before "_EnumSuper"
/home/yates/modetest/host/app/modetest/enum.h:805: error: expected
init-declarator before '&' token
/home/yates/modetest/host/app/modetest/enum.h:805: error: expected `;'
before '&' token
make: *** [/home/yates/modetest/host/app/modetest/nativelinux/enumpp.o]
Error 1

Compilation exited abnormally with code 2 at Fri Jan 6 11:41:16

Jan 7 '06 #4
Randy wrote:
Hi,

Can anyone point me to a complete, compilable example
of Besser's ENUM++ mechanism? I downloaded it from
CUJ and gave it a try but got errors just trying to compile
the header enum.h.

--Randy Yates


Can you give me a link to the code you downloaded?

Cheers! --M

Jan 7 '06 #5
Randy wrote:
Hi,

Can anyone point me to a complete, compilable example
of Besser's ENUM++ mechanism? I downloaded it from
CUJ and gave it a try but got errors just trying to compile
the header enum.h.

--Randy Yates


I found the code here:

ftp://ftp.cuj.com/pub/2003/cujjun2003.zip

The problem is that it appears Mr. Besser used an old (pre-C++03)
compiler. The problems can be fixed by adding the "typename" keyword at
various points (see
http://womble.decadentplace.org.uk/c...disambiguation)
and adding a few typedefs to obviate the type of problem discussed in
this FAQ:

http://www.parashift.com/c++-faq-lit...html#faq-35.18

For each of the two headers enum.h and StreamUDT.h, search for
"StringType::" and add "typename " before it like this:

typedef typename StringType::value_type value_type;

Do likewise for other types that are nested within template classes,
e.g.:

const typename std::basic_istream<charT, Traits>::pos_type
start_position=is.tellg();

and

typename _EnumSuper<_enumType, EnumSub, N>::StringType

Where a struct/class inherits from std::unary_function or
std::binary_function, add some typedefs in accord with the
aforementioned FAQ, e.g.:

struct Format: public std::unary_function<const char [], StringType>
{
typedef typename std::unary_function<const char [],
StringType>::result_type result_type;
typedef typename std::unary_function<const char [],
StringType>::argument_type argument_type;
// ...
};

and

struct StringLengthGreater
: public std::binary_function<const StringType*, const StringType*,
bool>
{
typedef typename std::binary_function<const char [],
StringType>::result_type result_type;
typedef typename std::binary_function<const char [],
StringType>::first_argument_type first_argument_type;
typedef typename std::binary_function<const char [],
StringType>::second_argument_type second_argument_type;
// ...
};

Then all the errors go away.

Cheers! --M

Jan 7 '06 #6
On 6 Jan 2006 11:25:41 -0800, "Randy" <ya***@ieee.org> wrote:
Can anyone point me to a complete, compilable example
of Besser's ENUM++ mechanism? I downloaded it from
CUJ and gave it a try but got errors just trying to compile
the header enum.h.


IMO, an "enum enhancement" that claims to be "easy to use" but "relies
on having the Boost preprocessor library [1] installed" isn't worth
the trouble.
It's also a good example of why CUJ has been 'discontinued'.

Best wishes,
Roland Pibinger
Jan 7 '06 #7
Hi M,

I still need some hand-holding as this is still not working
and it's beyond my C++ ability to find out why.

I made the changes you directed (I think) and am able
to compile error- and warning-free. The files are available
at

www.digitalsignallabs.com/enumpp.cpp
www.digitalsignallabs.com/enum.h
www.digitalsignallabs.com/StreamUDT.h

If, however, I add an enumeration declaration as Besser
shows in his article:

#include "enum.h"

int main(int argc, char **argv)
{
ENUM3(IdiotResponse, Yup, Nope, IDunno);

return 0;
}
I get errors:
g++ -c `cyg2dos /home/yates/modetest/host/app/modetest/enumpp.cpp`
-O3 -Wall -pthread -g -I /home/yates/modetest/host/inc/ -I
/home/yates/modetest/dsp/inc/ -DTARGET_NATIVE -DPLATFORM_LINUX -o
/home/yates/modetest/host/app/modetest/nativelinux/enumpp.o
/home/yates/modetest/host/app/modetest/enumpp.cpp:5:1: macro
"ENUM_GLOBAL_VALUES" passed 4 arguments, but takes just 2
/home/yates/modetest/host/app/modetest/enumpp.cpp: In function `int
main(int, char**)':
/home/yates/modetest/host/app/modetest/enumpp.cpp:5: error:
`ENUM_GLOBAL_VALUES' undeclared (first use this function)
/home/yates/modetest/host/app/modetest/enumpp.cpp:5: error: (Each
undeclared identifier is reported only once for each function it
appears in.)
/home/yates/modetest/host/app/modetest/enumpp.cpp:5: error: expected
`;' before "class"
Please help some more!

--Randy

Jan 9 '06 #8
Randy wrote:
Hi M,

I still need some hand-holding as this is still not working
and it's beyond my C++ ability to find out why.

I made the changes you directed (I think) and am able
to compile error- and warning-free. The files are available
at

www.digitalsignallabs.com/enumpp.cpp
www.digitalsignallabs.com/enum.h
www.digitalsignallabs.com/StreamUDT.h
Those look good.
If, however, I add an enumeration declaration as Besser
shows in his article:

#include "enum.h"

int main(int argc, char **argv)
{
ENUM3(IdiotResponse, Yup, Nope, IDunno);

return 0;
}
I get errors:
g++ -c `cyg2dos /home/yates/modetest/host/app/modetest/enumpp.cpp`
-O3 -Wall -pthread -g -I /home/yates/modetest/host/inc/ -I
/home/yates/modetest/dsp/inc/ -DTARGET_NATIVE -DPLATFORM_LINUX -o
/home/yates/modetest/host/app/modetest/nativelinux/enumpp.o
/home/yates/modetest/host/app/modetest/enumpp.cpp:5:1: macro
"ENUM_GLOBAL_VALUES" passed 4 arguments, but takes just 2
/home/yates/modetest/host/app/modetest/enumpp.cpp: In function `int
main(int, char**)':
/home/yates/modetest/host/app/modetest/enumpp.cpp:5: error:
`ENUM_GLOBAL_VALUES' undeclared (first use this function)
/home/yates/modetest/host/app/modetest/enumpp.cpp:5: error: (Each
undeclared identifier is reported only once for each function it
appears in.)
/home/yates/modetest/host/app/modetest/enumpp.cpp:5: error: expected
`;' before "class"
Please help some more!

--Randy


You might need to take the ENUM3 declaration outside of the function
body to give it external linkage. If I do that, the example works fine
with VC++6, which is the compiler the author used.

I did a somewhat cursory look at things on g++ 3.4.4, on which your
code doesn't work for me either, but I didn't see anything obviously
wrong. To reduce the noise, you can see the preprocessor error alone by
using the -E option, which yields:

macro "ENUM_GLOBAL_VALUES" passed 4 arguments, but takes just 2

The ultimate problem seems to be with the use of this macro:

#define ENUM_LIST(size, tuple) \
BOOST_PP_LIST_ENUM(BOOST_PP_TUPLE_TO_LIST(size, tuple))

I'm no Boost PP expert, and so I'll have to recommend that you take
this to the Boost User list at
http://lists.boost.org/mailman/listinfo.cgi/boost-users or perhaps to a
GNU forum. I didn't see anything about a compiler incompatibility on
Boost's website (indeed,
http://engineering.meta-comm.com/boo...processor.html
seems to indicate that it should be fully functional), so I'd talk to
the folks in the know.

I also briefly tried tracking down the author of the article to no
avail. You might be able to find him out there somewhere, and ask him
for help directly.

Sorry I can't be more help.

Cheers! --M

Jan 10 '06 #9
mlimber wrote:
using the -E option, which yields:

macro "ENUM_GLOBAL_VALUES" passed 4 arguments, but takes just 2

The ultimate problem seems to be with the use of this macro:

#define ENUM_LIST(size, tuple) \
BOOST_PP_LIST_ENUM(BOOST_PP_TUPLE_TO_LIST(size, tuple))

I'm no Boost PP expert, and so I'll have to recommend that you take
this to the Boost User list at
http://lists.boost.org/mailman/listinfo.cgi/boost-users or perhaps to
a
GNU forum. I didn't see anything about a compiler incompatibility on
Boost's website (indeed,
http://engineering.meta-comm.com/boo...processor.html
seems to indicate that it should be fully functional), so I'd talk to
the folks in the know.

I also briefly tried tracking down the author of the article to no
avail. You might be able to find him out there somewhere, and ask him
for help directly.

Sorry I can't be more help.


The quick dirty fix for your preprocessing error... First, include
<boost/preprocessor/tuple/rem.hpp> with the rest of the Boost.Preprocessor
includes. Then alter line 830 (in the definition of BEGIN_ENUM) from...

ENUM_GLOBAL_VALUES(type, value_list) \

....to...

ENUM_GLOBAL_VALUES(type, BOOST_PP_TUPLE_REM(N)(value_list)) \

Regards,
Paul Mensonides
Jan 10 '06 #10
"mlimber" <ml*****@gmail.com> writes:
[...]
Sorry I can't be more help.


No problem, M, and thanks for your help.

FYI, I've written my CEnum class to do what I needed. It took a few
hours, but it's suitable to the task and I've got my automatic
inserters and extractors. It's probably very unsophisticated
compared to the kinds of tools you guys are used to seeing, but
if you're interested I'll post it.
--
% Randy Yates % "The dreamer, the unwoken fool -
%% Fuquay-Varina, NC % in dreams, no pain will kiss the brow..."
%%% 919-577-9882 %
%%%% <ya***@ieee.org> % 'Eldorado Overture', *Eldorado*, ELO
http://home.earthlink.net/~yatescr
Jan 11 '06 #11

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by AngleWyrm | last post: by
8 posts views Thread by Klaus Schneider | last post: by
18 posts views Thread by Nebula | last post: by
21 posts views Thread by Andreas Huber | last post: by
18 posts views Thread by Visual Systems AB \(Martin Arvidsson\) | last post: by
2 posts views Thread by Randy | last post: by
10 posts views Thread by kar1107 | last post: by
34 posts views Thread by Steven Nagy | last post: by
185 posts views Thread by jacob navia | last post: by
2 posts views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by Anwar ali | last post: by

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.