Ejemplo n.º 1
0
void printCash(const string &line) {
    size_t position = 0;
    unsigned int price;
    unsigned int amount;

    Printer cashier;

    price = getPrice(line, position);
    amount = getPrice(line, position);

    if (price == amount) {
        cout << "ZERO" << endl;
        return;
    }

    if (price > amount) {
        cout << "ERROR" << endl;
        return;
    }

    amount -= price;

    for (auto i = cash.rbegin(); i != cash.rend() && amount != 0; ++i) {
        while (amount >= i->second) {
            cashier.print(i->first);
            amount -= i->second;
        }
    }

    cout << endl;
}
Ejemplo n.º 2
0
void printReversed(const string &line) {
    size_t position = 0;
    Printer p;
    unsigned int number;

    static vector<int> values;

    values.clear();

    while (line[position] != ';') {
        getUnsignedInteger(line, position, number);
        values.push_back(number);
    }

    getUnsignedInteger(line, position, number);

    if (number > values.size() ) {
        number = values.size();
    }

    int start = number - 1;
    while (start < values.size() ) {
        for (int i = start; i > start - (int)number; --i) {
            p.print(values[i]);
        }
        start += number;
    }

    for (int i = start - number + 1; i < values.size(); i++) {
        p.print(values[i]);
    }

    cout << endl;
}
Ejemplo n.º 3
0
void ParityAggrLit::accept(::Printer *v)
{ 
	Printer *printer = v->output()->printer<Printer>();
	printer->begin(head(), sign_, even_==fixed_, set_);
	foreach(CondLit &lit, conds_) lit.accept(printer);
	printer->end();
}
Ejemplo n.º 4
0
int main(int argc, char* argv[]){

	// c++11 initializer_list constructor
	Printer obj = {10};
	std::cout << obj() << std::endl;

	obj.print("obj.print");

	// mem_fn 转换
	auto func = std::mem_fn(&Printer::print);

	obj.data = 100;
	func(obj, "mem_fun");

	// bind 绑定
	auto func2 = std::bind(&Printer::print, &obj, _1);
	func2("bind");

	// bind操作符函数绑定
	auto func3 = std::bind(&Printer::operator(), &obj);
	std::cout << "bind operator() " << func3() << std::endl;

	// mem_fn 操作符转换为普通函数
	auto func4 = std::mem_fn(&Printer::operator());
	std::cout << "mem_fun operator() " << func4(obj) << std::endl;

	return 0;
}
Ejemplo n.º 5
0
int main( int argc, char** argv  )
{
	int deviceNum = 0;
	
	if( argc != 2 )
	{
		cout << "InkPlus <device number>" << endl;
		return -1;
	}

	const char* deviceFile = argv[1];
	
	try
	{
		cout << "Retrieving information about USB lp..." << deviceFile << endl;
		Printer firstPrinter = getusbprinterlevels(deviceFile);
		cout << "Found " << firstPrinter.Name() << endl;
	}
	catch( int e )
	{
		cout << "Error " << e << endl;
		return e;
	}
	
	return 0;
}
Ejemplo n.º 6
0
 void model::setupPrintData( Printer & p ) {
     p.addVariableToPrint(this->stateAt(0), "theta");
     p.addVariableToPrint(this->stateAt(1), "theta_dot");
     p.addVariableToPrint(m, "Mass");
     p.addVariableToPrint(c, "Dampening");
     p.addVariableToPrint(l, "Length");
 }
Ejemplo n.º 7
0
void JunctionAggrLit::accept(::Printer *v)
{
	Printer *printer = v->output()->printer<Printer>();
	printer->begin(head());
	foreach(CondLit &lit, conds_) lit.accept(printer);
	printer->end();
}
Ejemplo n.º 8
0
/**
 * Write the quoted element out to the stream.
 *
 * @param out -- The output stream to write the evaluate to.
 */
void Quoted_::Write_(Printer& out) const
{
    out.Indent();
    out << "'";
    out.IgnoreNextIndent();
    this->element.Write(out);
}
Ejemplo n.º 9
0
int main(int argc, const char **argv) {
    assert(Printer_Base::uni_special(0x80));
    assert(!Printer_Base::uni_special(0x79));
    assert(Printer_Base::strlen("\e[38;5;190mA\e[0m")==1);
    int width = 25;
    char filler = '_';
    double val = 1.234567901234;
    std::cout << Printer_Base::align("Left-aligned", width,
                                     Printer_Base::LEFT, filler) << "\r\n"
              << Printer_Base::align("Centered", width,
                                     Printer_Base::CENTER, filler) << "\r\n"
              << Printer_Base::align(val, width,
                                     Printer_Base::CENTER, filler) << "\r\n"
              << Printer_Base::align(val, width,
                                     Printer_Base::CENTER, filler, 8) << "\r\n"
              << Printer_Base::align("Right-aligned", width,
                                     Printer_Base::RIGHT, filler) << std::endl;
    Printer<4> printer;
    std::string rows[] {"Title","Row title","Row title",""},
    cols[] {"Col 1", "Col 2", "Col 3", "Col 4"};
    int data[] {0, 1, 2, 3, 4, 5, 6, 7};
    printer.push(&rows[0], &rows[0]+4).level();
    printer.push<int, 2, 4>(data, &cols[0], &cols[0]+4).level();
    Printer<6> widePrinter;
    widePrinter.insert(2, printer).level()
    .push<int, 4, 2>(data, &cols[0], &cols[0]+4);
    std::cout << widePrinter << std::endl;
}
Ejemplo n.º 10
0
void RR_CALL Printer::rr_log_fn (rr_dev dev, int type,
			       const char *buffer,
			       size_t len, void *closure)
{
  Printer *printer = static_cast<Printer*>(closure);
  printer->handle_rr_log(dev, type, buffer, len);
}
Ejemplo n.º 11
0
  void
fprint(FILE *out, Opnd opnd)
{
  Printer *printer = target_printer();
  printer->set_file_ptr(out);
  printer->print_opnd(opnd);
}
Ejemplo n.º 12
0
int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    
    if (argc != 2) {
        std::cout << "Usage: cmdimg image" << std::endl;
        return 0;
    }

    Printer *p = new Printer();
    std::cout << "Trying to open port" << std::endl;

    bool res = p->open("/dev/ttyAMA0");
    std::cout << "Status: " << res << std::endl;

    if (!res) {
        std::cerr << "Error opening port, aborting" << std::endl;
        return (0);
    }

    p->init();

    p->printImage(QImage(argv[1]));

    std::cout << "Closing Device" << std::endl;
    p->close();

    return 1;

    return a.exec();
}
Ejemplo n.º 13
0
void benchmark::BenchRunner::RunAll(Printer& printer, uint64_t num_evals, double scaling, const std::string& filter, bool is_list_only)
{
    if (!std::ratio_less_equal<benchmark::clock::period, std::micro>::value) {
        std::cerr << "WARNING: Clock precision is worse than microsecond - benchmarks may be less accurate!\n";
    }
#ifdef DEBUG
    std::cerr << "WARNING: This is a debug build - may result in slower benchmarks.\n";
#endif

    std::regex reFilter(filter);
    std::smatch baseMatch;

    printer.header();

    for (const auto& p : benchmarks()) {
        if (!std::regex_match(p.first, baseMatch, reFilter)) {
            continue;
        }

        uint64_t num_iters = static_cast<uint64_t>(p.second.num_iters_for_one_second * scaling);
        if (0 == num_iters) {
            num_iters = 1;
        }
        State state(p.first, num_evals, num_iters, printer);
        if (!is_list_only) {
            p.second.func(state);
        }
        printer.result(state);
    }

    printer.footer();
}
Ejemplo n.º 14
0
void stackPrintAlternate(const string &line) {
    int end;
    int start;
    char *data = const_cast<char*>(line.c_str());
    Printer p;

    end = line.length() - 1;

    back(data, start, end);
    p.print(&( data[start] ));

    while (true) {
        end = start - 1;
        back(data, start, end);
        if (start <= 0) {
            break;
        }

        end = start - 1;
        back(data, start, end);
        data[end + 1] = 0;

        if (end < 0) {
            break;
        }
        p.print(&( data[start] ));
    }
	cout << endl;
}
Ejemplo n.º 15
0
void MinMaxAggrLit::_accept(::Printer *v)
{
	Printer<MinMaxAggrLit, T> *printer = v->output()->printer<Printer<MinMaxAggrLit, T> >();
	printer->begin(AggrCond::Printer::State(aggrUid(), domain_.lastId()), head(), sign_, complete(), set_);
	if(lower()) { printer->lower(valLower_, lowerEq_); }
	if(upper()) { printer->upper(valUpper_, upperEq_); }
	printer->end();
}
Ejemplo n.º 16
0
    void print() const {
        Printer p;

        for (auto it = m_data.rbegin(); it != m_data.rend(); ++it) {
            p.print(*it);
        }
        cout << endl;
    }
Ejemplo n.º 17
0
void IncLit::accept(::Printer *v)
{
	if(type_ == VOLATILE)
	{
		Printer *printer = v->output()->printer<Printer>();
		printer->print(vol_window_);
	}
}
Ejemplo n.º 18
0
void RR_CALL Printer::rr_error_fn (rr_dev dev, int error_code,
				 const char *msg, size_t len,
				 void *closure)
{
  Printer *printer = static_cast<Printer*>(closure);

  printer->handle_rr_error (dev, error_code, msg, len);
}
Ejemplo n.º 19
0
bool Display::grounded(Grounder *g)
{
    head_->grounded(g);
    Printer *printer = g->output()->printer<Printer>();
    printer->show(show_);
    printer->print(head_.get());
    return true;
}
Ejemplo n.º 20
0
void UnPacker::UnPack(const std::string &aFileIn, const std::string &aDir)
{
	FILE *fOut, *fIn;
	if (fopen_s(&fIn, aFileIn.c_str(), "rb") || !fIn)
	{
		throw Error("Failed to open file " + aFileIn);
	}

	unsigned char cAlg;
	if (!fscanf_s(fIn, "%c", &cAlg))
	{
		throw Error("Error reading file");
	}

	ProxyUnPacker *unP;
	switch (cAlg)
	{
		case 0:
			unP = new UnPackerRLE(bufSize);
			break;
		case 1:
			unP = new UnPackerHuffman(bufSize);
			break;
		default:
			throw Error("Unknown type of compression");
	}
	unsigned int fileCount = unP->ReadInt(fIn);
	for (unsigned int i = 0; i < fileCount; ++i)
	{
		unsigned char fNameLen;
		unP->_SetNext(fIn, &fNameLen);
		std::string fName;
		unsigned char ch;
		for (unsigned int j = 0; j < fNameLen; ++j)
		{
			unP->_SetNext(fIn, &ch);
			fName.push_back(ch);
		}
		fName = aDir + fName;
		//**************************
		//fName = "_" + fName;
		//**************************
		if (fopen_s(&fOut, fName.c_str(), "wb") || !fOut)
		{
			throw Error("Failed to create file " + fName);
		}

		Printer pr;
		pr.PrintText("Decompression " + fName + ": 0%");
		unP->_UnPack(fIn, fOut, pr);
		pr.PrintPercent(100);
		pr.PrintText("\n");

		fclose(fOut);
	}
	delete unP;
	fclose(fIn);
}
Ejemplo n.º 21
0
bool Display::grounded(Grounder *g)
{
	Printer *printer = g->output()->printer<Printer>();
	printer->begin(static_cast<DisplayHeadLit&>(*head_).val(g), type_);
	foreach(Lit &lit, body_)
	{
		lit.grounded(g);
		if(!lit.fact() || lit.forcePrint()) { lit.accept(printer); }
	}
Ejemplo n.º 22
0
void SumAggrLit::accept(::Printer *v)
{ 
	Printer *printer = v->output()->printer<Printer>();
	printer->begin(head(), sign_, set());
	if(lower_.get() || assign_) printer->lower(lowerBound_);
	if(upper_.get() || assign_) printer->upper(upperBound_);
	foreach(CondLit &lit, conds_) lit.accept(printer);
	printer->end();
}
Ejemplo n.º 23
0
void MainWindow::printAnswers()
{
    ITextToSpeech::instance().speak("Opening a print dialog for printing your answers. Use your screen reader to work with the dialog.");

    Printer printer;

    QString result = printer.openPrintDialog(m_Crossword, this);

    ITextToSpeech::instance().speak(result);
}
Ejemplo n.º 24
0
//num2
int main(int argc, const char * argv[]) {
    Printer pnt;
    
    pnt.setString("Hello world!");
    pnt.showString();
    
    pnt.setString("I love C++");
    pnt.showString();
    
    return 0;
}
Ejemplo n.º 25
0
void print_backtrace(std::size_t frames = 32)
{
    using namespace backward;
    StackTrace stackTrace;
    Printer printer;

    stackTrace.load_here(frames);
    printer.object = true;
    printer.color = true;
    printer.print(stackTrace, stdout);
}
Ejemplo n.º 26
0
/**
 * Write the case out to the stream.
 *
 * @param out -- The output stream to write the if to.
 */
void Case_::Write_(Printer& out) const
{
    out.Indent();
    out.IgnoreNextIndent();

    out << "(case " << this->condition.ToString() << "\n";
    {
        Printer::TabMarker tab = out.Tab();
    }
    out.Indent();
    out << ')';
}
Ejemplo n.º 27
0
int main() {
	std::vector<int> container;

	for (int i = 0; i < 5; ++i) {
		container.push_back(i);
	}

	Printer<Out, Out, Out> printer;

	printer.print(container);

	return 0;
}
Ejemplo n.º 28
0
Printer* Printer::Find(node_ref* node)
{
	node_ref n;
		// Look in list to find printer definition
	for (int32 idx = 0; idx < sPrinters.CountItems(); idx++) {
		Printer* printer = sPrinters.ItemAt(idx);
		printer->SpoolDir()->GetNodeRef(&n);
		if (n == *node)
			return printer;
	}

		// None found, so return NULL
	return NULL;
}
Ejemplo n.º 29
0
// compare_to_reference is a short helper function for checking if a file is
// in the reference data set and if yes if the hash matches. Otherwise prints
// an error message.
static void compare_to_reference(const std::string& path, const std::string& hash,
  const Printer& printer, RefData& rd) {

  rd.fileMap[path] = 1;
  auto r = rd.refMap.find(path);
  if (r != rd.refMap.end()) {
    if (r->second != hash) {
      printer.cout("hash differs    :  " + path + "  found(" + hash
        + ") expected(" + r->second + ")");
    }
  } else {
    printer.cout("extra file      :  " + path + " with hash(" + hash + ")");
  }
}
Ejemplo n.º 30
0
void save() {
  if (fileSaved) {
    printer.printString("Saved "+loadedFilename);
    return;
  }
  if (loadedFilename.empty()) {
    saveAs();
  } else {
    saveRamToFile(loadedFilename);
    fileSaved = true;
    printer.printString("Saved "+loadedFilename);
    redrawScreen();
  }
}