Wrapper is generally defined as the packaging, or to bound an object.
A "wrapper class" is used to manage the resources so that it will be crystal-clear to every one. This wraps the resources by simply wrapping the pointer into an int. In this another function is called having less code.
The resources are wrapped in a proper manner so that code will be correct and clean. Wrapper class is also known as Adaptor class.
class int_ptr_wrapper
{
public:
int_ptr_wrapper(int value = 0) :
mInt(new int(value)) {}
// note! needs copy-constructor and copy-assignment operator!
~int_ptr_wrapper()
{
delete mInt;
}
private:
int* mInt;
};
There are two types of wrappers:-
- resource wrappers
- functional wrappers
1. Resource wrappers-
Functions provided by the OS
- UNIXs: open/close, mmap/munmap, dlopen/dlclose
- Windows: CreateFile/DestroyHandle, CreateFileMapping/CloseHandle, LoadLibrary/FreeLibrary
2. Functional wrappers-
Functions provided by OS
- UNIXs: write, read, dlsym
- Windows: ReadFile, WriteFile, GetProcAddress
0 Comment(s)