예제 #1
0
void testGet()
{
    if (os_) *os_ << "testGet()\n";

    ReaderList readers;
    readers.push_back(ReaderPtr(new Reader1));
    readers.push_back(ReaderPtr(new Reader2));

    unit_assert(readers.size() == 2);

    Reader1* reader1 = readers.get<Reader1>();
    unit_assert(reader1);

    Reader2* reader2 = readers.get<Reader2>();
    unit_assert(reader2);

    if (os_) *os_ << endl;
}
예제 #2
0
void testRead()
{
    if (os_) *os_ << "testRead()\n";

    ReaderList readers;
    readers.push_back(ReaderPtr(new Reader1));
    readers.push_back(ReaderPtr(new Reader2));

    TraData td;

    // note: composite pattern with accept/read will cause two calls
    // to accept(); the alternative is to maintain state between accept()
    // and read(), which opens possibility for misuse. 

    unit_assert(readers.get<Reader1>()->config.done == false);
    if (readers.accept("1", "head"))
        readers.read("1", "head", td);
    unit_assert(readers.get<Reader1>()->config.done == true);

    readers.get<Reader1>()->config.done = false;
    unit_assert(readers.get<Reader2>()->config.done == false);
    if (readers.accept("2", "head"))
        readers.read("2", "head", td);
    unit_assert(readers.get<Reader1>()->config.done == false);
    unit_assert(readers.get<Reader2>()->config.done == true);

    if (os_) *os_ << endl;
}
예제 #3
0
int main(int argc, char *argv[])
{
  ReaderList readers = ac::CorpusReaderFactory::readersAvailable();

  for (ReaderList::const_iterator iter = readers.begin();
    iter != readers.end(); ++iter)
  {
    std::cout << iter->description << " ( ";
    std::copy(iter->extensions.begin(), iter->extensions.end(),
        std::ostream_iterator<std::string>(std::cout, " "));
    std::cout << "): ";

    // Corresponds with CorpusReader::readerAvailable?
    if (ac::CorpusReaderFactory::readerAvailable(iter->readerType))
      std::cout << "OK";
    else
      std::cout << "Error in readerAvailable!";

    std::cout << std::endl;
  }


  return 0;
}