Beispiel #1
0
void Zprime_Py8::Loop(Long64_t nevts,const std::string& outName, bool PUsub)
{
  // check if chain exists
   if (fChain == 0) return;

   // number of events to be analyzed (nevts <= 0 -> all)
   Long64_t nentries = nevts > 0 ? nevts : fChain->GetEntriesFast();

   // book histograms
   printf("[Zprime_Py8::Loop(%i,\042%s\042)] book hists...",
	  (int)nevts,outName.c_str());
   book();
   printf("DONE!\n");

   // signal event store and data handler
   Event* pEvt                   = new Event(new Selectors::EtaRange(-6.,6.));
   DataHandler<Zprime_Py8>* pHdl = new DataHandler<Zprime_Py8>();
   printf("[Zprime_Py8::Loop(%i,\042%s\042)] Event at %p, DataHandler at %p\n",
	  (int)nevts,outName.c_str(),(void*)pEvt,(void*)pHdl);

   // event loop
   Long64_t iEvts = 0;
   while ( iEvts < nentries && pHdl->fillEvent(*this,*pEvt,iEvts,-1,0,
					       Vertex::SIGNAL) )
     {
       printf("[Zprime_Py8::Loop(%i,\042%s\042)] analyze event %i\n",
	      (int)nevts,outName.c_str(),(int)iEvts);
       analyze(*pEvt, PUsub); 
       pEvt->reset(); 
     }

   // write histograms
   if ( !outName.empty() && outName != "" ) { write(outName); }
}
Beispiel #2
0
void Library::addBook()
{
	/*
	 * addBook - prompts the user for book info and uses it to create
	 *					 a Book, which is added to holdings  
	 */
	if (DBG_FUN) std::cout << "Library::addBook" << std::endl;
	 
	std::string tmpTitle;  // temporary storage for user input
	std::string tmpAuthor;
	std::string tmpID;

	std::cout << "Title: ";
	getline(std::cin, tmpTitle); // No validation is done on input
	std::cout << "Author: ";
	getline(std::cin, tmpAuthor);
	std::cout << "Book ID (ISBN####): ";
	getline(std::cin, tmpID);

	int checkID = findBook(tmpID); // Look for that tmpID in holdings
	if ( checkID >=0 )
	{
		std::cout << "Sorry, that Book ID is already in use." << std::endl;
		return;
	}

	Book book(tmpID,tmpTitle,tmpAuthor);
	holdings.push_back(book);
	std::cout << "Added book " << tmpTitle << " with ID " << tmpID <<std::endl;
}
int main(){
    long P;
    scanf(" %ld", &P);

    std::vector<long> book(P);
    long num_ideas;
    {
        std::set<long> ideas;
        for (long i=0; i<P; ++i) {
            scanf(" %ld", &book[i]);
            ideas.insert(book[i]);
        }
        num_ideas = ideas.size();
    }



    std::map<long,long> idea_to_count;
    long kinds_of_idea = 0;
    long start = 0, end = 0;
    long mininum = LONG_MAX;
    while (true) {
        while (kinds_of_idea < num_ideas && end < P)
            if (!idea_to_count[book[end++]]++)
                ++kinds_of_idea;
        if (kinds_of_idea < num_ideas)
            break;
        while (kinds_of_idea == num_ideas)
            if (!--idea_to_count[book[start++]])
                --kinds_of_idea;
        mininum = std::min(mininum, end - start + 1);
    }
    printf("%ld\n", mininum);
}
void pawsWritingWindow::OnStringEntered(const char* /*name*/, int /*param*/, const char* value)
{
    const unsigned int MAX_BOOK_FILE_SIZE = 60000;

    csString fileName;
    iVFS* vfs = psengine->GetVFS();
    if (!value)
        return;

    fileName.Format("/planeshift/userdata/books/%s", value);
    if (!vfs->Exists(fileName))
    {
        psSystemMessage msg(0, MSG_ERROR, "File %s not found!", fileName.GetDataSafe());
        msg.FireEvent();
        return;
    }    
    csRef<iDataBuffer> data = vfs->ReadFile(fileName);
    if (data->GetSize() > MAX_BOOK_FILE_SIZE)
    {
        psSystemMessage msg(0, MSG_ERROR, "File too big, data trimmed to %d chars.", MAX_BOOK_FILE_SIZE );
        msg.FireEvent();
    }        
    csString book(data->GetData(), csMin(data->GetSize(), (size_t)MAX_BOOK_FILE_SIZE));
    book.ReplaceAll("\r\n", "\n");
    lefttext->SetText(book, true);
    
    psSystemMessage msg(0, MSG_ACK, "Book Loaded Successfully!" );
    msg.FireEvent();
}
std::vector<std::string> NetworkBookTree::BookItemWrapper::authors() const {
	const NetworkBookItem &bookItem = book();
	std::vector<std::string> authors;
	for (std::size_t i = 0; i < bookItem.Authors.size(); ++i) {
		authors.push_back(bookItem.Authors.at(i).DisplayName);
	}
	return authors;
}
 void debug1(bool flag) const
 {
     if(flag)
     std::cout<<"ISBN: "<<book()<<std::endl
              <<"PriceL "<<price<<std::endl
              <<"Min_quantiry: "<<min_qty<<std::endl
              <<"Discount Rate: "<<discount<<std::endl;
 }
int main()
{
    int sum = 0, value, // sum、value 和 units_sold 都是 int
        units_sold = 0; // sum 和 units_sold 初值为 0
    std::cout << " sum = " << sum 
              << " value = " << value
              << " units_sold = " << units_sold;
     Sales_item item;    // item 的类型是 Sales_item 
    std::string book("0-201-78345-X");  // book 通过一个string字面值初始化
    std::cout << book << std::endl;

    // 正确:price先被定义并赋值,随后被用于初始化discount
    double price = 109.99, discount = price * 0.16;
    // 正确:调用函数applyDiscount, 然后用函数的返回值初始化salePrice
    // double salePrice = applyDiscount(price, discount); 
    std::cout << " price = " << price 
              << " discount = " << discount
              << std::endl;

    int units_sold_1 = 0;
    int units_sold_2 = {0};
    int units_sold_3{0};
    int units_sold_4(0);

    long double ld = 3.1415926536;
    int a{ld}, b = {ld};    //  转换执行,丢失部分数据, 出现警告 
    //  warning: extended initializer lists only available with -std=c++11 or -std=gnu++11 [enabled by default]
    //  warning: narrowing conversion of 'ld' from 'long double' to 'int' inside { } is ill-formed in C++11 [-Wnarrowing]
    int c(ld), d = ld;      //  转换执行,并且确实丢失了部分值
    double a_d = ld;        // 
    double b_d = b;         //
    double c_d = c;         //
    double d_d = d;         //
    long double a_ld = a_d; // double 和 long double 转换存在错误   -8.87961e+043
    long double b_ld = b;   // int 和 long double 转换存在错误      -2
    long double c_ld = c_d; //
    long double d_ld = d_d; //

    std::cout << " a = " << a
              << " b = " << b
              << " c = " << c
              << " d = " << d
              << " a_d = " << a_d
              << " b_d = " << b_d
              << " c_d = " << c_d
              << " d_d = " << d_d
              << " a_ld = " << a_ld
              << " b_ld = " << b_ld
              << " c_ld = " << c_ld
              << " d_ld = " << d_ld
              << std::endl;

//    std::cin >> int input_value;    //  error: expected primary-expression before 'int'
//    int i = { 3.14 };   // warning: narrowing conversion of '3.1400000000000001e+0' from 'double' to 'int' inside { } is ill-formed in C++11 [-Wnarrowing]
//                        // error: 'int i' previously declared here
//    double salary = wage = 9999.99; //  error: 'wage' was not declared in this scope
//    int i = 3.14;   // error: redeclaration of 'int i'
}
Beispiel #8
0
bool EntryData::isWritable() const {
  Notebook *b = book();
  
  if (!b || b->isReadOnly())
    return false;
  if (isUnlocked())
    return true;
  if (isEmpty())
    return true;
  return isRecent() && App::instance()->cui()->match(cui_);
}
Beispiel #9
0
vector<int> Semester::AssignRoom(Request &request){
    vector<int> unbooked;
    vector<int> hours = request.hours();
    vector<int> res;
    // TODO: add free hours size = hours
    //check if a room has all the hours
    for(auto room = rooms.begin(); room != rooms.end(); room++){
        if(room->freeHours().size() >= hours.size()){
            return room->book(hours,request.name);
        }
    }
    if(rooms.size() > 0){
        unbooked = rooms[0].book(hours,request.name);
        for(auto room = rooms.begin()+1; room != rooms.end(); room++){
            res = room->book(unbooked, request.name);
            unbooked = res;
        }
    }
    return unbooked;
}
Beispiel #10
0
//! Test that WriteCompressed() followed by ReadCompressed() returns the same book
void CBook::TestIO() {
	{
		// test book with no position
		CBook book(NULL, s_out);
		book.TestMyIO();
	}

	{
		// test book with a pass position and a subposition from that
		CBook book(NULL, s_out);
		CQPosition pos;
		pos.Initialize("---------------------------**------**------------------O------O*", true);

		book.StoreRoot(pos.BitBoard(), CHeightInfoX(10, 4, false, pos.NEmpty()), 32, -300);
		pos.MakeMove(CMove(057));
		pos.Pass();
		book.StoreLeaf(pos.BitBoard(), CHeightInfoX(10, 4, false, pos.NEmpty()), 32);
		book.TestMyIO();
	}
	{
		// test book with only one entry
		CBook book(NULL, s_out);
		CQPosition pos;

		pos.Initialize();
		book.StoreLeaf(pos.BitBoard(), CHeightInfoX(10, 4, false, 60), 32);
		book.TestMyIO();
	}
	{
		// test book with two entries in a tree
		CBook book(NULL, s_out);
		CQPosition pos;
		pos.Initialize();

		book.StoreRoot(pos.BitBoard(), CHeightInfoX(10, 4, false, 60), 32, 16400);
		pos.MakeMove(CMove(045));
		book.StoreLeaf(pos.BitBoard(), CHeightInfoX(10, 4, false, 59), -32);
		book.TestMyIO();
	}
}
std::string NetworkBookTree::subtitle() const {
	int count = 0;
	std::string authorsString;
	const std::vector<NetworkBookItem::AuthorData> authors = book().Authors;
	for (std::vector<NetworkBookItem::AuthorData>::const_iterator it = authors.begin(); it != authors.end(); ++it) {
		if (!authorsString.empty()) {
			authorsString += ", ";
		}
		authorsString += it->DisplayName;
		++count;
	}
	if (mySummaryType == NONE && count == 1) {
		return std::string();
	}
	return authorsString;
}
Beispiel #12
0
int main(int argc, char *argv[]) {

	// Create Qt Application object
	QApplication app(argc, argv);

	// Create Order Book
	TradeBook book("tradeBookDB", 5432, "CMEGroup.csv");

	// Exec test exchange
	start_exchange();

	// Create GUI and connect it to tradebook
	GUI interface(0, &book);
	interface.show();

	return app.exec();
}
Beispiel #13
0
BasicOutput::BasicOutput(const char *name) {
  
  dir_name = name;
  
  output = new TObjArray::TObjArray();

  //..........................................................
  
  for(int i=0; i < MAX_BITS; ++i)
    m_ttbits.push_back(i+24);
  
  gDirectory->mkdir(name)->cd();
  book();
  gDirectory->cd("../");
  gDirectory->mkdir("BXDiff");
  
}
Beispiel #14
0
NoiseEvolution(char* path_, char* RunsList_){


  GetRuns(path_,RunsList_);

  //Open Reference File
  sprintf(refFile,"%s/Display_PedNoise_RunNb_%d.root",path,iov[0]);
  cout << "\nReference File " << refFile << endl;
  refFile_= new TRFIOFile(refFile);

  //Get Histo Names
  refFile_->cd("Noises");
  TIter nextkey(gDirectory->GetListOfKeys());
  TKey *key;
  while (key = (TKey*)nextkey()) {    
    const char * title;
    title=key->GetTitle();
    if (strncmp(title,"Noises_",6)==0 && strstr(title,"Cumulative")== NULL){
      vHistoNames.push_back(string(title));
      vHistoNBinsX.push_back(((TH1F*)key->ReadObj())->GetNbinsX());
      
      char tmp[128];
      LayerName(title,tmp);
      string tmp1(tmp);
      int i=0;
      while (i<vLayerName.size() && tmp1!=vLayerName[i]){i++;}
      if (i==vLayerName.size())
	vLayerName.push_back(tmp1);      
    }
  }

  book();

  
  for (int i=1;i<iovDim;i++){

    sprintf(inFile,"%s/Display_PedNoise_RunNb_%d.root",path,iov[i]);
    cout << "\nAnalyzing File " << inFile << endl;
    inFile_= new TRFIOFile(inFile);
  
    loop(iov[i]);
  }
  
  save();
}
void NetworkBookTree::BookItemWrapper::loadAll(shared_ptr<ZLNetworkRequest::Listener> listener) {
	if (myIsInitialized) {
		listener->finished();
		return;
	}

	NetworkBookItem &bookItem = book();

	BookItemWrapperScope *scope = new BookItemWrapperScope;
	scope->listener = listener;
	shared_ptr<ZLUserDataHolder> scopeData = new ZLUserDataHolder;
	scopeData->addUserData("scope", scope);

	if (bookItem.isFullyLoaded()) {
		onInformationLoaded(*scopeData, std::string());
		return;
	}
	bookItem.loadFullInformation(ZLExecutionUtil::createListener(scopeData, this, &NetworkBookTree::BookItemWrapper::onInformationLoaded));
}
Beispiel #16
0
extern "C" LWS_VISIBLE int
lws_plat_change_pollfd(struct lws_context *context,
		      struct lws *wsi, struct lws_pollfd *pfd)
{
	lws_conn *conn = (lws_conn *)wsi->sock;
	
	(void)context;
	if (pfd->events & POLLOUT) {
		conn->awaiting_on_writeable = 1;
		if (conn->writeable) {
 			mbed::util::FunctionPointer1<void, struct lws *> book(conn, &lws_conn::serialized_writeable);
			minar::Scheduler::postCallback(book.bind(wsi));
			lwsl_debug("%s: wsi %p (booked callback)\r\n", __func__, (void *)wsi);
		} else {
			
			lwsl_debug("%s: wsi %p (set awaiting_on_writeable)\r\n", __func__, (void *)wsi);
		}
	} else
		conn->awaiting_on_writeable = 0;
	
	return 0;
}
/*********************************************
*函数功能:装载图书数据
*函数参数:数据库链接参数
*函数返回值:图书容器
**********************************************/
list<Book> load_book_data(MYSQL *connect)
{
	MYSQL_RES *res = NULL;  
	MYSQL_ROW row  = NULL; 
	list<Book> list_book;
	const char *com = "select * from book";

	int re = mysql_real_query(connect, com, strlen(com));
	if(re != 0)
	{
		cout<<"query failed"<<endl;
		return list_book;
	}

	res = mysql_use_result(connect);
	if(NULL == res)
	{
		cout<<"result failed"<<endl;
		return list_book;
	}
	
	int num = mysql_num_fields(res);

	while(row = mysql_fetch_row(res))
	{
		char *b_name = row[0];
		char *author = row[1];
		char *publisher = row[2];
		float price = (float)atoi(row[3]);
		int total = atoi(row[4]);

		Book book(b_name, author, publisher, price, total);
		list_book.push_back(book);
	}

	mysql_free_result(res);

	return list_book;
}
void CalibSAMURAI(char *infile, char*outfile="fout.root"){
  TStopwatch t;
  t.Start();

  gSystem->Load("TAlSAMURAI_cc.so");

  TFile *fout = new TFile(outfile,"recreate");
  book(new TAlSAMURAI);
  push(infile,2000);
  //push(infile);
  start();
  gSystem->Sleep(5000);
  join();
  ((TTree*)gDirectory->Get("sm"))->Write();
  fout->Write();
  fout->Close();

  t.Stop();
  t.Print();

  exit();
}
Beispiel #19
0
int main(int argc, const char * argv[]) {
    
    //srand((unsigned int)(time(NULL)));
    
    Plane p;
    Airport air("John F. Kennedy Airport", "New York", 3);
    
    std::cout << "Welcome to " << air.getName() << ", " << air.getLocation() << ". \n\nWe currently fly to the following cities:\n";
    
    for(int i = 0; i < air.getDestinations().size(); i++)
        std::cout << air.getDestinations().at(i) << ", ";
    
    std::cout << std::endl;std::cout << std::endl;
    
    air.destinationFlights();
    
    std::cout << std::endl;
    
    Passenger passenger("Oyedotun","Oyesanmi", "Paris", SeatType::BUSINESS_CLASS);
    Booking book(passenger);
    book.seatAvailability(passenger, air);std::cout << std::endl;
    
    return 0;
}
Beispiel #20
0
void RecBookFile::SaveContent( )
{
    wxASSERT( m_xml_root );

    TiXmlElement book("book");
	int i;
    
    book.SetAttribute("RISM",  m_RISM.c_str() );
    book.SetAttribute("Composer", m_Composer.c_str() );    
    book.SetAttribute("Title", m_Title.c_str() );
    book.SetAttribute("Printer", m_Printer.c_str() );
    book.SetAttribute("Year", m_Year.c_str() );
    book.SetAttribute("Library", m_Library.c_str() );
    m_xml_root->InsertEndChild( book );
    
    TiXmlElement images("images");
    wxFileName dirname1 = wxFileName::DirName( m_imgFileDir );
    dirname1.MakeRelativeTo( wxFileName( m_filename ).GetFullPath() );
    //wxLogDebug( dirname1.GetPath() );
    images.SetAttribute("Path", dirname1.GetPath().c_str() );
    for ( i = 0; i < (int)m_imgFiles.GetCount(); i++)
    {
        TiXmlElement image("image");
        image.SetAttribute("filename", m_imgFiles[i].m_filename.c_str() );
        image.SetAttribute("flags", wxString::Format("%d", m_imgFiles[i].m_flags ).c_str() );
        images.InsertEndChild( image );
    }   
    m_xml_root->InsertEndChild( images );
    
    TiXmlElement axfiles("axfiles");
    wxFileName dirname2 = wxFileName::DirName( m_axFileDir );
    dirname2.MakeRelativeTo( wxFileName( m_filename ).GetFullPath() );
    //wxLogDebug( dirname2.GetPath() );
    axfiles.SetAttribute("Path", dirname2.GetPath().c_str() );
    for ( i = 0; i < (int)m_axFiles.GetCount(); i++)
    {
        TiXmlElement axfile("axfile");
        axfile.SetAttribute("filename", m_axFiles[i].m_filename.c_str() );
        axfile.SetAttribute("flags", wxString::Format("%d", m_axFiles[i].m_flags ).c_str() );
        axfiles.InsertEndChild( axfile );
    }   
    m_xml_root->InsertEndChild( axfiles );
	
    TiXmlElement adapt("adaptation");
    adapt.SetAttribute("full", wxString::Format("%d", m_fullOptimized ).c_str() );
	adapt.SetAttribute("nb_files_for_full", wxString::Format("%d", m_nbFilesOptimization ).c_str() );
    for ( i = 0; i < (int)m_optFiles.GetCount(); i++)
    {
        TiXmlElement adapt_file("file");
        adapt_file.SetAttribute("filename", m_optFiles[i].c_str() );
        adapt.InsertEndChild( adapt_file );
    }   
    m_xml_root->InsertEndChild( adapt );

	// binarization variables
	TiXmlElement binarization( "binarization" );
	binarization.SetAttribute( "pre_image_binarization_method", m_pre_image_binarization_method );
	binarization.SetAttribute( "pre_page_binarization_method", m_pre_page_binarization_method );
	binarization.SetAttribute( "pre_page_binarization_method_size", m_pre_page_binarization_method_size );
	binarization.SetAttribute( "pre_page_binarization_select", m_pre_page_binarization_select );
	m_xml_root->InsertEndChild( binarization );
}
Beispiel #21
0
void image()
{int i;
 randomize();
 settextstyle(1,HORIZ_DIR,9);
 for (i=-250;i<10;i+=5)
 {setcolor(BLACK);
  outtextxy(i-5,0,*Title);// "Hyper"
  setcolor(LIGHTBLUE);
  outtextxy(i,0,*Title);// "Hyper"
  Delay(1);
 }
 Delay(300);
 setcolor(LIGHTRED);
 settextstyle(3,HORIZ_DIR,16);
 for (i=1;i<7;i++)
 {outtextxy(210+i*60,60,*(Title+i));// "Reader"
  Delay(400);
 }
 Delay(100);
 for (i=1;i<7;i++)
 {settextstyle(4,0,i);
  setcolor(LIGHTCYAN);
  outtextxy(450,190,*(Title+7));// "2000"
  Delay(300);
  setcolor(BLACK);
  settextstyle(4,HORIZ_DIR,i);
  outtextxy(450,190,*(Title+7));// "2000"
 }
 setcolor(LIGHTCYAN);
 settextstyle(4,HORIZ_DIR,i);
 outtextxy(450,190,*(Title+7));// "2000"
 Delay(400);
 setcolor(BLUE);
 line(10,140,250,140);
 line(250,140,250,200);
 line(250,200,400,200);
 line(400,200,400,280);
 line(400,280,600,280);
 Delay(800);
 setcolor(LIGHTGREEN);
 settextstyle(2,0,7);
 outtextxy(20,200,*(Title+8));// "Produced by Zhao Chang."
 Delay(500);
 outtextxy(40,225,*(Title+9));// "Copyright (C)  2000"
 Delay(500);
 outtextxy(37,250,*(Title+10));// "ALL RIGHTS RESERVED."
 Delay(500);
 setcolor(LIGHTMAGENTA);
 settextstyle(1,0,2);
 outtextxy(340,350,*(Title+11));// "Press any key . . ."
 setcolor(WHITE);
 settextstyle(2,0,5);
 outtextxy(142,450,"Version");
 outtextxy(205,450,Version);
 outtextxy(377,450,"Update:");
 outtextxy(435,450,Update);
 people();
 book();
 Delay(2000);
 ClearKey();
 while (!kbhit())
 {ChangeColor();
  book();
  people();
  delaykey(30);
 }
 getch();
 restorecrtmode();
}
Beispiel #22
0
int main(void)
{
	mine();
	book();
	return 0;
}
std::string NetworkBookTree::BookItemWrapper::summary() const {
	return book().Summary;
}
std::vector<std::string> NetworkBookTree::BookItemWrapper::tags() const {
	return book().Tags;
}
Beispiel #25
0
bool EntryData::lateNotesAllowed() const {
  return !book()->isReadOnly();
}
int main(int argc, char * argv[])
{

	// Initialize MPI
	// Find out my identity in the default communicator
	MPI_Init(&argc, &argv);
	int rank;
	MPI_Comm_rank(MPI_COMM_WORLD, &rank);
	
	// Logic branch
	if (rank == 0) 
	{
		// ++++++++++++++++++++++++++++++
		// Master process
		// ++++++++++++++++++++++++++++++

		// Validate
		if (argc < 2)
		{
			std::cout << "Usage: " << argv[0] << " <text_file>" << std::endl;
			return 1;
		}

		const std::string filename(argv[1]);	
			
		// We will attempt to guess the book name
		std::string bookName;
		
		// Parse the file
		scottgs::book_type book( scottgs::parseFileToBook(filename, bookName) );
	
		// I have parsed the entire text file into book
		// Start some MPI Stuff
		std::cout << "I have prepped " << book.size() << " lines to be counted." << std::endl;
 
		// Invoke the master, map to workers
		scottgs::Timing timer;
		timer.start();
		std::map<std::string,int> bookCounterResults(scottgs::bookCounter(book));
		
		// Barrier to get all the desired output together
		// Warning, if threads do not call Barrier, then 
		// the MPI_Barrier busy waits
#if GJS_DEBUG_PRINT			
		std::cout << "main, barrier reached, waiting on workers" << std::endl;
#endif		  
		MPI_Barrier(MPI_COMM_WORLD);
		const double t = timer.getTotalElapsedTime();
		
		// Dump the results
		std::cout << "Global Word Count, in " << t << " s" << std::endl
			  << "===================================" << std::endl;  
		for (std::map<std::string,int>::const_iterator t=bookCounterResults.begin();t!=bookCounterResults.end();++t)
		{
			const std::string term(t->first);
			const int count = t->second;
			std::cout << "Term (" << term << ") occurs " << count << " times in "<< bookName << std::endl;
		}
		std::cout << "==================" << std::endl
			  << "Analysis Completed" << std::endl;
	}
	else 
	{	
		// ++++++++++++++++++++++++++++++
		// Workers
		// ++++++++++++++++++++++++++++++
		scottgs::verseCounter();
		MPI_Barrier(MPI_COMM_WORLD); // this is linked to the above barrier
	}

	// Shut down MPI
	MPI_Finalize();
	
	return 0;	
} // END of main
Beispiel #27
0
int main(int argc, const char * argv[]) {
    try {
        setlocale(LC_ALL, "");
        std::locale loc;
        wordMap words;

        // Define vars
        std::string filename = "Erlrouter.txt";
        char tempChar(0);
        std::string tempWord("");
        int lineCounter(1);

        // Open file
        std::ifstream book(filename.c_str());
        if(!book.is_open()) throw std::runtime_error("Die Datei \"" + filename + "\" konnte nicht geöffnet werden!");
        
/*      Get line || get word
        std::string line("");
        std::istream_iterator<std::string> iiter(book);
        std::istream_iterator<std::string> eos;
        for(int i = 0;i<=2;++i)
            std::cout << *iiter++ << std::endl; // Read word
            getline(book, line);
        std::cout << line << std::endl;
*/

        // Go through file and read in char-by-char
        do {
            tempChar = book.get();
            if(tempChar == '\n') lineCounter++;
            if(isspace(tempChar, loc)) {
                // Write word
                if(tempWord.length() > 0) {
                    if(isNomen(tempWord)) {
                        // We have a nomen!
                        addWordToMap(words, *new Nomen(tempWord, lineCounter));
                    } else if(isAkronym(tempWord)) {
                        // We have an acronym!
                        addWordToMap(words, *new Akronym(tempWord, lineCounter));
                    }
                }
                tempWord = "";
            } else if(isalpha(tempChar, loc)) {
                tempWord = tempWord + tempChar;
            }
        } while(book.good());
        book.close(); // Close file
        
        printMap(words);
        
        // Write to Index.txt
        std::string outputFilename("Index.txt");
        std::ofstream index(outputFilename.c_str());
        writeMap(words, index);
        
        return 0;
    } catch(std::exception &e) {
        std::cerr << e.what() << std::endl;
    } catch(...) {
        std::cerr << "Ein unbekannter Fehler trat auf." << std::endl;
    }
}
std::string NetworkBookTree::BookItemWrapper::title() const {
	return book().Title;
}
Beispiel #29
0
void Resolution::beginJob(void)
{
    theWindowsManager_ = theAnalysisManager_->getWindowsManager();
    book();
}
SearchEngine::SearchEngine()
{
	//read book records from book.txt and take in 10 pipe separated fields 
	ifstream book("book.txt");
      while(!getline(book, callNumber,'|').eof())
      {
        getline(book, title,'|');
        getline(book, subjects,'|');
        getline(book, author,'|');
        getline(book, description,'|');
        getline(book, publisher,'|');
        getline(book, city,'|');
        getline(book, year,'|');
        getline(book, series,'|');
        getline(book, notes, '\n');
            Book* objBook = new Book(callNumber, title, subjects, author, description, publisher, city, year, series, notes);
            CardCatalog.push_back(objBook);
      }
      book.close();
      
      //read periodic records from periodic.txt and take in 12 pipe separated fields
      ifstream periodic("periodic.txt");
      while(!getline(periodic, periodic_callNumber,'|').eof())
      {
        getline(periodic, periodic_title,'|');
        getline(periodic, periodic_subjects,'|');
        getline(periodic, periodic_author,'|');
        getline(periodic, periodic_description,'|');
        getline(periodic, periodic_publisher,'|');
        getline(periodic, periodic_publishing_history,'|');
        getline(periodic, periodic_series,'|');
        getline(periodic, periodic_notes,'|');
        getline(periodic, periodic_related_titles,'|');
        getline(periodic, periodic_other_forms_of_title,'|');
        getline(periodic, periodic_govt_doc_number, '\n');
            Periodic* objPeriodic = new Periodic(periodic_callNumber, periodic_title, periodic_subjects, periodic_author, 
            periodic_description, periodic_publisher, periodic_publishing_history, periodic_series, periodic_notes, 
            periodic_related_titles, periodic_other_forms_of_title, periodic_govt_doc_number);
            CardCatalog.push_back(objPeriodic);

      }
      periodic.close();
      
      //read video records from video.txt and take in 8 pipe separated fields
      ifstream video("video.txt");
      while(!getline(video, video_callNumber,'|').eof())
      {
        getline(video, video_title,'|');
        getline(video, video_subjects,'|');
        getline(video, video_description,'|');
        getline(video, video_distributor,'|');
        getline(video, video_notes,'|');
        getline(video, video_series,'|');
        getline(video, video_label, '\n');
            Video* objVideo = new Video(video_callNumber, video_title, video_subjects, video_description, 
            video_distributor, video_notes, video_series, video_label);
            CardCatalog.push_back(objVideo);
	
      }
      video.close();
      
      //read film records from periodic.txt and take in 6 pipe separated fields
      ifstream film("film.txt");
      while(!getline(film, film_callNumber,'|').eof())
      {
        getline(film, film_title,'|');
        getline(film, film_subjects,'|');
        getline(film, film_director,'|');
        getline(film, film_notes,'|');
        getline(film, film_year, '\n');
            Film* objFilm = new Film(film_callNumber, film_title, film_subjects, film_director, film_notes, film_year);
            CardCatalog.push_back(objFilm);

      }
      film.close();
}