void BigInt::ReadFromFile(const char* fileName) { ifstream ifst(fileName); string str; getline(ifst, str); StringToInt(str); }
void GLSLShader::splitBranches() { // Conversion to StatementPtr overload is ambiguous otherwise. StatementPtr main_stmt(main); StatementPtr ref; while (IfCodeNodePtr p = findBranch(main_stmt, ref)) { CodeNodePtr condition = p->getChildren()[0]; CodeNodePtr truePart = p->getChildren()[1]; CodeNodePtr falsePart = p->getChildren()[2]; string name = newRegisterName(); CodeNodePtr nameReference( new NameCodeNode( name, p->getType(), p->getFrequency(), NullValue, ValueNode::BUILTIN)); // suitable substitute for local replace(main_stmt, p, nameReference); DeclarationPtr decl(new Declaration(p->getType(), name)); AssignmentPtr assignTrue(new Assignment); assignTrue->define = false; assignTrue->lhs = name; assignTrue->rhs = truePart; AssignmentPtr assignFalse(new Assignment); assignFalse->define = false; assignFalse->lhs = name; assignFalse->rhs = falsePart; IfStatementPtr ifst(new IfStatement); ifst->condition = condition; ifst->setTrue(assignTrue); ifst->setFalse(assignFalse); BlockPtr newBlock(new Block); newBlock->statements.push_back(decl); newBlock->statements.push_back(ifst); newBlock->statements.push_back(ref); if (main_stmt == ref) { REN_DYNAMIC_CAST_PTR(main, Block, ref); assert(main); main_stmt = main; } else { replace(main_stmt, ref, newBlock); } } }
void OpenFile() { std::ifstream ifst(fileName, std::ifstream::binary); if (ifst.fail()) { throw L"ファイルの読み込みに失敗しました"; } code = std::string( std::istreambuf_iterator<char>(ifst), std::istreambuf_iterator<char>()); ifst.close(); }
string bint::read(char* c) { ifstream ifst(c); string str; ifst >> str; ifst.close(); return str; }
bool Arg_List::loadFile(const QString &fileName) { QFile file(fileName); if(!file.open(QFile::ReadOnly | QFile::Text)) { QMessageBox::warning(this, tr("Pifagor"), tr("Cannot read file %1:\n%2.").arg(fileName).arg(file.errorString())); return false; } QTextStream ifst(&file); QApplication::setOverrideCursor(Qt::WaitCursor); setPlainText(ifst.readAll()); QApplication::restoreOverrideCursor(); return true; }
int run ( ucam::util::RegistryPO const& rg) { ucam::util::PatternAddress<unsigned> input (rg.get<std::string> (HifstConstants::kInput) ); ucam::util::PatternAddress<unsigned> output (rg.get<std::string> (HifstConstants::kOutput) ); WeightFunctorT mwcopy; for ( ucam::util::IntRangePtr ir (ucam::util::IntRangeFactory ( rg, HifstConstants::kRangeOne ) ); !ir->done(); ir->next() ) { FORCELINFO ("Processing file " << input ( ir->get() ) ); boost::scoped_ptr< fst::VectorFst<ArcT> > ifst (fst::VectorFstRead<ArcT> ( input ( ir->get() ) ) ); boost::scoped_ptr< fst::VectorFst<Arc2T> > ofst (new fst::VectorFst<Arc2T>); Map ( *ifst, &*ofst, MapperT ( mwcopy ) ); fst::FstWrite<Arc2T> ( *ofst, output (ir->get() ) ); } };
void GeneratedKey(char *p_fname, char *q_fname, char *e_fname, char *name) { BigInt P(p_fname, false), Q(q_fname, false), E(e_fname, false); BigInt N = P * Q, Fi, FiEl("1"), D("1"); Fi = (P - BigInt("1")) * (Q - BigInt("1")); int amount = 5761456; /*std::ifstream num("simpleNum.txt"); amount = Space(num); num.close();*/ std::ifstream ifst("simpleNum.txt"); if(!ifst) { GenetateSimpleList(); ifst.open("simpleNum.txt"); } int **degree, i; char *buf_ch = new char[10]; BigInt A = BigInt(&Fi), B, buf_bi; degree = new int *[2]; for(i = 0; i < 2; i ++) degree[i] = new int [amount]; memset(degree[0], 0, 4 * amount); memset(degree[1], 0, 4 * amount); i = 0; bool end = true; while(end) { buf_ch = getSimpleNum(ifst); if((A % BigInt(buf_ch)) == BigInt("0")) { A /= BigInt(buf_ch); degree[0][i] = charToInt(buf_ch); degree[1][i]++; i = 0; ifst.seekg (0, ifst.beg); } else i++; if(A == BigInt("1")) end = false; } ifst.close(); for(i = 0; i < amount; i++) { if(degree[0][i] != 0) { A = B = BigInt(intToChar(degree[0][i])); A ^= BigInt(intToChar(degree[1][i])); B ^= BigInt(intToChar(degree[1][i] - 1)); buf_bi = A - B; FiEl *= buf_bi; } } FiEl--; BigInt DegreeNet[RNet]; DegreeNet[0] = D * E; DegreeNet[0] %= Fi; for(i = 1; i < RNet; i++) { DegreeNet[i] = DegreeNet[i-1] * DegreeNet[i-1]; DegreeNet[i] %= Fi; } BigInt degreeNum[RNet]; degreeNum[0] = BigInt("1"); for(int i = 1; i < RNet; i++) degreeNum[i] = degreeNum[i-1] * BigInt("2"); BigInt I("0"); for(int j = RNet-1; j >= 0;) { if(FiEl >= I + degreeNum[j]) { D *= DegreeNet[j]; D %= Fi; I += degreeNum[j]; } else j--; } char fname[32]; strcpy(fname, name); strcat(fname, "N.txt"); N.TextWrite(fname); strcpy(fname, name); strcat(fname, "D.txt"); D.TextWrite(fname); };