473,396 Members | 2,050 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,396 software developers and data experts.

crazy macro problem

Hi,

I'm trying to write a macro that will generate managed c++ wrappers of
map. I want a managed iterator and a managed map. I successfully built a
pair of classes (iterator and map) that work fine. I called it IntToIntMap
and IntToIntIterator. When I was finished, I realized that if I ever wanted
to map two other data types, I would have to do just as much work, so I
decided to make a macro to fake templating. So, I modeled the macro after
the working classes, but when it was finished it kept getting errors. Next,
I actually copied and pasted the working classes over the macro and re-did
the macro from known working code, but it still kept getting one error, and
for the life of me I can't understand why. Below is the code. I would be
very grateful if anyone could give me a pointer, or point me to a reference
that says why this is happening.

Thanks for any help in advance,
Chris

first, because it's simpler and more concise, here is how I use the macro:

#include "MapMacros.h"

namespace HelperDataStructures
{
MAKE_GC_MAP_AND_ITERATOR( int, int, IntToInt);
}

next... because it is also concise, this is the error it gives me:

C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\map(36) :
error C3602: 'Int_To_Int_Iterator': a __gc type object cannot be passed by
value

lastly, here is the macro definition:

#include <map>

using namespace System;

#define MAKE_GC_MAP_AND_ITERATOR( t1, t2, name )\
public __gc class name##Iterator: public IDisposable\
{\
public private:\
typedef std::map<t1, t2, std::less<t1> > mapType;\
typedef mapType::iterator itType;\
public private:\
itType * m_pIt;\
name##Iterator( itType it ): m_pIt( new itType( it ) ) {}\
public:\
typedef name##Iterator myType;\
name##Iterator( myType *it ): m_pIt( new itType( *it->m_pIt ) ) {}\
~name##Iterator() { Dispose(); }\
__property t1 get_First() { return (*m_pIt)->first; }\
__property t2 get_Second() { return (*m_pIt)->second; }\
__property void set_Second( t2 val ) { (*m_pIt)->second = val; }\
public:\
static bool op_Equality( myType *a, myType *b ) { return
(*a->m_pIt)==(*b->m_pIt); }\
static bool op_Inequality( myType *a, myType *b ) { return
(*a->m_pIt)!=(*b->m_pIt); }\
void Dispose() { delete m_pIt; m_pIt = NULL; }\
};\
[System::Reflection::DefaultMember(S"Item")]\
public __gc class name##map: public IDisposable\
{\
public private:\
typedef std::map<t1, t2, std::less<t1> > mapType;\
typedef name##Iterator gcItType;\
private:\
mapType * m_pMap;\
public:\
name##map(): m_pMap( new mapType ) {}\
~name##map() { Dispose(); }\
public:\
__property int get_Item( int i ) { return (*m_pMap)[ i ]; }\
__property void set_Item( int i, int val ) { (*m_pMap)[ i ] = val; }\
__property gcItType* get_Begin() { return new gcItType(
m_pMap->begin() ); }\
__property gcItType* get_End() { return new gcItType(
m_pMap->end() ); }\
__property int get_Size() { return m_pMap->size(); }\
__property bool get_Empty() { return m_pMap->empty(); }\
public:\
void Clear() { m_pMap->clear(); }\
gcItType* Erase( gcItType* i ) { return new gcItType( m_pMap->erase(
*i->m_pIt ) ); }\
gcItType* Find( int i ) { return new gcItType( m_pMap->find(
i ) ); }\
void Dispose() { delete m_pMap; m_pMap = NULL; }\
}
Nov 17 '05 #1
0 1181

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

Similar topics

25
by: Andrew Dalke | last post by:
Here's a proposed Q&A for the FAQ based on a couple recent threads. Appropriate comments appreciated X.Y: Why doesn't Python have macros like in Lisp or Scheme? Before answering that, a...
699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
11
by: doltharz | last post by:
Please Help me i'm doing something i though was to be REALLY EASY but it drives me crazy The complete code is at the end of the email (i mean newsgroup article), i always use Option...
8
by: David | last post by:
Hi, I am using header file for driver so Can I define macro to call Kernel function ? What are the generatl rules for defining macro. - David
20
by: Srinivas Mudireddy | last post by:
Hi, I am facing a problem with trying to conditionally compile inside a macro. I have a macro #define SET_VAL(x, y) ((x) = *(y)) But the problem is y can be NULL in which case I want to set...
6
by: Takeadoe | last post by:
Dear NG, Can someone assist me with writing the little code that is needed to run an update table query each time the database is opened? From what I've been able to glean from this group, the...
19
by: Genalube | last post by:
I have an application that will produce a Word document based on five separate queries this has required that I create a ADODB connection: 'Create connection to current database Dim Conn As...
6
by: jason | last post by:
Hi, I learned my lesson about passing pointers, but now I have a question about macros. Why does the function work and the MACRO which is doing the same thing on the surface, does not work in...
36
by: sh.vipin | last post by:
how to make large macro paste the code as it is Problem Explanation '-- For example in the program below /* a.c - starts here */ #define DECL_VARS() \ unsigned int a0;\ unsigned int a1;\...
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:
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...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.