Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Wrapper class in C++

    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 3.37k
    Comment on it

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: