21 #include "abg-internal.h"
23 ABG_BEGIN_EXPORT_DECLARATIONS
39 char_is_white_space(
int b);
42 char_is_comment_start(
int b);
60 char_is_delimiter(
int b,
bool include_white_space =
true,
61 bool include_square_bracket =
true,
62 bool include_equal =
true)
64 return ((include_square_bracket && (b ==
'['))
65 || (include_square_bracket && (b ==
']'))
68 || (include_equal && (b ==
'='))
70 || (include_white_space && char_is_white_space(b))
71 || char_is_comment_start(b));
86 char_is_property_value_char(
int b)
88 if (char_is_delimiter(b,
false,
103 char_is_section_name_char(
int b)
105 if (b ==
'[' || b ==
']' || b ==
'\n' || char_is_comment_start(b))
117 char_is_property_name_char(
int b)
119 if (char_is_delimiter(b))
131 char_is_function_name_char(
int b)
133 if (char_is_delimiter(b) || b ==
'(' || b ==
')')
146 char_is_function_argument_char(
int b)
148 if (b ==
'(' || b ==
')')
159 char_is_comment_start(
int b)
160 {
return b ==
';' || b ==
'#';}
168 char_is_white_space(
int b)
169 {
return b ==
' ' || b ==
'\t' || b ==
'\n';}
177 trim_white_space(
const string& str)
182 unsigned s = 0, e = str.size() -1;
185 if (!char_is_white_space(str[s]))
189 if (!char_is_white_space(str[e]))
192 return str.substr(s, e - s + 1);
198 struct property::priv
205 priv(
const string& name)
219 : priv_(new priv(name))
227 {
return priv_->name_;}
234 {priv_->name_ = name;}
244 struct property_value::priv
246 enum property_value::value_kind kind_;
248 priv(property_value::value_kind kind = ABSTRACT_PROPERTY_VALUE)
257 : priv_(new priv(ABSTRACT_PROPERTY_VALUE))
264 : priv_(new priv(kind))
270 property_value::value_kind
272 {
return priv_->kind_;}
277 property_value::operator
const string& ()
const
278 {
return as_string();}
288 struct string_property_value::priv
295 priv(
const string& c)
311 priv_(new priv(content))
319 {priv_->content_ = c;}
326 {
return priv_->content_;}
332 string_property_value::operator string()
const
333 {
return as_string();}
360 struct list_property_value::priv
362 vector<string> values_;
363 string representation_;
368 priv(
const vector<string>& vals)
384 priv_(new priv(values))
395 const vector<string>&
397 {
return priv_->values_;}
405 priv_->values_ = values;
406 priv_->representation_.clear();
415 if (priv_->representation_.empty())
417 for (vector<string>::const_iterator i = priv_->values_.begin();
418 i != priv_->values_.end();
421 if (i != priv_->values_.begin())
422 priv_->representation_ +=
",";
423 priv_->representation_ += *i;
426 return priv_->representation_;
456 struct tuple_property_value::priv
458 vector<property_value_sptr> value_items_;
464 priv(
const vector<property_value_sptr>& value_items)
465 : value_items_(value_items)
480 const vector<property_value_sptr>&
482 {
return priv_->value_items_;}
487 vector<property_value_sptr>&
489 {
return priv_->value_items_;}
501 if (priv_->string_rep_.empty())
503 priv_->string_rep_ +=
'{';
504 for (vector<property_value_sptr>::const_iterator i =
510 priv_->string_rep_ +=
",";
511 priv_->string_rep_ += (*i)->as_string();
513 priv_->string_rep_ +=
'}';
515 return priv_->string_rep_;
543 struct simple_property::priv
569 priv_(new priv(value))
587 {
return priv_->value_;}
594 {priv_->value_ = value;}
606 return priv_->value_->as_string().empty();
634 struct list_property::priv
659 priv_(new priv(value))
665 {
return priv_->value_;}
672 {priv_->value_ = value;}
702 struct tuple_property::priv
728 priv_(new priv(value))
736 {priv_->value_ = value;}
743 {
return priv_->value_;}
773 class config::section::priv
782 priv(
const string& name)
786 friend class config::section;
794 config::section::section(
const string& name)
795 : priv_(new priv(name))
803 config::section::section(
const string& name,
805 : priv_(new priv(name))
813 {
return priv_->name_;}
820 {
return priv_->properties_;}
827 {priv_->properties_ = properties;}
834 {priv_->properties_.push_back(prop);}
847 for (properties_type::const_iterator i = get_properties().begin();
848 i != get_properties().end();
850 if ((*i)->get_name() == prop_name)
873 unsigned cur_column_;
884 read_context(istream& in)
911 if (handle_escape(c,
true))
931 bool escaped =
false;
932 return peek(escaped);
945 get(
bool do_handle_escape =
true)
950 result = buf_.back();
956 if (do_handle_escape)
957 handle_escape(result);
1010 handle_escape(
char& c,
bool peek =
false)
1012 bool escaped =
false;
1080 read_next_char(
char& c)
1114 for (
bool is_ok = read_next_char(c);
1116 is_ok = read_next_char(c))
1120 return (c ==
'\n' || eof());
1130 for (
char c = peek(); good(); c = peek())
1131 if (char_is_white_space(c))
1135 return good() || eof();
1146 for (
char c = peek(); good(); c = peek())
1147 if (char_is_comment_start(c))
1151 return good() || eof();
1160 skip_white_spaces_or_comments()
1166 if (char_is_white_space(b))
1167 skip_white_spaces();
1168 else if (char_is_comment_start(b))
1173 return good() || eof();
1185 read_property_name(
string& name)
1188 if (!good() || !char_is_property_name_char(c))
1194 for (c = peek(); good(); c = peek())
1196 if (!char_is_property_name_char(c))
1214 read_function_name(
string& name)
1217 if (!good() || !char_is_function_name_char(c))
1223 for (c = peek(); good(); c = peek())
1225 if (!char_is_function_name_char(c))
1242 read_function_argument(
string& argument)
1245 if (!good() || !char_is_function_argument_char(c))
1251 for (c = peek(); good(); c = peek())
1253 if (!char_is_function_argument_char(c))
1279 skip_white_spaces_or_comments();
1284 if (!read_function_name(name) || name.empty())
1287 skip_white_spaces_or_comments();
1290 if (!good() || b !=
'(')
1294 if (!read_next_char(c))
1298 skip_white_spaces_or_comments();
1303 vector<string> arguments;
1310 if (!read_function_argument(arg))
1313 skip_white_spaces_or_comments();
1321 skip_white_spaces_or_comments();
1326 arguments.push_back(arg);
1332 expr.reset(
new function_call_expr(name, arguments));
1340 read_property_value()
1356 if (list && list->get_content().size() == 1)
1357 result.reset(
new string_property_value(list->get_content()[0]));
1376 bool escaped =
false;
1377 int b = peek(escaped);
1381 if (!escaped && char_is_delimiter(b,
false))
1386 for (b = peek(escaped); good(); b = peek(escaped))
1391 if (!escaped && !char_is_property_value_char(b))
1397 return trim_white_space(v);
1404 read_string_property_value()
1410 string value = read_string();
1411 result.reset(
new string_property_value(value));
1420 read_list_property_value()
1424 vector<string> content;
1428 str = read_string();
1431 content.push_back(str);
1433 skip_white_spaces();
1436 if (!good() || b !=
',')
1438 skip_white_spaces();
1443 skip_white_spaces();
1446 if (!content.empty())
1447 result.reset(
new list_property_value(content));
1459 read_tuple_property_value()
1473 vector<property_value_sptr> values;
1474 while (good() && peek() !=
'}')
1476 skip_white_spaces();
1477 if ((value = read_property_value()))
1478 values.push_back(value);
1479 skip_white_spaces();
1480 if (good() && peek() ==
',')
1494 result.reset(
new tuple_property_value(values));
1507 read_section_name(
string& name)
1510 if (!good() || !char_is_section_name_char(b))
1514 ABG_ASSERT(read_next_char(c) || char_is_section_name_char(b));
1517 for (b = peek(); good(); b = peek())
1519 if (!char_is_section_name_char(b))
1538 if (!read_property_name(name))
1541 skip_white_spaces();
1550 skip_white_spaces();
1554 property_sptr empty_value_property(
new simple_property(name));
1555 return empty_value_property;
1566 result.reset(
new tuple_property(name, tv));
1568 result.reset(
new list_property(name, lv));
1570 result.reset(
new simple_property(name, sv));
1596 if (!read_section_name(name))
1599 if (!skip_white_spaces())
1602 if (! read_next_char(c) || c !=
']')
1605 if (!skip_white_spaces_or_comments())
1611 properties.push_back(prop);
1612 skip_white_spaces_or_comments();
1615 if (!properties.empty())
1635 friend class config;
1640 priv(
const string& path,
1651 config::config(
const string& path,
1653 : priv_(new priv(path, sections))
1666 {
return priv_->path_;}
1673 {priv_->path_ = path;}
1678 {
return priv_->sections_;}
1685 {priv_->sections_ = sections;}
1704 read_context ctxt(input);
1706 while (input.good())
1708 ctxt.skip_white_spaces_or_comments();
1710 sections.push_back(section);
1715 return input.good() || input.eof();
1731 std::ifstream in(path.c_str(), std::ifstream::binary);
1818 if (!simple_prop->has_empty_value())
1819 result = simple_prop->get_value()->as_string();
1822 result = list_prop->get_value()->as_string();
1824 result = tuple_prop->get_value()->as_string();
1842 out << prop->get_name();
1843 string value = write_property_value(prop);
1845 out <<
" = " << write_property_value(prop);
1855 write_section(
const config::section& section,
1858 out <<
"[" << section.get_name() <<
"]\n";
1859 for (config::properties_type::const_iterator i =
1860 section.get_properties().begin();
1861 i != section.get_properties().end();
1865 write_property(*i, out);
1885 for (config::sections_type::const_iterator i = sections.begin();
1886 i != sections.end();
1889 write_section(**i, out);
1907 std::ofstream f(path.c_str(), std::ofstream::binary);
1928 std::ostream& output)
1955 struct function_call_expr::priv
1958 vector<string> arguments_;
1963 priv(
const string& name,
1964 const vector<string>& arguments)
1966 arguments_(arguments)
1976 function_call_expr::function_call_expr(
const string& name,
1977 const vector<string>& args)
1978 : priv_(new priv(name, args))
1986 {
return priv_->name_;}
1993 const vector<string>&
1995 {
return priv_->arguments_;}
2004 {
return priv_->arguments_;}
2020 read_context ctxt(input);
2021 return ctxt.read_function_call_expr(expr);
2038 std::istringstream in(input);
const vector< string > & get_arguments() const
Getter for the arguments of the function call expression.
bool read_sections(std::istream &input, config::sections_type §ions)
Parse the sections of an *.ini file.
virtual const string & as_string() const
Return a string representation of the .
const string_property_value_sptr & get_value() const
Getter for the string value of the property.
vector< section_sptr > sections_type
A convenience typedef for a vector of config::section_sptr.
list_property()
Default constructor for list_property.
bool read_config(istream &input, config &conf)
Parse an ini config file from an input stream.
virtual ~property()
Destructor of the property.
shared_ptr< string_property_value > string_property_value_sptr
A convenience typedef for a shared_ptr to string_property_value.
shared_ptr< list_property_value > list_property_value_sptr
A convenience typedef for a shared_ptr to list_property_value.
void set_content(const string &)
Setter of the content of the string property value.
This file contains the declarations for the ini file reader used in the libabigail library...
const vector< property_value_sptr > & get_value_items() const
Getter for the content of the tuple_property_value instance.
virtual ~string_property_value()
Destructor for the string_property_value.
Abstraction of a tuple property. A tuple property is a property which value is a tuple_property_value...
shared_ptr< function_call_expr > function_call_expr_sptr
Convenience typedef for a shared pointer to function_call_expr.
shared_ptr< property > property_sptr
Convenience typefef for shared_ptr to property.
simple_property * is_simple_property(const property *p)
Tests if a property is a simple property.
The abstraction of the structured content of an .ini file. This roughly follows what is explained at ...
virtual ~section()
Destructor of config::section.
tuple_property * is_tuple_property(const property *p)
Test if an instance of property is an instance of tuple_property.
bool write_sections(const config::sections_type §ions, std::ostream &out)
Serialize a vector of sections that make up an ini config file to an output stream.
bool has_empty_value() const
Test if the property has an empty value.
shared_ptr< section > section_sptr
A convenience typedef for a shared pointer to a config::section.
const sections_type & get_sections() const
virtual const string & as_string() const
Convert the string property value into a string.
void add_property(const property_sptr prop)
Add one property to this section.
Abstracts the value of a property representing a list of strings.
Toplevel namespace for libabigail.
list_property_value()
Default constructor of the list_property_value type.
string_property_value()
Constructor of the string_property_value type.
const string & get_path() const
simple_property()
Default constructor of the simple_property type.
shared_ptr< config > config_sptr
A convenience typedef for a shared pointer to config.
void set_sections(const sections_type §ions)
Set new sections to the ini config.
Base class of propertie values.
tuple_property_value * is_tuple_property_value(const property_value *v)
Test if a given instance of property_value is an instance of tuple_property_value too...
shared_ptr< simple_property > simple_property_sptr
Convenience typedef for a shared_ptr to an simple_property.
The base class of the different kinds of properties of an INI file.
list_property * is_list_property(const property *p)
Test if an instance of a property is actually an instance of list_property.
void set_value(const list_property_value_sptr &value)
Setter for the value of the list_property.
bool write_config(const config &conf, std::ostream &output)
Serialize an instance of config to an output stream.
A simple property. That is, one which value is a string_property_value.
A property value that is a tuple.
string_property_value * is_string_property_value(const property_value *v)
Test if a given property value is a string property value.
void set_content(const vector< string > &)
Setter of the content of the list_property_value.
const vector< string > & get_content() const
Getter of the content of the list_property_value.
void set_value(const tuple_property_value_sptr value)
Setter for the tuple value of the property.
#define ABG_ASSERT(cond)
This is a wrapper around the 'assert' glibc call. It allows for its argument to have side effects...
const properties_type & get_properties() const
Get the properties of the section.
value_kind get_kind() const
Getter for the kind of the property_value type.
virtual ~list_property()
Destructor of the list_property type.
vector< property_sptr > properties_type
A convenience typedef for a vector of property_sptr.
virtual const string & as_string() const
Convert to the instance of tuple_property_value to a string.
const string & get_name() const
Getter of the name of the property.
virtual ~tuple_property()
Destructor for the tuple_property type.
bool read_function_call_expr(std::istream &input, function_call_expr_sptr &expr)
Read a function call expression and build its representation.
shared_ptr< tuple_property_value > tuple_property_value_sptr
Convenience typedef for a shared_ptr to a tuple_property_value.
const string & get_name() const
Get the name of the section.
virtual ~tuple_property_value()
Destructor of the tuple_property_value type.
tuple_property_value(const vector< property_value_sptr > &)
Constructor for the tuple_property_value type.
shared_ptr< tuple_property > tuple_property_sptr
Convenience typedef for a shared_ptr of tuple_property.
shared_ptr< list_property > list_property_sptr
A convenience typedef for a shared_ptr to a list_property.
void set_name(const string &name)
Setter of the name of the property.
virtual ~simple_property()
Destructor of the simple_property type.
A property value which is a string.
void set_properties(const properties_type &properties)
Set the properties of the section.
void set_path(const string &path)
Set the path to the config file.
property()
Constructor of property.
list_property_value * is_list_property_value(const property_value *v)
Test if an instance of is a list_property_value.
property_sptr find_property(const string &prop_name) const
Find a property that has a given name.
const string & get_name() const
Getter of the name of the function being called.
const list_property_value_sptr & get_value() const
Getter for the value of the list_property_value.
tuple_property()
Default constructor of the tuple_property type.
const tuple_property_value_sptr & get_value() const
Getter for the tuple value of the property.
shared_ptr< property_value > property_value_sptr
Convenience typedef for a shared_ptr to property_value.
A class representing a list property.
virtual ~property_value()
Destructor for the proprerty_value type.
property_value()
Default constructor for the property_value type.
void set_value(const string_property_value_sptr &value)
Setter for the string value of the property.