]> git.tdb.fi Git - builder.git/blobdiff - source/vssolutiongenerator.cpp
Refactor InternalTask to take a functor
[builder.git] / source / vssolutiongenerator.cpp
index 0c60689a42094b3777256d1b4da9efa837ea487e..5fd8e4dff2a10d0371227f9f76c136ef0d04ba4b 100644 (file)
@@ -2,6 +2,7 @@
 #include <msp/io/file.h>
 #include <msp/io/print.h>
 #include "builder.h"
+#include "internaltask.h"
 #include "sourcepackage.h"
 #include "vcxprojectfile.h"
 #include "vssolutionfile.h"
 using namespace std;
 using namespace Msp;
 
-VsSolutionGenerator::VsSolutionGenerator(Builder &b):
-       Tool(b, "VSSG")
-{ }
-
-Target *VsSolutionGenerator::create_target(const list<Target *> &, const string &)
+Target *VsSolutionGenerator::create_target(const vector<Target *> &, const string &)
 {
        throw logic_error("Not implemented");
 }
@@ -22,26 +19,20 @@ Target *VsSolutionGenerator::create_target(const list<Target *> &, const string
 Task *VsSolutionGenerator::run(const Target &target) const
 {
        const VsSolutionFile &solution = dynamic_cast<const VsSolutionFile &>(target);
-       Worker *worker = new Worker(solution);
-       return new InternalTask(worker);
+       return new InternalTask([&solution]{ return _run(solution); });
 }
 
-
-VsSolutionGenerator::Worker::Worker(const VsSolutionFile &t):
-       target(t)
-{ }
-
-void VsSolutionGenerator::Worker::main()
+bool VsSolutionGenerator::_run(const VsSolutionFile &solution)
 {
-       const SourcePackage &spkg = *target.get_package();
+       const SourcePackage &spkg = *solution.get_package();
        Builder &builder = spkg.get_builder();
 
-       IO::BufferedFile out(target.get_path().str(), IO::M_WRITE);
+       IO::BufferedFile out(solution.get_path().str(), IO::M_WRITE);
        IO::print(out, "Microsoft Visual Studio Solution File, Format Version 12.00\n");
        IO::print(out, "MinimumVisualStudioVersion = 10.0.40219.1\n");
 
        vector<const VcxProjectFile *> projects;
-       for(const Target *t: target.get_dependencies())
+       for(const Target *t: solution.get_dependencies())
                if(const VcxProjectFile *project = dynamic_cast<const VcxProjectFile *>(t))
                        projects.push_back(project);
 
@@ -74,5 +65,5 @@ void VsSolutionGenerator::Worker::main()
        IO::print(out, "\tEndGlobalSection\n");
        IO::print(out, "EndGlobal\n");
 
-       status = Task::SUCCESS;
+       return true;
 }