示例#1
0
void tst_QSqlField::setValue()
{
    QSqlField field1 ( "test", QVariant::Int );
    QSqlField field2 ( "test", QVariant::String );
    QSqlField field3 ( "test", QVariant::Bool );
    QSqlField field4 ( "test", QVariant::Double );
    field1.clear();
    QFETCH( int, ival );
    QFETCH( QString, sval );
    QFETCH( double, dval );
    QFETCH( bool, bval );
    field1.setValue( ival );
    QCOMPARE( field1.value().toInt(), ival );
    // setValue should also reset the NULL flag
    QVERIFY( !field1.isNull() );

    field2.setValue( sval );
    QCOMPARE( field2.value().toString(), sval );
    field3.setValue( QVariant( bval) );
    QVERIFY( field3.value().toBool() == bval );
    field4.setValue( dval );
    QCOMPARE( field4.value().toDouble(), dval );
    field4.setReadOnly( true );
    field4.setValue( "Something_that's_not_a_double" );
    QCOMPARE( field4.value().toDouble(), dval );
}
示例#2
0
void tst_QSqlField::operator_Equal()
{
    QSqlField field1( "test", QVariant::String );
    QSqlField field2( "test2", QVariant::String );
    QSqlField field3( "test", QVariant::Int );
    QSqlField field4("test", QVariant::String, QString("ATable"));
    QSqlField field5("test2", QVariant::String, QString("ATable"));
    QSqlField field6("test", QVariant::String, QString("BTable"));

    QVERIFY( !(field1 == field2) );
    QVERIFY( !(field1 == field3) );
    QVERIFY(field1 != field4);
    QVERIFY(field1 != field5);
    QVERIFY(field1 != field6);
    QVERIFY(field4 != field5);
    QVERIFY(field4 != field6);

    field2.setName( "test" );
    QVERIFY( field1 == field2 );
    QVERIFY( field1 == field2 );
    field1.setValue( "Harry" );
    QVERIFY( !(field1 == field2) );
    field2.setValue( "Harry" );
    QVERIFY( field1 == field2 );
    field1.setReadOnly( true );
    QVERIFY( !(field1 == field2) );
    field2.setReadOnly( true );
    QVERIFY( field1 == field2 );
    field4.setTableName("BTable");
    QCOMPARE(field4, field6);
    field6.setName("test3");
    QVERIFY(field4 != field6);
}
示例#3
0
void TestQgsFields::field()
{
    QgsField original;
    original.setName( "name" );
    original.setType( QVariant::Int );
    original.setLength( 5 );
    original.setPrecision( 2 );

    //test constructors for QgsFields::Field
    QgsFields::Field fieldConstructor1( original, QgsFields::OriginJoin, 5 );
    QCOMPARE( fieldConstructor1.field, original );
    QCOMPARE( fieldConstructor1.origin, QgsFields::OriginJoin );
    QCOMPARE( fieldConstructor1.originIndex, 5 );

    QgsFields::Field fieldConstructor2;
    QCOMPARE( fieldConstructor2.origin, QgsFields::OriginUnknown );
    QCOMPARE( fieldConstructor2.originIndex, -1 );

    //test equality operators
    QgsFields::Field field1( original, QgsFields::OriginJoin, 5 );
    QgsFields::Field field2( original, QgsFields::OriginJoin, 5 );
    QVERIFY( field1 == field2 );
    QgsFields::Field field3( original, QgsFields::OriginEdit, 5 );
    QVERIFY( field1 != field3 );
    QgsFields::Field field4( original, QgsFields::OriginJoin, 6 );
    QVERIFY( field1 != field4 );
}
示例#4
0
void TestQgsFields::indexFromName()
{
    QgsFields fields;
    QgsField field( QString( "testfield" ) );
    field.setAlias( "testfieldAlias" );
    fields.append( field );
    QgsField field2( QString( "testfield2" ) );
    fields.append( field2 );
    QgsField field3( QString( "testfield3" ) );
    fields.append( field3 );

    QCOMPARE( fields.indexFromName( QString( "bad" ) ), -1 );
    QCOMPARE( fields.lookupField( QString( "bad" ) ), -1 );
    QCOMPARE( fields.indexFromName( QString( "testfield" ) ), 0 );
    QCOMPARE( fields.lookupField( QString( "testfield" ) ), 0 );
    QCOMPARE( fields.indexFromName( QString( "testfield3" ) ), 2 );
    QCOMPARE( fields.lookupField( QString( "testfield3" ) ), 2 );

    //indexFromName is case sensitive, fieldNameIndex isn't
    QCOMPARE( fields.indexFromName( QString( "teStFiEld2" ) ), -1 );
    QCOMPARE( fields.lookupField( QString( "teStFiEld2" ) ), 1 );

    //test that fieldNameIndex prefers exact case matches over case insensitive matches
    QgsField sameNameDifferentCase( QString( "teStFielD" ) );
    fields.append( sameNameDifferentCase );
    QCOMPARE( fields.lookupField( QString( "teStFielD" ) ), 3 );

    //test that the alias is only matched with fieldNameIndex
    QCOMPARE( fields.indexFromName( "testfieldAlias" ), -1 );
    QCOMPARE( fields.lookupField( "testfieldAlias" ), 0 );
    QCOMPARE( fields.lookupField( "testfieldalias" ), 0 );
}
void CodeBuilder::FormatArray(const string& type, const string& varName, const int& _arraySize, const string& comment)
{
    int arraySize = _arraySize;
    if(arraySize == 0)
    {
        //an array of zero length is undefined.. don't put it in the header..
        mStringing<<"\n//The array size for the follwoing variable was generated as 0. We put 1, to make it legal code.\n";
         arraySize = 1;
    }

    string field2(varName +"["+ rr::ToString(arraySize)+"];");
    mStringing<<left<<setw(mSizeOfVarField1)<<type    << setw(mSizeOfVarField2)<<field2;

    if(comment.size())
    {
        mStringing<<left<<setw(mSizeOfVarField3)<<"//" + comment;
    }
    mStringing<<"\n";

    //Add the size for each array, so we don't have to calculate later on..
    if(_arraySize == 0)
    {
        arraySize = 0;
    }

    mStringing<<left<<setw(mSizeOfVarField1)<<"D_S const int"    << setw(mSizeOfVarField2)<<varName + "Size=" + rr::ToString(arraySize) + ";";
    mStringing<<endl;
}
示例#6
0
void TestQuery::constructor()
{
  QcSqlField field1("field1");
  QcSqlField field2("field2");
  QcSqlField field3("field3");

  check_sql(field1 == 1, "field1 = 1");
  check_sql(field1 != 1, "field1 != 1");
  check_sql(field1 < 1, "field1 < 1");
  check_sql(field1 > 1, "field1 > 1");
  check_sql(field1 <= 1, "field1 <= 1");
  check_sql(field1 >= 1, "field1 >= 1");

  // check_sql(not field1 == 1, "(NOT field1 = 1)");
  check_sql(Not(field1 == 1), "(NOT field1 = 1)");
  check_sql(field1 == 1 and field2 == 2, "(field1 = 1 AND field2 = 2)");
  check_sql(field1 == 1 or field2 == 2, "(field1 = 1 OR field2 = 2)");
  check_sql((field1 == 1 and field2 == 2) or field3 == 3,
            "((field1 = 1 AND field2 = 2) OR field3 = 3)");

  QcDatabase database; // Flavour is ANSI
  QcDatabaseTable table(&database, "table");

  check_sql(table.sql_query(), "");

  check_sql(table.sql_query().all(), "SELECT * FROM table;");
  check_sql(table.sql_query().add_column(field1).all(), "SELECT field1 FROM table;");
  check_sql(table.sql_query().add_column(field1).add_column(field2).all().filter(field1 > 1),
            "SELECT field1, field2 FROM table WHERE field1 > 1;");
  check_sql(table.sql_query().add_column(field1).add_column(field2).all().filter((field1 > 1 and field1 < 10) or field2 > 2),
            "SELECT field1, field2 FROM table WHERE ((field1 > 1 AND field1 < 10) OR field2 > 2);");
  check_sql(table.sql_query().order_by(field1).all(),
            "SELECT * FROM table ORDER BY field1;");
  check_sql(table.sql_query().order_by(field1.desc()).all(),
            "SELECT * FROM table ORDER BY field1 DESC;");

  // Fixme: ->as
  check_sql(table.sql_query().add_column(Min(field1)->as("min_field1")).all(),
            "SELECT MIN(field1) AS min_field1 FROM table;");

  // Fixme: INSERT INTO table VALUES (?, ...);
  check_sql(table.sql_query().add_column(field1).insert(),
            "INSERT INTO table (field1) VALUES (?);");
  check_sql(table.sql_query().add_column(field1).add_column(field2).insert(),
            "INSERT INTO table (field1, field2) VALUES (?, ?);");

  check_sql(table.sql_query().add_column(field1).update().filter(field1 > 1),
            "UPDATE table SET field1 = ? WHERE field1 > 1;");
  check_sql(table.sql_query().add_column(field1).add_column(field2).update().filter(field1 > 1),
            "UPDATE table SET field1 = ?, field2 = ? WHERE field1 > 1;");

  check_sql(table.sql_query().delete_().filter(field1 > 1),
            "DELETE FROM table WHERE field1 > 1;");

  check_sql(table.sql_query().add_column(ST_AsBinary(field1)).all(),
            "SELECT ST_AsBinary(field1) FROM table;");
  check_sql(table.sql_query().add_column(field1).add_column(field2, ST_GeomFromWKB()).insert(),
            "INSERT INTO table (field1, field2) VALUES (?, ST_GeomFromWKB(?));");
}
示例#7
0
void tst_QSqlField::type()
{
    QSqlField field1( "string", QVariant::String );
    QSqlField field2( "string", QVariant::Bool );
    QSqlField field3( "string", QVariant::Double );
    QVERIFY( field1.type() == QVariant::String );
    QVERIFY( field2.type() == QVariant::Bool );
    QVERIFY( field3.type() == QVariant::Double );
}
示例#8
0
void TestQgsFields::byName()
{
  QgsFields fields;
  QgsField field( QStringLiteral( "testfield" ) );
  fields.append( field );
  QgsField field2( QStringLiteral( "testfield2" ) );
  fields.append( field2 );

  QCOMPARE( fields.field( "testfield" ), field );
  QCOMPARE( fields.field( "testfield2" ), field2 );
}
示例#9
0
void TestQgsFields::byName()
{
    QgsFields fields;
    QgsField field( "testfield" );
    fields.append( field );
    QgsField field2( "testfield2" );
    fields.append( field2 );

    QCOMPARE( fields.field( "testfield" ), field );
    QCOMPARE( fields.field( "testfield2" ), field2 );
}
示例#10
0
void TestQgsFields::fieldOrigin()
{
    QgsFields fields;
    QgsField field( QString( "testfield" ) );
    fields.append( field , QgsFields::OriginJoin );
    QgsField field2( QString( "testfield2" ) );
    fields.append( field2, QgsFields::OriginExpression );

    QCOMPARE( fields.fieldOrigin( 0 ), QgsFields::OriginJoin );
    QCOMPARE( fields.fieldOrigin( 1 ), QgsFields::OriginExpression );
    QCOMPARE( fields.fieldOrigin( 2 ), QgsFields::OriginUnknown );
}
示例#11
0
void TargetsDialog::createTargetFromSelection()
{
	if (StelApp::getInstance().getStelObjectMgr().getWasSelected()) {
		QList<StelObjectP> selectedObjects = StelApp::getInstance().getStelObjectMgr().getSelectedObject();
		QListIterator<StelObjectP> objectIterator(selectedObjects);
		StelCore* core = StelApp::getInstance().getCore();
		while (objectIterator.hasNext()) {
			StelObjectP stelObject = objectIterator.next();
			QString type = stelObject->getType();
			QString englishName = stelObject->getEnglishName();
			if (englishName == "") {
				englishName = "No Name";
			}
			float magnatude = stelObject->getVMagnitude(core);
			double angularSize = stelObject->getAngularSize(core);
			
			Vec3d pos;
			double ra, dec;
			// ra/dec in J2000
			pos = stelObject->getJ2000EquatorialPos(core);
			StelUtils::rectToSphe(&ra, &dec, pos);
			
		    QSqlField field1("name", QVariant::String);
			QSqlField field2("right_ascension", QVariant::Double);
			QSqlField field3("declination", QVariant::Double);
			QSqlField field4("target_type_id", QVariant::Int);
			QSqlField field5("magnitude", QVariant::Double);
			QSqlField field6("size", QVariant::Double);
			field1.setValue(QVariant(englishName));
			field2.setValue(QVariant(ra));
			field3.setValue(QVariant(dec));
			field4.setValue(QVariant(1));
			field5.setValue(QVariant(magnatude));
			field6.setValue(QVariant(angularSize));
			QSqlRecord newRecord = QSqlRecord();
			newRecord.append(field1);
			newRecord.append(field2);
			newRecord.append(field3);
			newRecord.append(field4);
			newRecord.append(field5);
			newRecord.append(field6);
			
			if (tableModel->insertRecord(-1, newRecord)) {
				ui->targetsListView->setCurrentIndex(tableModel->index(tableModel->rowCount() - 1, 1));
			} else {
				qWarning() << "LogBook: could not insert new target.  The error is: " << tableModel->lastError();
			}
		}
	} else {
		qDebug() << "====> Nothing selected.";
	}
}	
示例#12
0
Farm::Farm(float density): Region(density, "Farm")
{
	// Set standard background
	for (int x = 0; x < REGIONSIZE; x++)
	{
		for (int y = 0; y < REGIONSIZE; y++)
		{
			if (lbRNG::decision(0.05))
			{
				// Random tree or two
				replace(x,y, new Tile("grass-light","tree-light"));
			} else {
				replace(x,y, new Tile("grass-light"));
				
				if (lbRNG::decision(0.01))
				{
					getTileAt(x, y)->setMob(new Sheep(getTileAt(x, y)));
					
				}
			}
			
		}
	}
	
	// Add Barn
	Feature barn(5,5);
	barn.addAll("floor-wood-light");
	barn.addBorder("wall-wood-light");
	barn.addDoor("door-wood-open","door-wood-closed", N);

	// Add fields
	Field field1(8,5);
	Field field2(4,9);
	
	field1.generate();
	field2.generate();
	
	field1.clearBorder();
	
	field1.addBorder("dirt-light");
	field1.addBorder("fence-wood");
	field1.addDoor("air","air",N);
	field1.addDoor("air","air",S);
	
	// Place down new tiles
	replace(3,3,barn.tiles);
	replace(2,9,field1.tiles);
	replace(10,5,field2.tiles);
	
	INFO("Generated Farm");
}
示例#13
0
void TestQgsFields::qforeach()
{
    QgsFields fields;
    QgsField field( QString( "1" ) );
    fields.append( field );
    QgsField field2( QString( "2" ) );
    fields.append( field2 );

    int i = 0;
    Q_FOREACH ( const QgsField& field, fields )
    {
        QCOMPARE( field, fields.at( i ) );
        ++i;
    }
示例#14
0
void TestQgsFields::count()
{
    QgsFields fields;
    QCOMPARE( fields.count(), 0 );
    QCOMPARE( fields.size(), 0 );

    QgsField field( "testfield" );
    fields.append( field );
    QCOMPARE( fields.count(), 1 );
    QCOMPARE( fields.size(), 1 );

    QgsField field2( "testfield2" );
    fields.append( field2 );
    QCOMPARE( fields.count(), 2 );
    QCOMPARE( fields.size(), 2 );
}
示例#15
0
void TestQgsFields::appendExpressionField()
{
    QgsFields fields;
    QgsField field( QString( "testfield" ) );
    fields.append( field );
    QgsField field2( QString( "testfield2" ) );
    fields.append( field2 );

    QgsField dupeName( QString( "testfield" ) );
    QVERIFY( !fields.appendExpressionField( dupeName, 1 ) );

    //good name
    QgsField exprField( QString( "expression" ) );
    QVERIFY( fields.appendExpressionField( exprField, 5 ) );
    QCOMPARE( fields.count(), 3 );
    QCOMPARE( fields.fieldOrigin( 2 ), QgsFields::OriginExpression );
    QCOMPARE( fields.fieldOriginIndex( 2 ), 5 );
}
示例#16
0
void TestQgsFields::allAttrsList()
{
    QgsFields fields;
    QgsAttributeList attrList = fields.allAttributesList();
    QVERIFY( attrList.isEmpty() );

    QgsField field( QString( "testfield" ) );
    fields.append( field );
    QgsField field2( QString( "testfield2" ) );
    fields.append( field2 );
    QgsField field3( QString( "testfield3" ) );
    fields.append( field3 );

    attrList = fields.allAttributesList();
    QCOMPARE( attrList.at( 0 ), 0 );
    QCOMPARE( attrList.at( 1 ), 1 );
    QCOMPARE( attrList.at( 2 ), 2 );
}
示例#17
0
void TestQgsFields::toList()
{
    QgsFields fields;
    QList<QgsField> list = fields.toList();
    QVERIFY( list.isEmpty() );

    QgsField field( QString( "testfield" ) );
    fields.append( field );
    QgsField field2( QString( "testfield2" ) );
    fields.append( field2 );
    QgsField field3( QString( "testfield3" ) );
    fields.append( field3 );

    list = fields.toList();
    QCOMPARE( list.at( 0 ), field );
    QCOMPARE( list.at( 1 ), field2 );
    QCOMPARE( list.at( 2 ), field3 );
}
示例#18
0
void tst_QSqlField::operator_Equal()
{
    QSqlField field1( "test", QVariant::String );
    QSqlField field2( "test2", QVariant::String );
    QSqlField field3( "test", QVariant::Int );
    QVERIFY( !(field1 == field2) );
    QVERIFY( !(field1 == field3) );
    field2.setName( "test" );
    QVERIFY( field1 == field2 );
    QVERIFY( field1 == field2 );
    field1.setValue( "Harry" );
    QVERIFY( !(field1 == field2) );
    field2.setValue( "Harry" );
    QVERIFY( field1 == field2 );
    field1.setReadOnly( true );
    QVERIFY( !(field1 == field2) );
    field2.setReadOnly( true );
    QVERIFY( field1 == field2 );
}
示例#19
0
void TestQgsFields::byIndex()
{
    QgsFields fields;
    QgsField field( "testfield" );
    fields.append( field );
    QgsField field2( "testfield2" );
    fields.append( field2 );

    QCOMPARE( fields[0], field );
    QCOMPARE( fields[1], field2 );

    const QgsFields& constFields = fields;
    QCOMPARE( constFields[0], field );
    QCOMPARE( constFields[1], field2 );
    QCOMPARE( constFields.at( 0 ), field );
    QCOMPARE( constFields.at( 1 ), field2 );
    QCOMPARE( constFields.field( 0 ), field );
    QCOMPARE( constFields.field( 1 ), field2 );
}
void BarlowsDataMapper::insertNewBarlow()
{
    QSqlField field1("model", QVariant::String);
    QSqlField field2("vendor", QVariant::String);
    QSqlField field3("factor", QVariant::Double);
	field1.setValue(QVariant("Model"));
	field2.setValue(QVariant("Vendor"));
	field3.setValue(QVariant(1.0));
	QSqlRecord newRecord = QSqlRecord();
	newRecord.append(field1);
	newRecord.append(field2);
	newRecord.append(field3);
	
	if (tableModel->insertRecord(-1, newRecord)) {
		widget->barlowsListView->setCurrentIndex(tableModel->index(tableModel->rowCount() - 1, 1));
	} else {
		qWarning() << "LogBook: could not insert new barlow.  The error is: " << tableModel->lastError();
	}
}
示例#21
0
void TestQgsFields::extend()
{
    QgsFields destination;
    QgsField field( "testfield" );
    destination.append( field );
    QgsField field2( "testfield2" );
    destination.append( field2 );

    QgsFields source;
    QgsField field3( "testfield3" );
    source.append( field3, QgsFields::OriginJoin, 5 );
    QgsField field4( "testfield4" );
    source.append( field4 );

    QCOMPARE( destination.count(), 2 );
    destination.extend( source );
    QCOMPARE( destination.count(), 4 );
    QCOMPARE( destination.at( 2 ), field3 );
    QCOMPARE( destination.at( 3 ), field4 );
}
示例#22
0
void TestQgsFields::fieldOriginIndex()
{
    QgsFields fields;
    QgsField field( QString( "testfield" ) );
    fields.append( field , QgsFields::OriginProvider, 5 );
    QCOMPARE( fields.fieldOriginIndex( 0 ), 5 );

    QgsField field2( QString( "testfield2" ) );
    fields.append( field2, QgsFields::OriginProvider, 10 );
    QCOMPARE( fields.fieldOriginIndex( 1 ), 10 );

    QgsField field3( QString( "testfield3" ) );
    //field origin index not specified with OriginProvider, should be automatic
    fields.append( field3, QgsFields::OriginProvider );
    QCOMPARE( fields.fieldOriginIndex( 2 ), 2 );

    QgsField field4( QString( "testfield4" ) );
    //field origin index not specified with other than OriginProvider, should remain -1
    fields.append( field4, QgsFields::OriginEdit );
    QCOMPARE( fields.fieldOriginIndex( 3 ), -1 );
}
示例#23
0
void TestQgsFields::indexFromName()
{
  QgsFields fields;
  QgsField field( QString( "testfield" ) );
  fields.append( field );
  QgsField field2( QString( "testfield2" ) );
  fields.append( field2 );
  QgsField field3( QString( "testfield3" ) );
  fields.append( field3 );

  QCOMPARE( fields.indexFromName( QString( "bad" ) ), -1 );
  QCOMPARE( fields.fieldNameIndex( QString( "bad" ) ), -1 );
  QCOMPARE( fields.indexFromName( QString( "testfield" ) ), 0 );
  QCOMPARE( fields.fieldNameIndex( QString( "testfield" ) ), 0 );
  QCOMPARE( fields.indexFromName( QString( "testfield3" ) ), 2 );
  QCOMPARE( fields.fieldNameIndex( QString( "testfield3" ) ), 2 );

  //indexFromName is case sensitive, fieldNameIndex isn't
  QCOMPARE( fields.indexFromName( QString( "teStFiEld2" ) ), -1 );
  QCOMPARE( fields.fieldNameIndex( QString( "teStFiEld2" ) ), 1 );
}
示例#24
0
void TestQgsFields::remove()
{
    QgsFields fields;

    //test for no crash
    fields.remove( 1 );

    QgsField field( "testfield" );
    fields.append( field );
    QgsField field2( "testfield2" );
    fields.append( field2 );

    //test for no crash
    fields.remove( -1 );
    fields.remove( 5 );

    //remove valid field
    fields.remove( 0 );
    QCOMPARE( fields.count(), 1 );
    QCOMPARE( fields.at( 0 ).name(), QString( "testfield2" ) );
    QCOMPARE( fields.indexFromName( "testfield2" ), 0 );
}
示例#25
0
int main(int argc, char** argv)
{
    try
    {
        nitf_Error e;

//        Foo<int>* foo = new Bar<int>();
//        delete foo;

        nitf_Field* cField = nitf_Field_construct(100, NITF_BCS_N, &e);
        nitf::Field field(cField);

        {
            nitf::Field field2(cField);
        }

        std::cout << field.isValid() << std::endl;


        nitf_BandInfo* cBandInfo = nitf_BandInfo_construct(&e);
        assert(cBandInfo);

        nitf::BandInfo info(cBandInfo);

        std::cout << (int)info.getNumLUTs() << std::endl;

        std::cout << "HERE!!!!!!!!!!!!!!!!!!!!" << std::endl;
        nitf::SubWindow sub;
        nitf::SubWindow sub2 = sub;
        sub.setNumRows(5);

        nitf::PixelSkip p(1, 1);
        sub.setDownSampler(p);
        sub.setDownSampler(p);
        sub.setDownSampler(p);
        sub.setDownSampler(p);

        nitf::PixelSkip p2(1, 1);
        sub.setDownSampler(p2);
        sub.setDownSampler(p);


        nitf_SubWindow* subw = nitf_SubWindow_construct(&e);
        nitf::SubWindow sub3(subw);
        std::cout << sub.getNumRows() <<  " == " << sub2.getNumRows() << std::endl;


        nitf::List list;
        nitf::List list2 = list;

        {
            nitf::FileHeader header;
            nitf::FileHeader header2(header.clone());
            //should be not equal
            std::cout << "Equal? " << (header == header2) << std::endl;
            nitf::FileHeader header3(header2);
            //these two should be equal
            std::cout << "Equal? " << (header3 == header2) << std::endl;
        }

        nitf::HashTable hash;

        nitf::Extensions extensions;
        {
            nitf::ImageSegment imageSeg;
            nitf::ImageSubheader imageSub;

            imageSeg.getSubheader().getImageId() = "Test Image";
            std::cout << imageSeg.getSubheader().getImageId().toString() << std::endl;
            nitf::Field f = imageSeg.getSubheader().getImageId();
            std::cout << f.toString() << std::endl;

            nitf::ImageSegment imageSeg2 = imageSeg.clone();
            nitf::ImageSubheader imageSub2(imageSub.clone());

            extensions = imageSub.getExtendedSection();
        }

        nitf::TextSegment tSeg;
        nitf::TextSubheader tSub;

        nitf::GraphicSegment gSeg;
        nitf::GraphicSubheader gSub;

        nitf::DESegment dSeg;
        nitf::DESubheader dSub;

        nitf::LabelSegment rSeg;
        nitf::LabelSubheader rSub;

        nitf::TRE tre("JITCID");
        //tre.print();
        std::cout << "HERE!!!!!" << std::endl;

        nitf::Reader reader;
        nitf::Writer writer;


        //open a file
        sys::OS os;
        std::vector< std::string > files;
        for (int i = 1; i < argc; ++i)
        {
            if (!os.exists(argv[i]))
                std::cout << "Error -> File does not exist: " << argv[i] << std::endl;
            else
                files.push_back(argv[i]);
        }

        for (std::vector< std::string >::iterator it = files.begin(); it != files.end(); ++it)
        {
            nitf::IOHandle handle(*it);
            nitf::Reader rdr;
            nitf::Record rec = rdr.read(handle);

            std::cout << "CODEWORDS: " << rec.getHeader().getSecurityGroup().getCodewords().toString() << std::endl;
            rec.getHeader().getSecurityGroup().getCodewords() = "TEST";
            std::cout << "CODEWORDS: " << rec.getHeader().getSecurityGroup().getCodewords().toString() << std::endl;
            nitf::FileSecurity security;
            rec.getHeader().setSecurityGroup(security);
            std::cout << "CODEWORDS: " << rec.getHeader().getSecurityGroup().getCodewords().toString() << std::endl;
            std::cout << "Num Images: " << rec.getImages().getSize() << std::endl;
        }

        nitf_SubWindow_destruct(&subw);
        nitf_Field_destruct(&cField);
        nitf_BandInfo_destruct(&cBandInfo);
    }
    catch(except::Exception& ex)
    {
        std::cerr << "ERROR: " << ex.getMessage() << std::endl;
        return 1;
    }

    return 0;
}
      return fvMatrixHolder< Type >( laplacian( ds, field(), name ), Deps( &field ) );
    }
    
    template< class Type, class GType >
    inline fvMatrixHolder< Type > laplacian( const GeometricFieldHolder< GType, fvPatchField, volMesh >& field1, 
					     GeometricFieldHolder< Type, fvPatchField, volMesh >& field2 )
    {
      return fvMatrixHolder< Type >( laplacian( field1(), field2() ), Deps( &field1, &field2 )  );
    }
   
    template< class Type, class GType >
    inline fvMatrixHolder< Type > laplacian( const GeometricFieldHolder< GType, fvPatchField, volMesh >& field1, 
					     GeometricFieldHolder< Type, fvPatchField, volMesh >& field2
					     const word& name )
    {
      return fvMatrixHolder< Type >( laplacian( field1(), field2(), name ), Deps( &field1, &field2 )  );
    }

    template< class Type, class GType >
    inline fvMatrixHolder< Type > laplacian( const GeometricFieldHolder< GType, vsPatchField, surfaceMesh >& field1, 
					     GeometricFieldHolder< Type, fvPatchField, volMesh >& field2 )
    {
      return fvMatrixHolder< Type >( laplacian( field1(), field2() ), Deps( &field1, &field2 )  );
    }
   
    template< class Type, class GType >
    inline fvMatrixHolder< Type > laplacian( const GeometricFieldHolder< GType, vsPatchField, surfaceMesh >& field1, 
					     GeometricFieldHolder< Type, fvPatchField, volMesh >& field2
					     const word& name )
    {
      return fvMatrixHolder< Type >( laplacian( field1(), field2(), name ), Deps( &field1, &field2 )  );
示例#27
0
 ~A()
 {
     delete field2();
 }
示例#28
0
/*
 *	NAME
 *		stringSectionSize - determine memory needed for strings
 *
 *	SYNOPSIS
 */
static int
stringSectionSize(
    FILE *stream,
    int	*pNumEntries,
    int	*pSectionSize)
/*
 *	DESCRIPTION
 *		Determines the amount of memory required to store the
 *		color name strings and also the number of strings.
 *
 *	RETURNS
 *		XcmsSuccess if succeeded, otherwise XcmsFailure.
 *
 */
{
    char buf[XCMSDB_MAXLINELEN];
    char token[XCMSDB_MAXLINELEN];
    char token2[XCMSDB_MAXLINELEN];
    char *pBuf;
    char *f1;
    char *f2;
    size_t i;

    unsigned int numEntries = 0;
    unsigned int sectionSize = 0;

    *pNumEntries = 0;
    *pSectionSize = 0;

    /*
     * Advance to START_TOKEN
     *	 Anything before is just considered as comments.
     */

    while((pBuf = fgets(buf, XCMSDB_MAXLINELEN, stream)) != NULL) {
	if ((sscanf(buf, "%s %s", token, token2))
		&& (strcmp(token, START_TOKEN) == 0)) {
	    if (strcmp(token2, FORMAT_VERSION) != 0) {
		/* text file not in the right format */
		return(XcmsFailure);
	    }
	    break;
	} /* else it was just a blank line or comment */
    }

    if (pBuf == NULL) {
	return(XcmsFailure);
    }

    while((fgets(buf, XCMSDB_MAXLINELEN, stream)) != NULL) {
	if ((sscanf(buf, "%s", token)) && (strcmp(token, END_TOKEN) == 0)) {
	    break;
	}

	if (field2(buf, DELIM_CHAR, &f1, &f2) != XcmsSuccess) {
	    return(XcmsFailure);
	}

	numEntries++;
	if (numEntries >= INT_MAX)
	    return(XcmsFailure);

	i = strlen(f1);
	if (i >= INT_MAX - sectionSize)
	    return(XcmsFailure);
	sectionSize += i + 1;
	for (; i; i--, f1++) {
	    /* REMOVE SPACES FROM COUNT */
	    if (isspace(*f1)) {
		sectionSize--;
	    }
	}

	i = strlen(f2);
	if (i >= INT_MAX - sectionSize)
	    return(XcmsFailure);
	sectionSize += i + 1;
	for (; i; i--, f2++) {
	    /* REMOVE SPACES FROM COUNT */
	    if (isspace(*f2)) {
		sectionSize--;
	    }
	}

    }

    *pNumEntries = (int) numEntries;
    *pSectionSize = (int) sectionSize;

    return(XcmsSuccess);
}
示例#29
0
program()
{

    //check command syntax
    //edit filename
    if (dcount(COMMAND,FM)<2)
        abort("Syntax is 'edic osfilename'");

    var verbose=OPTIONS.ucase().index("V");

    var editor=osgetenv("VISUAL");
    var linenopattern="$LINENO ";
    if (not editor)
        editor.osgetenv("EDITOR");

    //TODO simplify this editor finding code

    //enable edit at first error for crimson editor (no quotes around filename for cedt)
    if (editor.lcase().index("cedt") and not editor.index("$") )
        editor^=" /L:$LINENO $FILENAME";

    //look for installed nano
    //if (SLASH eq "\\" and not index(PLATFORM_,"x64")) {
    var nanopath="";
    if (SLASH eq "\\") {

        //look for nano.exe next to edic.exe
        if (not editor)
            nanopath=EXECPATH.swap("edic","nano");
        if (nanopath.osfile())
            editor="nano $LINENO'$FILENAME'";
    }

    //look for nano in parent bin
    if (not editor) {
        nanopath="..\\bin\\nano.exe";
        if (nanopath.osfile())
            editor="nano $LINENO'$FILENAME'";
    }

    //look for nano in release directory during exodus development
    if (not editor) {
        nanopath="..\\..\\release\\cygwin\\bin\\nano.exe";
        if (nanopath.osfile())
            editor="..\\..\\release\\cygwin\\bin\\nano $LINENO'$FILENAME'";
        else {
            nanopath="..\\"^nanopath;
            if (nanopath.osfile())
                editor="..\\..\\..\\release\\cygwin\\bin\\nano $LINENO'$FILENAME'";
        }
    }

    if (editor.index("nano"))
        linenopattern="+$LINENO ";

    //otherwise on windows try to locate CYGWIN nano or vi
    var cygwinpath="";
    if (not editor and SLASH eq "\\") {
        //from environment variable
        cygwinpath=osgetenv("CYGWIN_BIN");
        //else from current disk
        if (not cygwinpath)
            cygwinpath="\\cygwin\\bin\\";
        //else from c:
        if (not osdir(cygwinpath))
            cygwinpath="c:\\cygwin\\bin\\";
        //else give up
        if (not osdir(cygwinpath))
            cygwinpath="";

        if (cygwinpath and cygwinpath[-1] ne SLASH)
            cygwinpath^=SLASH;
        //editor=cygwinpath^"bash --login -i -c \"/bin/";
        editor=cygwinpath;
        if (osfile(cygwinpath^"nano.exe") or osfile("nano.exe")) {
            editor="nano $LINENO'$FILENAME'";
            if (osfile(cygwinpath^"nano.exe"))
                editor.splicer(1,0,cygwinpath);
            //editor^="\"";
            linenopattern="+$LINENO ";
        } else if (osfile(cygwinpath^"vi.exe") or osfile("vi.exe")) {
            editor="vi -c \":$LINENO\" $FILENAME";
            if (osfile(cygwinpath^"vi.exe"))
                editor.splicer(1,0,cygwinpath);
            //editor^="\"";
        } else
            editor="";
    }
    if (SLASH eq "\\") {
        //configure nanorc (on windows)
        //TODO same for non-windows
        //nano on windows looks for nanorc config file as follows (probably merges all found)
        //C:\cygwin\usr\local\etc\nanorc
        //C:\cygwin\etc\nanorc (only if cygwin exists)
        //C:\Documents and Settings\USERNAME\.nanorc  ($HOMEDRIVE$HOMEPATH)
        var nanorcfilename;
        if (cygwinpath) {
            nanorcfilename=cygwinpath.field(SLASH,1,dcount(cygwinpath,SLASH)-2) ^ SLASH ^ "etc" ^ SLASH ^ "nanorc";
        } else {
            nanorcfilename=osgetenv("HOME");
            if (not nanorcfilename)
                nanorcfilename=osgetenv("HOMEDRIVE") ^ osgetenv("HOMEPATH");
            if (nanorcfilename[-1] ne SLASH)
                nanorcfilename^=SLASH;
            nanorcfilename^=".nanorc";
        }
        if (not osfile(nanorcfilename)) {
            //var nanorctemplatefilename=EXECPATH.field(SLASH,1,dcount(EXECPATH,SLASH)-1) ^ SLASH ^ "nanorc";
            var nanorctemplatefilename=nanopath.field(SLASH,1,dcount(nanopath,SLASH)-1) ^ SLASH ^ "nanorc";
            if (not osfile(nanorctemplatefilename))
                nanorctemplatefilename.swapper("release","..\\release");
            //if (not osfile(nanorctemplatefilename))
            //	nanorctemplatefilename.swapper("release","..\\"^PLATFORM_^"\\release");
            if (oscopy(nanorctemplatefilename,nanorcfilename)) {
                printl("Copied " ^ nanorctemplatefilename.quote() ^ " to " ^ nanorcfilename.quote());
                var ().input("Note: nano c++ syntax highlighting has been installed. Press Enter ... ");
            } else {
                errputl("Could not copy " ^ nanorctemplatefilename.quote() ^ " to " ^ nanorcfilename.quote());
                if (not osfile(nanorctemplatefilename))
                    errputl("nano syntax highlighting file is missing.");
            }
        }
        if(not osgetenv("HOME"))
            ossetenv("HOME",osgetenv("HOMEDRIVE") ^ osgetenv("HOMEPATH"));
    }

    if (not editor) {
        if (SLASH eq "/")
            editor="nano ";
        else
            editor="notepad";
        printl("Environment EDITOR not set. Using " ^ editor);
    }

    //editor="vi";
    editor.swapper("nano ", "nano --const --nowrap --autoindent --suspend ");

    if (editor.index("nano"))
        printl("http://www.nano-editor.org/dist/v2.1/nano.html");

    //configure nano syntax highlighting
    var filenames=field(COMMAND,FM,2,99999);
    var nfiles=dcount(filenames,FM);
    var filen=0;
    while (filen<nfiles) {
        filen+=1;
        var filename=filenames.a(filen).unquote();

        //split out trailing line number after :
        var startatlineno=field(filename,":",2);
        if (startatlineno.isnum())
            filename=field(filename,":",1);
        else
            startatlineno="";

        filename.trimmerb(".");
        if (not index(field2(filename,SLASH,-1),"."))
            filename^=".cpp";

        var iscompilable=filename.field2(".",-1)[1].lcase() ne "h";

        //make absolute in case EDITOR changes current working directory
        var editcmd=editor;
        if (editcmd.index("$ABSOLUTEFILENAME")) {
            editcmd.swapper("$ABSOLUTEFILENAME","$FILENAME");

            filename=oscwd()^SLASH^filename;
        }
        //prepare a skeleton exodus cpp file
        var newfile=false;
        if (iscompilable and not osfile(filename)) {

            var basefilename=field2(filename,SLASH,-1);
            basefilename=basefilename.field(".",dcount(basefilename,".")-1);

            var progtype;
            var question="1=Normal Program, 2=External Subroutine or Function";
            //question^="\n3=main(), 4=simple so/dll\n";
            question^="\n"^basefilename.quote()^" does not exist. Create what? (1-2) ";
            while (true) {
                if (basefilename.substr(1,5).lcase() eq "dict_")
                    progtype=5;
                else
                    progtype.input(question);
                if (progtype eq 2)
                    progtype="classlib";
                else if (progtype eq 3)
                    progtype="main";
                else if (progtype eq 4)
                    progtype="mainlib";
                else if (progtype eq 1)
                    progtype="class";
                else if (progtype eq 5)
                    progtype="dict";
                else
                    stop();
                break;
            }

            newfile=true;
            var blankfile="";
            if (progtype eq "main" or progtype eq "mainlib") {
                startatlineno="4,9";
                blankfile^="#include <exodus/exodus.h>\n";
                blankfile^="\n";
                blankfile^="program() {\n";
                blankfile^="\tprintl(\""^basefilename^" says 'Hello World!'\");\n";
                if (progtype eq "mainlib")
                    blankfile^="\treturn 0;\n";
                blankfile^="}\n";
                if (progtype eq "mainlib")
                    blankfile.swapper("program()","function "^basefilename^"()");
            } else if (progtype eq "class" or progtype eq "classlib") {
                startatlineno="6,9";
                blankfile^="#include <exodus/program.h>\n";
                //programinit() as 2nd line to avoid ppl in external functions before programinit
                //blankfile^="\n";
                blankfile^="programinit()\n";
                blankfile^="\n";
                blankfile^="function main(";
                //the .h maker not able to parse this yet and is rather clumsy anyway
                //if (progtype eq "classlib")
                //	blankfile^="/*in arg1, out arg2*/";
                blankfile^=") {\n";
                blankfile^="\tprintl(\""^basefilename^" says 'Hello World!'\");\n";
                blankfile^="\treturn 0;\n";
                blankfile^="}\n";
                blankfile^="\nprogramexit()";
                blankfile^="\n";

                if (progtype eq "classlib")
                    blankfile.swapper("program","library");
            } else if (progtype eq "dict") {
                startatlineno="6,9";
                blankfile^="#include <exodus/dict.h>\n\n";
                //programinit() as 2nd line to avoid ppl in external functions before programinit
                //blankfile^="\n";
                blankfile^="dict(EXAMPLEDICTID1) {\n";
                blankfile^="\tANS=RECORD(1)^\"x\";\n";
                blankfile^="}\n\n";

                blankfile^="dict(EXAMPLEDICTID2) {\n";
                blankfile^="\tANS=RECORD(2)^\"x\";\n";
                blankfile^="}\n";

            }

            if (blankfile[1] ne "\n")
                blankfile^="\n";
            if (SLASH ne "/")
                blankfile.swapper("\n","\r\n");

            if (not oswrite(blankfile,filename))
                stop("Cannot create "^filename^". Invalid file name, or no rights here.");
            //      startatlineno="4,9";
            //startatlineno="";
        }

        var editcmd0=editcmd;
        var linenopattern0=linenopattern;

        //keep editing and compiling until no errors
        while (true) {

            editcmd=editcmd0;
            linenopattern=linenopattern0;

            //record the current file update timestamp
            var fileinfo=osfile(filename);

            //build the edit command
            if (editcmd.index("$LINENO")) {
                if (not startatlineno)
                    linenopattern="";
                else
                    linenopattern.swapper("$LINENO",startatlineno.field(",",1));
                editcmd.swapper("$LINENO",linenopattern);
            }
            if (editcmd.index("$FILENAME"))
                editcmd.swapper("$FILENAME",filename);
            else
                editcmd ^= " " ^ filename;

            //call the editor
            if (verbose)
                printl(editcmd);
            osshell(editcmd);

            //if the file hasnt been updated
            var fileinfo2=osfile(filename);
            if (fileinfo2 ne fileinfo)
                newfile=false;
            else {
                //delete the skeleton
                printl("File unchanged. Not saving.");
                if (newfile)
                    osdelete(filename);
                //move to the next file
                break;
            }

            //clear the screen (should be cls on win)
            if (SLASH eq "/")
                osshell("clear");
            //else
            //	osshell("cls");

            if (not iscompilable)
                break;

            //build the compiler command
            var compiler="compile";
            var compileoptions="";
            var compilecmd=compiler ^ " " ^ filename.quote() ^ compileoptions;
            //capture the output
            var compileoutputfilename=filename ^ ".2";
            if (SLASH eq "/")
                compilecmd ^= " 2>&1 | tee " ^ compileoutputfilename.quote();
            else
                compilecmd ^= " > " ^ compileoutputfilename.quote() ^ " 2>&1";

            //call the compiler
            if (verbose)
                printl(compilecmd);
            osshell(compilecmd);

            //var tt;
            //tt.inputl("Press Enter ...");

            //if any errors then loop back to edit again
            var errors;
            if (osread(errors,compileoutputfilename)) {
                osdelete(compileoutputfilename);

                if (SLASH ne "/")
                    print(errors);

                startatlineno="";
                var charn;
                //gnu style error lines
                if (charn=index(errors, ": error:")) {
                    startatlineno=errors.substr(charn-9,9);

                    //printl(startatlineno);
                    startatlineno=startatlineno.field2(":",2);
                    //printl(startatlineno);
                    //msvc style error lines
                    //test.cpp(6) : error C2143: syntax error : missing ';' before '}'
                } else if (charn=index(errors,") : error ")) {
                    startatlineno=errors.substr(charn-10,10).field2("(",2);
                }
                if (startatlineno) {
                    print("Press any key to re-edit at line "^startatlineno^" ... ");
                    var().input("");
                    continue;
                }
            }

            break;
        }

    }
}
示例#30
0
/*
 *	NAME
 *		ReadColornameDB - Read the Color Name Database
 *
 *	SYNOPSIS
 */
static Status
ReadColornameDB(
    FILE *stream,
    XcmsPair *pRec,
    char *pString)
/*
 *	DESCRIPTION
 *		Loads the Color Name Database from a text file.
 *
 *	RETURNS
 *		XcmsSuccess if succeeded, otherwise XcmsFailure.
 *
 */
{
    char buf[XCMSDB_MAXLINELEN];
    char token[XCMSDB_MAXLINELEN];
    char token2[XCMSDB_MAXLINELEN];
    char *f1;
    char *f2;
    char *pBuf;

    /*
     * Advance to START_TOKEN
     *	 Anything before is just considered as comments.
     */

    while((pBuf = fgets(buf, XCMSDB_MAXLINELEN, stream)) != NULL) {
	if ((sscanf(buf, "%s %s", token, token2))
		&& (strcmp(token, START_TOKEN) == 0)) {
	    if (strcmp(token2, FORMAT_VERSION) != 0) {
		/* text file not in the right format */
		return(XcmsFailure);
	    }
	    break;
	} /* else it was just a blank line or comment */
    }

    if (pBuf == NULL) {
	return(XcmsFailure);
    }

    /*
     * Process lines between START_TOKEN to END_TOKEN
     */

    while ((fgets(buf, XCMSDB_MAXLINELEN, stream)) != NULL) {
	if ((sscanf(buf, "%s", token)) && (strcmp(token, END_TOKEN) == 0)) {
	    /*
	     * Found END_TOKEN so break out of for loop
	     */
	    break;
	}

	/*
	 * Get pairs
	 */
	if (field2(buf, DELIM_CHAR, &f1, &f2) != XcmsSuccess) {
	    /* Invalid line */
	    continue;
	}

	/*
	 * Add strings
	 */

	/* Left String */
	pRec->first = pString;
	_XcmsCopyISOLatin1Lowered(pString, f1);
	pString += (1 + RemoveSpaces(pString));
	pRec->second = pString;
	/* Right String */
	_XcmsCopyISOLatin1Lowered(pString, f2);
	pString += RemoveSpaces(pString) + 1;
	pRec++;

    }

    return(XcmsSuccess);
}