Ex,
I was looking for an INI parser library on Win32 (not what I usually work with beyond admin work). Do you have a link or the name of the libarary I can use to search with.
Thanks
Interim.
Linux registry
quote:I don''t see what you would need a library for. A recent thread here discuss the subject.
Original post by Interim
I was looking for an INI parser library on Win32 (not what I usually work with beyond admin work). Do you have a link or the name of the libarary I can use to search with.
quote:
Original post by Interim
[...]Do you have a link or the name of the libarary I can use to search with.[...]
The main functions are GetPrivateProfileString and WritePrivateProfileString, but there are a few others(for writing integers and enumerating the sections/keys under a section). There is a list of functions that operate on ini files under Registry Functions. It''s near the bottom, just before the list of obsolete functions. Please stay away from the functions that write/read to/from win.ini as it suffers the same problems as the registry =-)
The only real ''problem'' with them is that it takes extra work to do heirarchial data structures, like you might need to have some data values that hold the name of another section to look under.
"Walk not the trodden path, for it has borne it's burden." -John, Flying Monk
ACtually, I always wondered why the heck windows used the
[z]
a=b
c=d
format when something like
z.a=b
z.c=d
Is easier to understand (the information about scope is right there) AND it lets you do your own little hierarchy.
The only disadvantage is it could lead to spaghetti configuration
a.b=1
b.b=2
a.c=1
But the programs could simply read the crap in, and sort it before writing it back out.
[z]
a=b
c=d
format when something like
z.a=b
z.c=d
Is easier to understand (the information about scope is right there) AND it lets you do your own little hierarchy.
The only disadvantage is it could lead to spaghetti configuration
a.b=1
b.b=2
a.c=1
But the programs could simply read the crap in, and sort it before writing it back out.
Well, for one its less typing (even if you copy and paste), especially when you have nested structures:
lots of overhead in the second example (the section name repeated 6 times and a subsection repeated 3 times vs 1 in the ini), but you would need special handling to do the pointer-like thing with ini files and it isnt so obvious what is going on.
[ship1]health=100armor=50shields=637items=*ship1_items[ship1_items]item1=uber lazerz 1000item2=light bombs 5-7item3=improbability drivevsship1.health=100ship1.armor=50ship1.shields=637ship1.items.item1=uber lazerz 1000ship1.items.item2=light bombs 5-7ship1.items.item3=improbability drive
lots of overhead in the second example (the section name repeated 6 times and a subsection repeated 3 times vs 1 in the ini), but you would need special handling to do the pointer-like thing with ini files and it isnt so obvious what is going on.
"Walk not the trodden path, for it has borne it's burden." -John, Flying Monk
Thanks for the link. It''s helpful. I was hoping for something that had more robust Datastructs for INI files, such as a dictionary. This isn''t for "fun" or "education", just a project I wanted to complete for work to ease my chores.
I may just stick to Python in this case. I wrote the code with ConfigParser modules (handles INIs) and will probably just use py2exe to make it portable.
Thanks.
As for a Linux registry. I would prefer not. However, I would like to see more standard rules for storing configuration parameters. OS X''s plists are nice in that regard.
Interim.
I may just stick to Python in this case. I wrote the code with ConfigParser modules (handles INIs) and will probably just use py2exe to make it portable.
Thanks.
As for a Linux registry. I would prefer not. However, I would like to see more standard rules for storing configuration parameters. OS X''s plists are nice in that regard.
Interim.
You can use a class like the one below, and provide serialize functions (read/write). My class below is awful, and the monster was originally a hacked together internal structure to represent hierarchial/complex IMAP commands. However, I found it useful for another project where I keep the configuration as a sings instance of this class, which works well as different layers or modules can override eachother.
However, I wouldn''t recommend usage of it.
#ifndef _CW__VAR_H_#define _CW__VAR_H_ #pragma warning (disable : 4786)#include <fstream>#include <map>#include <sstream>#include <string>#include <vector>#include "..\include\range.h" namespace cw{ class var{public: enum mode { Null, Int, Float, Range, String, List, Assoc }; var() : _type(Null) {} var(const var &value) : _type(value._type) { if(_type == Null) return; else if(_type == Int) _int = value._int; else if(_type == Float) _float = value._float; else if(_type == Range) _range = value._range; else if(_type == String) _string = value._string; else if(_type == List) _list = value._list; else if(_type == Assoc) { for(std::map<std::string, var *>::const_iterator i = value._assoc.begin(); i != value._assoc.end(); i++) _assoc[(*i).first] = new var(*((*i).second)); } } var(mode value) : _type(value), _int(0), _float(0) {} var(const int value) : _type(Int), _int(value) {} var(const float value) : _type(Float), _float(value) {} var(const range &value) : _type(Range), _range(value) {} var(const std::string &value) : _type(String), _string(value) {} ~var() { _assoc_clear(); } var & operator=(const mode rvalue) { _int = 0; _float = 0; _range = 0; _string = ""; _list.clear(); _assoc_clear(); _type = rvalue; return *this; } var & cast(mode type) { if(_type != type) { if(type == Int) _int = _cast_to_int(); else if(type == Float) _float = _cast_to_float(); else if(type == Range) _cast_to_range(); // Note cast is stored in _range else if(type == String) _cast_to_string(); // Note cast is stored in _string // !!! What about List & Assoc ??? _type = type; } return *this; } // var & operator=(const var &rvalue); var & operator=(const int rvalue) { if(_type != Int) { _string = ""; _list.clear(); _assoc_clear(); _type = Int; } _int = rvalue; return *this; } var & operator=(const float rvalue) { if(_type != Float) { _string = ""; _list.clear(); _assoc_clear(); _type = Float; } _float = rvalue; return *this; } var & operator=(const range &rvalue) { if(_type != Range) { _string = ""; _list.clear(); _assoc_clear(); _type = Range; } _range = rvalue; return *this; } var & operator=(const std::string &rvalue) { if(_type != String) { _list.clear(); _assoc_clear(); _type = String; } _string = rvalue; return *this; } bool operator==(const var &rvalue) { if(_type != rvalue._type) return false; if(_type == Null) return true; if(_type == Int) return _int == rvalue._int; if(_type == Float) return _float == rvalue._float; if(_type == Range) return _range == rvalue._range; if(_type == String) return _string == rvalue._string; // !!! What about List & Assoc ??? } inline bool operator==(const mode rvalue) { return _type == rvalue; } inline bool operator!=(const mode rvalue) { return _type != rvalue; } inline bool operator==(const int rvalue) { return (_type == Int) ? _int == rvalue : false; } inline bool operator==(const float rvalue) { return (_type == Float) ? _float == rvalue : false; } inline bool operator==(const range &rvalue) { return (_type == Range) ? _range == rvalue : false; } inline bool operator==(const std::string &rvalue) { return (_type == String) ? _string == rvalue : false; } inline bool is_null(void) { return _type == Null; } inline bool is_int(void) { return _type == Int; } inline bool is_float(void) { return _type == Float; } inline bool is_range(void) { return _type == Range; } inline bool is_string(void) { return _type == String; } inline bool is_list(void) { return _type == List; } inline bool is_assoc(void) { return _type == Assoc; } inline mode type(void) { return _type; } inline int as_int(void) { return (_type == Int) ? _int : _cast_to_int(); } inline float as_float(void) { return (_type == Float) ? _float : _cast_to_float(); } inline range & as_range(void) { return (_type == Range) ? _range : _cast_to_range(); } inline std::string & as_string(void) { return (_type == String) ? _string : _cast_to_string(); } inline std::vector<var> &list(void) { return _list; }// inline std::map<std::string, var> &assoc(void) { return _assoc; } var & operator[](const int rvalue) { if(rvalue < 0) _list.push_back(var()); else if(rvalue < _list.size()) return _list[rvalue]; else _list.resize(rvalue + 1); return _list.back(); } var & operator[](const std::string &rvalue) { std::map<std::string, var *>::const_iterator i = _assoc.find(rvalue); if(i == _assoc.end()) return *(_assoc[rvalue] = new var()); return *((*i).second); } inline var & back(void) { return _list.back(); } inline int size(void) { if(_type = List) return _list.size(); else if(_type = Assoc) return _assoc.size(); return 0; } void print_r(std::ofstream &file, int indent); void print_r(const char *filename, const char *text, int text_len) { std::ofstream file(filename); if(file.is_open()) { file.write(text, text_len); file << "\xd\xa"; print_r(file, 0); file.close(); } } private: int _cast_to_int(void) { if(_type == Float) return (int)_float; if(_type == Range) return _range.begin(); if(_type == String) return atoi(_string.c_str()); return 0; // if Null or List/Assoc } float _cast_to_float(void) { if(_type == Int) return (float)_int; if(_type == Range) return (float)_range.begin(); if(_type == String) return atof(_string.c_str()); return 0; // if Null or List/Assoc } range & _cast_to_range(void) { if(_type == Int) _range = _int; else if(_type == Float) _range = (int)_float; else if(_type == String) // Attempt to extract (begin:end) range from string, but currently: _range = strtol(_string.c_str(), 0, 10); return _range; } std::string & _cast_to_string(void) { std::stringstream x; if(_type == Int) x << _int; else if(_type == Float) x << _float; else if(_type == Range) x << _range.begin() << ":" << _range.end(); return _string = x.str(); } void _assoc_clear(void) { for(std::map<std::string, var *>::const_iterator i = _assoc.begin(); i != _assoc.end(); i++) delete (*i).second; _assoc.clear(); } mode _type; int _int; float _float; range _range; std::string _string; std::vector<var> _list; std::map<std::string, var *> _assoc; static var _null_object;}; } #endif // #ifndef _CW__VAR_H_
Ok, way off topic here, but:
Prefect - where did that screen name come from?
Ok, back to the topic:
I still don''t think that Linux needs a registry. Why would it?
(Stolen from Programmer One)
UNIX is an operating system, OS/2 is half an operating system, Windows is a shell, and DOS is a boot partition virus
Prefect - where did that screen name come from?
Ok, back to the topic:
I still don''t think that Linux needs a registry. Why would it?
(Stolen from Programmer One)
UNIX is an operating system, OS/2 is half an operating system, Windows is a shell, and DOS is a boot partition virus
Ford Prefect is a character from Douglas Adams'' Hitch-Hiker''s Guide to the Galaxy.
Linux doesn''t need something called a "registry" (some argue that it''s already present in /etc), but a standardized config file format sure would be helpful, for two reasons:
- humans don''t need to learn new syntaxes all the time
- it''s easier to write configuration front-ends (whether ncurses-based or graphical is not the point)
cu,
Prefect
Linux doesn''t need something called a "registry" (some argue that it''s already present in /etc), but a standardized config file format sure would be helpful, for two reasons:
- humans don''t need to learn new syntaxes all the time
- it''s easier to write configuration front-ends (whether ncurses-based or graphical is not the point)
cu,
Prefect
Widelands - laid back, free software strategy
quote:
Original post by Prefect
Ford Prefect is a character from Douglas Adams'' Hitch-Hiker''s Guide to the Galaxy.
Ahh.... You''ve read that too. I thought that was where it came from, just wanted to be sure.
(Stolen from Programmer One)
UNIX is an operating system, OS/2 is half an operating system, Windows is a shell, and DOS is a boot partition virus
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement