Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > What is a Wrapper

Reply
Thread Tools

What is a Wrapper

 
 
utab
Guest
Posts: n/a
 
      10-01-2006
Dear all,

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

Regards

 
Reply With Quote
 
 
 
 
Moonlit
Guest
Posts: n/a
 
      10-01-2006
Hi

-


"utab" <> wrote in message
news: 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


 
Reply With Quote
 
 
 
 
utab
Guest
Posts: n/a
 
      10-01-2006

Moonlit wrote:
> Hi
>
> -
>
>
> "utab" <> wrote in message
> news: 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,

 
Reply With Quote
 
Moonlit
Guest
Posts: n/a
 
      10-01-2006



"utab" <> wrote in message
news: ups.com...
>
> Moonlit wrote:
>> Hi
>>
>> -
>>
>>
>> "utab" <> wrote in message
>> news: 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


 
Reply With Quote
 
Frederick Gotham
Guest
Posts: n/a
 
      10-01-2006
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
 
Reply With Quote
 
Frederick Gotham
Guest
Posts: n/a
 
      10-01-2006
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
 
Reply With Quote
 
utab
Guest
Posts: n/a
 
      10-01-2006

Moonlit wrote:
> "utab" <> wrote in message
> news: ups.com...
> >
> > Moonlit wrote:
> >> Hi
> >>
> >> -
> >>
> >>
> >> "utab" <> wrote in message
> >> news: 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,

 
Reply With Quote
 
utab
Guest
Posts: n/a
 
      10-01-2006

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

 
Reply With Quote
 
Arve Sollie
Guest
Posts: n/a
 
      10-01-2006
> 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" <> wrote in message
news: oups.com...
>
> Moonlit wrote:
>> "utab" <> wrote in message
>> news: ups.com...
>> >
>> > Moonlit wrote:
>> >> Hi
>> >>
>> >> -
>> >>
>> >>
>> >> "utab" <> wrote in message
>> >> news: 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,
>



 
Reply With Quote
 
utab
Guest
Posts: n/a
 
      10-01-2006

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" <> wrote in message
> news: oups.com...
> >
> > Moonlit wrote:
> >> "utab" <> wrote in message
> >> news: ups.com...
> >> >
> >> > Moonlit wrote:
> >> >> Hi
> >> >>
> >> >> -
> >> >>
> >> >>
> >> >> "utab" <> wrote in message
> >> >> news: 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Wrapper on magic line? Nilsson Mats Perl 0 12-09-2003 02:48 PM
Deployment of DTSPKG.DLL wrapper Marlene Arauz ASP .Net 0 11-10-2003 07:50 PM
wrapper function for uploading files Brian Pittman ASP .Net 3 07-30-2003 06:09 PM
Re: Coding a c# wrapper class to unmanaged C++ program, need some guidance Brendan Duffy ASP .Net 0 07-25-2003 12:49 AM
Anyone know of a ASP.NET wrapper for HTMLTidy? Showjumper ASP .Net 2 07-04-2003 01:26 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57