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

Wrapper objects

I would like to know more about C++ wrappers. What is a wrapper object
in C++ and why is it neccessary? I am trying to create a templated
linked list data structure to store any object or primitive however I'm
told it would work best with a wrapper object. I did a google search
and came up with a java
definition(http://javaalmanac.com/egs/java.lang/Wrap.html) would it
work for C++ the same way?

Nov 10 '05 #1
5 2779
ni*****@gmail.com wrote:
I would like to know more about C++ wrappers. What is a wrapper object
in C++ and why is it neccessary?
A wrapper object is an object that acts as a wrapper round another
object. That could mean almost anything.

I am trying to create a templated linked list data structure to store any object or primitive however I'm
told it would work best with a wrapper object. I did a google search
and came up with a java
definition(http://javaalmanac.com/egs/java.lang/Wrap.html) would it
work for C++ the same way?


No it would not.
First you need to clarify your requirements. Do you mean a list which
can hold objects of one single type (a homogenous list)? Well C++
already has that. Or do you mean a list which can hold different types
simultanously (a heterogenous list)? If that is what you mean then where
does the template fit in?

Can't help until you answer this fundamental question.

john
Nov 10 '05 #2
ni*****@gmail.com wrote:
I would like to know more about C++ wrappers. What is a wrapper object
in C++ and why is it neccessary? I am trying to create a templated
linked list data structure to store any object or primitive however I'm
told it would work best with a wrapper object. I did a google search
and came up with a java
definition(http://javaalmanac.com/egs/java.lang/Wrap.html) would it
work for C++ the same way?


A wrapper object is probably a reference to using the constructor and
destructor for automatic and exception safe resource allocation and
deallocation. I'm not sure what your source means by suggesting it, but
perhaps s/he was thinking of something like boost::shared_ptr to hold
elements if they are pointers (this doesn't really apply if the objects
are not pointers).

See Stroustrup's paper on the subject of wrapping:

http://www.research.att.com/~bs/wrapper.pdf

BTW, there's already a templatized linked list in the STL, and you
shouldn't roll your own unless you have to (e.g. for a data structures
class).

Cheers! --M

Nov 10 '05 #3
ben
ni*****@gmail.com wrote:
I would like to know more about C++ wrappers. What is a wrapper object
in C++ and why is it neccessary? I am trying to create a templated
linked list data structure to store any object or primitive however I'm
told it would work best with a wrapper object. I did a google search
and came up with a java
definition(http://javaalmanac.com/egs/java.lang/Wrap.html) would it
work for C++ the same way?

A wrapper object most likely would act on behalf of the object in wraps,
in a way that would make accessing the wrapped object:
possible (e.g. if the wrapped object is somewhere on the Internet);
easier (e.g. if the wrapped object has a crumblesome interface);
safer (e.g. keeps locks, reference counting, etc);
faster (by utilizing optimized operation, by caching last result, etc);
recordable (bookkeeping debug information, records exception, etc);
abstract (by doing away some unnecessary operations and so make it
compliant to other similar objects);
more flexible (e.g. the damage done by changing the public interface of
the wrapped object is contained);
more managible (e.g. if the wrapper does give a simpler interface, etc.)

There are also cases when a wrapper object wraps around an interface
that does not explicitly use C++ class objects. These wrappers
simplifies, encapsulates, restructures, refactors and in some cases
adapts the wrapped interface to suit your needs.

Ben
Nov 10 '05 #4

<ni*****@gmail.com> a écrit dans le message de news:
11**********************@g44g2000cwa.googlegroups. com...
I would like to know more about C++ wrappers. What is a wrapper object
in C++ and why is it neccessary?
Example:
I develop algorithms to do image processing. I can use a few image
processing library to help me
do several basic operations on images. lets say I have 2 library A and B and
each of them have a function
to transform a color image to grey scale.

Now the 2 available functions (one in library A and 1 in B) dont share the
same parameters list and dont even share
the same name. But I want to flexibility to easily use eigther the function
from A or B. So I make a wrapper
around the 2 functions. Basically its a function that can call library A or
B and it deal with the details like the possible
diffenrence in the parameters list.

Once you have wrapped everything you want, its now easy to add a third
library or to kill one you dont want anymore,
since you always deal with generic functions, and never a library specific
interface.

Eric

I am trying to create a templated
linked list data structure to store any object or primitive however I'm
told it would work best with a wrapper object. I did a google search
and came up with a java
definition(http://javaalmanac.com/egs/java.lang/Wrap.html) would it
work for C++ the same way?

Nov 10 '05 #5
Here is another way to look at it. A wrapper is simply a method or
class that delegates traffic to another method or class.

Consider a DLL. A DLL can only expose methods - not objects
themselves. If I want to have a class object in a DLL, you have to
expose methods that are public from outside the DLL. Those methods
would then delegate the calls to the inner class object methods. The
exposed DLL methods would then be called wrapper methods.

Here is another example. Let's take Java for instance. Java runs on
top of a JVM meaning it is garbage collected, etc. To communicate with
the outside world, Java uses what is called the JNI (or Java Native
Interfaces). All communication with the outside world (e.g. external
processes, system libraries, DLLs, etc.) must go through the JNI. A
common thing to do is to create "proxy" or "wrapper" objects that
mimick the functionality of the external libraries and handle all of
the JNI communication. That way, your application would just use the
wrapper objects without worrying how it works with the JNI below. Make
sense?

Nov 11 '05 #6

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

Similar topics

2
by: James S | last post by:
Hi, Basically I've been fighting with this code for a few days now and can't seem to work around this problem. Included is the output, the program I use to get this error and the source code for...
2
by: Hallvard B Furuseth | last post by:
What's the difference between a built-in method and a method-wrapper object? Why has only the former a __self__, even though both are tied to the object on which to perform the operation? Why do...
12
by: Egil M?ller | last post by:
Is there any way to create transparent wrapper objects in Python? I thought implementing __getattribute__ on either the wrapper class or its metaclass would do the trick, but it does not work for...
0
by: Peer Dr. Griebel | last post by:
Hi, I'm currently working on a Python Management Console. During inspection of my objects I stumbled over method-wrapper objects. Such an object may be obtained e.g. as method_wrapper =...
1
by: Dylan Phillips | last post by:
I've often used Java's Numeric Wrapper Objects when numeric properties can have a null state. This is very useful with optional properties for which 0 has meaning. For example: //Java Code...
3
by: Michael Brown | last post by:
Hey there, it's been a long time since I've done alot in C++ (pre windows stuff).. so I've got this lib that I've written a wrapper for so I can work with it in C#.. I created the wrapper as an ATL...
4
by: Stephen | last post by:
Hi I am currently developing a web application that has a third party component on it. The third party component is a graph component from Xceed that uses a number of dlls. The problems occur...
22
by: linwu02 | last post by:
I am trying to write a Wrapper for our web wrapping engine, Cameleon. Currently Cameleon is able to answer certain SQL queries but with a restriction that all SQL queries must have a predicate....
2
by: Ole Nielsby | last post by:
I need to wrap managed objects in unmanaged objects in a general manner, i.e. I need a C++ COM style object that will wrap any managed object. I expected (optimistically) to be able to declare...
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: 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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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...

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.