コード例 #1
0
ファイル: HTTPMap.cpp プロジェクト: TheGuv/Firmware
int HTTPMap::getDataLen() //For Content-Length header
{
  //This will be called before any read occurs, so let's generate our string object
  //Generate string
  generateString();
  return m_len;
}
コード例 #2
0
//---------------------------------------------------------------------------
String TFormRandomCode::generateString(const unsigned int length) const
{
  String string = "  ";
  for (unsigned int i=0; i!=length; ++i)
  {
    string+=generateString();
  }
  string+=";";
  return string;
}
コード例 #3
0
ファイル: string.cpp プロジェクト: tktk/dp.old
 StringBase::StringBase(
     const StringBase &  _OTHER
 )
     : SIZE(
         _OTHER.SIZE
     )
     , STRING(
         static_cast< const char * >(
             generateString(
                 _OTHER.STRING
                 , this->SIZE
                 , sizeof( char )
             )
         )
     )
 {
 }
コード例 #4
0
//---------------------------------------------------------------------------
void __fastcall TFormRandomCode::ButtonGenerateClick(TObject *Sender)
{
  RichEdit1->Lines->Clear();
  RichEdit1->Lines->Add("#include <iostream>");
  RichEdit1->Lines->Add("#include <string>");
  RichEdit1->Lines->Add("#include <vector>");
  RichEdit1->Lines->Add("");
  RichEdit1->Lines->Add("int main(int argc, char* argv[])");
  RichEdit1->Lines->Add("{");

  for (int i=0; i<50; ++i)
  {
    RichEdit1->Lines->Add(generateString(3+rand()%10));
  }

  RichEdit1->Lines->Add("  return 0;");
  RichEdit1->Lines->Add("}");

}
コード例 #5
0
ファイル: string.cpp プロジェクト: tktk/dp.old
 StringBase::StringBase(
     const char *    _STRING
 )
     : SIZE(
         calcSize(
             _STRING
         )
     )
     , STRING(
         static_cast< const char * >(
             generateString(
                 _STRING
                 , this->SIZE
                 , sizeof( char )
             )
         )
     )
 {
 }
コード例 #6
0
ファイル: test.cpp プロジェクト: SeppJorgen/School
int main()
{
	hashTable* nein = hashTableCreate(TABLE_SIZE);
	int count = 0;
	int i = 0;
	int percents[] = { 50, 75, 90, 99 };
	//char *string[] = { "hello", "hellod", "hellod" };
	


	srand((unsigned int)time(NULL));
	for (i = 0; i < 1000; i++)
	{
		int len = (rand() % 15) + 3;
		char *generated_string = generated_string = generateString(len);
		int index = BKDRHash(generated_string, len);
		addIntoList(nein->data, index, generated_string);
		
	}

	return 0;
}
コード例 #7
0
QString RandomString::generateString() {
    return generateString(m_stringLength);
}
コード例 #8
0
ファイル: Tester.cpp プロジェクト: campbcha/translators
void Tester::generateTestFile(std::string testFileName) {
	// Generate number of lexemes to use in file
	int numLexemes = rand() % (MAX_LEXEMES + 1);
	std::ofstream testFile;

	// Create test file stream
	testFile.open(testFileName.c_str());
	if ( testFile.is_open() == false ) {
		throw new Exception("Unable to open file to write");
	}

	// Generate file of lexemes
	for ( int i = 0; i < numLexemes; i++ ){
		int lexemeType = rand() % TAG_MAX;
		std::string lexemeStr;

		//generate type of lexeme
		switch ( lexemeType ) {
		case FUNCTION_COSINE:
			lexemeStr = "cos";
			break;
		case FUNCTION_LOGARITHM:
			lexemeStr = "logn";
			break;
		case FUNCTION_PRINTLN:
			lexemeStr = "println";
			break;
		case FUNCTION_SINE:
			lexemeStr = "sin";
			break;
		case FUNCTION_TANGENT:
			lexemeStr = "tan";
			break;
		case OPERATOR_ADDITION:
			lexemeStr = "+";
			break;
		case OPERATOR_AND:
			lexemeStr = "and";
			break;
		case OPERATOR_DIVISION:
			lexemeStr = "/";
			break;
		case OPERATOR_EQUALITY:
			lexemeStr = "=";
			break;
		case OPERATOR_EXPONENTIATION:
			lexemeStr = "^";
			break;
		case OPERATOR_LESS_THAN:
			lexemeStr = "<";
			break;
		case OPERATOR_MODULUS:
			lexemeStr = "%";
			break;
		case OPERATOR_MULTIPLICATION:
			lexemeStr = "*";
			break;
		case OPERATOR_NOT:
			lexemeStr = "not";
			break;
		case OPERATOR_OR:
			lexemeStr = "or";
			break;
		case OPERATOR_SUBTRACTION:
			lexemeStr = "-";
			break;
		case PARENTHESIS_CLOSE:
			lexemeStr = ")";
			break;
		case PARENTHESIS_OPEN:
			lexemeStr = "(";
			break;
		case STATEMENT_ASSIGN:
			lexemeStr = "assign";
			break;
		case STATEMENT_IF:
			lexemeStr = "if";
			break;
		case STATEMENT_IFF:
			lexemeStr = "iff";
			break;
		case STATEMENT_LET:
			lexemeStr = "let";
			break;
		case STATEMENT_WHILE:
			lexemeStr = "while";
			break;
		case TYPE_BOOLEAN:
			lexemeStr = "bool";
			break;
		case TYPE_INTEGER:
			lexemeStr = "int";
			break;
		case TYPE_REAL:
			lexemeStr = "real";
			break;
		case TYPE_STRING:
			lexemeStr = "string";
			break;
		case VALUE_BOOLEAN:
			lexemeStr = generateBoolean();
			break;
		case VALUE_INTEGER:
			lexemeStr = generateInteger();
			break;
		case VALUE_REAL:
			lexemeStr = generateReal();
			break;
		case VALUE_STRING:
			lexemeStr = generateString();
			break;
		default:
			lexemeStr = "ERROR";
			break;
		}

		testFile << lexemeStr;
		testFile << generateWhiteSpace();

		tagList.push_back(lexemeType);
		stringList.push_back(lexemeStr);
	}
	
	testFile.close();
}
コード例 #9
0
ファイル: FileTests.cpp プロジェクト: Catchouli-old/ali
void FileTests::run()
{
	bool success = false;

	// Generate random strings
	char* filename = generateString(20);
	char* randomString = generateString(100);

	begintest("Create file with random name: " << filename);
		File file(filename);
	endtest(file.isOpen());

	begintest("Write 100 bytes to file");
		int bytesWritten = file.write(randomString);
	endtest(bytesWritten == 100);

	begintest("Close file");
		file.close();
	endtest(!file.isOpen());

	begintest("Open same file by default constructor + call to open()");
		File file2;
		file2.open(filename, false);
	endtest(file2.isOpen());

	begintest("Delete file and check it doesn't exist");
		file2.deleteFile();
	endtest(!File::exists(filename));

	// Generate new filename and string
	ali::dealloc(filename);
	ali::dealloc(randomString);
	filename = generateString(20);
	randomString = generateString(200);

	begintest("Write to file and then read it again");
		success = false;

		// Write to a file
		file.open(filename);
		file.write(randomString);
		file.close();
		file.open(filename);

		// Allocate memory for buffer
		int read = 0;
		char* buffer = (char*)ali::alloc(file.getLength()+1);

		// If read more than 0 bytes
		if ((read = file.read(buffer)) > 0)
		{
			// If read string is identical to written string, success = true
			success = (strcmp(buffer, randomString) == 0);
		}
		
		// Clean up test
		ali::dealloc(buffer);
		file.deleteFile();
	endtest(success);

	// Clean up files
	file.close();
	file2.close();

	// Clean up memory
	ali::dealloc(filename);
	ali::dealloc(randomString);
}
コード例 #10
0
ファイル: main.cpp プロジェクト: yitping/typingtutor
int main(int argc, char * argv[])
{
	int ch, opt;
	int errflag;
	char *optargTrainingSet=NULL, optargSep=',';
	std::vector<char> trainingSet;
	
	while ((opt = getopt(argc, argv, ":hc:s:")) != -1)
	{
		switch (opt)
		{
			case 'h':
				errflag++;
				break;
			case 'c':
				optargTrainingSet = optarg;
				break;
			case 's':
				sscanf(optarg, "%c", &optargSep);
				break;
			case ':':
				std::cerr << "option -" << optopt << "requires an operand" << std::endl;
				errflag++;
				break;
			case '?':
				std::cerr << "unrecognized option:-" << optopt << std::endl;
				errflag++;
				break;
		}
	}
	
	if (errflag || (optargTrainingSet == NULL))
	{
		printCLHelp(argv[0]);
		return EXIT_FAILURE;
	}
	
	if (splitStringToChar(optargTrainingSet, trainingSet, optargSep) != 0)
	{
		return EXIT_FAILURE;
	}
	
	// Initialize app
	initTT();
	
	//char a[] = {'a', 's', 'd', 'f', ' '};
	charsRefer = generateString(trainingSet.data(), (int)trainingSet.size(), buffersize);
	charsTyped.resize(buffersize);
	charsTyped.clear();
	
	setupScreen();
	updateReferLine(charsRefer);
	updateActionLine(charsTyped, charsRefer);
	updateInfoLine();
	updateCursorPosition(charsTyped);
	
	ch = getch();
	while (ch != ASCII_CTRL_C)
	{
		if (!isPrintableKey(ch) && !isSpecialKey(ch))
		{
			ch = getch();
			continue;
		}
		switch (ch)
		{
			case ASCII_BACKSPACE:
			case ASCII_DELETE:
				std::cout << (char) ASCII_CTRL_G; // sound the bell
				refresh();
				break;
			case ASCII_CTRL_R:
				resetStatistics();
			case ASCII_NEWLINE:
			case ASCII_CRETURN:
				if (isEOL(charsTyped) || (ch == ASCII_CTRL_R))
				{
					charsRefer = generateString(trainingSet.data(), (int)trainingSet.size(), buffersize);
					updateReferLine(charsRefer);
					clearActionLine();
					clearBuffer(charsTyped);
				}
				break;
			default:
				if (addChar(charsTyped, ch))
				{
					updateActionLine(charsTyped, charsRefer);
				}
				updateInfoLine();
				updateCursorPosition(charsTyped);
		}
		ch = getch();
	}
	
	refresh();
	endwin();
	
	/*
	std::cout << "buffersize= " << buffersize << std::endl;
	std::cout << "reference = " << charsRefer.size() << std::endl;
	std::cout << "capacity  = " << charsTyped.capacity() << std::endl;
	std::cout << "typed_in  = " << charsTyped.size() << std::endl;
	 */
	printf("Goodbye!\n");
	return 0;
}
コード例 #11
0
int main(int argc, char *argv[])
{
	FILE *fout, *input;
	uint8_t *buffer;
	uint32_t length;
	uint16_t numofelemHuffman = 0;
	std::vector<Node> check;
	std::vector<Node>::iterator it;
	char* outfile; 

	codified coded[256];
	
	Node left, right, top, *Hufftree;
	unsigned int i;
	if (argc != 3)
	{
		std::cout<<"Argumente insuficiente";
		return -1;
	}

	//Partea de compresie
	if (strcmp(argv[1],"-c")==0)
	{
		Node *aux = new Node();
		int *v = new int[256];

		//Crearea numelui fisierului de iesire 
		input = fopen(argv[2], "rb");
		outfile = new char[strlen(argv[2])+ 5];
		//memset(outfile, sizeof(char), strlen(argv[2]) + 5);
		strcpy(outfile,argv[2]);
		strcat(outfile,".cmp");
		fout = fopen(outfile, "wb");

		//Citirea intregului fisier intr-un vector, calcularea frecventelor 
		//fiecarui caracter si depozitarea lor intr-un vector
		fseek(input, 0, SEEK_END);
		length = ftell(input);
		fseek(input, 0, SEEK_SET);
		buffer = new uint8_t[length];
		memset(v, 0, sizeof(int)*256);
		while (fread(buffer, sizeof(uint8_t)* length, 1, input) == 1);
		for (i = 0; i<= length - 1; i++)
		{
			if(v[(int)buffer[i]] == 0)
			{
				aux->symbol = buffer[i];
				check.push_back(*aux);
			}
			v[(int)buffer[i]]++;
		}

		//depozitarea in heap a fiecarui caracter, impreuna cu frecventa si probabilitatea
		Heap<Node> heap(check.size());
		for (it = check.begin(); it != check.end(); ++it)
		{	
			(*it).freq	= v[(int)(*it).symbol];
			(*it).probability = (double)v[(int)(*it).symbol]/length;
			heap.insert(*it);
		}
		delete[] v;
		//partea de extragere din Heap si de constructie a arborelui
		while (heap.getSize() > 1)
		{
			left = heap.extractMin();
			right = heap.extractMin();
			if (left.left == NULL && left.right == NULL && right.left == NULL && right.right == NULL)
			{
				numofelemHuffman += 3;
			}
			else if (left.left == NULL && left.right == NULL)
			{
				numofelemHuffman += 2;
			}
			else if (right.left == NULL && right.right == NULL)
			{
				numofelemHuffman += 2;
			}
			else numofelemHuffman += 1;
			top.freq = left.freq + right.freq;
			top.probability = left.probability + right.probability;
			top.height = std::max(left.height, right.height) + 1;
			top.symbol = std::min(left.symbol, right.symbol);
			top.left = new Node;
			top.right = new Node;
			*top.left = left;
			*top.right = right;
			heap.insert(top);
		}
		Hufftree = new Node;
		*Hufftree = heap.extractMin();

		//Partea de serializare a arborelui Huffman
		HuffmanSerializedNode vec[numofelemHuffman];
		uint16_t index = 0;
		HuffCreateVector(Hufftree, vec, index);

		//generarea codului pentru fiecare caracter si printarea dimensiunilor si arborelui in fisier
		generateCode(vec, coded, 0, 0, 0);
		fwrite(&numofelemHuffman, sizeof(uint16_t), 1, fout);
		fwrite(vec, sizeof(HuffmanSerializedNode), numofelemHuffman, fout);
		fwrite(&length, sizeof(uint32_t), 1, fout);

		//codificarea textului si printarea
		BitString (buffer, coded, length, fout);

		Hufftree->deallocate();
		delete aux;
		delete[] buffer;
		delete[] outfile;
		fclose(input);
		fclose(fout);
	}
	//Partea de decompresie
	else if (strcmp(argv[1], "-d") == 0)
	{
		input = fopen(argv[2], "rb");
		outfile = new char[strlen(argv[2])+ 14];
		strcpy(outfile,"decompressed_");
		strncat(outfile,argv[2], strlen(argv[2]) - 4 );
		fout = fopen(outfile, "wb");
		if (fout == NULL) {
			std::cout<<"fisierul de out nu se deschide";
			return -1;
		}
		//Folosesc fread asa pentru a evita warning-urile de la compilarea cu -O2
		if (!fread(&numofelemHuffman, sizeof(uint16_t), 1, input))
			return -1;
		HuffmanSerializedNode Huffmantree[numofelemHuffman];
		if (!fread(&Huffmantree, sizeof(HuffmanSerializedNode), numofelemHuffman, input))
			return -1;
		if (!fread(&length, sizeof(uint32_t), 1, input))
			return -1;
		generateString (input, fout, Huffmantree, length);
		delete[] outfile;
		fclose(input);
		fclose(fout);
	}
	return 0;
}