-/* $Id$
-
-This file is part of builder
-Copyright © 2006-2010 Mikko Rasa, Mikkosoft Productions
-Distributed under the LGPL
-*/
-
#include <set>
#include <cstdlib>
#include <msp/core/getopt.h>
Target *Builder::get_target(const string &n) const
{
- // XXX Used for getting targets by path. get_target(const FS::Path &)?
TargetMap::const_iterator i = targets.find(n);
if(i!=targets.end())
return i->second;
return 0;
}
+FileTarget *Builder::get_target_by_path(const FS::Path &p) const
+{
+ TargetMap::const_iterator i = targets_by_path.find(p.str());
+ if(i!=targets_by_path.end())
+ return static_cast<FileTarget *>(i->second);
+ return 0;
+}
+
Target *Builder::get_header(const string &include, const FS::Path &from, const list<string> &path)
{
string hash(8, 0);
problems.push_back(Problem(p, d));
}
-void Builder::add_target(FileTarget *t)
+void Builder::add_target(Target *t)
{
- targets.insert(TargetMap::value_type(t->get_path().str(), t));
+ targets.insert(TargetMap::value_type(t->get_name(), t));
new_tgts.push_back(t);
}
-void Builder::add_target(VirtualTarget *t)
+void Builder::register_path(const FS::Path &path, FileTarget *t)
{
- targets.insert(TargetMap::value_type(t->get_name(), t));
- new_tgts.push_back(t);
+ targets_by_path.insert(TargetMap::value_type(path.str(), t));
}
void Builder::usage(const char *reason, const char *argv0, bool brief)
// Apply what-ifs
for(StringList::iterator i=what_if.begin(); i!=what_if.end(); ++i)
{
- FileTarget *tgt = dynamic_cast<FileTarget *>(get_target((cwd/ *i).str()));
+ FileTarget *tgt = get_target_by_path(cwd/ *i);
if(!tgt)
{
IO::print(IO::cerr, "Unknown what-if target %s\n", *i);
{
Target *tgt = get_target(*i);
if(!tgt)
- tgt = get_target((cwd/ *i).str());
+ tgt = get_target_by_path(*i);
+ if(!tgt)
+ tgt = get_target_by_path(cwd/ *i);
if(!tgt)
{
IO::print("I don't know anything about %s\n", *i);
Target *Builder::get_header(const FS::Path &fn)
{
- Target *tgt = get_target(fn.str());
+ Target *tgt = get_target_by_path(fn);
if(tgt) return tgt;
if(FS::is_reg(fn))
for(StringList::iterator i=candidates.begin(); i!=candidates.end(); ++i)
{
- string full = (path/ *i).str();
- Target *tgt = get_target(full);
+ FS::Path full = path/ *i;
+ Target *tgt = get_target_by_path(full);
if(tgt)
{
}
else if(FS::is_reg(full))
{
- tgt = new SystemLibrary(*this, full);
+ tgt = new SystemLibrary(*this, full.str());
return tgt;
}
}