{"id":4212,"date":"2022-01-29T08:07:46","date_gmt":"2022-01-29T08:07:46","guid":{"rendered":"http:\/\/truelogic.org\/wordpress\/?p=4212"},"modified":"2022-01-29T08:07:47","modified_gmt":"2022-01-29T08:07:47","slug":"13a-wxwidgets-character-buffer","status":"publish","type":"post","link":"https:\/\/truelogic.org\/wordpress\/2022\/01\/29\/13a-wxwidgets-character-buffer\/","title":{"rendered":"13a. wxWidgets &#8211; Character Buffer"},"content":{"rendered":"\n<p><strong>OVERVIEW<\/strong><\/p>\n\n\n\n<p>Character buffers are used to store buffers in memory for further processing or transferring to other objects. wxWidgets has wxMemoryBuffer which deals with raw bytes, but that is very rarely used. For handing characters, it has two classes:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>wxCharBuffer for handling multi-byte C strings<\/li><li>wxWCharBuffer for handling wide-char C strings<\/li><\/ul>\n\n\n\n<p>Most modern applications handle strings as widechar so here we look at how to use <em>wxWCharBuffer<\/em>. In the sample code below, we initialize a string with printable characters from ASCII code 32 to 126. Then we initialize a <em>wxWCharBuffer<\/em> to store the contents of the string. The buffer is a copy of the contents of the <em>wxString<\/em> variable, so when we change the value of <em>wxString<\/em>, it does not affect the contents of the <em>wxWCharBuffer<\/em>. Finally we shrink the size of the buffer.<\/p>\n\n\n\n<p><strong>SAMPLE CODE<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">charbuffer.cpp<\/pre>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include &lt;wx\/wxprec.h&gt;\n#ifndef WX_PRECOMP\n\t#include &lt;wx\/wx.h&gt;\n#endif\n#include &lt;wx\/buffer.h&gt;\n\nint main(int argc, char **argv) {\n\n\twxString str = wxT(&quot;&quot;);\n\tfor(int i=32; i&lt; 126; i++) {\n\t  char c = (char) i;\n\t  str.Append(c);\n\t}\n\twxPuts(str);\n\twxWCharBuffer buff(str.Length());\n\tbuff = str.c_str();\n\twxPuts(buff);\n\twxPuts(&quot;------------&quot;);\n\tstr = wxT(&quot;dummy&quot;);\n\twxPuts(str);\n\twxPuts(buff);\n\n\twxPuts(&quot;-----------&quot;);\n\tbuff.shrink(10);\n\twxPuts(buff);\t\n\twxPuts(buff&#x5B;2]);\n\t\n}\n<\/pre><\/div>\n\n\n<p>The output is given below<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"771\" height=\"127\" src=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-29-13-33-50.png\" alt=\"\" class=\"wp-image-4215\" srcset=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-29-13-33-50.png 771w, https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-29-13-33-50-620x102.png 620w, https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-29-13-33-50-300x49.png 300w, https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-29-13-33-50-768x127.png 768w\" sizes=\"auto, (max-width: 771px) 100vw, 771px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>OVERVIEW Character buffers are used to store buffers in memory for further processing or transferring to other objects. wxWidgets has wxMemoryBuffer which deals with raw <a class=\"mh-excerpt-more\" href=\"https:\/\/truelogic.org\/wordpress\/2022\/01\/29\/13a-wxwidgets-character-buffer\/\" title=\"13a. wxWidgets &#8211; Character Buffer\">[&#8230;]<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":3595,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[302,365],"tags":[],"class_list":["post-4212","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cc","category-wxwidgets"],"_links":{"self":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/4212","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/comments?post=4212"}],"version-history":[{"count":4,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/4212\/revisions"}],"predecessor-version":[{"id":4217,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/4212\/revisions\/4217"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/media\/3595"}],"wp:attachment":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/media?parent=4212"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/categories?post=4212"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/tags?post=4212"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}