Share to: share facebook share twitter share wa share telegram print page

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.

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 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 resource acquisition is initialization (RAII) 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

Read other articles:

Russian photographer In this name that follows Eastern Slavic naming customs, the patronymic is Yusupovich and the family name is Osmanov. Murad OsmannMurad Osmann and Natalia Zakharova at Web Summit 2017BornMurad Yusupovich Osmanov (1985-05-15) 15 May 1985 (age 38)Dagestan ASSR, Russian SFSR, USSRNationalityRussianOccupationPhotographerKnown forFollow me projectSpouse Natalia Zakharova ​(m. 2015)​ Murad Yusupovich Osmanov (Russian: Мурад Юсуп…

الاتحاد الإستوني لكرة القدم الاسم المختصر EJL الرياضة كرة القدم أسس عام 1921 (منذ 103 سنوات) المقر تالين  الانتسابات الفيفا : 1923 UEFA  : 1992 رمز الفيفا EST  الموقع الرسمي www.jalgpall.ee تعديل مصدري - تعديل   الشعار السابق للاتحاد تأسس الاتحاد الأستوني لكرة القدم في عام 1921م وانضم إل…

SMK Negeri 14 BandungInformasiDidirikan1987JenisNegeriAkreditasi Teknik Perbaikan Bodi Otomotif (A) Multimedia (A) Animasi (B) Desain Komunikasi Visual (A) Desain Dan Produksi Kria Tekstil (A) Desain Dan Produksi Kria Kulit (A) Desain Dan Produksi Kria Keramik (A) Desain Dan Produksi Kria Logam (A) Desain Dan Produksi Kria Kayu (A) Nomor Statistik Sekolah761026025001Nomor Pokok Sekolah Nasional20219160Kepala SekolahR. Dudi Rudiatna, S.Pd., S.ST., MT.Ketua KomiteHermanJumlah kelas7…

Election in Kentucky Main article: 2020 United States presidential election 2020 United States presidential election in Kentucky ← 2016 November 3, 2020 2024 → Turnout59.7%   Nominee Donald Trump Joe Biden Party Republican Democratic Home state Florida Delaware Running mate Mike Pence Kamala Harris Electoral vote 8 0 Popular vote 1,326,646 772,474 Percentage 62.09% 36.15% County results Congressional district results Precinct results Trump  …

This article is about the year 1885. For M-1885, see Model 1885. Calendar year Millennium: 2nd millennium Centuries: 18th century 19th century 20th century Decades: 1860s 1870s 1880s 1890s 1900s Years: 1882 1883 1884 1885 1886 1887 1888 1885 by topic Humanities Archaeology Architecture Art Film Literature Poetry Music By country Australia Belgium Brazil Canada China Denmark France Germany New Zealand Norway Portugal Russia South Africa Spain Sweden United Kingdom United State…

Street in Sydney, Australia Elizabeth StreetNew South WalesElizabeth Street, looking south from the intersection of Hunter Street, 11 January 1933.Sydney, New South Wales, AustraliaNorth endSouth endCoordinates 33°51′59″S 151°12′39″E / 33.866321°S 151.210767°E / -33.866321; 151.210767 (North end) 33°54′26″S 151°12′28″E / 33.907293°S 151.207685°E / -33.907293; 151.207685 (South end) General informationTypeStreetLength…

Japanese television brand of Sony Group This article contains content that is written like an advertisement. Please help improve it by removing promotional content and inappropriate external links, and by adding encyclopedic content written from a neutral point of view. (August 2022) (Learn how and when to remove this message) BraviaOwnerSony Group CorporationTypemainly LCD, LED & OLED HDTVRetail availability2005–presentMenu interface XrossMediaBar (2005–2013) Google TV (2011–2013) Til…

Multi-period sanctuary and archaeological site This article is about ancient site. For 19th century fortification, see Fort Tas-Silġ. Tas-SilġPart of the late ruins at Tas-SilġShown within MaltaAlternative nameTa' BerikkaLocationŻejtun[1]/Marsaxlokk, MaltaCoordinates35°50′45.3″N 14°33′7.5″E / 35.845917°N 14.552083°E / 35.845917; 14.552083TypeTempleVillageMonasteryFortificationPart ofMegalithic Temples of MaltaHistoryMaterialLimestoneFound…

F1 22 Logo permainanPublikasiWW: 1 Juli, 2022[a]GenreBalapanLisensiLisensi proprietarium Bahasa Daftar Belanda, Inggris, Italia, Jepang, Jerman, Polandia, Portugis Brasil, Prancis, Rusia, Spanyol dan Tionghoa Sederhana 60 Karakteristik teknisPlatformWindows, PlayStation 5, PlayStation 4, Xbox Series X dan S dan Xbox One MesinEGO Engine 4.0ModePermainan video pemain tunggal, permainan video multipemain dan co-op mode Formatdistribusi digital Metode inputpapan tombol komputer, tetikus dan …

この項目には、一部のコンピュータや閲覧ソフトで表示できない文字が含まれています(詳細)。 数字の大字(だいじ)は、漢数字の一種。通常用いる単純な字形の漢数字(小字)の代わりに同じ音の別の漢字を用いるものである。 概要 壱万円日本銀行券(「壱」が大字) 弐千円日本銀行券(「弐」が大字) 漢数字には「一」「二」「三」と続く小字と、「壱」「弐」…

Social issue of Homelessness of the Youth The examples and perspective in this article may not represent a worldwide view of the subject. You may improve this article, discuss the issue on the talk page, or create a new article, as appropriate. (April 2020) (Learn how and when to remove this message) Homeless children sleeping in New York City, 1890. Photographed by Jacob Riis. Youth homelessness is the problem of homelessness of young people around the globe. Overview Youth homelessness is a si…

Dassault AviationLogo Stato Francia Forma societariaSociété anonyme Borse valoriEuronext: AM ISINFR0000121725 Fondazione1929 come Société des Avions Marcel Bloch Fondata daMarcel Bloch Sede principaleParigi GruppoGruppo Dassault ControllateDassault Falcon Jet Corp. Dassault Falcon Services Sogitec Industries Dassault International Inc. Thales Persone chiaveMarcel Dassault, Auguste Le Révérend, Benno-Claude Vallières, Serge Dassault, Charles Edelstenne, Éric Trappier SettoreAeronauti…

Freshwaterclass=notpageimage| Location of Freshwater in Newfoundland and Labrador Freshwater is a local service district and designated place in the Canadian province of Newfoundland and Labrador. Geography Freshwater, Conception Bay is in Newfoundland within Subdivision H of Division No. 1.[1] Demographics As a designated place in the 2016 Census of Population conducted by Statistics Canada, Freshwater, Conception Bay recorded a population of 228 living in 99 of its 147 total private dw…

Scottish political party The subject of this article is participating in the 2024 general election to the House of Commons of the United Kingdom on 4 July, and has had no MPs in the House of Commons since Parliament was dissolved on 30 May. Some parts of this article may be out of date during this period. Please feel free to improve this article (but note that updates without valid and reliable references will be removed) or discuss changes on the talk page. Alba Party Pàrtaidh AlbaLe…

الروم الأنطاكيّون Έλληνες της Αντιόχειας معمودية طفل من أسرة رومية أنطاكية تركية في مدينة أنطاكية التعداد الكلي حوالي 1.8 مليون نسمة[1] مناطق الوجود المميزة  سوريا ‏ 520,000 - 700,000 [2][3]  لبنان ‏ 600,000 [4][5][6]  الولايات المتحدة ‏ 100,000 [7]  ك…

Prime minister of New Zealand from 1972 to 1974 For the American army surgeon, see Norman T. Kirk. The Right HonourableNorman KirkKirk in 196629th Prime Minister of New ZealandIn office8 December 1972 – 31 August 1974MonarchElizabeth IIDeputyHugh WattGovernor-GeneralDenis BlundellPreceded byJack MarshallSucceeded byBill Rowling16th Minister of Foreign AffairsIn office8 December 1972 – 31 August 1974Prime MinisterHimselfPreceded byKeith HolyoakeSucceeded byBill Rowling7th…

Russian airborne radar Not to be confused with Zaslon Active Protection System. Zaslon - MMiG-31 showing Zaslon antennaCountry of originRussiaTypePESARange400 km for 20 m2 RCS[1][2](282 km for 5 m2[3])Diameter1.4 meters The Russian (former USSR) BRLS-8B Zaslon (Barrier) is an all-weather multimode airborne radar developed between 1975 and 1980 by the Tikhomirov Scientific Research Institute of Instrument Design as part of the weapons control system of the MiG-31 supe…

Silicon wafer manufacturerSiltronic AGFormerlyWacker-Chemitronic GmbH (1968-1994)Wacker Siltronic GmbH (1994-1996)Wacker Siltronic AG (1996-2004)Company typePublic (Aktiengesellschaft)Traded asFWB: SHLMDAX componentISINDE000WAF3001IndustryElectronicsFounded1968; 56 years ago (1968) in BurghausenHeadquartersMunich, GermanyRevenue €1.4 billion[1] (2021)Operating income €316.9 million (2021)[1]Net income €289.6 million (2021)[1]Total assets …

Negara Bagian IndianaNegara bagian BenderaLambangJulukan: The Hoosier StateMotto: The Crossroads of America bahasa Indonesia: Persimpangan AmerikaHimne daerah: On the Banks of the Wabash, Far AwayPeta Amerika Serikat dengan Indiana ditandaiNegaraAmerika SerikatSebelum menjadi negara bagianWilayah IndianaBergabung ke Serikat11 Desember 1816 (ke-19)Ibu kota(dan kota terbesar)IndianapolisMetropolitan terbesarIndianapolis RayaPemerintahan • GubernurEric Holcomb (R) •…

Thomas SchlammeSchlamme pada 2016LahirThomas David Schlamme22 Mei 1950 (umur 74)Houston, Texas, ASPekerjaanSutradara, produserSuami/istriChristine Lahti ​(m. 1983)​Anak3 Thomas David Schlamme (/ʃlɑːmiː/;[1] lahir 22 Mei 1950) adalah seorang sutradara televisi Amerika Serikat, yang dikenal karena kolaborasinya dengan Aaron Sorkin.[2][3] Ia dikenal karena karyanya sebagai produser eksekutif pada The West Wing dan Studio 60 on the Sunset…

Index: pl ar de en es fr it arz nl ja pt ceb sv uk vi war zh ru af ast az bg zh-min-nan bn be ca cs cy da et el eo eu fa gl ko hi hr id he ka la lv lt hu mk ms min no nn ce uz kk ro simple sk sl sr sh fi ta tt th tg azb tr ur zh-yue hy my ace als am an hyw ban bjn map-bms ba be-tarask bcl bpy bar bs br cv nv eml hif fo fy ga gd gu hak ha hsb io ig ilo ia ie os is jv kn ht ku ckb ky mrj lb lij li lmo mai mg ml zh-classical mr xmf mzn cdo mn nap new ne frr oc mhr or as pa pnb ps pms nds crh qu sa sah sco sq scn si sd szl su sw tl shn te bug vec vo wa wuu yi yo diq bat-smg zu lad kbd ang smn ab roa-rup frp arc gn av ay bh bi bo bxr cbk-zam co za dag ary se pdc dv dsb myv ext fur gv gag inh ki glk gan guw xal haw rw kbp pam csb kw km kv koi kg gom ks gcr lo lbe ltg lez nia ln jbo lg mt mi tw mwl mdf mnw nqo fj nah na nds-nl nrm nov om pi pag pap pfl pcd krc kaa ksh rm rue sm sat sc trv stq nso sn cu so srn kab roa-tara tet tpi to chr tum tk tyv udm ug vep fiu-vro vls wo xh zea ty ak bm ch ny ee ff got iu ik kl mad cr pih ami pwn pnt dz rmy rn sg st tn ss ti din chy ts kcg ve 
Prefix: a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9 
Kembali kehalaman sebelumnya