To install click the Add extension button. That's it.

The source code for the WIKI 2 extension is being checked by specialists of the Mozilla Foundation, Google, and Apple. You could also do it yourself at any point in time.

4,5
Kelly Slayton
Congratulations on this excellent venture… what a great idea!
Alexander Grigorievskiy
I use WIKI 2 every day and almost forgot how the original Wikipedia looks like.
Live Statistics
English Articles
Improved in 24 Hours
Added in 24 Hours
What we do. Every page goes through several hundred of perfecting techniques; in live mode. Quite the same Wikipedia. Just better.
.
Leo
Newton
Brights
Milds

Wrapper library

From Wikipedia, the free encyclopedia

Wrapper libraries (or library wrappers) consist of a thin layer of code (a "shim") which translates a library's existing interface into a compatible interface. This is done for several reasons:

  • To refine a poorly designed or complicated interface
  • Allow code to work together which otherwise cannot (e.g. incompatible data formats)
  • Enable cross language and/or runtime interoperability

Wrapper libraries can be implemented using the adapter, façade, and to a lesser extent, proxy design patterns.

YouTube Encyclopedic

  • 1/3
    Views:
    25 316
    560
    18 945
  • How to update RDP Wrapper manually
  • CakePHP 3.4 Tutorial For Beginners Step by Step - 9 - Displaying Logged-in user details in View ctp
  • AR in Processing

Transcription

Structure and implementation

The specific way in which a wrapper library is implemented is highly specific to the environment it is being written in and the scenarios which it intends to address. This is especially true in the case when cross language/runtime interoperability is a consideration.

Example

The following provides a general illustration of a common wrapper library implementation. In this example, a C++ interface acts as a "wrapper" around a C-language interface.

C interface

int pthread_mutex_init(pthread_mutex_t * mutex , pthread_mutexattr_t * attr);
int pthread_mutex_destroy (pthread_mutex_t * mutex);
int pthread_mutex_lock (pthread_mutex_t * mutex );
int pthread_mutex_unlock (pthread_mutex_t * mutex );

C++ wrapper

class Mutex
{
     pthread_mutex_t mutex;

public:
     Mutex() 
     {
          pthread_mutex_init(&mutex, 0);
     }

     ~Mutex()
     {
          pthread_mutex_destroy(&mutex);
     }

private:
     friend class Lock;

     void lock()
     {
          pthread_mutex_lock(&mutex);
     }

     void unlock()
     {
          pthread_mutex_unlock(&mutex);
     }
};

class Lock
{
private:
      Mutex &mutex;

public:
      Lock(Mutex &mutex): mutex{mutex}
      {
            mutex.lock();
      }

      ~Lock()
      {
            mutex.unlock();
      }
};

The original C interface can be regarded as error prone, particularly in the case where users of the library forget to unlock an already locked mutex. The new interface effectively utilizes RAII (Resource Acquisition is Initialization) in the new Mutex and Lock classes to ensure Mutexs are eventually unlocked and pthread_mutex_t objects are automatically released.

The above code closely mimics the implementation of boost::scoped_lock and boost::mutex which are part of the boost::thread library.

Driver wrappers

Cross-language/runtime interoperability

Some wrapper libraries exist to act as a bridge between a client application and a library written using an incompatible technology. For instance, a Java application may need to execute a system call. However system calls are typically exposed as C library functions. To resolve this issue Java implements wrapper libraries which make these system calls callable from a Java application.

In order to achieve this, languages like Java provide a mechanism called foreign function interface that makes this possible. Some examples of these mechanisms include:

Existing wrapper libraries

Some examples of existing wrapper libraries:

See also

This page was last edited on 23 March 2024, at 00:55
Basis of this page is in Wikipedia. Text is available under the CC BY-SA 3.0 Unported License. Non-text media are available under their specified licenses. Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc. WIKI 2 is an independent company and has no affiliation with Wikimedia Foundation.