diff options
-rw-r--r-- | docs/manual.qbk | 21 | ||||
-rw-r--r-- | docs/samples/custom_memory_management.cpp | 25 | ||||
-rw-r--r-- | docs/samples/load_stream.cpp | 68 | ||||
-rw-r--r-- | docs/samples/weekly-shift_jis.xml | 78 | ||||
-rw-r--r-- | docs/samples/weekly-utf-16.xml | bin | 0 -> 3186 bytes | |||
-rw-r--r-- | docs/samples/weekly-utf-8.xml | 78 |
6 files changed, 254 insertions, 16 deletions
diff --git a/docs/manual.qbk b/docs/manual.qbk index 8b3bea6..5668906 100644 --- a/docs/manual.qbk +++ b/docs/manual.qbk @@ -375,22 +375,11 @@ You can use the following accessor functions to change or get current memory man Allocation function is called with the size (in bytes) as an argument and should return a pointer to memory block with alignment that is suitable for pointer storage and size that is greater or equal to the requested one. If the allocation fails, the function has to return null pointer (throwing an exception from allocation function results in undefined behavior). Deallocation function is called with the pointer that was returned by the previous call or with a null pointer; null pointer deallocation should be handled as a no-op. If memory management functions are not thread-safe, library thread safety is not guaranteed.
-This is a simple example of custom memory management:
-
- void* custom_allocate(size_t size)
- {
- return new (std::nothrow) char[size];
- }
-
- void custom_deallocate(void* ptr)
- {
- delete[] static_cast<char*>(ptr);
- }
-
- int main()
- {
- pugi::set_memory_management_functions(custom_allocate, custom_deallocate);
- }
+This is a simple example of custom memory management ([@samples/custom_memory_management.cpp])
+
+[import samples/custom_memory_management.cpp]
+[code_custom_memory_management_decl]
+[code_custom_memory_management_call]
When setting new memory management functions, care must be taken to make sure that there are no live pugixml objects. Otherwise when the objects are destroyed, the new deallocation function will be called with the memory obtained by the old allocation function, resulting in undefined behavior.
diff --git a/docs/samples/custom_memory_management.cpp b/docs/samples/custom_memory_management.cpp new file mode 100644 index 0000000..01a2acf --- /dev/null +++ b/docs/samples/custom_memory_management.cpp @@ -0,0 +1,25 @@ +#include "pugixml.hpp"
+
+#include <new>
+
+//[code_custom_memory_management_decl
+void* custom_allocate(size_t size)
+{
+ return new (std::nothrow) char[size];
+}
+
+void custom_deallocate(void* ptr)
+{
+ delete[] static_cast<char*>(ptr);
+}
+//]
+
+int main()
+{
+//[code_custom_memory_management_call
+ pugi::set_memory_management_functions(custom_allocate, custom_deallocate);
+//]
+
+ pugi::xml_document doc;
+ doc.load("<node/>");
+}
diff --git a/docs/samples/load_stream.cpp b/docs/samples/load_stream.cpp new file mode 100644 index 0000000..4aba8bd --- /dev/null +++ b/docs/samples/load_stream.cpp @@ -0,0 +1,68 @@ +#include "pugixml.hpp"
+
+#include <fstream>
+#include <iomanip>
+#include <iostream>
+
+void print_doc(const char* message, const pugi::xml_document& doc, const pugi::xml_parse_result& result)
+{
+ std::cout
+ << message
+ << "\t: load result '" << result.description() << "'"
+ << ", first character of root name: U+" << std::hex << std::uppercase << std::setw(4) << std::setfill('0') << pugi::as_wide(doc.first_child().name())[0]
+ << ", year: " << doc.first_child().first_child().first_child().child_value()
+ << std::endl;
+}
+
+int main()
+{
+ pugi::xml_document doc;
+
+ {
+ std::ifstream stream("weekly-utf-8.xml");
+ pugi::xml_parse_result result = doc.load(stream);
+
+ // first character of root name: U+9031, year: 1997
+ print_doc("UTF8 file from narrow stream", doc, result);
+ }
+
+ {
+ std::ifstream stream("weekly-utf-16.xml");
+ pugi::xml_parse_result result = doc.load(stream);
+
+ // first character of root name: U+9031, year: 1997
+ print_doc("UTF16 file from narrow stream", doc, result);
+ }
+
+ {
+ // Since wide streams are treated as UTF-16/32 ones, you can't load the UTF-8 file from a wide stream
+ // directly if you have localized characters; you'll have to provide a UTF8 locale (there is no
+ // standard one; you can use utf8_codecvt_facet from Boost (WHAT?))
+ std::wifstream stream("weekly-utf-8.xml");
+ pugi::xml_parse_result result = doc.load(stream);
+
+ // first character of root name: U+00E9, year: 1997
+ print_doc("UTF8 file from wide stream", doc, result);
+ }
+
+ {
+ // Since wide streams are treated as UTF-16/32 ones, you can't load the UTF-16 file from a wide stream
+ // at all; you'll have to provide a UTF16 locale (WHAT??)
+ std::wifstream stream("weekly-utf-16.xml");
+ pugi::xml_parse_result result = doc.load(stream);
+
+ // first character of root name: U+0000, year:
+ print_doc("UTF16 file from wide stream", doc, result);
+ }
+
+ {
+ // Since encoding names are non-standard, you can't load the Shift-JIS (or any other non-ASCII) file
+ // from a wide stream portably; this code assumes Microsoft C Runtime Libraries (WHAT???)
+ std::wifstream stream("weekly-shift_jis.xml");
+ stream.imbue(std::locale(".932"));
+ pugi::xml_parse_result result = doc.load(stream);
+
+ // first character of root name: U+9031, year: 1997
+ print_doc("Shift-JIS file from wide stream", doc, result);
+ }
+}
diff --git a/docs/samples/weekly-shift_jis.xml b/docs/samples/weekly-shift_jis.xml new file mode 100644 index 0000000..7421455 --- /dev/null +++ b/docs/samples/weekly-shift_jis.xml @@ -0,0 +1,78 @@ +<?xml version="1.0" encoding="Shift_JIS"?>
+<!DOCTYPE 週報 SYSTEM "weekly-shift_jis.dtd">
+<!-- 週報サンプル -->
+<週報>
+ <年月週>
+ <年度>1997</年度>
+ <月度>1</月度>
+ <週>1</週>
+ </年月週>
+
+ <氏名>
+ <氏>山田</氏>
+ <名>太郎</名>
+ </氏名>
+
+ <業務報告リスト>
+ <業務報告>
+ <業務名>XMLエディターの作成</業務名>
+ <業務コード>X3355-23</業務コード>
+ <工数管理>
+ <見積もり工数>1600</見積もり工数>
+ <実績工数>320</実績工数>
+ <当月見積もり工数>160</当月見積もり工数>
+ <当月実績工数>24</当月実績工数>
+ </工数管理>
+ <予定項目リスト>
+ <予定項目>
+ <P>XMLエディターの基本仕様の作成</P>
+ </予定項目>
+ </予定項目リスト>
+ <実施事項リスト>
+ <実施事項>
+ <P>XMLエディターの基本仕様の作成</P>
+ </実施事項>
+ <実施事項>
+ <P>競合他社製品の機能調査</P>
+ </実施事項>
+ </実施事項リスト>
+ <上長への要請事項リスト>
+ <上長への要請事項>
+ <P>特になし</P>
+ </上長への要請事項>
+ </上長への要請事項リスト>
+ <問題点対策>
+ <P>XMLとは何かわからない。</P>
+ </問題点対策>
+ </業務報告>
+
+ <業務報告>
+ <業務名>検索エンジンの開発</業務名>
+ <業務コード>S8821-76</業務コード>
+ <工数管理>
+ <見積もり工数>120</見積もり工数>
+ <実績工数>6</実績工数>
+ <当月見積もり工数>32</当月見積もり工数>
+ <当月実績工数>2</当月実績工数>
+ </工数管理>
+ <予定項目リスト>
+ <予定項目>
+ <P><A href="http://www.goo.ne.jp">goo</A>の機能を調べてみる</P>
+ </予定項目>
+ </予定項目リスト>
+ <実施事項リスト>
+ <実施事項>
+ <P>更に、どういう検索エンジンがあるか調査する</P>
+ </実施事項>
+ </実施事項リスト>
+ <上長への要請事項リスト>
+ <上長への要請事項>
+ <P>開発をするのはめんどうなので、Yahoo!を買収して下さい。</P>
+ </上長への要請事項>
+ </上長への要請事項リスト>
+ <問題点対策>
+ <P>検索エンジンで車を走らせることができない。(要調査)</P>
+ </問題点対策>
+ </業務報告>
+ </業務報告リスト>
+</週報>
diff --git a/docs/samples/weekly-utf-16.xml b/docs/samples/weekly-utf-16.xml Binary files differnew file mode 100644 index 0000000..6c8622a --- /dev/null +++ b/docs/samples/weekly-utf-16.xml diff --git a/docs/samples/weekly-utf-8.xml b/docs/samples/weekly-utf-8.xml new file mode 100644 index 0000000..497f572 --- /dev/null +++ b/docs/samples/weekly-utf-8.xml @@ -0,0 +1,78 @@ +<?xml version="1.0"?>
+<!DOCTYPE 騾ア蝣ア SYSTEM "weekly-utf-8.dtd">
+<!-- 騾ア蝣ア繧オ繝ウ繝励Ν -->
+<騾ア蝣ア>
+ <蟷エ譛磯ア>
+ <蟷エ蠎ヲ>1997</蟷エ蠎ヲ>
+ <譛亥コヲ>1</譛亥コヲ>
+ <騾ア>1</騾ア>
+ </蟷エ譛磯ア>
+
+ <豌丞錐>
+ <豌>螻ア逕ー</豌>
+ <蜷>螟ェ驛</蜷>
+ </豌丞錐>
+
+ <讌ュ蜍吝ア蜻翫Μ繧ケ繝>
+ <讌ュ蜍吝ア蜻>
+ <讌ュ蜍吝錐>XML繧ィ繝繧」繧ソ繝シ縺ョ菴懈</讌ュ蜍吝錐>
+ <讌ュ蜍吶さ繝シ繝>X3355-23</讌ュ蜍吶さ繝シ繝>
+ <蟾・謨ー邂。逅>
+ <隕狗ゥ阪b繧雁キ・謨ー>1600</隕狗ゥ阪b繧雁キ・謨ー>
+ <螳溽クセ蟾・謨ー>320</螳溽クセ蟾・謨ー>
+ <蠖捺怦隕狗ゥ阪b繧雁キ・謨ー>160</蠖捺怦隕狗ゥ阪b繧雁キ・謨ー>
+ <蠖捺怦螳溽クセ蟾・謨ー>24</蠖捺怦螳溽クセ蟾・謨ー>
+ </蟾・謨ー邂。逅>
+ <莠亥ョ夐逶ョ繝ェ繧ケ繝>
+ <莠亥ョ夐逶ョ>
+ <P>XML繧ィ繝繧」繧ソ繝シ縺ョ蝓コ譛ャ莉墓ァ倥ョ菴懈</P>
+ </莠亥ョ夐逶ョ>
+ </莠亥ョ夐逶ョ繝ェ繧ケ繝>
+ <螳滓命莠矩繝ェ繧ケ繝>
+ <螳滓命莠矩>
+ <P>XML繧ィ繝繧」繧ソ繝シ縺ョ蝓コ譛ャ莉墓ァ倥ョ菴懈</P>
+ </螳滓命莠矩>
+ <螳滓命莠矩>
+ <P>遶カ蜷井サ也、セ陬ス蜩√ョ讖溯ス隱ソ譟サ</P>
+ </螳滓命莠矩>
+ </螳滓命莠矩繝ェ繧ケ繝>
+ <荳企聞縺ク縺ョ隕∬ォ倶コ矩繝ェ繧ケ繝>
+ <荳企聞縺ク縺ョ隕∬ォ倶コ矩>
+ <P>迚ケ縺ォ縺ェ縺</P>
+ </荳企聞縺ク縺ョ隕∬ォ倶コ矩>
+ </荳企聞縺ク縺ョ隕∬ォ倶コ矩繝ェ繧ケ繝>
+ <蝠城。檎せ蟇セ遲>
+ <P>XML縺ィ縺ッ菴輔°繧上°繧峨↑縺縲</P>
+ </蝠城。檎せ蟇セ遲>
+ </讌ュ蜍吝ア蜻>
+
+ <讌ュ蜍吝ア蜻>
+ <讌ュ蜍吝錐>讀懃エ「繧ィ繝ウ繧ク繝ウ縺ョ髢狗匱</讌ュ蜍吝錐>
+ <讌ュ蜍吶さ繝シ繝>S8821-76</讌ュ蜍吶さ繝シ繝>
+ <蟾・謨ー邂。逅>
+ <隕狗ゥ阪b繧雁キ・謨ー>120</隕狗ゥ阪b繧雁キ・謨ー>
+ <螳溽クセ蟾・謨ー>6</螳溽クセ蟾・謨ー>
+ <蠖捺怦隕狗ゥ阪b繧雁キ・謨ー>32</蠖捺怦隕狗ゥ阪b繧雁キ・謨ー>
+ <蠖捺怦螳溽クセ蟾・謨ー>2</蠖捺怦螳溽クセ蟾・謨ー>
+ </蟾・謨ー邂。逅>
+ <莠亥ョ夐逶ョ繝ェ繧ケ繝>
+ <莠亥ョ夐逶ョ>
+ <P><A href="http://www.goo.ne.jp">goo</A>縺ョ讖溯ス繧定ェソ縺ケ縺ヲ縺ソ繧</P>
+ </莠亥ョ夐逶ョ>
+ </莠亥ョ夐逶ョ繝ェ繧ケ繝>
+ <螳滓命莠矩繝ェ繧ケ繝>
+ <螳滓命莠矩>
+ <P>譖エ縺ォ縲√←縺縺縺讀懃エ「繧ィ繝ウ繧ク繝ウ縺後≠繧九°隱ソ譟サ縺吶k</P>
+ </螳滓命莠矩>
+ </螳滓命莠矩繝ェ繧ケ繝>
+ <荳企聞縺ク縺ョ隕∬ォ倶コ矩繝ェ繧ケ繝>
+ <荳企聞縺ク縺ョ隕∬ォ倶コ矩>
+ <P>髢狗匱繧偵☆繧九ョ縺ッ繧√s縺ゥ縺縺ェ縺ョ縺ァ縲〆ahoo!繧定イキ蜿弱@縺ヲ荳九&縺縲</P>
+ </荳企聞縺ク縺ョ隕∬ォ倶コ矩>
+ </荳企聞縺ク縺ョ隕∬ォ倶コ矩繝ェ繧ケ繝>
+ <蝠城。檎せ蟇セ遲>
+ <P>讀懃エ「繧ィ繝ウ繧ク繝ウ縺ァ霆翫r襍ー繧峨○繧九%縺ィ縺後〒縺阪↑縺縲ゑシ郁ヲ∬ェソ譟サシ</P>
+ </蝠城。檎せ蟇セ遲>
+ </讌ュ蜍吝ア蜻>
+ </讌ュ蜍吝ア蜻翫Μ繧ケ繝>
+</騾ア蝣ア>
|