Ejemplo n.º 1
0
int main(int argc, char *argv[])
{   
    // Declare input and ouput stream objects and open input stream
    std::ifstream inStream(argv[1]);
    if (inStream.fail())
    {
        std::cout << "Input file opening failed.\n";
        exit(1);
    }
    std::ofstream outStream("MSS_Results.txt", std::ios::app);
    
    while (!inStream.eof())
    {
        // Declare a string for the line, get next line, declare vector for ints
        std::string line;
        getline(inStream, line);
        std::vector<int> intVect;
        
        // Fill the vector with the ints in the line
        fillVector(line, intVect);

        // Declare subarray vectors and sum variable
        std::vector<int> subArray1;
        std::vector<int> subArray2;
        int sum;
        
        // Call function to calculate the maximum sum of a subarray
        enumMSS(intVect, subArray1, sum);
        
        // Write vector contents and sum to the output file
        outputToFile(outStream, intVect, subArray1, sum);
        
        // Call the next function to calculate the maximum sum of a subarray
        betterEnumMSS(intVect, subArray2, sum);
        
        // Write vector contents and sum to the output file
        outputToFile(outStream, intVect, subArray2, sum);
        
        
    }
    
    // Close input and output streams
    inStream.close();
    outStream.close();
    
    return 0;
}
// Add a new item to the inventory
bool Inventory::addNewStock(const Stock &newStock)
{
	if(inInventory(newStock))
	{
		std::cout << "The item " << newStock.name << " already exists." << std::endl;
		return false;
	}
	items.push_back(newStock);

	outputToFile();

	return true;
}
Ejemplo n.º 3
0
void PrintDialog::storeValues()
{
	getOptions(); // options were not set get last options with this hack

	m_doc->Print_Options.printer = PrintDest->currentText();
	m_doc->Print_Options.filename = QDir::fromNativeSeparators(LineEdit1->text());
	m_doc->Print_Options.toFile = outputToFile();
	m_doc->Print_Options.copies = numCopies();
	m_doc->Print_Options.outputSeparations = outputSeparations();
	m_doc->Print_Options.separationName = separationName();
	m_doc->Print_Options.allSeparations = allSeparations();
	if (m_doc->Print_Options.outputSeparations)
		m_doc->Print_Options.useSpotColors = true;
	else
		m_doc->Print_Options.useSpotColors = doSpot();
	m_doc->Print_Options.useColor = color();
	m_doc->Print_Options.mirrorH  = mirrorHorizontal();
	m_doc->Print_Options.mirrorV  = mirrorVertical();
	m_doc->Print_Options.useICC   = ICCinUse();
	m_doc->Print_Options.doClip   = doClip();
	m_doc->Print_Options.doGCR    = doGCR();
	m_doc->Print_Options.prnEngine= printEngine();
	m_doc->Print_Options.setDevParam = doDev();
	m_doc->Print_Options.useDocBleeds  = docBleeds->isChecked();
	m_doc->Print_Options.bleeds.Top    = BleedTop->value() / m_doc->unitRatio();
	m_doc->Print_Options.bleeds.Left   = BleedLeft->value() / m_doc->unitRatio();
	m_doc->Print_Options.bleeds.Right  = BleedRight->value() / m_doc->unitRatio();
	m_doc->Print_Options.bleeds.Bottom = BleedBottom->value() / m_doc->unitRatio();
	m_doc->Print_Options.markLength = markLength->value() / m_doc->unitRatio();
	m_doc->Print_Options.markOffset = markOffset->value() / m_doc->unitRatio();
	m_doc->Print_Options.cropMarks  = cropMarks->isChecked();
	m_doc->Print_Options.bleedMarks = bleedMarks->isChecked();
	m_doc->Print_Options.registrationMarks = registrationMarks->isChecked();
	m_doc->Print_Options.colorMarks = colorMarks->isChecked();
	m_doc->Print_Options.includePDFMarks = usePDFMarks->isChecked();
	if (OtherCom->isChecked())
	{
		m_doc->Print_Options.printerCommand = Command->text();
		m_doc->Print_Options.useAltPrintCommand = true;
	}
	else
		m_doc->Print_Options.useAltPrintCommand = false;
#ifdef HAVE_CUPS
	m_doc->Print_Options.printerOptions = PrinterOpts;
#else
	m_doc->Print_Options.printerOptions = QString();
#endif
	m_doc->Print_Options.devMode = DevMode;
}
// Add stock to an item that is already in the Inventory.
bool Inventory::addStock(const Stock &additionalStock)
{
	// Is item already in the Inventory?
	if(!inInventory(additionalStock))
	{
		std::cout << "No stock in the Inventory matches \"" << additionalStock.name << "\"." << std::endl;
		return false;
	}
	// Find an iterator to the item that needs to be updated.
	std::vector<Stock>::iterator currentStock = find(items.begin(), items.end(), additionalStock);
	// Add the new stock to the current stock.
	currentStock->itm.add(std::pair<double,double>(additionalStock.itm.yards(), additionalStock.itm.costPerYard()));
	// Add the stock to the inventory.txt file.
	outputToFile();
	return true;
}
Ejemplo n.º 5
0
		// Destructor
		~NumericFile()
		{
			// Perform an action based on the value of closingAction
			switch (closingAction)
			{
			case FileCloseAction::OUTPUT: // Output the contents to 'fileName'
				{
					outputToFile();
					break;
				}
			case FileCloseAction::APPEND: // Append the contents to 'fileName'
				{
					appendToFile();
					break;
				}
			}
		}
// Remove stock from the inventory, remove the item from the inventory if no stock left
bool Inventory::subtractStock(const std::string &name, double amt)
{
	if(!inInventory(name))
	{
		std::cout << "No stock in the inventory matches \"" << name << "\"" << std::endl;
		return false;
	}
	std::vector<Stock>::iterator currentStock = find_if(items.begin(), items.end(), stockByName(name));

	currentStock->itm.subtract(amt);
	if(currentStock->itm.yards() == 0)
	{
		removeStock(name);
	}
	outputToFile();
	return true;
}
Ejemplo n.º 7
0
bool
QPrinter::prepare(PMPrintSettings *s)
{
  if (!psession && PMCreateSession(&psession) != noErr)
    return FALSE;
  if (*s == kPMNoPrintSettings) {
    if (PMCreatePrintSettings(s) != noErr)
      return FALSE;
    if (PMSessionDefaultPrintSettings(psession, *s) != noErr)
      return FALSE;
  } else {
    if (PMSessionValidatePrintSettings(psession, *s, kPMDontWantBoolean) != noErr)
      return FALSE;
  }
  if (minPage() != 0 || maxPage() != 0)
    PMSetPageRange(*s, minPage(), maxPage());
  if (d->printRange != AllPages) {
    PMSetFirstPage(*s, fromPage(), TRUE);
    PMSetLastPage(*s, toPage(), TRUE);
  }
  PMSetColorMode(*s, colorMode() == GrayScale ? kPMGray : kPMColor);
  PMSetCopies(*s, numCopies(), TRUE);
  if (outputToFile()) {
    CFStringRef cfstring = qstring2cfstring(outputFileName());
    CFURLRef outFile = CFURLCreateWithFileSystemPath(kCFAllocatorSystemDefault, cfstring,
                                                     kCFURLPOSIXPathStyle, false);
    PMSessionSetDestination(psession, *s, kPMDestinationFile, kPMDocumentFormatPDF, outFile);
    CFRelease(outFile);
    CFRelease(cfstring);
  }

  QString printName = printerName();
  if (!printName.isEmpty()) {
    CFStringRef pname = qstring2cfstring(printName);
    PMSessionSetCurrentPrinter(psession, pname);
    CFRelease(pname);
  }
  return TRUE;
}
Ejemplo n.º 8
0
/*!
    \internal
*/
bool QPrinter::printSetup()
{
    if(!psession && PMCreateSession(&psession) != noErr)
        return FALSE;
    QMacBlockingFunction block;
    //setup
    if(!prepare(&psettings))
        return FALSE;
    {   //simulate modality
        QWidget modal_widg(0, __FILE__ "__modal_dlg",
                           Qt::WType_TopLevel | Qt::WStyle_Customize | Qt::WStyle_DialogBorder);
        qt_enter_modal(&modal_widg);
        Boolean ret;
        if(!outputToFile() && PMSessionPrintDialog(psession, psettings, pformat, &ret) != noErr)
            ret = FALSE;
        qt_leave_modal(&modal_widg);
        if(!ret)
            return FALSE;
    }

    interpret(&psettings);
    return TRUE;
}
Ejemplo n.º 9
0
void PrintDialog::SelEngine(const QString& eng)
{
	prefs->set("CurrentPrnEngine", printEngineMap[printEngines->currentText()]);
	bool psSupported = outputToFile();
	psSupported |= (eng == CommonStrings::trPostScript1);
	psSupported |= (eng == CommonStrings::trPostScript2);
	psSupported |= (eng == CommonStrings::trPostScript3);
	if (psSupported)
	{
		PrintSep->setEnabled( true );
		UseICC->setEnabled( m_doc->HasCMS );
		usePDFMarks->setEnabled(true);
	}
	else
	{
		setCurrentComboItem(PrintSep, tr("Print Normal"));
		PrintSep->setEnabled( false );
		setCurrentComboItem(SepArt, tr("All"));
		SepArt->setEnabled( false );
		UseICC->setEnabled( false );
		UseICC->setChecked( false );
		usePDFMarks->setEnabled(false);
	}
}
Ejemplo n.º 10
0
void PrintDialog::setStoredValues(const QString& fileName, bool gcr)
{
	if (m_doc->Print_Options.firstUse)
		getDefaultPrintOptions(m_doc->Print_Options, gcr);
	
	int selectedDest = PrintDest->findText(m_doc->Print_Options.printer);
	if ((selectedDest > -1) && (selectedDest < PrintDest->count()))
	{
		PrintDest->setCurrentIndex(selectedDest);
		prefs->set("CurrentPrn", PrintDest->currentText());
		if (PrintDest->currentText() == tr("File"))
			LineEdit1->setText(fileName);
		SelPrinter(PrintDest->currentText());
	}
	OtherCom->setChecked(m_doc->Print_Options.useAltPrintCommand);
	if (OtherCom->isChecked())
	{
		SelComm();
		Command->setText(m_doc->Print_Options.printerCommand);
	}
	RadioButton1->setChecked(prefs->getBool("PrintAll", true));
	CurrentPage->setChecked(prefs->getBool("CurrentPage", false));
	bool printRangeChecked=prefs->getBool("PrintRange", false);
	RadioButton2->setChecked(printRangeChecked);
	pageNr->setEnabled(printRangeChecked);
	pageNr->setText(prefs->get("PageNr", "1-1"));
	Copies->setValue(1);
	PrintSep->setCurrentIndex(m_doc->Print_Options.outputSeparations);
	colorType->setCurrentIndex(m_doc->Print_Options.useColor ? 0 : 1);
	ColorList usedSpots;
	m_doc->getUsedColors(usedSpots, true);
	QStringList spots = usedSpots.keys();
	spots.prepend( tr("Black"));
	spots.prepend( tr("Yellow"));
	spots.prepend( tr("Magenta"));
	spots.prepend( tr("Cyan"));
	spots.prepend( tr("All"));
	int selectedSep = spots.indexOf(m_doc->Print_Options.separationName);
	if ((selectedSep > -1) && (selectedSep < SepArt->count()))
		SepArt->setCurrentIndex(selectedSep);
	if (PrintSep->currentIndex() == 1)
		SepArt->setEnabled(true);
	setPrintEngine(m_doc->Print_Options.prnEngine);
	MirrorHor->setChecked(m_doc->Print_Options.mirrorH);
	MirrorVert->setChecked(m_doc->Print_Options.mirrorV);
	devPar->setChecked(m_doc->Print_Options.setDevParam);
	GcR->setChecked(m_doc->Print_Options.doGCR);
	ClipMarg->setChecked(m_doc->Print_Options.doClip);
	spotColors->setChecked(!m_doc->Print_Options.useSpotColors);
	bool iccInUse  = m_doc->HasCMS ? m_doc->Print_Options.useICC : false;
	bool psPrinter = PrinterUtil::isPostscriptPrinter(PrintDest->currentText()) || outputToFile();
	UseICC->setChecked( psPrinter ? iccInUse : false );
	UseICC->setEnabled( psPrinter );
	docBleeds->setChecked(m_doc->Print_Options.useDocBleeds);
	if (docBleeds->isChecked())
	{
		BleedTop->setValue(m_doc->bleeds()->Top*unitRatio);
		BleedBottom->setValue(m_doc->bleeds()->Bottom*unitRatio);
		BleedRight->setValue(m_doc->bleeds()->Right*unitRatio);
		BleedLeft->setValue(m_doc->bleeds()->Left*unitRatio);
	}
	else
	{
		BleedTop->setValue(m_doc->Print_Options.bleeds.Top*unitRatio);
		BleedBottom->setValue(m_doc->Print_Options.bleeds.Bottom*unitRatio);
		BleedRight->setValue(m_doc->Print_Options.bleeds.Right*unitRatio);
		BleedLeft->setValue(m_doc->Print_Options.bleeds.Left*unitRatio);
	}
	BleedTop->setEnabled(!docBleeds->isChecked());
	BleedBottom->setEnabled(!docBleeds->isChecked());
	BleedRight->setEnabled(!docBleeds->isChecked());
	BleedLeft->setEnabled(!docBleeds->isChecked());
	markLength->setValue(m_doc->Print_Options.markLength*unitRatio);
	markOffset->setValue(m_doc->Print_Options.markOffset*unitRatio);
	cropMarks->setChecked(m_doc->Print_Options.cropMarks);
	bleedMarks->setChecked(m_doc->Print_Options.bleedMarks);
	registrationMarks->setChecked(m_doc->Print_Options.registrationMarks);
	colorMarks->setChecked(m_doc->Print_Options.colorMarks);
	usePDFMarks->setChecked(m_doc->Print_Options.includePDFMarks);
}
Ejemplo n.º 11
0
PrintDialog::PrintDialog( QWidget* parent, ScribusDoc* doc, const PrintOptions& printOptions, bool gcr, QStringList spots)
		: QDialog( parent )
{
	setupUi(this);
	setModal(true);
	cdia = 0;
	m_doc = doc;
	unit = doc->unitIndex();
	unitRatio = unitGetRatioFromIndex(doc->unitIndex());
	prefs = PrefsManager::instance()->prefsFile->getContext("print_options");
	DevMode = printOptions.devMode;
	PrinterOpts = "";
	setWindowIcon(QIcon(loadIcon("AppIcon.png")));
 	pageNrButton->setIcon(QIcon(loadIcon("ellipsis.png")));
	printEngines->addItem( CommonStrings::trPostScript1 );
	printEngines->addItem( CommonStrings::trPostScript2 );
	printEngines->addItem( CommonStrings::trPostScript3 );
	markLength->setNewUnit(unit);
	markLength->setMinimum(1*unitRatio);
	markLength->setMaximum(3000*unitRatio);
	markOffset->setNewUnit(unit);
	markOffset->setMinimum(0);
	markOffset->setMaximum(3000*unitRatio);
	BleedBottom->setNewUnit(unit);
	BleedBottom->setMinimum(0);
	BleedBottom->setMaximum(3000*unitRatio);
	BleedLeft->setNewUnit(unit);
	BleedLeft->setMinimum(0);
	BleedLeft->setMaximum(3000*unitRatio);
	BleedRight->setNewUnit(unit);
	BleedRight->setMinimum(0);
	BleedRight->setMaximum(3000*unitRatio);
	BleedTop->setNewUnit(unit);
	BleedTop->setMinimum(0);
	BleedTop->setMaximum(3000*unitRatio);
	previewButton->setEnabled(!previewDinUse);
	// Fill printer list
	QString Pcap;
	QString printerName;
	QStringList printerNames = PrinterUtil::getPrinterNames();
	int numPrinters = printerNames.count();
	for( int i = 0; i < numPrinters; i++)
	{
		printerName = printerNames[i];
		PrintDest->addItem(printerName);
		if( printerName == printOptions.printer )
		{
			PrintDest->setCurrentIndex(PrintDest->count()-1);
			prefs->set("CurrentPrn", PrintDest->currentText());
		}
	}

	PrintDest->addItem( tr("File"));

	// Fill Separation list
	QString sep[] =
	    {
	        tr("All"), tr("Cyan"), tr("Magenta"), tr("Yellow"),
	        tr("Black")
	    };
	size_t sepArray = sizeof(sep) / sizeof(*sep);
	for (uint prop = 0; prop < sepArray; ++prop)
		SepArt->addItem(sep[prop]);
	SepArt->addItems(spots);

	if (m_doc->pagePositioning() != 0)
	{
		BleedTxt3->setText( tr( "Inside:" ) );
		BleedTxt4->setText( tr( "Outside:" ) );
	}

	QString prnDevice = printOptions.printer;
	if (prnDevice.isEmpty())
		prnDevice = PrintDest->currentText();
	if ((prnDevice == tr("File")) || (PrintDest->count() == 1))
	{
		PrintDest->setCurrentIndex(PrintDest->count()-1);
		prefs->set("CurrentPrn", PrintDest->currentText());
		DateiT->setEnabled(true);
		LineEdit1->setEnabled(true);
		if (!printOptions.filename.isEmpty())
			LineEdit1->setText(QDir::toNativeSeparators(printOptions.filename));
		ToolButton1->setEnabled(true);
	}

	setMaximumSize(sizeHint());
	PrintDest->setFocus();
	// signals and slots connections
	connect( OKButton, SIGNAL( clicked() ), this, SLOT( okButtonClicked() ) );
	connect( OKButton_2, SIGNAL( clicked() ), this, SLOT( reject() ) );
	connect( PrintDest, SIGNAL(activated(const QString&)), this, SLOT(SelPrinter(const QString&)));
	connect( printEngines, SIGNAL(activated(const QString&)), this, SLOT(SelEngine(const QString&)));
	connect( RadioButton1, SIGNAL(toggled(bool)), this, SLOT(SelRange(bool)));
	connect( CurrentPage, SIGNAL(toggled(bool)), this, SLOT(SelRange(bool)));
	connect( pageNrButton, SIGNAL(clicked()), this, SLOT(createPageNumberRange()));
	connect( PrintSep, SIGNAL(activated(int)), this, SLOT(SelMode(int)));
	connect( ToolButton1, SIGNAL(clicked()), this, SLOT(SelFile()));
	connect( OtherCom, SIGNAL(clicked()), this, SLOT(SelComm()));
	connect( previewButton, SIGNAL(clicked()), this, SLOT(previewButtonClicked()));
	connect( docBleeds, SIGNAL(clicked()), this, SLOT(doDocBleeds()));
	connect( OptButton, SIGNAL( clicked() ), this, SLOT( SetOptions() ) );

	setStoredValues(printOptions.filename, gcr);
#if defined(_WIN32)
	if (!outputToFile())
		PrinterUtil::initDeviceSettings( PrintDest->currentText(), DevMode );
#endif

	printEngineMap = PrinterUtil::getPrintEngineSupport(PrintDest->currentText(), outputToFile());
	refreshPrintEngineBox();

	bool ps1Supported = printEngineMap.contains(CommonStrings::trPostScript1);
	bool ps2Supported = printEngineMap.contains(CommonStrings::trPostScript2);
	bool ps3Supported = printEngineMap.contains(CommonStrings::trPostScript3);
	bool psSupported  = (ps1Supported || ps2Supported || ps3Supported);
	printEngines->setEnabled(psSupported || outputToFile());
	UseICC->setEnabled(m_doc->HasCMS && psSupported);
}
Ejemplo n.º 12
0
//
// Main Function Implementation ///////////////////////////////////
//
   int main( int argc, char* argv[] )
      {
       struct pcb_table myPCB = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };   // pcb table
       struct pcb_table *pcbPtr = NULL;   //pcb pointer
       bool isThread = false;   // check if the meta a thread
       bool toFile = false;   // check if the log needs to output to file
       int currentProcess = 0;   // current running process
       pthread_t myThread;   // thread

       currentLog = logList;

       // read config file
       readConfig( argv[1], &myPCB );

       // check if need to print to monitor or file
       if(myPCB.logMode == 1 || myPCB.logMode == 2 )
          toMonitor = true;
       if(myPCB.logMode == 1 || myPCB.logMode == 3 )
          toFile = true;

       // read meta data file, update pointer
       readMeta( myPCB.dataFile, &pcbList, myPCB, &processCounter);
       pcbPtr = pcbList;

       // start timer
       clock_gettime( CLOCK_REALTIME, &startTime ); 

       // print start log
       clock_gettime( CLOCK_REALTIME, &endTime );
       totalTime = timeLap( startTime, endTime );
       recordLog( &logList, &currentLog, totalTime, "Simulator program starting" );
       if( toMonitor )
          printLog( currentLog );

       // print log
       clock_gettime( CLOCK_REALTIME, &endTime );
       totalTime = timeLap( startTime, endTime );
       recordLog( &logList, &currentLog, totalTime, "OS: preparing all processes" );
       if( toMonitor )
          printLog( currentLog );

       // loop around processes
       while( processCounter > 0 )
          {
          // if the process hasn't finished
          if( pcbPtr -> current != NULL )
             {
              // print log
              clock_gettime( CLOCK_REALTIME, &endTime );
              totalTime = timeLap( startTime, endTime );
              recordLog( &logList, &currentLog, totalTime, "OS: seleting next process" );
              if( toMonitor )
                 printLog( currentLog );

              // print log
              clock_gettime( CLOCK_REALTIME, &endTime );
              totalTime = timeLap( startTime, endTime );
              metaStartLog( pcbPtr -> current, pcbPtr, logComment );
              recordLog( &logList, &currentLog, totalTime, logComment );
              if( toMonitor )
                 printLog( currentLog );

              // if the current meta is process
              if( pcbPtr -> current -> component == 'P' )
                 {
                  runProcess( pcbPtr -> current, &pcbPtr );
                  if( pcbPtr -> currentLeft == 0 )
                     {
                      clock_gettime( CLOCK_REALTIME, &endTime );
                      totalTime = timeLap( startTime, endTime );
                      interruptLog(pcbPtr -> current, logComment);
                      recordLog( &logList, &currentLog, totalTime, logComment );
                      if( toMonitor )
                         printLog( currentLog );

                      pcbPtr -> current = pcbPtr -> current -> next;
                      if( pcbPtr -> current != NULL && pcbPtr -> current -> component == 'P' )
                         pcbPtr -> currentLeft = pcbPtr -> current -> cyc_time;
                      if(pcbPtr -> current == NULL)
                         processCounter --;
                     }
                 }

              // if the current meta needs spawn thread
              else
                 {
                  // spawn thread
                  pthread_create( &myThread, NULL, thread_perform, (void*) pcbPtr );

                  // print log
                  clock_gettime( CLOCK_REALTIME, &endTime );
                  totalTime = timeLap( startTime, endTime );
                  blockLog(pcbPtr->current, logComment);
                  recordLog( &logList, &currentLog, totalTime, logComment );
                  if( toMonitor )
                     printLog( currentLog );

                  // block process
                  blockProcess(&pcbList, pcbPtr, &blockQueue);
                 }
             }

          // select next process in queue
          if(pcbPtr -> next == NULL)
             pcbPtr = pcbList;
          else
             pcbPtr = pcbPtr -> next;
          }

       // print ending log
       clock_gettime( CLOCK_REALTIME, &endTime );
       totalTime = timeLap( startTime, endTime );
       recordLog( &logList, &currentLog, totalTime, "Simulator program ending" );
       if( toMonitor )
          printLog( currentLog );

       // output to file
       if( toFile )
          outputToFile( logList, myPCB );

       return 0;
      }   // end of main