animetrics / PlistCpp

C++ plist reader and writer. Supports XML and binary Apple Property list (plist) formats.
140 stars 64 forks source link

how can i use with windows #12

Open tianqibucuohao opened 9 years ago

tianqibucuohao commented 9 years ago

i downed the zip yesterday. i need to read and write the plist file. i copyed some files to my project as the README said., also the hold include folder . and cpp file added

include "plist.hpp"

using namespace plist; my function add like this map<string, boost::and> dict; Plist::readPlist("sample.plist", dict);

but, when i complied, it failed. It linking error . show me unresolved external "void __cdecl Plist::readPlist()..."

animetrics commented 9 years ago

Hi,

You must now also include Plist.cpp and PlistDate.cpp in your project.

Best, Marc

On Tue, Sep 30, 2014 at 01:52:18AM -0700, lich wrote:

i downed the zip yesterday. i need to read and write the plist file. i copyed some files to my project as the README said., also the hold include folder . and cpp file added

include "plist.hpp"

using namespace plist; my function add like this map dict; Plist::readPlist("sample.plist", dict);

but, when i complied, it failed. It linking error . show me unresolved external "void __cdecl Plist::readPlist()..."

— Reply to this email directly or view it on GitHub.*

tianqibucuohao commented 9 years ago

Thanks @animetrics. Now, i include Plist.cpp and PlistDate.cpp in my project. And i try it out. New questions comes after complied, the results has 120 errors and 2 warning. All errors from plist.cpp, like this plist.hpp(44) : error C2146: syntax error : missing ';' before identifier 'integer_type'; plist.cpp(46) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int; plist.cpp(131) : error C2146: syntax error : missing ';' before identifier 'getCount'; plist.cpp(151) : error C2039: 'x' : is not a member of 'Plist::hostLittleEndian::'; plist.cpp(174) : error C2974: 'Plist::writeXMLSimpleNode' : invalid template argument for 'T', type expected; plist.cpp(273) : error C2662: 'std::vector<_Ty,_Alloc>::push_back' : cannot convert 'this' pointer from 'std::vector' to 'std::vector<_Ty,_Alloc> &' Reason: cannot convert from 'std::vector' to 'std::vector<_Ty,_Alloc>' Conversion requires a second user-defined-conversion operator or constructor;

Am i did anything wrong? I do not install boost::any , so i cpoy boost folder to my project . I try to run runTest.bat Release, and shows me cant`t find the path.

Best, Lich

animetrics commented 9 years ago

What version of MSVC are you using? Do the example tests work when you use cmake to build the project?

Marc

On Tue, Oct 07, 2014 at 07:07:27PM -0700, lich wrote:

Thanks. Now, i include Plist.cpp and PlistDate.cpp in my project. And i try it out. New questions comes after complied, the results has 120 errors and 2 warning. All errors from plist.cpp, like this plist.hpp(44) : error C2146: syntax error : missing ';' before identifier 'integer_type'; plist.cpp(46) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int; plist.cpp(131) : error C2146: syntax error : missing ';' before identifier 'getCount'; plist.cpp(151) : error C2039: 'x' : is not a member of 'Plist::hostLittleEndian::'; plist.cpp(174) : error C2974: 'Plist::writeXMLSimpleNode' : invalid template argument for 'T', type expected; plist.cpp(273) : error C2662: 'std::vector<_Ty,_Alloc>::push_back' : cannot convert 'this' pointer from 'std::vector' to 'std::vector<_Ty,_Alloc> &' Reason: cannot convert from 'std::vector' to 'std::vector<_Ty,_Alloc>' Conversion requires a second user-defined-conversion operator or constructor;

Am i did anything wrong? I do not install boost::any , so i cpoy boost folder to my project . I try to run runTest.bat Release, and shows me cant`t find the path.

Best, Lich

— Reply to this email directly or view it on GitHub.*

tianqibucuohao commented 9 years ago

My version of MSVC is vc8.0. The example tests didnt work when i use cmake to build the project. So I include all the file of include folder and src folder into my project, except the file runTests.cpp and plistTests.cpp. Compiled, it didnt show errrors differences from last time. It just show cant find the "atoll" fucntion statement, even I include file <stdlib.h>. Now , I changed function "atol" from function "atoll". It may cause some question that I dont know. Finally, after change function, it works and now I learn to how to use it.

Thank you very much @animetrics

Lich

tianqibucuohao commented 9 years ago

I don`t know why always show me "function " is not a member of 'plist' and 'function'identifier not found when i try to use some function, for example, function " countDictionary", "stringFromvalue" and so on. But I found them all in 'Plist'.

Lich

tianqibucuohao commented 9 years ago

another question, how can i travel all the node of the plist file?

Lich

animetrics commented 9 years ago

Hi Lich,

When you deserialize a plist, there are no longer "nodes". It is in native stdlib containers of c++. So you iterate through it the same way you would iterate through maps, vectors, etc.

Marc

On Fri, Oct 10, 2014 at 01:04:38AM -0700, lich wrote:

another question, how can i travel all the node od the plist file?

Lich

— Reply to this email directly or view it on GitHub.*

tianqibucuohao commented 9 years ago

For example, my plist file struct like this:

First Name Lich FileName LichFile Sex Male

After iterated through map and vector, I saw the result by print "key : value: " format.

key:First key: FileName value : LichFile key: Name value: Lich key: Sex value:Male

Why the key "FileName" print before the key "Name"?

Lich

tianqibucuohao commented 9 years ago

Is it associated with map type, less? how do i print the right way as same as my plist file struction? template < class Key, class Type, class Traits = less, class Allocator=allocator<pair <const Key, Type> >

class map;

animetrics commented 9 years ago

A dictionary or associative array, in most languages, does not allow the user to choose an arbitrary ordering. By nature, a dictionary is meant to be looked up by key:

cout<<dict["Name"]<<endl; cout<<dict["FileName"]<<endl;

so the order in which it is stored is not important and the implementation usually chooses the ordering to be optimal for lookup (in the C++ map container, keys are sorted). Therefore, in general, you should not rely on any serialization/deserialization to preserve an ordering. If you need to specify an arbitrary ordering, the proper data structure is an array. You should have an array of keys and then an array of values, both according to the ordering you want.

On Fri, Oct 10, 2014 at 08:41:37PM -0700, lich wrote:

For example, my plist file struct like this

First

Name Lich FileName LichFile

After iterated through map and vector, I saw the result by print "key : value: " format.

key:First

key: FileName value : LichFile key: Name value: Lich

Why the key "FileName" print before the key "Name"?

— Reply to this email directly or view it on GitHub.*

tianqibucuohao commented 9 years ago

How to add the data to the dictionary from the plist file? If my plist file like this,

First Name Lich FileName LichFile Sex Male

And Plist::readPlist("myplist.plist", dict); I want to add a key-string data item into that included . Coud I travel the map first, and after travel vector that My code like this, "if (baParent.type() == typeid(map<string, boost::any>) // { map<string, boost::any> dictTemp = boost::any_cast<map<\string, boost:;any> >(it->second); dictTemp[key]=anyString; } But, run over, write to the file. Nothing changed the file. After running, file will be changed that what I want.

First Name Lich FileName LichFile Sex Male Age twenty
tianqibucuohao commented 9 years ago

I have used map insert function, tried to add the data, buf fail. Suppose, I got the position of which is in , changed type from boost:;any to map. Now, whether I got the pointer of map after changed type,
if yes, i use the function of c++ map or vector container , insert data, review the file after write to the dick. Nothing change. What I forgot to do? Or because of I use the local variables, over it is life scope? I think the variable memory was released , so after run over, it can`t re-write in the root-dictionary. Is it ? @animetrics

Lich

animetrics commented 9 years ago

Hi Lich,

It is difficult for me to understand what you are trying to do. Can you send the code?

Marc

On Wed, Oct 15, 2014 at 07:09:36PM -0700, lich wrote:

I have used map insert function, tried to add the data, buf fail. Suppose, I got the position of which is in , changed type from boost:;any to map. Now, whether I got the pointer of map after changed type,

if yes, i use the function of c++ map or vector container , insert data, review the file after write to the dick. Nothing change. What I forgot to do? Or because of I use the local variables, over it is life scope?

Lich

— Reply to this email directly or view it on GitHub.*

tianqibucuohao commented 9 years ago

Okey! First, I want to add some infomation into the plist file. And my plist file like this, I need to my age infomation in it . Before: f

After just I needed:

s


Second, here my code (not of all): void InsertNewInfo(boost::any* ba, std::string key, boost::any baNewData) {   if (ba->type() == typeid(std::map<std::string, boost::any>)  {      std::map<std::string, boost::any>* dict = boost::any_cast< std::map<std::string, boost::any> >(ba);      std::map<std::string, boost::any>::iterator it = dict->begin();      for( ; it != dict->end() ; ++it)      {        if ( /* Here I want to add  */  )       {        dict[key.c_str()] = baNewData;   }  }

}

Here , my main function called InsertNewInfo. main() {  std::map<std::string, boost::any> root_dict;   Plist::readPlist("Inf.plist", root_dict);   std::string key = "age";   std::string value = "23";   boost::any baData = value;  boost::any baSecond = root_dict->second;  InsertNewInfo(&baSecond, key, baData); &nbsp:Plist::writePlistXML("Inf_new.plist", root_dict);

}

But run the program, Inf.plist file is as the same as Inf_new.plist file. Nothing changed Inf.plist file. @animetrics Lich.

QiuShiHuang commented 9 years ago

I need to translate a Apple plist file. I've included all downloaded files. However, the program does not work properly. This's what I've written in Main.

std::map<std::string, boost::any> dict; Plist::readPlist("D:\111", dict);

This's where I was interrupted position.

In plist.cpp throw Error("This type is not supported");

I think I need a hand to solve this problem.

I'm sorry to leave MSG at there.