• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            隨筆 - 224  文章 - 41  trackbacks - 0
            <2025年5月>
            27282930123
            45678910
            11121314151617
            18192021222324
            25262728293031
            1234567

            享受編程

            常用鏈接

            留言簿(11)

            隨筆分類(lèi)(159)

            隨筆檔案(224)

            文章分類(lèi)(2)

            文章檔案(4)

            經(jīng)典c++博客

            搜索

            •  

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            大師:https://github.com/animetrics/PlistCpp

            發(fā)布了多個(gè)平臺(tái),生成和解析plist文件,這里只給出windows平臺(tái)下的應(yīng)用。下載
            使用方法如下:

            read a plist from disk whose root node is a
            dictionary:
            
            map<string, boost::any> dict; 
            Plist::readPlist("binaryExample1.plist", dict);
             
             
            To write a plist, e.g. dictionary
            
            map<string, boost::any> dict;
            populateDictionary(dict);
            Plist::writePlistXML("xmlExampleWritten.plist", dict);
             
            // PListCpp.cpp : 定義控制臺(tái)應(yīng)用程序的入口點(diǎn)。
            //

            #include 
            "stdafx.h"
            #include 
            "Plist.hpp"
            #include 
            <iostream>
            #include 
            <fstream>
            #include 
            <iterator>

            using namespace std;

            int _tmain(int argc, _TCHAR* argv[])
            {
                map
            <string, boost::any> dict; 
                Plist::readPlist(
            "XMLExample1.plist", dict);

                map
            <string,boost::any>::iterator it;
                
            for(it=dict.begin();it!=dict.end();++it)
                
            {
                    cout
            <<"key: "<<it->first <<endl;
                }


                
            const vector<boost::any>& plistArray = boost::any_cast<const vector<boost::any>& >(dict.find("testArray")->second);
                cout
            <<boost::any_cast<const int64_t&>(plistArray[0])<<endl;
                cout
            <<boost::any_cast<const string&>(plistArray[1]).c_str()<<endl;

                
            //

                
            return 0;
            }



            /*
            static void checkDictionary(const map<string, boost::any>& dict)
            {
                    string actualString = "hello there";
                    double actualDouble = 1.34223;
                    int actualInt = -3455;

                    // checking byte array
                    std::ifstream stream("testImage.png", std::ios::binary);
                    if(!stream)
                        throw std::runtime_error("Can't open file: testImage.png");

                    int start = stream.tellg();
                    stream.seekg(0, std::ifstream::end);
                    int size = ((int) stream.tellg()) - start;
                    std::vector<char> actualData(size);
                    if(size > 0)
                    {
                        stream.seekg(0, std::ifstream::beg);
                        stream.read( (char *)&actualData[0], size );
                    }
                    else
                    {
                        throw std::runtime_error("Can't read zero length data");
                    }

            #ifdef TEST_VERBOSE
                    cout<<"   Checking data"<<endl<<"     length: "<<endl;
            #endif


                    const vector<char>& plistData = boost::any_cast<const vector<char>& >(dict.find("testImage")->second);

                    // length
                    CHECK_EQUAL(actualData.size(), plistData.size());
            #ifdef TEST_VERBOSE
                    cout<<"                            done."<<endl<<"     Data values: "<<endl;
            #endif


                    // data
                    CHECK_ARRAY_EQUAL(actualData.data(), plistData.data(), actualData.size());
            #ifdef TEST_VERBOSE
                    cout<<"                            done."<<endl;
            #endif


                    // checking double

            #ifdef TEST_VERBOSE
                    cout<<"   Checking double "<<endl;
            #endif


                    CHECK_CLOSE(actualDouble,boost::any_cast<const double&>(dict.find("testDouble")->second), 1E-5); 
            #ifdef TEST_VERBOSE
                    cout<<"                            done."<<endl;
            #endif


                    // checking float 
                    
            #ifdef TEST_VERBOSE
                    cout<<"   Checking float "<<endl;
            #endif


                    CHECK_CLOSE(actualDouble,boost::any_cast<const double&>(dict.find("testFloat")->second), 1E-5); 
            #ifdef TEST_VERBOSE
                    cout<<"                            done."<<endl;
            #endif


                    // checking int
            #ifdef TEST_VERBOSE
                    cout<<"   Checking int "<<endl;
            #endif


                    CHECK_EQUAL(actualInt, boost::any_cast<const int64_t&>(dict.find("testInt")->second));
            #ifdef TEST_VERBOSE
                    cout<<"                            done."<<endl;
            #endif


                    // checking string
            #ifdef TEST_VERBOSE
                    cout<<"   Checking string "<<endl;
            #endif


                    CHECK_ARRAY_EQUAL(actualString.c_str(),  boost::any_cast<const string&>(dict.find("testString")->second).c_str(), actualString.size());
            #ifdef TEST_VERBOSE
                    cout<<"                            done."<<endl;
            #endif


                    // checking array
            #ifdef TEST_VERBOSE
                    cout<<"   Checking array "<<endl;
            #endif

                    const vector<boost::any>& plistArray = boost::any_cast<const vector<boost::any>& >(dict.find("testArray")->second);
                    int actualArrayItem0 = 34;
                    string actualArrayItem1 = "string item in array";
                    CHECK_EQUAL(actualArrayItem0, boost::any_cast<const int64_t&>(plistArray[0]));
                    CHECK_ARRAY_EQUAL(actualArrayItem1.c_str(), boost::any_cast<const string&>(plistArray[1]).c_str(), actualArrayItem1.size());
            #ifdef TEST_VERBOSE
                    cout<<"                            done."<<endl;
            #endif


                    // checking long array (need to do this because there is different logic if
                    // the length of the array is >= 15 elements
                    
            #ifdef TEST_VERBOSE
                    cout<<"   Checking long array "<<endl;
            #endif

                    const vector<boost::any>& plistArrayLarge = boost::any_cast<const vector<boost::any>& >(dict.find("testArrayLarge")->second);
                    int i = 0;
                    for(vector<boost::any>::const_iterator it = plistArrayLarge.begin(); 
                            i < 256;
                            ++it, ++i)
                        CHECK_EQUAL(i, boost::any_cast<const int64_t&>(*it));
            #ifdef TEST_VERBOSE
                    cout<<"                            done."<<endl;
            #endif


                    // checking long dict (need to do this because there is different logic if the length
                    // of the dict is >= 15 elements
                    
            #ifdef TEST_VERBOSE
                    cout<<"   Checking long dict "<<endl;
            #endif

                    const map<string, boost::any>& plistDictLarge = boost::any_cast<const map<string, boost::any>& >(dict.find("testDictLarge")->second);
                    i = 0;
                    for(map<string, boost::any>::const_iterator it = plistDictLarge.begin();
                            i < 256;
                            ++it, ++i)
                        CHECK_EQUAL(i, boost::any_cast<const int64_t&>(it->second));
            #ifdef TEST_VERBOSE
                    cout<<"                            done."<<endl;
            #endif


                    // checking date

            #ifdef TEST_VERBOSE
                    cout<<"   Checking date "<<endl;
            #endif


                    int actualDate = 338610664;
                    CHECK_EQUAL((int) actualDate, (int) boost::any_cast<const PlistDate&>(dict.find("testDate")->second).timeAsAppleEpoch());
            //        cout<<"time as xml convention "<<boost::any_cast<const PlistDate&>(dict.find("testDate")->second).timeAsXMLConvention()<<endl;
            #ifdef TEST_VERBOSE
                    cout<<"                            done."<<endl;
            #endif



                    // checking bools

            #ifdef TEST_VERBOSE
                    cout<<"   Checking bools "<<endl;
            #endif


                    bool actualTrue = true;
                    bool actualFalse = false;
                    CHECK_EQUAL(actualTrue, boost::any_cast<const bool&>(dict.find("testBoolTrue")->second));
                    CHECK_EQUAL(actualFalse, boost::any_cast<const bool&>(dict.find("testBoolFalse")->second));
            #ifdef TEST_VERBOSE
                    cout<<"                            done."<<endl;
            #endif


            //        cout<<"testString = "<<boost::any_cast<const string&>(dict.find("testString")->second)<<endl;
            //        cout<<"testDouble = "<<boost::any_cast<const double&>(dict.find("testDouble")->second)<<endl;
            //        cout<<"testInt = "<<boost::any_cast<const int&>(dict.find("testInt")->second)<<endl;
            //        cout<<"testDate = "<<boost::any_cast<const PlistDate&>(dict.find("testDate")->second).timeAsXMLConvention()<<endl;
                    //cout<<"testDate = "<<boost::any_cast<const PlistDate&>(dict.find("testDate")->second).timeAsAppleEpoch()<<endl;

            }

            SUITE(PLIST_TESTS)
            {

                TEST(READ_XML)
                {
                    map<string, boost::any> dict; 
                    Plist::readPlist("XMLExample1.plist", dict);

            #ifdef TEST_VERBOSE
                    cout<<"READ_XML test"<<endl<<endl;
            #endif

                    checkDictionary(dict);
            #ifdef TEST_VERBOSE
                    cout<<endl<<"READ_XML test done"<<endl<<endl;
            #endif

                }

                TEST(READ_BINARY)
                {
                    map<string, boost::any> dict; 
                    Plist::readPlist("binaryExample1.plist", dict);

            #ifdef TEST_VERBOSE
                    cout<<"READ_BINARY test"<<endl<<endl;
            #endif

                    checkDictionary(dict);
            #ifdef TEST_VERBOSE
                    cout<<endl<<"READ_BINARY test done"<<endl<<endl;
            #endif

                }

                TEST(WRITE_BINARY)
                {
                    map<string, boost::any> dict;
                    createMessage(dict);
            #ifdef TEST_VERBOSE
                    cout<<"WRITE_BINARY test"<<endl<<endl;
            #endif

                    Plist::writePlistBinary("binaryExampleWritten.plist", dict);
                    dict.clear();
                    Plist::readPlist("binaryExampleWritten.plist", dict);
                    checkDictionary(dict);
            #ifdef TEST_VERBOSE
                    cout<<endl<<"WRITE_BINARY test done"<<endl<<endl;
            #endif

                }

                TEST(WRITE_XML)
                {
                    map<string, boost::any> dict;
                    createMessage(dict);
            #ifdef TEST_VERBOSE
                    cout<<"WRITE_XML test"<<endl<<endl;
            #endif

                    Plist::writePlistXML("xmlExampleWritten.plist", dict);
                    dict.clear();
                    Plist::readPlist("xmlExampleWritten.plist", dict);
                    checkDictionary(dict);
            #ifdef TEST_VERBOSE
                    cout<<endl<<"WRITE_XML test done"<<endl<<endl;
            #endif

                }

                TEST(WRITE_BINARY_TO_BYTE_ARRAY)
                {
            #ifdef TEST_VERBOSE
                    cout<<"WRITE_BINARY_TO_BYTE_ARRAY test"<<endl<<endl;
            #endif

                    vector<char> data;
                    map<string, boost::any> dict;
                    createMessage(dict);
                    Plist::writePlistBinary(data, dict);
                    map<string, boost::any> dictCheck;
                    Plist::readPlist(&data[0], data.size(), dictCheck);
                    checkDictionary(dictCheck);
            #ifdef TEST_VERBOSE
                    cout<<endl<<"WRITE_BINARY_TO_BYTE_ARRAY test done"<<endl<<endl;
            #endif

                }

                TEST(WRITE_XML_TO_BYTE_ARRAY)
                {
            #ifdef TEST_VERBOSE
                    cout<<"WRITE_XML_TO_BYTE_ARRAY test"<<endl<<endl;
            #endif

                    vector<char> data;
                    map<string, boost::any> dict;
                    createMessage(dict);
                    Plist::writePlistXML(data, dict);
                    map<string, boost::any> dictCheck;
                    Plist::readPlist(&data[0], data.size(), dictCheck);
                    checkDictionary(dictCheck);
            #ifdef TEST_VERBOSE
                    cout<<endl<<"WRITE_XML_TO_BYTE_ARRAY test done"<<endl<<endl;
            #endif

                }

                TEST(DATE)
                {
                    PlistDate date;

                    // check comparisons.

                    double objectTime = date.timeAsAppleEpoch();

                    PlistDate dateGreater(date);
                    dateGreater.setTimeFromAppleEpoch(objectTime + 1);
                    PlistDate dateLess(date);
                    dateLess.setTimeFromAppleEpoch(objectTime - 1);

                    CHECK_EQUAL(1, PlistDate::compare(dateGreater, dateLess));
                    CHECK_EQUAL(-1, PlistDate::compare(dateLess, dateGreater));
                    CHECK_EQUAL(0, PlistDate::compare(date, date));

                    CHECK(dateGreater > dateLess);
                    CHECK(dateLess < dateGreater);
                    CHECK(date == date);

                    dateGreater.setTimeFromAppleEpoch(objectTime + 100);

                    time_t seconds = dateGreater.secondsSinceDate(date);

                    CHECK_EQUAL(100, seconds);
                }

            }
            */
             
            posted on 2012-06-05 17:09 漂漂 閱讀(4501) 評(píng)論(0)  編輯 收藏 引用

            只有注冊(cè)用戶(hù)登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問(wèn)   Chat2DB   管理


            久久婷婷五月综合色高清| 欧美一级久久久久久久大| 精品乱码久久久久久久| 亚洲国产精品久久| 亚洲精品高清一二区久久| 久久久久99精品成人片直播| 91亚洲国产成人久久精品网址| 久久久久国色AV免费观看| 亚洲精品乱码久久久久久中文字幕 | 亚洲va久久久噜噜噜久久狠狠| 精品综合久久久久久97超人| 无码任你躁久久久久久| 久久久久久久久久久久中文字幕| 亚洲一区二区三区日本久久九| 国产毛片欧美毛片久久久| 国产毛片久久久久久国产毛片| 亚洲AV日韩精品久久久久| 久久精品无码一区二区三区免费| 久久国产欧美日韩精品| 久久九色综合九色99伊人| 久久香蕉国产线看观看精品yw| 亚洲天堂久久久| 久久精品免费大片国产大片| 国产精品对白刺激久久久| 久久青青草视频| 无码乱码观看精品久久| 久久99精品国产麻豆不卡| A狠狠久久蜜臀婷色中文网| 久久夜色精品国产欧美乱| 7777精品伊人久久久大香线蕉| 久久久久无码国产精品不卡| 国产真实乱对白精彩久久| 色综合久久88色综合天天| 久久精品aⅴ无码中文字字幕重口| 香蕉99久久国产综合精品宅男自 | 久久无码中文字幕东京热| 久久男人AV资源网站| 久久成人18免费网站| 久久精品国产99久久丝袜| 久久黄色视频| 一本久久精品一区二区|