wrapper library
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.
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. include // previous declarations... int pthread_mutex_init(pthread_mutex_t* mutex , const 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); // more functions... export module org.posix.PosixThread; import ; export namespace org::posix { // previous wrappers... class ThreadMutex { private: ::pthread_mutex_t mutex; friend class ThreadLock; void lock() noexcept { ::pthread_mutex_lock(&mutex); } void unlock() noexcept { ::pthread_mutex_unlock(&mutex); } public: ThreadMutex() { ::pthread_mutex_init(&mutex, 0); } ~ThreadMutex() { ::pthread_mutex_destroy(&mutex); } }; class ThreadLock { private: ThreadMutex& mutex; public: explicit ThreadLock(ThreadMutex& mutex): mutex{mutex} { mutex.lock(); } ~ThreadLock() { mutex.unlock(); } }; // more wrappers... } 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 resource acquisition is initialization (RAII) in the new and classes to ensure s are eventually unlocked and objects are automatically released. The above code closely mimics the implementation of and classes from Boost which are part of the Boost.Thread library. ==See also== Wrapper function Wrapper pattern Glue code
References
No reference rows published for this article.
Cite this article
MLA
"wrapper library." encyclopegia.org, 2025, https://encyclopegia.org/wiki/wrapper-library. Accessed 24 November 2026.
Chicago
"wrapper library." encyclopegia.org. Accessed November 24, 2026. https://encyclopegia.org/wiki/wrapper-library.
APA
encyclopegia.org. (2025). wrapper library. Retrieved November 24, 2026, from https://encyclopegia.org/wiki/wrapper-library
Accessed November 24, 2026 · CC BY-SA 4.0 · citation page · JSON