コード例 #1
0
std::string
Dictionary::translate_plural(const Entries& dict, const std::string& msgid, const std::string& msgid_plural, int count)
{
  Entries::const_iterator i = dict.find(msgid);

  if (i != dict.end())
  {
    const std::vector<std::string>& msgstrs = i->second;
    unsigned int n = 0;
    n = plural_forms.get_plural(count);
    assert(/*n >= 0 &&*/ n < msgstrs.size());

    if (!msgstrs[n].empty())
      return msgstrs[n];
    else
      if (count == 1) // default to english rules
        return msgid;
      else
        return msgid_plural;
  }
  else
  {
    log_info << "Couldn't translate: " << msgid << std::endl;
    log_info << "Candidates: " << std::endl;
    for (i = dict.begin(); i != dict.end(); ++i)
      log_info << "'" << i->first << "'" << std::endl;

    if (count == 1) // default to english rules
      return msgid;
    else
      return msgid_plural;
  }
}
コード例 #2
0
ファイル: PLS.cpp プロジェクト: mitya57/QMPlay2
bool PLS::_write(const Entries &list)
{
	Writer *writer = ioCtrl.rawPtr< Writer >();
	writer->write(QString("[playlist]\r\nNumberOfEntries=" + QString::number(list.size()) + "\r\n").toUtf8());
	for (int i = 0; i < list.size(); i++)
	{
		const Playlist::Entry &entry = list[i];
		QString idx = QString::number(i+1);
		QString url = entry.url;
		const bool isFile = url.startsWith("file://");
		if (isFile)
			url.remove(0, 7);
#ifdef Q_OS_WIN
		if (isFile)
			url.replace("/", "\\");
#endif
		if (!url.isEmpty())
			writer->write(QString("File" + idx + "=" + url + "\r\n").toUtf8());
		if (!entry.name.isEmpty())
			writer->write(QString("Title" + idx + "=" + QString(entry.name).replace('\n', '\001') + "\r\n").toUtf8());
		if (entry.length >= 0)
			writer->write(QString("Length" + idx + "=" + QString::number(entry.length) + "\r\n").toUtf8());
		if (entry.selected)
			writer->write(QString("QMPlay_sel" + idx + "=" + QString::number(entry.selected) + "\r\n").toUtf8());
		if (entry.queue)
			writer->write(QString("QMPlay_queue" + idx + "=" + QString::number(entry.queue) + "\r\n").toUtf8());
		if (entry.GID)
			writer->write(QString("QMPlay_GID" + idx + "=" + QString::number(entry.GID) + "\r\n").toUtf8());
		if (entry.parent)
			writer->write(QString("QMPlay_parent" + idx + "=" + QString::number(entry.parent) + "\r\n").toUtf8());
	}
	return true;
}
コード例 #3
0
ファイル: dictionary.hpp プロジェクト: Flakebi/stk-code
 Func foreach(Func func)
 {
   for(Entries::iterator i = entries.begin(); i != entries.end(); ++i)
   {
     func(i->first, i->second);
   }
   return func;
 }
コード例 #4
0
ファイル: tracked.cpp プロジェクト: SunnyKale/geordi
 void op_delete(void * const p, bool const array, std::size_t const s) {
   if (array) ::operator delete[](p);
   else ::operator delete(p);
   std::vector<boost::reference_wrapper<Entry const> > v;
   for (Entries::const_iterator j = entries.begin(); j != entries.end(); ++j)
     if (p <= j->p && boost::implicit_cast<void const *>(j->p) <= static_cast<char *>(p) + s)
       v.push_back(boost::cref(*j));
   if (array) { info i; i() << "delete["; more_ostreaming::delimit(i(), v); i() << ']'; }
   else { assert(v.size() == 1); info()() << "delete(" << v.front() << ")"; }
 }
コード例 #5
0
void ViennaMiniForm::setMaterialLibrary(MaterialManager::Library& lib)
{
    typedef MaterialManager::Library::Entries          Entries;
    typedef MaterialManager::Library::EntryIterator    EntryIterator;

    Entries metals = lib.getMaterialsOfCategory("metal");
    for(EntryIterator iter = metals.begin(); iter != metals.end(); iter++)
    {
        list_metals << QString::fromStdString(vmat::id(*iter));
    }
    ui->comboBoxContactMaterial->addItems(list_metals);
    QObject::connect(ui->comboBoxContactMaterial, SIGNAL(activated(QString)), this, SLOT(setSegmentMaterial(QString)));

    Entries oxides = lib.getMaterialsOfCategory("oxide");
    for(EntryIterator iter = oxides.begin(); iter != oxides.end(); iter++)
    {
        list_oxides << QString::fromStdString(vmat::id(*iter));
    }
    ui->comboBoxOxideMaterial->addItems(list_oxides);
    QObject::connect(ui->comboBoxOxideMaterial, SIGNAL(activated(QString)), this, SLOT(setSegmentMaterial(QString)));

    Entries semiconductors = lib.getMaterialsOfCategory("semiconductor");
    for(EntryIterator iter = semiconductors.begin(); iter != semiconductors.end(); iter++)
    {
        list_semiconductors << QString::fromStdString(vmat::id(*iter));
    }
    ui->comboBoxSemiconductorMaterial->addItems(list_semiconductors);
    QObject::connect(ui->comboBoxSemiconductorMaterial, SIGNAL(activated(QString)), this, SLOT(setSegmentMaterial(QString)));
}
コード例 #6
0
ファイル: logflipper.cpp プロジェクト: b3sigma/logflipper
int main(int argc, char* argv[])
{

  if(argc < 3) {
    printf("Usage whateveryoujusttyped.exe readFileName writeFileName\n");
    return -1;
  }

  const char* readFilename = argv[1];
  const char* writeFilename = argv[2];

  std::ifstream readFile(readFilename);
  if(!readFile.is_open()) {
    printf("Couldn't open %s for reading\n", readFilename);
    return -1;
  }

  std::ofstream writeFile(writeFilename);
  if(!writeFile.is_open()) {
    printf("Couldn't open %s for writing\n", writeFilename);
    return -1;
  }

  typedef std::list<std::string> Entries;
  Entries entries;

  std::string currentEntry;
  std::string line;
  while(std::getline(readFile, line)) {
    if(strstr(line.c_str(), "===") != NULL) {
      if(!currentEntry.empty()) {
        entries.push_back(currentEntry);
      }
      currentEntry.clear();
    }

    currentEntry += line;
    currentEntry += "\n";
  }
  if(!currentEntry.empty()) {
    entries.push_back(currentEntry);
  }
  readFile.close();

  for(auto entryIt = entries.rbegin();
    entryIt != entries.rend();
    ++entryIt) {
    writeFile << (*entryIt);
  }
  writeFile.close();

  return 0;
}
コード例 #7
0
ファイル: tracked.cpp プロジェクト: SunnyKale/geordi
 ~LeakReporter() {
   std::vector<boost::reference_wrapper<Entry const> > v;
   for (Entries::const_iterator i = entries.begin(); i != entries.end(); ++i)
     if (i->status != destructed) v.push_back(boost::cref(*i));
   if (!v.empty() && !muted)
   {
     std::ostringstream oss;
       // We don't use cout here because apparently it can be unavailable by the time this code runs (judging by the segfaults I observed when this code used cout).
     more_ostreaming::delimit(oss, v);
     std::printf("%sleaked: %s.", parsep, oss.str().c_str());
     abort();
   }
 }
コード例 #8
0
std::string
Dictionary::translate(const Entries& dict, const std::string& msgid)
{
  Entries::const_iterator i = dict.find(msgid);
  if (i != dict.end() && !i->second.empty())
  {
    return i->second[0];
  }
  else
  {
    log_info << "Couldn't translate: " << msgid << std::endl;
    return msgid;
  } 
}
コード例 #9
0
ファイル: CalendarCell.C プロジェクト: 913862627/wt
void CalendarCell::update(const dbo::ptr<UserAccount>& user, const WDate& date)
{
  date_ = date;
  user_ = user;

  clear();

  dbo::Session& session = PlannerApplication::plannerApplication()->session;
  dbo::Transaction transaction(session);
  
  WString day;
  day += boost::lexical_cast<std::string>(date.day());
  if (date.day() == 1)
    day += " " + WDate::longMonthName(date.month());
  WText* header = new WText(day);
  header->setStyleClass("cell-header");
  addWidget(header);

  typedef dbo::collection< dbo::ptr<Entry> > Entries;
  Entries entries = user->entriesInRange(date, date.addDays(1));

  const unsigned maxEntries = 4;
  unsigned counter = 0;
  for (Entries::const_iterator i = entries.begin();
       i != entries.end(); ++i, ++counter) {
    if (counter == maxEntries) {
      WText* extra = 
	new WText(tr("calendar.cell.extra")
		  .arg((int)(entries.size() - maxEntries)));
      extra->setStyleClass("cell-extra");
      addWidget(extra);

      extra->clicked().preventPropagation();
      extra->clicked().connect(this, &CalendarCell::showAllEntriesDialog);
      
      break;
    }

    WString format = EntryDialog::timeFormat;
    addWidget(new WText((*i)->start.toString(format) +
			"-" + 
			(*i)->stop.toString(format) + 
			": " + (*i)->summary));
  }

  transaction.commit();
}
コード例 #10
0
ファイル: dictionary.cpp プロジェクト: dustinduse/etlegacy
std::string
Dictionary::translate_plural(const Entries& dict, const std::string& msgid, const std::string& msgid_plural, int count) const
{
	Entries::const_iterator it = dict.find(msgid);
	if (it != dict.end())
	{
		unsigned int                  n         = plural_forms.get_plural(count);
		const std::vector<std::string>& msgstrs = it->second;
		if (n >= msgstrs.size())
		{
			log_error << "Plural translation not available (and not set to empty): '" << msgid << "'" << std::endl;
			log_error << "Missing plural form: " << n << std::endl;
			return msgid;
		}

		if (!msgstrs[n].empty())
		{
			return msgstrs[n];
		}
		else
		if (count == 1) // default to english rules
		{
			return msgid;
		}
		else
		{
			return msgid_plural;
		}
	}
	else
	{
		log_info << "Couldn't translate: " << msgid << std::endl;
		log_info << "Candidates: " << std::endl;
		for (it = dict.begin(); it != dict.end(); ++it)
			log_info << "'" << it->first << "'" << std::endl;

		if (count == 1) // default to english rules
		{
			return msgid;
		}
		else
		{
			return msgid_plural;
		}
	}
}
コード例 #11
0
Path Directory::find(const Path& fileName, SensType sens) const
{
  if( fileName.toString().empty() )
  {
    Logger::warning( "!!! WARNING: Directory: cannot try find zero lenght name" );
    return "";
  }

  Entries files = entries();
  files.setSensType( sens );
  int index = files.findFile( fileName.baseName() );
  if( index >= 0 )
  {
    return files.item( index ).fullpath;
  }

  return "";
}
コード例 #12
0
void DefineEntry::accept()
{
#ifdef DEBUG
    qDebug("DefineEntry::accpet()");
#endif
    if (!EntryProperties->count())
    {
        QMessageBox::warning(this, "No properties", "Please, define some entry's\nproperties", 0, 0, 0);
        return;
    }

    if (EntryName->text() == "")
    {
        QMessageBox::warning(this, "No entry name", "Please, define entry name", 0, 0, 0);
        return;
    }

    Entries *entries = IQApp->entries();

    Entry *entry;

    if (editEntry)
    {
        if (EntryName->text() != editEntry->getName() && entries->isIn(EntryName->text()))
        {
            QMessageBox::warning(this, "Entry exists", "Entry with such name\nexists. Please, choose another.", 0, 0, 0);
            return;
        }

        entry = editEntry;
        entry->clear();
        entry->setName(EntryName->text());
    }
    else if ((entry = entries->isIn(EntryName->text())))
    {
        QMessageBox::warning(this, "Entry exists", "Entry with such name\nexists. Please, choose another.", 0, 0, 0);
        return;
    }
    else
        entry = new Entry(EntryName->text());

    for (uint i = 0; true; i++)
    {
        PropertyBoxItem *pbi;

        if ((pbi = static_cast<PropertyBoxItem *>(EntryProperties->item(i))))
        {
            entry->addProperty(new PropertyStruct(pbi));
        }
        else
            break;
    }
    
    entry->setDefaultPic(defaultPic);

    if (!editEntry)
        entries->addEntry(entry);

    entry->checkPropertiesID();

    DefineEntryBase::accept();
}
コード例 #13
0
ファイル: tracked.cpp プロジェクト: SunnyKale/geordi
 unsigned int id(Tracked const & t) { return entry(&t) - &entries.front(); }
コード例 #14
0
ファイル: tracked.cpp プロジェクト: SunnyKale/geordi
  namespace detail
  {
    using geordi::error;
    using geordi::parsep;

    bool muted = false;

    struct info: boost::noncopyable
    {
      info() { if(!muted) std::cout << parsep; }
      ~info() { if(!muted) std::cout << parsep; }
      std::ostream & operator()() const
      {
        static std::ostream s(0); // used as null sink
        return muted ? s : std::cout;
      }
    };

    enum Status { fresh, pillaged, destructed };

    struct Entry {
      Tracked const * p;
      char const * name;
      Status status;
    };

    typedef std::vector<Entry> Entries;
    Entries entries;
      // Keeping track of Trackeds outside of the objects themselves allows us to give nice diagnostics for operations on objects that have already perished.
      // Invariant: If multiple entries have identical p, then all but the last have status==destructed.

    std::ostream & operator<<(std::ostream & o, Entry const & e)
    { return o << e.name << &e - &entries.front(); }

    Entry * entry(Tracked const * const r) {
      for (Entries::reverse_iterator i(entries.rbegin()); i != entries.rend(); ++i) if (i->p == r) return &*i;
      return 0;
    }

    void make_entry(Tracked const * const r) {
      if (Entry * const e = entry(r)) if (e->status != destructed) error()() << "leaked: " << *e << '.';
      Entry const e = { r, "?", fresh };
      entries.push_back(e);
    }

    void assert_status_below(Tracked const * const r, Status const st, std::string const & s) {
      Entry * const e = entry(r);
      if(!e) error()() << "tried to " << s << " non-existent object.";
      if (e->status < st) return;
      error()() << "tried to " << s << (e->status == pillaged ? " pillaged " : " destructed ") << *e << '.';
    }

    void * op_new(std::size_t const s, bool const array, void * const r, char const * const name) {
      if (!r) return 0;
      info()() << "new(" << name << (array ? "[]" : "") << ")";
      return r;
    }

    void op_delete(void * const p, bool const array, std::size_t const s) {
      if (array) ::operator delete[](p);
      else ::operator delete(p);
      std::vector<boost::reference_wrapper<Entry const> > v;
      for (Entries::const_iterator j = entries.begin(); j != entries.end(); ++j)
        if (p <= j->p && boost::implicit_cast<void const *>(j->p) <= static_cast<char *>(p) + s)
          v.push_back(boost::cref(*j));
      if (array) { info i; i() << "delete["; more_ostreaming::delimit(i(), v); i() << ']'; }
      else { assert(v.size() == 1); info()() << "delete(" << v.front() << ")"; }
    }

    void Tracked::set_name(char const * const s) const { entry(this)->name = s; }

    Tracked::Tracked() { make_entry(this); }

    Tracked::Tracked(Tag const & t): tag(t) { make_entry(this); }

    Tracked::Tracked(Tracked const & i): tag((assert_status_below(&i, pillaged, "copy"), i.tag)) { make_entry(this); }

    void Tracked::operator=(Tracked const & r) {
      assert_status_below(this, destructed, "assign to");
      assert_status_below(&r, pillaged, "assign from");
      entry(this)->status = fresh;
    }

    Tracked::Tracked(Tracked && r)
    { assert_status_below(&r, pillaged, "move"); make_entry(this); entry(&r)->status = pillaged; }

    void Tracked::operator=(Tracked && r) {
      assert_status_below(this, destructed, "move-assign to");
      assert_status_below(&r, pillaged, "move");
      entry(this)->status = fresh;
      entry(&r)->status = pillaged;
    }

    Tracked::~Tracked()
    { assert_status_below(this, destructed, "re-destruct"); entry(this)->status = destructed; }

    struct LeakReporter {
      ~LeakReporter() {
        std::vector<boost::reference_wrapper<Entry const> > v;
        for (Entries::const_iterator i = entries.begin(); i != entries.end(); ++i)
          if (i->status != destructed) v.push_back(boost::cref(*i));
        if (!v.empty() && !muted)
        {
          std::ostringstream oss;
            // We don't use cout here because apparently it can be unavailable by the time this code runs (judging by the segfaults I observed when this code used cout).
          more_ostreaming::delimit(oss, v);
          std::printf("%sleaked: %s.", parsep, oss.str().c_str());
          abort();
        }
      }
    } leakReporter; // Must come after entries, so it will be destructed first.

    unsigned int id(Tracked const & t) { return entry(&t) - &entries.front(); }

  } // namespace detail
コード例 #15
0
ファイル: operations.hpp プロジェクト: allannielsen/termhub
inline children launch_pipeline(const Entries &entries) 
{ 
    BOOST_ASSERT(entries.size() >= 2); 

    children cs; 
    detail::file_handle fhinvalid; 

    boost::scoped_array<detail::pipe> pipes(new detail::pipe[entries.size() - 1]); 

#if defined(BOOST_POSIX_API) 
    { 
        typename Entries::size_type i = 0; 
        const typename Entries::value_type::context_type &ctx = entries[i].context; 

        detail::info_map infoin, infoout; 

        if (ctx.stdin_behavior.get_type() != stream_behavior::close) 
        { 
            detail::stream_info si = detail::stream_info(ctx.stdin_behavior, false); 
            infoin.insert(detail::info_map::value_type(STDIN_FILENO, si)); 
        } 

        BOOST_ASSERT(ctx.stdout_behavior.get_type() == stream_behavior::close); 
        detail::stream_info si2(close_stream(), true); 
        si2.type_ = detail::stream_info::use_handle; 
        si2.handle_ = pipes[i].wend().release(); 
        infoout.insert(detail::info_map::value_type(STDOUT_FILENO, si2)); 

        if (ctx.stderr_behavior.get_type() != stream_behavior::close) 
        { 
            detail::stream_info si = detail::stream_info(ctx.stderr_behavior, true); 
            infoout.insert(detail::info_map::value_type(STDERR_FILENO, si)); 
        } 

        detail::posix_setup s; 
        s.work_directory = ctx.work_directory; 

        pid_t pid = detail::posix_start(entries[i].executable, entries[i].arguments, ctx.environment, infoin, infoout, s); 

        detail::file_handle fhstdin; 

        if (ctx.stdin_behavior.get_type() == stream_behavior::capture) 
        { 
            fhstdin = detail::posix_info_locate_pipe(infoin, STDIN_FILENO, false); 
            BOOST_ASSERT(fhstdin.valid()); 
        } 

        cs.push_back(child(pid, fhstdin, fhinvalid, fhinvalid)); 
    } 

    for (typename Entries::size_type i = 1; i < entries.size() - 1; ++i) 
    { 
        const typename Entries::value_type::context_type &ctx = entries[i].context; 
        detail::info_map infoin, infoout; 

        BOOST_ASSERT(ctx.stdin_behavior.get_type() == stream_behavior::close); 
        detail::stream_info si1(close_stream(), false); 
        si1.type_ = detail::stream_info::use_handle; 
        si1.handle_ = pipes[i - 1].rend().release(); 
        infoin.insert(detail::info_map::value_type(STDIN_FILENO, si1)); 

        BOOST_ASSERT(ctx.stdout_behavior.get_type() == stream_behavior::close); 
        detail::stream_info si2(close_stream(), true); 
        si2.type_ = detail::stream_info::use_handle; 
        si2.handle_ = pipes[i].wend().release(); 
        infoout.insert(detail::info_map::value_type(STDOUT_FILENO, si2)); 

        if (ctx.stderr_behavior.get_type() != stream_behavior::close) 
        { 
            detail::stream_info si = detail::stream_info(ctx.stderr_behavior, true); 
            infoout.insert(detail::info_map::value_type(STDERR_FILENO, si)); 
        } 

        detail::posix_setup s; 
        s.work_directory = ctx.work_directory; 

        pid_t pid = detail::posix_start(entries[i].executable, entries[i].arguments, ctx.environment, infoin, infoout, s); 

        cs.push_back(child(pid, fhinvalid, fhinvalid, fhinvalid)); 
    } 

    { 
        typename Entries::size_type i = entries.size() - 1; 
        const typename Entries::value_type::context_type &ctx = entries[i].context; 

        detail::info_map infoin, infoout; 

        BOOST_ASSERT(ctx.stdin_behavior.get_type() == stream_behavior::close); 
        detail::stream_info si1(close_stream(), false); 
        si1.type_ = detail::stream_info::use_handle; 
        si1.handle_ = pipes[i - 1].rend().release(); 
        infoin.insert(detail::info_map::value_type(STDIN_FILENO, si1)); 

        if (ctx.stdout_behavior.get_type() != stream_behavior::close) 
        { 
            detail::stream_info si = detail::stream_info(ctx.stdout_behavior, true); 
            infoout.insert(detail::info_map::value_type(STDOUT_FILENO, si)); 
        } 

        if (ctx.stderr_behavior.get_type() != stream_behavior::close) 
        { 
            detail::stream_info si = detail::stream_info(ctx.stderr_behavior, true); 
            infoout.insert(detail::info_map::value_type(STDERR_FILENO, si)); 
        } 

        detail::posix_setup s; 
        s.work_directory = ctx.work_directory; 

        pid_t pid = detail::posix_start(entries[i].executable, entries[i].arguments, ctx.environment, infoin, infoout, s); 

        detail::file_handle fhstdout, fhstderr; 

        if (ctx.stdout_behavior.get_type() == stream_behavior::capture) 
        { 
            fhstdout = detail::posix_info_locate_pipe(infoout, STDOUT_FILENO, true); 
            BOOST_ASSERT(fhstdout.valid()); 
        } 

        if (ctx.stderr_behavior.get_type() == stream_behavior::capture) 
        { 
            fhstderr = detail::posix_info_locate_pipe(infoout, STDERR_FILENO, true); 
            BOOST_ASSERT(fhstderr.valid()); 
        } 

        cs.push_back(child(pid, fhinvalid, fhstdout, fhstderr)); 
    } 
#elif defined(BOOST_WINDOWS_API) 
    STARTUPINFOA si; 
    detail::win32_setup s; 
    s.startupinfo = &si; 

    { 
        typename Entries::size_type i = 0; 
        const typename Entries::value_type::context_type &ctx = entries[i].context; 

        detail::stream_info sii = detail::stream_info(ctx.stdin_behavior, false); 
        detail::file_handle fhstdin; 
        if (sii.type_ == detail::stream_info::use_pipe) 
            fhstdin = sii.pipe_->wend(); 

        BOOST_ASSERT(ctx.stdout_behavior.get_type() == stream_behavior::close); 
        detail::stream_info sio(close_stream(), true); 
        sio.type_ = detail::stream_info::use_handle; 
        sio.handle_ = pipes[i].wend().release(); 

        detail::stream_info sie(ctx.stderr_behavior, true); 

        s.work_directory = ctx.work_directory; 

        ::ZeroMemory(&si, sizeof(si)); 
        si.cb = sizeof(si); 
        PROCESS_INFORMATION pi = detail::win32_start(entries[i].executable, entries[i].arguments, ctx.environment, sii, sio, sie, s); 

        if (!::CloseHandle(pi.hThread)) 
            boost::throw_exception(boost::system::system_error(boost::system::error_code(::GetLastError(), boost::system::get_system_category()), "boost::process::launch_pipeline: CloseHandle failed")); 

        cs.push_back(child(pi.dwProcessId, fhstdin, fhinvalid, fhinvalid, detail::file_handle(pi.hProcess))); 
    } 

    for (typename Entries::size_type i = 1; i < entries.size() - 1; ++i) 
    { 
        const typename Entries::value_type::context_type &ctx = entries[i].context; 

        BOOST_ASSERT(ctx.stdin_behavior.get_type() == stream_behavior::close); 
        detail::stream_info sii(close_stream(), false); 
        sii.type_ = detail::stream_info::use_handle; 
        sii.handle_ = pipes[i - 1].rend().release(); 

        detail::stream_info sio(close_stream(), true); 
        sio.type_ = detail::stream_info::use_handle; 
        sio.handle_ = pipes[i].wend().release(); 

        detail::stream_info sie(ctx.stderr_behavior, true); 

        s.work_directory = ctx.work_directory; 

        ::ZeroMemory(&si, sizeof(si)); 
        si.cb = sizeof(si); 
        PROCESS_INFORMATION pi = detail::win32_start(entries[i].executable, entries[i].arguments, ctx.environment, sii, sio, sie, s); 

        if (!::CloseHandle(pi.hThread)) 
            boost::throw_exception(boost::system::system_error(boost::system::error_code(::GetLastError(), boost::system::get_system_category()), "boost::process::launch_pipeline: CloseHandle failed")); 

        cs.push_back(child(pi.dwProcessId, fhinvalid, fhinvalid, fhinvalid, detail::file_handle(pi.hProcess))); 
    } 

    { 
        typename Entries::size_type i = entries.size() - 1; 
        const typename Entries::value_type::context_type &ctx = entries[i].context; 

        BOOST_ASSERT(ctx.stdin_behavior.get_type() == stream_behavior::close); 
        detail::stream_info sii(close_stream(), false); 
        sii.type_ = detail::stream_info::use_handle; 
        sii.handle_ = pipes[i - 1].rend().release(); 

        detail::file_handle fhstdout, fhstderr; 

        detail::stream_info sio(ctx.stdout_behavior, true); 
        if (sio.type_ == detail::stream_info::use_pipe) 
            fhstdout = sio.pipe_->rend(); 
        detail::stream_info sie(ctx.stderr_behavior, true); 
        if (sie.type_ == detail::stream_info::use_pipe) 
            fhstderr = sie.pipe_->rend(); 

        s.work_directory = ctx.work_directory; 

        ::ZeroMemory(&si, sizeof(si)); 
        si.cb = sizeof(si); 
        PROCESS_INFORMATION pi = detail::win32_start(entries[i].executable, entries[i].arguments, ctx.environment, sii, sio, sie, s); 

        if (!::CloseHandle(pi.hThread)) 
            boost::throw_exception(boost::system::system_error(boost::system::error_code(::GetLastError(), boost::system::get_system_category()), "boost::process::launch_pipeline: CloseHandle failed")); 

        cs.push_back(child(pi.dwProcessId, fhinvalid, fhstdout, fhstderr, detail::file_handle(pi.hProcess))); 
    } 
#endif 

    return cs; 
} 
コード例 #16
0
 void Set(Entries& entries)
 {
     Set( entries.Ptr(), entries.Size() );
 }
コード例 #17
0
void ArchiveTestCase<ClassFactoryT>::ExtractArchive(wxInputStream& in)
{
    typedef Ptr<EntryT> EntryPtr;
    typedef std::list<EntryPtr> Entries;
    typedef typename Entries::iterator EntryIter;

    auto_ptr<InputStreamT> arc(m_factory->NewStream(in));
    int expectedTotal = m_testEntries.size();
    EntryPtr entry;
    Entries entries;

    if ((m_options & PipeIn) == 0)
        OnArchiveExtracted(*arc, expectedTotal);

    while (entry = EntryPtr(arc->GetNextEntry()), entry.get() != NULL) {
        wxString name = entry->GetName(wxPATH_UNIX);

        // provide some context for the error message so that we know which
        // iteration of the loop we were on
        string error_entry((_T(" '") + name + _T("'")).mb_str());
        string error_context(" failed for entry" + error_entry);

        TestEntries::iterator it = m_testEntries.find(name);
        CPPUNIT_ASSERT_MESSAGE(
            "archive contains an entry that shouldn't be there" + error_entry,
            it != m_testEntries.end());

        const TestEntry& testEntry = *it->second;

        wxDateTime dt = testEntry.GetDateTime();
        if (dt.IsValid())
            CPPUNIT_ASSERT_MESSAGE("timestamp check" + error_context,
                                   dt == entry->GetDateTime());

        // non-seekable entries are allowed to have GetSize == wxInvalidOffset
        // until the end of the entry's data has been read past
        CPPUNIT_ASSERT_MESSAGE("entry size check" + error_context,
            testEntry.GetLength() == entry->GetSize() ||
            ((m_options & PipeIn) != 0 && entry->GetSize() == wxInvalidOffset));
        CPPUNIT_ASSERT_MESSAGE(
            "arc->GetLength() == entry->GetSize()" + error_context,
            arc->GetLength() == entry->GetSize());

        if (name.Last() != _T('/'))
        {
            CPPUNIT_ASSERT_MESSAGE("!IsDir" + error_context,
                !entry->IsDir());
            wxCharBuffer buf(testEntry.GetSize() + 1);
            CPPUNIT_ASSERT_MESSAGE("Read until Eof" + error_context,
                arc->Read(buf.data(), testEntry.GetSize() + 1).Eof());
            CPPUNIT_ASSERT_MESSAGE("LastRead check" + error_context,
                arc->LastRead() == testEntry.GetSize());
            CPPUNIT_ASSERT_MESSAGE("data compare" + error_context,
                !memcmp(buf.data(), testEntry.GetData(), testEntry.GetSize()));
        } else {
            CPPUNIT_ASSERT_MESSAGE("IsDir" + error_context, entry->IsDir());
        }

        // GetSize() must return the right result in all cases after all the
        // data has been read
        CPPUNIT_ASSERT_MESSAGE("entry size check" + error_context,
            testEntry.GetLength() == entry->GetSize());
        CPPUNIT_ASSERT_MESSAGE(
            "arc->GetLength() == entry->GetSize()" + error_context,
            arc->GetLength() == entry->GetSize());

        if ((m_options & PipeIn) == 0) {
            OnEntryExtracted(*entry, testEntry, arc.get());
            delete it->second;
            m_testEntries.erase(it);
        } else {
            entries.push_back(entry);
        }
    }

    // check that the end of the input archive was reached without error
    CPPUNIT_ASSERT(arc->Eof());

    // for non-seekable streams these data are only guaranteed to be
    // available once the end of the archive has been reached
    if (m_options & PipeIn) {
        for (EntryIter i = entries.begin(); i != entries.end(); ++i) {
            wxString name = (*i)->GetName(wxPATH_UNIX);
            TestEntries::iterator j = m_testEntries.find(name);
            OnEntryExtracted(**i, *j->second);
            delete j->second;
            m_testEntries.erase(j);
        }
        OnArchiveExtracted(*arc, expectedTotal);
    }
}
コード例 #18
0
ファイル: tracked.cpp プロジェクト: SunnyKale/geordi
 std::ostream & operator<<(std::ostream & o, Entry const & e)
 { return o << e.name << &e - &entries.front(); }
コード例 #19
0
ファイル: PLS.cpp プロジェクト: mitya57/QMPlay2
Playlist::Entries PLS::_read()
{
	Reader *reader = ioCtrl.rawPtr< Reader >();
	Entries list;

	QString playlistPath = filePath(reader->getUrl());
	if (playlistPath.startsWith("file://"))
		playlistPath.remove(0, 7);
	else
		playlistPath.clear();

	const QList< QByteArray > playlistLines = readLines();
	for (int i = 0; i < playlistLines.count(); ++i)
	{
		const QByteArray &line = playlistLines[i];
		if (line.isEmpty())
			continue;
		int idx = line.indexOf('=');
		if (idx < 0)
			continue;

		int number_idx = -1;
		for (int i = 0; i < line.length(); ++i)
		{
			if (line[i] == '=')
				break;
			if (line[i] >= '0' && line[i] <= '9')
			{
				number_idx = i;
				break;
			}
		}
		if (number_idx == -1)
			continue;

		QByteArray key = line.left(number_idx);
		QByteArray value = line.mid(idx+1);
		int entry_idx = line.mid(number_idx, idx - number_idx).toInt() - 1;

		prepareList(&list, entry_idx);
		if (entry_idx < 0 || entry_idx > list.size() - 1)
			continue;

		if (key == "File")
			list[entry_idx].url = Url(value, playlistPath);
		else if (key == "Title")
			list[entry_idx].name = value.replace('\001', '\n');
		else if (key == "Length")
			list[entry_idx].length = value.toInt();
		else if (key == "QMPlay_sel")
			list[entry_idx].selected = value.toInt();
		else if (key == "QMPlay_queue")
			list[entry_idx].queue = value.toInt();
		else if (key == "QMPlay_GID")
			list[entry_idx].GID = value.toInt();
		else if (key == "QMPlay_parent")
			list[entry_idx].parent = value.toInt();
	}

	return list;
}
コード例 #20
0
ファイル: tracked.cpp プロジェクト: SunnyKale/geordi
 Entry * entry(Tracked const * const r) {
   for (Entries::reverse_iterator i(entries.rbegin()); i != entries.rend(); ++i) if (i->p == r) return &*i;
   return 0;
 }
コード例 #21
0
ファイル: tracked.cpp プロジェクト: SunnyKale/geordi
 void make_entry(Tracked const * const r) {
   if (Entry * const e = entry(r)) if (e->status != destructed) error()() << "leaked: " << *e << '.';
   Entry const e = { r, "?", fresh };
   entries.push_back(e);
 }