From c51884994862b02613c2c0ae75b1f8d39e0f1ee5 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Tue, 10 Jul 2012 18:38:41 +0300 Subject: [PATCH] Use ObjectLoaders where appropriate --- source/architecture.cpp | 2 +- source/architecture.h | 6 +----- source/binarypackage.cpp | 4 ++-- source/binarypackage.h | 3 +-- source/builder.cpp | 14 +++++++------- source/builder.h | 3 +-- source/component.cpp | 12 ++++++------ source/component.h | 8 ++------ source/condition.cpp | 6 +++--- source/condition.h | 5 +---- source/config.cpp | 4 ++-- source/config.h | 5 +---- source/package.cpp | 6 +++--- source/package.h | 9 +++------ source/sourcepackage.cpp | 38 ++++++++++++++++---------------------- source/sourcepackage.h | 5 ++--- 16 files changed, 52 insertions(+), 78 deletions(-) diff --git a/source/architecture.cpp b/source/architecture.cpp index 5c88354..97ed2fe 100644 --- a/source/architecture.cpp +++ b/source/architecture.cpp @@ -197,7 +197,7 @@ void Architecture::parse_specification(const string &spec) Architecture::Loader::Loader(Architecture &a): - arch(a) + DataFile::ObjectLoader(a) { add("prefix", &Architecture::cross_prefix); } diff --git a/source/architecture.h b/source/architecture.h index 5446c04..c322c3a 100644 --- a/source/architecture.h +++ b/source/architecture.h @@ -11,14 +11,10 @@ class Builder; class Architecture { public: - class Loader: public Msp::DataFile::Loader + class Loader: public Msp::DataFile::ObjectLoader { - private: - Architecture &arch; - public: Loader(Architecture &); - Architecture &get_object() { return arch; } }; typedef std::list PatternList; diff --git a/source/binarypackage.cpp b/source/binarypackage.cpp index b9c558e..514481f 100644 --- a/source/binarypackage.cpp +++ b/source/binarypackage.cpp @@ -60,7 +60,7 @@ BinaryPackage *BinaryPackage::from_flags(Builder &builder, const string &name, c BinaryPackage::Loader::Loader(BinaryPackage &p): - Package::Loader(p) + DataFile::DerivedObjectLoader(p) { add("need_path", &BinaryPackage::need_path); add("build_info", &Loader::build_info); @@ -68,5 +68,5 @@ BinaryPackage::Loader::Loader(BinaryPackage &p): void BinaryPackage::Loader::build_info() { - load_sub(static_cast(pkg).export_binfo); + load_sub(obj.export_binfo); } diff --git a/source/binarypackage.h b/source/binarypackage.h index 8c0d0e9..b47d468 100644 --- a/source/binarypackage.h +++ b/source/binarypackage.h @@ -10,11 +10,10 @@ Builder. class BinaryPackage: public Package { public: - class Loader: public Package::Loader + class Loader: public Msp::DataFile::DerivedObjectLoader { public: Loader(BinaryPackage &); - BinaryPackage &get_object() { return static_cast(pkg); } private: void build_info(); }; diff --git a/source/builder.cpp b/source/builder.cpp index 96df23b..94bbce0 100644 --- a/source/builder.cpp +++ b/source/builder.cpp @@ -606,7 +606,7 @@ string Builder::helpmsg; Builder::Loader::Loader(Builder &b, const FS::Path &s): - bld(b), + DataFile::ObjectLoader(b), src(s) { add("binary_package", &Loader::binpkg); @@ -617,13 +617,13 @@ Builder::Loader::Loader(Builder &b, const FS::Path &s): void Builder::Loader::binpkg(const string &n) { - BinaryPackage *pkg = new BinaryPackage(bld, n); + BinaryPackage *pkg = new BinaryPackage(obj, n); load_sub(*pkg); } void Builder::Loader::cross_prefix(const string &a, const string &p) { - bld.cross_prefixes[a] = p; + obj.cross_prefixes[a] = p; } void Builder::Loader::profile(const string &n) @@ -631,14 +631,14 @@ void Builder::Loader::profile(const string &n) StringMap prf; ProfileLoader ldr(prf); load_sub_with(ldr); - bld.profile_tmpl.insert(ProfileTemplateMap::value_type(n, prf)); + obj.profile_tmpl.insert(ProfileTemplateMap::value_type(n, prf)); } void Builder::Loader::package(const string &n) { - SourcePackage *pkg = new SourcePackage(bld, n, src); - if(!bld.main_pkg) - bld.main_pkg = pkg; + SourcePackage *pkg = new SourcePackage(obj, n, src); + if(!obj.main_pkg) + obj.main_pkg = pkg; load_sub(*pkg); } diff --git a/source/builder.h b/source/builder.h index 78244e8..e524864 100644 --- a/source/builder.h +++ b/source/builder.h @@ -30,10 +30,9 @@ The main application class. Controls and owns everything. Rules the world. class Builder: public Msp::RegisteredApplication { private: - class Loader: public Msp::DataFile::Loader + class Loader: public Msp::DataFile::ObjectLoader { private: - Builder &bld; Msp::FS::Path src; public: diff --git a/source/component.cpp b/source/component.cpp index f5ca812..0bfc2fc 100644 --- a/source/component.cpp +++ b/source/component.cpp @@ -235,7 +235,7 @@ PathList Component::collect_source_files() const Component::Loader::Loader(Component &c): - comp(c) + DataFile::ObjectLoader(c) { add("source", &Loader::source); add("install", &Component::install); @@ -247,22 +247,22 @@ Component::Loader::Loader(Component &c): void Component::Loader::source(const string &s) { - comp.sources.push_back(s); + obj.sources.push_back(s); } void Component::Loader::require(const string &n) { - Package *req = comp.pkg.get_builder().get_package_manager().find_package(n); + Package *req = obj.pkg.get_builder().get_package_manager().find_package(n); if(req) - comp.requires.push_back(req); + obj.requires.push_back(req); } void Component::Loader::build_info() { - load_sub(comp.build_info); + load_sub(obj.build_info); } void Component::Loader::install_map() { - load_sub(comp.install_map, comp.pkg.get_source()); + load_sub(obj.install_map, obj.pkg.get_source()); } diff --git a/source/component.h b/source/component.h index cdb3f8d..140cca1 100644 --- a/source/component.h +++ b/source/component.h @@ -2,7 +2,7 @@ #define COMPONENT_H_ #include -#include +#include #include #include "buildinfo.h" #include "installmap.h" @@ -20,14 +20,10 @@ their own. class Component { public: - class Loader: public Msp::DataFile::Loader + class Loader: public Msp::DataFile::ObjectLoader { - private: - Component ∁ - public: Loader(Component &); - Component &get_object() { return comp; } private: void source(const std::string &); void require(const std::string &); diff --git a/source/condition.cpp b/source/condition.cpp index c80134d..13861ba 100644 --- a/source/condition.cpp +++ b/source/condition.cpp @@ -59,7 +59,7 @@ bool Condition::eval() Condition::Loader::Loader(Condition &c): - cond(c) + DataFile::ObjectLoader(c) { add("require", &Loader::require); add("build_info", &Loader::build_info); @@ -67,10 +67,10 @@ Condition::Loader::Loader(Condition &c): void Condition::Loader::require(const string &pkg) { - cond.requires.push_back(pkg); + obj.requires.push_back(pkg); } void Condition::Loader::build_info() { - load_sub(cond.build_info); + load_sub(obj.build_info); } diff --git a/source/condition.h b/source/condition.h index 954adee..c1bf7a3 100644 --- a/source/condition.h +++ b/source/condition.h @@ -11,11 +11,8 @@ class SourcePackage; class Condition { public: - class Loader: public Msp::DataFile::Loader + class Loader: public Msp::DataFile::ObjectLoader { - private: - Condition &cond; - public: Loader(Condition &); private: diff --git a/source/config.cpp b/source/config.cpp index a518b63..d96140f 100644 --- a/source/config.cpp +++ b/source/config.cpp @@ -143,12 +143,12 @@ Config::Option::Option(const string &n, const string &v, const string &d): Config::Loader::Loader(Config &c): - conf(c) + DataFile::ObjectLoader(c) { add("option", &Loader::option); } void Config::Loader::option(const string &n, const string &v) { - conf.set_option(n, v); + obj.set_option(n, v); } diff --git a/source/config.h b/source/config.h index d7f7351..6babde9 100644 --- a/source/config.h +++ b/source/config.h @@ -31,11 +31,8 @@ public: typedef std::map OptionMap; private: - class Loader: public Msp::DataFile::Loader + class Loader: public Msp::DataFile::ObjectLoader { - private: - Config &conf; - public: Loader(Config &); private: diff --git a/source/package.cpp b/source/package.cpp index 38829f7..f74b4a0 100644 --- a/source/package.cpp +++ b/source/package.cpp @@ -39,14 +39,14 @@ void Package::configure(const StringMap &opts, unsigned flag) Package::Loader::Loader(Package &p): - pkg(p) + DataFile::ObjectLoader(p) { add("require", &Loader::require); } void Package::Loader::require(const string &n) { - Package *req = pkg.builder.get_package_manager().find_package(n); + Package *req = obj.builder.get_package_manager().find_package(n); if(req) - pkg.requires.push_back(req); + obj.requires.push_back(req); } diff --git a/source/package.h b/source/package.h index e107abc..546a892 100644 --- a/source/package.h +++ b/source/package.h @@ -3,7 +3,7 @@ #include #include -#include +#include #include "buildinfo.h" class Builder; @@ -19,14 +19,11 @@ packages and the builderrc file for binary packages with no pkg-config support. class Package { public: - class Loader: public Msp::DataFile::Loader + class Loader: public Msp::DataFile::ObjectLoader { public: Loader(Package &); - Package &get_object() { return pkg; } - protected: - Package &pkg; - + private: void require(const std::string &); }; diff --git a/source/sourcepackage.cpp b/source/sourcepackage.cpp index 904e2b4..63f3bba 100644 --- a/source/sourcepackage.cpp +++ b/source/sourcepackage.cpp @@ -243,8 +243,8 @@ void SourcePackage::create_targets() } -SourcePackage::Loader::Loader(Package &p): - Package::Loader(p) +SourcePackage::Loader::Loader(SourcePackage &p): + DataFile::DerivedObjectLoader(p) { add("version", &SourcePackage::version); add("description", &SourcePackage::description); @@ -263,19 +263,18 @@ SourcePackage::Loader::Loader(Package &p): void SourcePackage::Loader::finish() { - SourcePackage &spkg = static_cast(pkg); - spkg.components.sort(component_sort); + obj.components.sort(component_sort); for(map::const_iterator i=install_map.begin(); i!=install_map.end(); ++i) { - for(ComponentList::iterator j=spkg.components.begin(); j!=spkg.components.end(); ++j) + for(ComponentList::iterator j=obj.components.begin(); j!=obj.components.end(); ++j) { const StringList &sources = j->get_sources(); for(StringList::const_iterator k=sources.begin(); k!=sources.end(); ++k) { if(!i->first.compare(0, k->size(), *k)) { - const_cast(j->get_install_map()).add_mapping(spkg.source/i->first, i->second); + const_cast(j->get_install_map()).add_mapping(obj.source/i->first, i->second); } } } @@ -288,36 +287,33 @@ void SourcePackage::Loader::feature(const string &n, const string &d) feat.descr = d; feat.def_value = "no"; load_sub(feat); - static_cast(pkg).features.push_back(feat); + obj.features.push_back(feat); } void SourcePackage::Loader::condition(const string &c) { - SourcePackage &spkg = static_cast(pkg); - Condition cond(spkg, c); + Condition cond(obj, c); load_sub(cond); - spkg.conditions.push_back(cond); + obj.conditions.push_back(cond); } template void SourcePackage::Loader::component(const string &n) { - SourcePackage &spkg = static_cast(pkg); - Component comp(spkg, t, n); + Component comp(obj, t, n); load_sub(comp); - spkg.components.push_back(comp); + obj.components.push_back(comp); } void SourcePackage::Loader::build_info() { - load_sub(static_cast(pkg).build_info); + load_sub(obj.build_info); } void SourcePackage::Loader::headers(const string &n) { IO::print("%s: Note: headers components are deprecated\n", get_source()); - SourcePackage &spkg = static_cast(pkg); - Component comp(spkg, Component::LIBRARY, n); + Component comp(obj, Component::LIBRARY, n); load_sub(comp); const StringList &sources = comp.get_sources(); for(StringList::const_iterator i=sources.begin(); i!=sources.end(); ++i) @@ -326,16 +322,15 @@ void SourcePackage::Loader::headers(const string &n) void SourcePackage::Loader::tarball(const string &n) { - SourcePackage &spkg = static_cast(pkg); if(n=="@src") { - for(ComponentList::iterator i=spkg.components.begin(); i!=spkg.components.end(); ++i) + for(ComponentList::iterator i=obj.components.begin(); i!=obj.components.end(); ++i) if(i->get_type()==Component::TARBALL && i->get_name()==n) load_sub(*i); } else { - Component trbl(spkg, Component::TARBALL, n); + Component trbl(obj, Component::TARBALL, n); load_sub(trbl); } } @@ -343,8 +338,7 @@ void SourcePackage::Loader::tarball(const string &n) void SourcePackage::Loader::tar_file(const string &f) { IO::print("%s: Note: tar_file is deprecated\n", get_source()); - SourcePackage &spkg = static_cast(pkg); - for(ComponentList::iterator i=spkg.components.begin(); i!=spkg.components.end(); ++i) + for(ComponentList::iterator i=obj.components.begin(); i!=obj.components.end(); ++i) if(i->get_type()==Component::TARBALL && i->get_name()=="@src") - const_cast(i->get_sources()).push_back((spkg.source/f).str()); + const_cast(i->get_sources()).push_back((obj.source/f).str()); } diff --git a/source/sourcepackage.h b/source/sourcepackage.h index 8ba3eb3..11f4794 100644 --- a/source/sourcepackage.h +++ b/source/sourcepackage.h @@ -34,14 +34,13 @@ public: DATA = 8 }; - class Loader: public Package::Loader + class Loader: public Msp::DataFile::DerivedObjectLoader { private: std::map install_map; public: - Loader(Package &); - SourcePackage &get_object() { return static_cast(pkg); } + Loader(SourcePackage &); private: virtual void finish(); void feature(const std::string &, const std::string &); -- 2.45.2