473,394 Members | 1,800 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,394 software developers and data experts.

How to wrapper Native C++ Template?

Ed
Hi, dear all,
I want to wrapper the legacy C++ Template Class to be used by the C#
code, so I try to wrapper the legacy C++ code into CLI/C++ code first.

One problem is how to wrapper C++ template class, such as List, Queue,
etc?

Here is a snippet of Native Code:

//Native code:
namespace Unmgd
{
template <class Tclass ArrayList
{
private:
T* mArray;
Int mLength;
public:
T Get(int index)
{
return mArray[index];
}
void Set(int index, T value)
{
mArray[index] = value;
}

};

class ListofInts : public ArrayList<int {};
class ListofFloats: public ArrayList<float{};
class ListofShorts: public ArrayList<short{};

}

So, what's the best way to do the wrapper of these classes, such as
ListofInts , ListofFloats?
My wrapper code is:

//Wrapper code:
namespace Mgd
{
template <class T1, class T2public ref class ArrayList
{
public:
property T1 default[int]
{
T1 get(int index)
{
return (*Native())[index];
}
void set(int index, T1 value)
{
(*Native())[index] = value;
}
}

internal:
virtual T2* Native() = 0;

};

public ListofInts : public ArrayList<int, Unmgd::ListofInts>
{
private:
//mpNative is the pointer to the native instance.
Unmgd::ListofInts* mpNative;

internal:
virtual Unmgd::ListofInts* Native() override
{
return mpNative;
}
};

}

Nov 12 '07 #1
0 1322

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

Similar topics

1
by: Samuel R. Neff | last post by:
We have a class that is a basic wrapper around a native 3rd party C DLL. We created an NUnit test against the wrapper and it passes fine the first time. However, when we run the tests again, it...
9
by: WithPit | last post by:
I am trying to create an Managed C++ Wrapper around an unmanaged library which contains C++ code. Some of the unmanaged methods returns an returntype which is of the abstract base type (for...
0
by: IndulgentCoder | last post by:
Hi all, I'm new to scripts forum. I've a .NET wrapper class written in c# that makes some calls to native dlls using platform invocation. The native dlls inturn perform read operation on MSOffice...
3
by: benben | last post by:
I have always found Stroustrup's paper on generalized member function wrapper (http://www.research.att.com/~bs/wrapper.pdf) an interesting one. Recently I started to play with it. As I tried to put...
0
by: =?Utf-8?B?V0o=?= | last post by:
I have some native classes in MFC extension DLL. They are not MFC sub-classes, but they use MFC dialogs... If I want to keep those native classes in the current project/DLL, can I create the...
0
by: Julien Biezemans | last post by:
Hi everyone, I've written a file:// scheme stream wrapper that acts like chroot() (but is more flexible, does not require root privileges and works on any platform). Everything works just fine...
1
by: cctv.star | last post by:
I need to dynamically load and call .NET assembly from native application, written in C++. I'm trying to do this by creating a (managed) module, written in C++/ CLI, whose header can be...
4
by: Christian Schmidt | last post by:
Hi all, I'm trying to implement a std::vector-like wrapper for IList. The hard part seems to be operator, because it returns an unmanaged reference. Probably I have to use pin_ptr to achieve this,...
5
by: GCRhoads | last post by:
I have some templated functions and I want to write a call wrapper class for it. I also want to pass the function object from this class to some functions that will then call the function...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...

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.