Пример #1
0
inline void Serialiser::decode( std::string const &key,
    std::map<std::string, T> &value )
{
    Map *temp = objectContext_;
    Map::iterator pos = objectContext_->find( key );

    if( pos == objectContext_->end() )
	throw UnknownKeyException( key );

    Primitive &v = pos->second.get();
    objectContext_ = &boost::get<Map>( v.value );
    decodedPointers_[v.index] = &value;

    ClassFactoryMap::iterator fiter = factories().find( Codec<T>::classID() );
    if( fiter == factories().end() )
	throw UnknownTypeException(Codec<T>::classID());

    for( Map::iterator iter = objectContext_->begin();
	iter != objectContext_->end(); ++iter )
    {
	T *t = static_cast<T *>(fiter->second());
	decode( iter->first, *t );
	value.insert( std::make_pair(iter->first, *t) );
	delete t;
    }

    objectContext_ = temp;

}
Пример #2
0
inline void Serialiser::decode( std::string const &key, T * &value )
{
    Map::iterator pos = objectContext_->find( key );

    if( pos == objectContext_->end() )
	throw UnknownKeyException( key );

    Primitive &v = pos->second.get();
    Pointer &p = boost::get<Pointer>(v.value);
    int index = p.index;
    if( index == 0 )
	value = 0;
    else
    {
	ObjectCasterMap::iterator ociter = casters().find(p.type);
	if( ociter == casters().end() )
	    throw UnknownTypeException(p.type);

	BaseCasterMap::iterator bciter = ociter->second.find(
	    toast::type_id<T>().name() );
	if( bciter == ociter->second.end() )
	    throw UnknownCastException(p.type, toast::type_id<T>().name());

	IndexObjectMap::iterator diter = decodedPointers_.find(index);

	if( diter != decodedPointers_.end() )
	{
	    value = static_cast<T *>( bciter->second(diter->second) );
	}
	else
	{
	    ClassFactoryMap::iterator fiter = factories().find( p.type );
	    if( fiter == factories().end() )
		throw UnknownTypeException(p.type);

	    ObjectMap::iterator objIter = referencedValues_.find(index);
	    if( objIter == referencedValues_.end() )
		throw ObjectNotDecodedException(p.index);

	    Array *temp = arrayContext_;
	    Array context;
	    context.push_back( objIter->second );
	    void *obj = fiter->second();
	    arrayContext_ = &context;
	    value = static_cast<T *>( bciter->second(obj) );
	    decode( 0, *value );
	    arrayContext_ = temp;
	    decodedPointers_[index] = obj;
	}
    }
}
Пример #3
0
Message* Message::createMessage(Message::Type type)
{
    Q_ASSERT(factories()->contains(type));
    if (!factories()->contains(type)) {
        qDebug() << "ERROR: unrecognized message type" << type << "!";
        return 0;
    }

    MessageFactory factory = factories()->value(type);
    Message* message = (*factory)();
    if (message)
        message->m_type = type;
    return message;
}
Пример #4
0
int main(int argc, char* argv[]) {
	QApplication app(argc, argv);
	Swift::QtEventLoop eventLoop;
	Swift::BoostNetworkFactories factories(&eventLoop);

	boost::program_options::options_description desc("Options");
	desc.add_options()
		("help", "Show this help message")
		("debug", "Run in debug mode")
		("override-path", boost::program_options::value<std::string>(), "Override the default storage path with this one");
	boost::program_options::variables_map options;
	try {
		boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), options);
	} catch (const boost::program_options::unknown_option& option) {
#if BOOST_VERSION >= 104200
		std::cout << "Ignoring unknown option " << option.get_option_name() << " but continuing." <<  std::endl;
#else
		std::cout << "Error: " << option.what() << " (continuing)" <<  std::endl;
#endif
	}
	boost::program_options::notify(options);

	if (options.count("help") > 0) {
		std::cout << "Eve-Xin is a skill planning utility for Eve Online." << std::endl;
		std::cout << std::endl;
		std::cout << "Usage: " << argv[0] << " [OPTIONS]..." << std::endl;
		std::cout << std::endl;
		std::cout << desc << std::endl;
		return 1;
	}

	EveXin::QtEveXin eveXin(&factories, options);
	return app.exec();
}
Пример #5
0
int main(int argc, char* argv[]) {
	QApplication app(argc, argv);
	Swift::QtEventLoop eventLoop;
	Swift::BoostNetworkFactories factories(&eventLoop);
	EveXin::QtEveXin eveXin(&factories);
	return app.exec();
}
Пример #6
0
 OBFunctionFactory* OBFunctionFactory::GetFactory(const std::string &name)
 {
   std::vector<OBFunctionFactory*> factories(GetFactoriesRef());
   for (unsigned int i = 0; i < factories.size(); ++i)
     if (factories.at(i)->GetName() == name)
       return factories.at(i);
   return 0;
 }
Пример #7
0
  QList<Extension *> PluginManager::extensions(QObject *parent)
  {
    loadFactories();
    if(d->extensionsLoaded)
      return d->extensions;

    foreach(PluginFactory *factory, factories(Plugin::ExtensionType)) {
      Extension *extension = static_cast<Extension *>(factory->createInstance(parent));
      d->extensions.append(extension);
    }
Пример #8
0
shared_ptr<ISimController> OMCFactory::loadSimControllerLib(PATH simcontroller_path, type_map simcontroller_type_map)
{
  LOADERRESULT result = LoadLibrary(simcontroller_path, simcontroller_type_map);

  if (result != LOADER_SUCCESS)
    throw ModelicaSimulationError(MODEL_FACTORY,string("Failed loading SimConroller library!") + simcontroller_path);

  map<string, factory<ISimController,PATH,PATH> >::iterator iter;
  map<string, factory<ISimController,PATH,PATH> >& factories(simcontroller_type_map.get());
  iter = factories.find("SimController");

  if (iter ==factories.end())
    throw ModelicaSimulationError(MODEL_FACTORY,"No such SimController library");

  return shared_ptr<ISimController>(iter->second.create(_library_path, _modelicasystem_path));
}
Пример #9
0
std::unique_ptr<SubtitlesProvider> SubtitlesProviderFactory::GetProvider(agi::BackgroundRunner *br) {
	auto preferred = OPT_GET("Subtitle/Provider")->GetString();
	auto sorted = GetSorted(factories(), preferred);

	std::string error;
	for (auto factory : sorted) {
		try {
			auto provider = factory->create(factory->subtype, br);
			if (provider) return provider;
		}
		catch (agi::UserCancelException const&) { throw; }
		catch (agi::Exception const& err) { error += factory->name + ": " + err.GetMessage() + "\n"; }
		catch (...) { error += factory->name + ": Unknown error\n"; }
	}

	throw error;
}
Пример #10
0
std::vector<std::string> SubtitlesProviderFactory::GetClasses() {
	return ::GetClasses(factories());
}
Пример #11
0
void Serialiser::registerFactory( std::string const &classID,
    void *(*factory)() )
{
    factories().insert( std::make_pair(classID, factory) );
}
Пример #12
0
MessageFactory Message::installMessageFactory(Message::Type type, MessageFactory factory)
{
    factories()->insert(type, factory);
    return factory;
}
Пример #13
0
    Registry::Registry() {
#ifdef WIN32
      const char* envVar = "PATH";
      const char sep = ';';
#else
      const char* envVar = "LD_LIBRARY_PATH";
      const char sep = ':';
#endif
      char *search_path = ::getenv(envVar);
      if (search_path) {
        DEBUGMSG((std::string("searching factories in ") + envVar))
        std::string path(search_path);
        std::string::size_type pos = 0;
        std::string::size_type newpos = 0;
        while (pos != std::string::npos) {
          std::string dirName;
          // get the next entry in the path
          newpos = path.find(sep, pos);
          if (newpos != std::string::npos) {
            dirName = path.substr(pos, newpos - pos);
            pos = newpos+1;
          } else {
            dirName = path.substr(pos);
            pos = newpos;
          }
          DEBUGMSG((std::string(" looking into ") + dirName))
          // look for files called "*.factories" in the directory
          DIR *dir = opendir(dirName.c_str());
          if (dir) {
            struct dirent * entry;
            while ((entry = readdir(dir))) {
              std::string name(entry->d_name);
              std::string::size_type extpos = name.find(".components");

              if ((extpos != std::string::npos) &&
                  ((extpos+11) == name.size()) &&
                  ((entry->d_type == DT_REG) || (entry->d_type == DT_LNK))) {
                DEBUGMSG((std::string("  reading ") + name))
                std::ifstream factories((dirName + '/' + name).c_str());
                std::string lib, fact;
#ifndef NDEBUG
                int factoriesCount = 0;
#endif
                while (!factories.eof()) {
                  std::getline(factories, lib, ':');
                  if (factories.fail()) break;
                  std::getline(factories, fact);
                  if (factories.fail()) break;
                  m_factories.insert(std::make_pair(fact, FactoryInfo(lib)));
#ifndef NDEBUG
                  ++factoriesCount;
#endif
                }
#ifndef NDEBUG
                DEBUGSTRM << "  found " << factoriesCount\
                          << " factories" << std::endl;
#endif
              }
            }
            closedir(dir);
          }
        }
      }
    }
Пример #14
0
void PluginLoader::loadPlugins(
        iscore::ApplicationRegistrar& registrar,
        const iscore::ApplicationContext& context)
{
    auto folders = pluginsDir();

    // Here, the plug-ins that are effectively loaded.
    std::vector<iscore::Plugin_QtInterface*> availablePlugins;

    // Load static plug-ins
    for(QObject* plugin : QPluginLoader::staticInstances())
    {
        if(auto iscore_plug = dynamic_cast<iscore::Plugin_QtInterface*>(plugin))
            availablePlugins.push_back(iscore_plug);
    }

    QSet<QString> pluginFiles;
#if !defined(ISCORE_STATIC_QT)
    // Load dynamic plug-ins
    for(const QString& pluginsFolder : folders)
    {
        QDir pluginsDir(pluginsFolder);
        for(const QString& fileName : pluginsDir.entryList(QDir::Files))
        {
            auto plug = loadPlugin(pluginsDir.absoluteFilePath(fileName), availablePlugins);

            if(!plug.first.isEmpty())
            {
                pluginFiles.insert(plug.first);
            }

            if(plug.second)
            {
                availablePlugins.push_back(plug.second);
            }
        }
    }
#endif

    // First bring in the plugin objects
    registrar.registerPlugins(
                pluginFiles.toList(),
                availablePlugins);


    // Here, it is important not to collapse all the for-loops
    // because for instance a ApplicationPlugin from plugin B might require the factory
    // from plugin A to be loaded prior.
    // Load all the factories.
    for(iscore::Plugin_QtInterface* plugin : availablePlugins)
    {
        auto facfam_interface = dynamic_cast<FactoryList_QtInterface*> (plugin);

        if(facfam_interface)
        {
            for(auto&& elt : facfam_interface->factoryFamilies())
            {
                registrar.registerFactory(std::move(elt));
            }
        }
    }

    // Load all the application context plugins.
    // We have to order them according to their dependencies
    PluginDependencyGraph graph;
    for(auto plugin : availablePlugins)
    {
        graph.addNode(dynamic_cast<QObject*>(plugin));
    }

    graph.visit([&] (QObject* plugin) {
        auto ctrl_plugin = dynamic_cast<GUIApplicationContextPlugin_QtInterface*> (plugin);
        if(ctrl_plugin)
        {
            auto plug = ctrl_plugin->make_applicationPlugin(context);
            registrar.registerApplicationContextPlugin(plug);
        }
    });

    // Load what the plug-ins have to offer.
    for(auto plugin : availablePlugins)
    {
        auto panel_plugin = dynamic_cast<PanelFactory_QtInterface*> (plugin);
        if(panel_plugin)
        {
            auto panels = panel_plugin->panels();
            for(auto panel : panels)
            {
                registrar.registerPanel(panel);
            }
        }

        auto commands_plugin = dynamic_cast<CommandFactory_QtInterface*> (plugin);
        if(commands_plugin)
        {
            registrar.registerCommands(commands_plugin->make_commands());
        }

        auto factories_plugin = dynamic_cast<FactoryInterface_QtInterface*> (plugin);
        if(factories_plugin)
        {
            for(auto& factory_family : registrar.components().factories)
            {
                for(auto&& new_factory : factories_plugin->factories(context, factory_family.first))
                {
                    factory_family.second->insert(std::move(new_factory));
                }
            }
        }
    }
}