]> git.tdb.fi Git - builder.git/commitdiff
Use ObjectLoaders where appropriate
authorMikko Rasa <tdb@tdb.fi>
Tue, 10 Jul 2012 15:38:41 +0000 (18:38 +0300)
committerMikko Rasa <tdb@tdb.fi>
Tue, 10 Jul 2012 20:55:52 +0000 (23:55 +0300)
16 files changed:
source/architecture.cpp
source/architecture.h
source/binarypackage.cpp
source/binarypackage.h
source/builder.cpp
source/builder.h
source/component.cpp
source/component.h
source/condition.cpp
source/condition.h
source/config.cpp
source/config.h
source/package.cpp
source/package.h
source/sourcepackage.cpp
source/sourcepackage.h

index 5c88354634695e1689b186cb8b65a9648b724da3..97ed2fe07dce2a0b0ebe9c5be4325e2c91486378 100644 (file)
@@ -197,7 +197,7 @@ void Architecture::parse_specification(const string &spec)
 
 
 Architecture::Loader::Loader(Architecture &a):
-       arch(a)
+       DataFile::ObjectLoader<Architecture>(a)
 {
        add("prefix", &Architecture::cross_prefix);
 }
index 5446c04235f3f0465fe64c93f62fc31ce6fdfc4e..c322c3a580d23d7a676295295c20efc7fbc02e0f 100644 (file)
@@ -11,14 +11,10 @@ class Builder;
 class Architecture
 {
 public:
-       class Loader: public Msp::DataFile::Loader
+       class Loader: public Msp::DataFile::ObjectLoader<Architecture>
        {
-       private:
-               Architecture &arch;
-
        public:
                Loader(Architecture &);
-               Architecture &get_object() { return arch; }
        };
 
        typedef std::list<Pattern> PatternList;
index b9c558eff44f96a9dcb4f21c0d80c9da8af19036..514481f0066c56a3febb253a81708d3ff51c16da 100644 (file)
@@ -60,7 +60,7 @@ BinaryPackage *BinaryPackage::from_flags(Builder &builder, const string &name, c
 
 
 BinaryPackage::Loader::Loader(BinaryPackage &p):
-       Package::Loader(p)
+       DataFile::DerivedObjectLoader<BinaryPackage, Package>(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<BinaryPackage &>(pkg).export_binfo);
+       load_sub(obj.export_binfo);
 }
index 8c0d0e9ec39c7a741c94fe908a8f92aa08d74803..b47d468fe138ccf761c64d88b1f3169c2b3a51f6 100644 (file)
@@ -10,11 +10,10 @@ Builder.
 class BinaryPackage: public Package
 {
 public:
-       class Loader: public Package::Loader
+       class Loader: public Msp::DataFile::DerivedObjectLoader<BinaryPackage, Package>
        {
        public:
                Loader(BinaryPackage &);
-               BinaryPackage &get_object() { return static_cast<BinaryPackage &>(pkg); }
        private:
                void build_info();
        };
index 96df23b7df5c0394800fa21caf59160fff8cdac0..94bbce04d3a552480994b2d4597fdeb5e154f3b1 100644 (file)
@@ -606,7 +606,7 @@ string Builder::helpmsg;
 
 
 Builder::Loader::Loader(Builder &b, const FS::Path &s):
-       bld(b),
+       DataFile::ObjectLoader<Builder>(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);
 }
index 78244e8c2980081bfcfb43ff85558cad443cddad..e524864564cfee83b64d59acddea2709eb334b6e 100644 (file)
@@ -30,10 +30,9 @@ The main application class.  Controls and owns everything.  Rules the world.
 class Builder: public Msp::RegisteredApplication<Builder>
 {
 private:
-       class Loader: public Msp::DataFile::Loader
+       class Loader: public Msp::DataFile::ObjectLoader<Builder>
        {
        private:
-               Builder &bld;
                Msp::FS::Path src;
 
        public:
index f5ca812169c3d4b4910289c4bf97a8d1962fd502..0bfc2fc4da119e614c9017e7b6093fc82c60a457 100644 (file)
@@ -235,7 +235,7 @@ PathList Component::collect_source_files() const
 
 
 Component::Loader::Loader(Component &c):
-       comp(c)
+       DataFile::ObjectLoader<Component>(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());
 }
index cdb3f8d8dba01f9829d917c6cdb0157848595986..140cca16f667a40def5f4497b1c772a66df5a6c0 100644 (file)
@@ -2,7 +2,7 @@
 #define COMPONENT_H_
 
 #include <string>
-#include <msp/datafile/loader.h>
+#include <msp/datafile/objectloader.h>
 #include <msp/fs/path.h>
 #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<Component>
        {
-       private:
-               Component &comp;
-
        public:
                Loader(Component &);
-               Component &get_object() { return comp; }
        private:
                void source(const std::string &);
                void require(const std::string &);
index c80134d237a7707a4f439b7cebd17ff62c9b582d..13861ba5aea01a8ad0466c44b3991094ad50f94d 100644 (file)
@@ -59,7 +59,7 @@ bool Condition::eval()
 
 
 Condition::Loader::Loader(Condition &c):
-       cond(c)
+       DataFile::ObjectLoader<Condition>(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);
 }
index 954adeece62cffe4d45578f4a060c87d78775ce0..c1bf7a3f3da6423e1f8d64e148a6d63e43328afb 100644 (file)
@@ -11,11 +11,8 @@ class SourcePackage;
 class Condition
 {
 public:
-       class Loader: public Msp::DataFile::Loader
+       class Loader: public Msp::DataFile::ObjectLoader<Condition>
        {
-       private:
-               Condition &cond;
-
        public:
                Loader(Condition &);
        private:
index a518b6302f8fd6cdea0fb4fd4d5e06fd06f991bc..d96140fdc9feb60b1ac83bc204d89a52acea9f33 100644 (file)
@@ -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<Config>(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);
 }
index d7f7351f00d4420eb324cb492abbf388b2732645..6babde995d94ad7628d70f385bead9ed211a067a 100644 (file)
@@ -31,11 +31,8 @@ public:
        typedef std::map<std::string, Option> OptionMap;
 
 private:
-       class Loader: public Msp::DataFile::Loader
+       class Loader: public Msp::DataFile::ObjectLoader<Config>
        {
-       private:
-               Config &conf;
-
        public:
                Loader(Config &);
        private:
index 38829f758c76af4f44cde0ec1a88565b42238a22..f74b4a09bdda43e905df82ff8584009b2da0b9db 100644 (file)
@@ -39,14 +39,14 @@ void Package::configure(const StringMap &opts, unsigned flag)
 
 
 Package::Loader::Loader(Package &p):
-       pkg(p)
+       DataFile::ObjectLoader<Package>(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);
 }
index e107abc273fd1f691ef7d31cc55cfd36d3197d6d..546a892ab409a58e258378868845eec4b80befa4 100644 (file)
@@ -3,7 +3,7 @@
 
 #include <list>
 #include <string>
-#include <msp/datafile/loader.h>
+#include <msp/datafile/objectloader.h>
 #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<Package>
        {
        public:
                Loader(Package &);
-               Package &get_object() { return pkg; }
-       protected:
-               Package &pkg;
-
+       private:
                void require(const std::string &);
        };
 
index 904e2b49e5524a54434bf9a600c1644264ad2ab0..63f3bba5848c47c4bbaa6c534dd3bb7e9a41d4ab 100644 (file)
@@ -243,8 +243,8 @@ void SourcePackage::create_targets()
 }
 
 
-SourcePackage::Loader::Loader(Package &p):
-       Package::Loader(p)
+SourcePackage::Loader::Loader(SourcePackage &p):
+       DataFile::DerivedObjectLoader<SourcePackage, Package>(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<SourcePackage &>(pkg);
-       spkg.components.sort(component_sort);
+       obj.components.sort(component_sort);
 
        for(map<string, string>::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<InstallMap &>(j->get_install_map()).add_mapping(spkg.source/i->first, i->second);
+                                       const_cast<InstallMap &>(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<SourcePackage &>(pkg).features.push_back(feat);
+       obj.features.push_back(feat);
 }
 
 void SourcePackage::Loader::condition(const string &c)
 {
-       SourcePackage &spkg = static_cast<SourcePackage &>(pkg);
-       Condition cond(spkg, c);
+       Condition cond(obj, c);
        load_sub(cond);
-       spkg.conditions.push_back(cond);
+       obj.conditions.push_back(cond);
 }
 
 template<Component::Type t>
 void SourcePackage::Loader::component(const string &n)
 {
-       SourcePackage &spkg = static_cast<SourcePackage &>(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<SourcePackage &>(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<SourcePackage &>(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<SourcePackage &>(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<SourcePackage &>(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<StringList &>(i->get_sources()).push_back((spkg.source/f).str());
+                       const_cast<StringList &>(i->get_sources()).push_back((obj.source/f).str());
 }
index 8ba3eb3c899fa4febd920ba9b18bcc2e6920e535..11f47940dc29f8712a79cd1da203bfe39d52d19d 100644 (file)
@@ -34,14 +34,13 @@ public:
                DATA = 8
        };
 
-       class Loader: public Package::Loader
+       class Loader: public Msp::DataFile::DerivedObjectLoader<SourcePackage, Package>
        {
        private:
                std::map<std::string, std::string> install_map;
 
        public:
-               Loader(Package &);
-               SourcePackage &get_object() { return static_cast<SourcePackage &>(pkg); }
+               Loader(SourcePackage &);
        private:
                virtual void finish();
                void feature(const std::string &, const std::string &);