Exemplo n.º 1
0
Arquivo: 29.c Projeto: ytaoWang/test
int main(int argc,char *argv[])
{
    int a[] = {1,2,3,4,5};
    int b[] = {5,4,3,2,1};

    
    printf("sequence:%d\n",is_sequence(a,b,sizeof(a)/sizeof(a[0])));
    printf("sequence:%d\n",is_sequence(b,a,sizeof(a)/sizeof(a[0])));

    return 0;
}
Exemplo n.º 2
0
pgsReferenceGen::pgsReferenceGen(pgsThread * app, const wxString & table,
		const wxString & column, const bool & sequence, const long & seed) :
	pgsObjectGen(seed), m_app(app), m_table(table), m_column(column),
			m_sequence(sequence)
{
	// We need an empty symbol table for calling pgsExecute.eval(...)
	pgsVarMap vars;
	
	// Count the number of lines in the table
	pgsOperand result = pgsExecute(wxString() << wxT("SELECT count(*) FROM ")
			<< m_table, 0, m_app).eval(vars);
	wxASSERT(result->is_record());
	wxString value = result->value();
	if (!value.IsEmpty())
	{
		m_nb_rows = pgsMapm::pgs_str_mapm(result->number().value());
	}
	else
	{
		m_nb_rows = 0;
	}
	wxLogScriptVerbose(wxT("REFGEN: Number of rows in %s: %s"), m_table.c_str(),
			pgsMapm::pgs_mapm_str(m_nb_rows).c_str());
	
	// Create an integer generator with that number of lines
	m_randomizer = pgsRandomizer(pnew pgsIntegerGen(0, m_nb_rows - 1,
			is_sequence(), m_seed));
}
pgsDateTimeGen::pgsDateTimeGen(wxDateTime min, wxDateTime max,
		const bool & sequence, const long & seed) :
	pgsObjectGen(seed), m_min(min.IsEarlierThan(max) || min.IsEqualTo(max) ? min : max),
			m_max(max.IsLaterThan(min) || max.IsEqualTo(min) ? max : min),
			m_range(m_max.Subtract(m_min).GetSeconds()), m_sequence(sequence)
{
	m_randomizer = pgsRandomizer(pnew pgsIntegerGen(0, std::string(m_range
			.ToString().mb_str()).c_str(), is_sequence(), m_seed));
}
Exemplo n.º 4
0
pgsTimeGen::pgsTimeGen(wxDateTime min, wxDateTime max, const bool & sequence,
		const long & seed) :
	pgsObjectGen(seed), m_min(min.IsEarlierThan(max) || min.IsEqualTo(max) ? min : max),
			m_max(max.IsLaterThan(min) || max.IsEqualTo(min) ? max : min),
			m_range(m_max.Subtract(m_min).GetSeconds()), m_sequence(sequence)
{
	m_min.SetYear(1970); // We know this date is not a DST date
	m_min.SetMonth(wxDateTime::Jan);
	m_min.SetDay(1);
	m_randomizer = pgsRandomizer(pnew pgsIntegerGen(0, std::string(m_range
			.ToString().mb_str()).c_str(), is_sequence(), m_seed));
}
Exemplo n.º 5
0
pgsRealGen::pgsRealGen(const MAPM & min, const MAPM & max,
		const UCHAR & precision, const bool & sequence, const long & seed) :
	pgsObjectGen(seed), m_min(wxMin(min, max)), m_max(wxMax(min, max)),
			m_range(m_max - m_min), m_sequence(sequence)
{
	m_pow = MAPM(10).pow(MAPM(precision));
	m_int_max = pgsMapm::pgs_mapm_round(m_range * m_pow) + 1;

	m_randomizer = is_sequence()
			? pgsRandomizer(pnew pgsIntegerGen::pgsSequentialIntGen(m_int_max, m_seed))
			: pgsRandomizer(pnew pgsIntegerGen::pgsNormalIntGen(m_int_max, m_seed));
}
Exemplo n.º 6
0
int main (int argc, char *argv[]) {
    FILE *fp = fopen(FILE_NAME, "rb+");
    char buffer[READ_SIZE];
    int writer = ftell(fp);
    int reader = writer;
    while (!feof(fp)) {
        fread(buffer, sizeof(char), READ_SIZE, fp);
        if (is_sequence(buffer)) {
           printf("%s\n", buffer);
	   reader = ftell(fp);
        } else {
            fseek(fp, writer, SEEK_SET);
            fwrite(buffer, sizeof(char), 1, fp);
            ++reader;
            writer = ftell(fp);
    	    fseek(fp, reader, SEEK_SET);
        }
    }
    char end[] =  "!";
    fwrite(end, sizeof(char), reader-writer, fp);
    fclose(fp);
}
Exemplo n.º 7
0
 bool valid() const { return !( !is_sequence() && base_.empty());}