473,387 Members | 1,528 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.

What is a Wrapper

Dear all,

In programming terminology, what is a wrapper and where is it used?

Regards

Oct 1 '06 #1
16 3389
Hi

-
"utab" <um********@gmail.comwrote in message
news:11**********************@e3g2000cwe.googlegro ups.com...
Dear all,

In programming terminology, what is a wrapper and where is it used?
Well for instance you could use a C++ wrapper class around regular C code.

For instance in my personal generic library I have a wrapper class around
the pnglib libary I can the open an ifstream of a .png file and read it with
operator>or write png files with operator<<. This also works for memory
streams etc. The C++ wrapper takes care of memory allocation and freeing the
memory and of the complexity of setting the pointers to static members to
replace the standard C FILE oriented operations.

i.e. the complexity is inside the C++ wrapper class. The wrapper class
itself is extremely simple to use. Instead of looking in the manual of png
everytime I can now load and save png in a very simple way.
>
Regards
Regards, Ron AF Greve

http://moonlit.xs4all.nl
Oct 1 '06 #2

Moonlit wrote:
Hi

-
"utab" <um********@gmail.comwrote in message
news:11**********************@e3g2000cwe.googlegro ups.com...
Dear all,

In programming terminology, what is a wrapper and where is it used?
Well for instance you could use a C++ wrapper class around regular C code.

For instance in my personal generic library I have a wrapper class around
the pnglib libary I can the open an ifstream of a .png file and read it with
operator>or write png files with operator<<. This also works for memory
streams etc. The C++ wrapper takes care of memory allocation and freeing the
memory and of the complexity of setting the pointers to static members to
replace the standard C FILE oriented operations.

i.e. the complexity is inside the C++ wrapper class. The wrapper class
itself is extremely simple to use. Instead of looking in the manual of png
everytime I can now load and save png in a very simple way.

Regards

Regards, Ron AF Greve

http://moonlit.xs4all.nl
Thanks Ron,

So in a simple manner, it is a code block to make things easier for
mixed-language programming(for the original C library in your case.).
Then briefly speaking, this is related to using more than one language
in your code. Am I correct?

Regards,

Oct 1 '06 #3

"utab" <um********@gmail.comwrote in message
news:11*********************@h48g2000cwc.googlegro ups.com...
>
Moonlit wrote:
>Hi

-
"utab" <um********@gmail.comwrote in message
news:11**********************@e3g2000cwe.googlegr oups.com...
Dear all,

In programming terminology, what is a wrapper and where is it used?
Well for instance you could use a C++ wrapper class around regular C
code.

For instance in my personal generic library I have a wrapper class around
the pnglib libary I can the open an ifstream of a .png file and read it
with
operator>or write png files with operator<<. This also works for memory
streams etc. The C++ wrapper takes care of memory allocation and freeing
the
memory and of the complexity of setting the pointers to static members to
replace the standard C FILE oriented operations.

i.e. the complexity is inside the C++ wrapper class. The wrapper class
itself is extremely simple to use. Instead of looking in the manual of
png
everytime I can now load and save png in a very simple way.
>
Regards

Regards, Ron AF Greve

http://moonlit.xs4all.nl

Thanks Ron,

So in a simple manner, it is a code block to make things easier for
mixed-language programming(for the original C library in your case.).
Then briefly speaking, this is related to using more than one language
in your code. Am I correct?
I think it is indeed mostly ( if not always ) used to make things easier.

The second statement is a bit more difficult to answer since C is for the
most part also C++. But all of my wrapper classes are indeed around regular
C functions/ libraries and not around C++ libraries. But I could imagine
that when you have a complex C++ library and you only want to use part of it
you might still want to write a wrapper class around it (then again maybe
the library itself should have been redesigned) . But from a practical point
of view I think that is right.
>
Regards,
--
Regards, Ron AF Greve

http://moonlit.xs4all.nl
Oct 1 '06 #4
utab posted:
In programming terminology, what is a wrapper and where is it used?

I'm not sure if this is a generally accepted meaning of the term, but I
take "wrapper" to mean anything which erects a 20-foot-tall wall around
something and provides a nice simple interface to the outside world. For
instance, we might create a wrapper for working with individual bits in
memory:

#include <climits>

class BitHandle {
private:

char unsigned *p;
unsigned index;

public:

operator bool() const
{
return *p & 1U<<index;
}

BitHandle &operator=(bool const val)
{
if(val) *p |= 1U<<index;
else *p &= ~(1U<<index);

return *this;
}

BitHandle &operator++() const
{
if(CHAR_BIT == index) ++p, index = 0;
else ++index;

return *this;
}
};

--

Frederick Gotham
Oct 1 '06 #5
Frederick Gotham posted:
BitHandle &operator++() const

Of course, that shouldn't be const (but then again it wasn't a full example
to start off with).

--

Frederick Gotham
Oct 1 '06 #6

Moonlit wrote:
"utab" <um********@gmail.comwrote in message
news:11*********************@h48g2000cwc.googlegro ups.com...

Moonlit wrote:
Hi

-
"utab" <um********@gmail.comwrote in message
news:11**********************@e3g2000cwe.googlegro ups.com...
Dear all,

In programming terminology, what is a wrapper and where is it used?
Well for instance you could use a C++ wrapper class around regular C
code.

For instance in my personal generic library I have a wrapper class around
the pnglib libary I can the open an ifstream of a .png file and read it
with
operator>or write png files with operator<<. This also works for memory
streams etc. The C++ wrapper takes care of memory allocation and freeing
the
memory and of the complexity of setting the pointers to static members to
replace the standard C FILE oriented operations.

i.e. the complexity is inside the C++ wrapper class. The wrapper class
itself is extremely simple to use. Instead of looking in the manual of
png
everytime I can now load and save png in a very simple way.

Regards


Regards, Ron AF Greve

http://moonlit.xs4all.nl
Thanks Ron,

So in a simple manner, it is a code block to make things easier for
mixed-language programming(for the original C library in your case.).
Then briefly speaking, this is related to using more than one language
in your code. Am I correct?

I think it is indeed mostly ( if not always ) used to make things easier.

The second statement is a bit more difficult to answer since C is for the
most part also C++. But all of my wrapper classes are indeed around regular
C functions/ libraries and not around C++ libraries. But I could imagine
that when you have a complex C++ library and you only want to use part of it
you might still want to write a wrapper class around it (then again maybe
the library itself should have been redesigned) . But from a practical point
of view I think that is right.

Regards,

--
Regards, Ron AF Greve

http://moonlit.xs4all.nl
Thanks again,

What do you mean by this

"But I could imagine
that when you have a complex C++ library and you only want to use part
of it
you might still want to write a wrapper class around it "

You mean to copy the parts you like to use for a complete C
application(in a class).

Is that also related with compatibility while using two languages. I
mean type compatibility, for instance C does not have a built-in vector
type but C++ has. And while writing some code which needs to use
vectors in the code for instance, you use a proper C++ wrapper in the
proper interface to use these features of C++ in C. Am I completely
confusing or on the right way?

Regards,
Regards,

Oct 1 '06 #7

Frederick Gotham wrote:
utab posted:
In programming terminology, what is a wrapper and where is it used?


I'm not sure if this is a generally accepted meaning of the term, but I
take "wrapper" to mean anything which erects a 20-foot-tall wall around
something and provides a nice simple interface to the outside world. For
instance, we might create a wrapper for working with individual bits in
memory:

#include <climits>

class BitHandle {
private:

char unsigned *p;
unsigned index;

public:

operator bool() const
{
return *p & 1U<<index;
}

BitHandle &operator=(bool const val)
{
if(val) *p |= 1U<<index;
else *p &= ~(1U<<index);

return *this;
}

BitHandle &operator++() const
{
if(CHAR_BIT == index) ++p, index = 0;
else ++index;

return *this;
}
};

--

Frederick Gotham
Dear Frederick,

So that is a way to make things more understantable from the
programmers point of view. Using the existing but in a fancier
interface(in a different form).

Regards

Oct 1 '06 #8
Is that also related with compatibility while using two languages. I
mean type compatibility, for instance C does not have a built-in vector
type but C++ has. And while writing some code which needs to use
Does C++ implement a Vector type ?
STL maybe, but not C++ as an intrinsic type, as far as I know.

"utab" <um********@gmail.comwrote in message
news:11**********************@k70g2000cwa.googlegr oups.com...
>
Moonlit wrote:
>"utab" <um********@gmail.comwrote in message
news:11*********************@h48g2000cwc.googlegr oups.com...
>
Moonlit wrote:
Hi

-
"utab" <um********@gmail.comwrote in message
news:11**********************@e3g2000cwe.googlegr oups.com...
Dear all,

In programming terminology, what is a wrapper and where is it used?
Well for instance you could use a C++ wrapper class around regular C
code.

For instance in my personal generic library I have a wrapper class
around
the pnglib libary I can the open an ifstream of a .png file and read
it
with
operator>or write png files with operator<<. This also works for
memory
streams etc. The C++ wrapper takes care of memory allocation and
freeing
the
memory and of the complexity of setting the pointers to static members
to
replace the standard C FILE oriented operations.

i.e. the complexity is inside the C++ wrapper class. The wrapper class
itself is extremely simple to use. Instead of looking in the manual of
png
everytime I can now load and save png in a very simple way.

Regards
Regards, Ron AF Greve

http://moonlit.xs4all.nl

Thanks Ron,

So in a simple manner, it is a code block to make things easier for
mixed-language programming(for the original C library in your case.).
Then briefly speaking, this is related to using more than one language
in your code. Am I correct?

I think it is indeed mostly ( if not always ) used to make things easier.

The second statement is a bit more difficult to answer since C is for the
most part also C++. But all of my wrapper classes are indeed around
regular
C functions/ libraries and not around C++ libraries. But I could imagine
that when you have a complex C++ library and you only want to use part of
it
you might still want to write a wrapper class around it (then again maybe
the library itself should have been redesigned) . But from a practical
point
of view I think that is right.
>
Regards,

--
Regards, Ron AF Greve

http://moonlit.xs4all.nl

Thanks again,

What do you mean by this

"But I could imagine
that when you have a complex C++ library and you only want to use part
of it
you might still want to write a wrapper class around it "

You mean to copy the parts you like to use for a complete C
application(in a class).

Is that also related with compatibility while using two languages. I
mean type compatibility, for instance C does not have a built-in vector
type but C++ has. And while writing some code which needs to use
vectors in the code for instance, you use a proper C++ wrapper in the
proper interface to use these features of C++ in C. Am I completely
confusing or on the right way?

Regards,
Regards,

Oct 1 '06 #9

Arve Sollie wrote:
Is that also related with compatibility while using two languages. I
mean type compatibility, for instance C does not have a built-in vector
type but C++ has. And while writing some code which needs to use

Does C++ implement a Vector type ?
STL maybe, but not C++ as an intrinsic type, as far as I know.

"utab" <um********@gmail.comwrote in message
news:11**********************@k70g2000cwa.googlegr oups.com...

Moonlit wrote:
"utab" <um********@gmail.comwrote in message
news:11*********************@h48g2000cwc.googlegro ups.com...

Moonlit wrote:
Hi

-
"utab" <um********@gmail.comwrote in message
news:11**********************@e3g2000cwe.googlegro ups.com...
Dear all,

In programming terminology, what is a wrapper and where is it used?
Well for instance you could use a C++ wrapper class around regular C
code.

For instance in my personal generic library I have a wrapper class
around
the pnglib libary I can the open an ifstream of a .png file and read
it
with
operator>or write png files with operator<<. This also works for
memory
streams etc. The C++ wrapper takes care of memory allocation and
freeing
the
memory and of the complexity of setting the pointers to static members
to
replace the standard C FILE oriented operations.

i.e. the complexity is inside the C++ wrapper class. The wrapper class
itself is extremely simple to use. Instead of looking in the manual of
png
everytime I can now load and save png in a very simple way.

Regards


Regards, Ron AF Greve

http://moonlit.xs4all.nl

Thanks Ron,

So in a simple manner, it is a code block to make things easier for
mixed-language programming(for the original C library in your case.).
Then briefly speaking, this is related to using more than one language
in your code. Am I correct?

I think it is indeed mostly ( if not always ) used to make things easier.

The second statement is a bit more difficult to answer since C is for the
most part also C++. But all of my wrapper classes are indeed around
regular
C functions/ libraries and not around C++ libraries. But I could imagine
that when you have a complex C++ library and you only want to use part of
it
you might still want to write a wrapper class around it (then again maybe
the library itself should have been redesigned) . But from a practical
point
of view I think that is right.

Regards,


--
Regards, Ron AF Greve

http://moonlit.xs4all.nl
Thanks again,

What do you mean by this

"But I could imagine
that when you have a complex C++ library and you only want to use part
of it
you might still want to write a wrapper class around it "

You mean to copy the parts you like to use for a complete C
application(in a class).

Is that also related with compatibility while using two languages. I
mean type compatibility, for instance C does not have a built-in vector
type but C++ has. And while writing some code which needs to use
vectors in the code for instance, you use a proper C++ wrapper in the
proper interface to use these features of C++ in C. Am I completely
confusing or on the right way?

Regards,
Regards,
Of course STL, thanks for the warning

Oct 1 '06 #10
utab posted:
Dear Frederick,

So that is a way to make things more understantable from the
programmers point of view. Using the existing but in a fancier
interface(in a different form).

The idea is "encapsulation", i.e. the separation of one complicated idea
from another.

Let's take "std::string" for example. People always cheer about how much
more simple it is to work with than null-terminated arrays of char.

But the reality is this: Nothing has been simplified -- the code for
"std::string" contains the same nitty-gritty pointers and manipulation of
null-terminated char arrays.

The only thing that's changed is that a partition has been put up between
"this stuff" and "that stuff", giving the idea that things have been
simplified.

It's like having two petry dishes side by side, each containing a little
blob of liquid. If we zoom out, we don't seen anything that complicated,
just two blobs of liquid side by side... but if we zoom in on one of them,
we'll see all the complexity of the molecular bonds and so forth...

The idea behind encapsulation is to zoom out and look at the big picture --
it makes everything look nice and simple in our minds.

Wrappers make encapsulation possible. You could say that "std::string" is a
wrapper for simplifing the complexity of working with strings.

--

Frederick Gotham
Oct 1 '06 #11
In article <11**********************@h48g2000cwc.googlegroups .com>,
utab <um********@gmail.comwrote:
>So that is a way to make things more understantable from the
programmers point of view. Using the existing but in a fancier
interface(in a different form).
Kind of. What wrappers often intend to provide is some way to
modify a set of existing interfaces to be more in line with the
criterea and view and design of something else. Obviously then
it is not always successful, or easy. Sometimes it is a way to
establish a bridge to a library or between 2 libraries. An
adapter if you will.

Also, wrappers can often be used to constrain or change or even
check the expectations of the thing be wrapped. For instance,
a thread here yesterday showed somebody wrapped std::vector to
detect a possible out of range situation.
--
Greg Comeau / 20 years of Comeauity! Intel Mac Port now in alpha!
Comeau C/C++ ONLINE == http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
Oct 1 '06 #12
In article <12*************@corp.supernews.com>,
Arve Sollie <ne********@codeworks.nowrote:
>Is that also related with compatibility while using two languages. I
mean type compatibility, for instance C does not have a built-in vector
type but C++ has. And while writing some code which needs to use

Does C++ implement a Vector type ?
Builtin arrays.
>STL maybe, but not C++ as an intrinsic type, as far as I know.
Otherwise yeah, stuff like std::vector, std::string etc
which are library.
--
Greg Comeau / 20 years of Comeauity! Intel Mac Port now in alpha!
Comeau C/C++ ONLINE == http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
Oct 1 '06 #13


"utab" <um********@gmail.comwrote in message
news:11**********************@k70g2000cwa.googlegr oups.com...
>
Moonlit wrote:
>"utab" <um********@gmail.comwrote in message
news:11*********************@h48g2000cwc.googlegr oups.com...
>
Moonlit wrote:
Hi

-
"utab" <um********@gmail.comwrote in message
news:11**********************@e3g2000cwe.googlegr oups.com...
Dear all,

In programming terminology, what is a wrapper and where is it used?
Well for instance you could use a C++ wrapper class around regular C
code.

For instance in my personal generic library I have a wrapper class
around
the pnglib libary I can the open an ifstream of a .png file and read
it
with
operator>or write png files with operator<<. This also works for
memory
streams etc. The C++ wrapper takes care of memory allocation and
freeing
the
memory and of the complexity of setting the pointers to static members
to
replace the standard C FILE oriented operations.

i.e. the complexity is inside the C++ wrapper class. The wrapper class
itself is extremely simple to use. Instead of looking in the manual of
png
everytime I can now load and save png in a very simple way.

Regards
Regards, Ron AF Greve

http://moonlit.xs4all.nl

Thanks Ron,

So in a simple manner, it is a code block to make things easier for
mixed-language programming(for the original C library in your case.).
Then briefly speaking, this is related to using more than one language
in your code. Am I correct?

I think it is indeed mostly ( if not always ) used to make things easier.

The second statement is a bit more difficult to answer since C is for the
most part also C++. But all of my wrapper classes are indeed around
regular
C functions/ libraries and not around C++ libraries. But I could imagine
that when you have a complex C++ library and you only want to use part of
it
you might still want to write a wrapper class around it (then again maybe
the library itself should have been redesigned) . But from a practical
point
of view I think that is right.
>
Regards,

--
Regards, Ron AF Greve

http://moonlit.xs4all.nl

Thanks again,

What do you mean by this

"But I could imagine
that when you have a complex C++ library and you only want to use part
of it
you might still want to write a wrapper class around it "

You mean to copy the parts you like to use for a complete C
application(in a class).

Is that also related with compatibility while using two languages. I
mean type compatibility, for instance C does not have a built-in vector
type but C++ has. And while writing some code which needs to use
vectors in the code for instance, you use a proper C++ wrapper in the
proper interface to use these features of C++ in C. Am I completely
confusing or on the right way?
Hm, that's a bit hard for me to answer since I never have come across code
that uses C++ functions from C.

As mentioned in other parts of this thread I think it is mostly used for
encapsulation. Making something easier to use. You put the effort in once to
make the class correct and handle all the dificulties of the encapsulated
thing (be it a library, a bunch of functions or maybe even other C++
classes). And for then on you only have to use the simple interface of your
C++ class.

But I don't think there is really a 'tight' definition of a wrapper class
(at least not that I know of). So as long as you wrap things inside it, it
probably is a moot point whether it is a wrapper or not. But I think the way
most people feel about it is in the previous paragraph, i.e. encapsulation,
hiding the complexity of something inside the wrapper class..
>
Regards,
Regards,
--
Regards, Ron AF Greve

http://moonlit.xs4all.nl
Oct 1 '06 #14
utab schrieb:
In programming terminology, what is a wrapper and where is it used?
I think it is the same as the Adapter design pattern:
http://en.wikipedia.org/wiki/Wrapper
http://en.wikipedia.org/wiki/Adapter_pattern

A wrapper/adapter presents an interface using some code with has another
interface.

The reason could be everything from interlanguage programming (calling C++
from C or vice versa) to wrapping an ostream into a C++ interator
(ostream_iterator<template). The links give other examples too.

--
Thomas
http://www.netmeister.org/news/learn2quote.html
Oct 1 '06 #15
On Sun, 01 Oct 2006 17:46:55 +0200, "Thomas J. Gritzan" wrote:
>utab schrieb:
>In programming terminology, what is a wrapper and where is it used?

A wrapper/adapter presents an interface using some code with has another
interface.
IMO, there is a subtle difference between adapter and wrapper in C++.
Adapted code is somehow 'visible' to the user (think of container
adapters) whereas wrappers entirely hide the wrapped code. Adapters
are workarounds (like a USB to PS/2 keyboard adaper).

Best wishes,
Roland Pibinger
Oct 1 '06 #16
Greg Comeau <co****@comeaucomputing.comwrote:
>utab <um********@gmail.comwrote:
>>So that is a way to make things more understantable from the
programmers point of view. Using the existing but in a fancier
interface(in a different form).
>Kind of. What wrappers often intend to provide is some way to
modify a set of existing interfaces to be more in line with the
criterea and view and design of something else. Obviously then
it is not always successful, or easy. Sometimes it is a way to
establish a bridge to a library or between 2 libraries. An
adapter if you will.
>Also, wrappers can often be used to constrain or change or even
check the expectations of the thing be wrapped.
Yes, I agree with this -- a wrapper doesn't necessarily form
a simpler interface than the one below it, nor does it necessarily
interface one underlying programming language to another. It
does change the interface (while doing little or no actual
processing) to meet some set of different expectation.

Steve
Oct 3 '06 #17

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

Similar topics

9
by: gulu man | last post by:
Hi, What is the substitute for COM objects in .NET? How can I create something similar to com in .net? Is it still possible? Thank you
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...
2
by: moose | last post by:
Hi, In C++/CLI (with VS2005 beta2) I wrote a little wrapper around a native dll (to which I headers and .lib). Wrapper was a ref class with some methods calling native functions from native dll....
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....
6
by: RichG | last post by:
Does anyone remember this: Set datapath to "c:\somewhere" dNetUse "SomeTable" do some db work I asked the question a couple of days ago about how to attach a recordset or some form of data to...
3
by: bobc | last post by:
Using SQL Server 2000... I wrote a wrapper to call a sub proc (code provided below). The intended varchar value returned in the output parameter of each proc is a string implementation of an...
9
by: =?Utf-8?B?RWR3YXJkUw==?= | last post by:
I would greatly appreciate some help on passing managed object into unmanaged code. I need to pass a reference (address of) of a managed class into unmanaged code (written by a thrid party). The...
8
by: Viktor | last post by:
Can somebody give me an explanation what happened here (or point me to some docs)? Code: HMMM = None def w(fn): print 'fn:', id(fn) HMMM = fn
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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:
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
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.