Пример #1
0
void writeTypedListElement( TAThread thread, const TypedListElement * value ) {
    const int * start;
    switch ( value->type ) {
        case IntTObjCode    : writeString( thread, "IntTObj"     ); writeInt   ( thread, value->data.IntTObj     ); break;
        case CharTObjCode   : writeString( thread, "CharTObj"    ); writeChar  ( thread, value->data.CharTObj    ); break;
        case ShortTObjCode  : writeString( thread, "ShortTObj"   ); writeShort ( thread, value->data.ShortTObj   ); break;
        case LongTObjCode   : writeString( thread, "LongTObj"    ); writeLong  ( thread, value->data.LongTObj    ); break;
        case LLongTObjCode  : writeString( thread, "LLongTObj"   ); writeLLong ( thread, value->data.LLongTObj   ); break;
        case IntMaxTObjCode : writeString( thread, "IntMaxTObj"  ); writeIntMax( thread, value->data.IntMaxTObj  ); break;
        case SizeTObjCode   : writeString( thread, "SizeTObj"    ); writeSize  ( thread, value->data.SizeTObj    ); break;
        case PtrDiffTObjCode: writeString( thread, "PtrDiffTObj" ); writeLong  ( thread, value->data.PtrDiffTObj ); break;
        case WIntTObjCode   : writeString( thread, "WIntTObj"    ); writeWChar ( thread, value->data.WIntTObj    ); break;
        case FloatTObjCode:
            start = (int *)& value->data.FloatTObj;
            writeString( thread, "FloatTObj" );
            writeIntArray( thread, start, sizeof( float ) / sizeof( int ) );
            break;
        case DoubleTObjCode:
            start = (int *)& value->data.DoubleTObj;
            writeString( thread, "DoubleTObj" );
            writeIntArray( thread, start, sizeof( double ) / sizeof( int ) );
            break;
        case LongDoubleTObjCode:
            start = (int *)& value->data.LongDoubleTObj;
            writeString( thread, "LongDoubleTObj" );
            writeIntArray( thread, start, sizeof( long double ) / sizeof( int ) );
            break;
        case CStringCode    : writeString( thread, "CString"     ); writeString ( thread, value->data.CString     ); break;
        case WStringCode    : writeString( thread, "WString"     ); writeWString( thread, value->data.WString     ); break;
        case VoidTPtrObjCode: writeString( thread, "VoidTPtrObj" ); writePointer( thread, value->data.VoidTPtrObj ); break;
        default: assertion( 0, "writeTypedListElement : unsupported type" ); break;
    }
} // writeTypedListElement
Пример #2
0
/*
 * Writes an integer array of len length to a file fileName.
 * Returns 0 if successful, 1 if not.
 */
int writeIntArrayFile( const char* fileName, int * ar, size_t len ){
    FILE * matrixFile;
#ifdef OS_LINUX
    matrixFile = fopen( fileName, "w" );
    if( matrixFile==NULL ){
        printf("Error in attempt to write \"%s\" file\n",fileName);
        return 1;
    }
#endif
#ifdef OS_WIN
    errno_t err;
    err = fopen_s( &matrixFile, fileName, "wb" );
    if( err!=0 ){
        printf("Error in attempt to write \"%s\" file\n",fileName);
        return 1;
    }
#endif
    fseek(matrixFile,0,SEEK_SET);       // go to the top of file

    int ret = 0;
    ret = writeFileStart( matrixFile );      if(ret<0) goto writeIntArrayFileLabel;

    size_t sr;
    size_t si;
    si = sizeof(long long int); sr = writeAll( matrixFile, (void *)&len, si );
    if( checkTransfer( "writeCMatrix/1", si, sr, dPRINTOK ) ) goto writeIntArrayFileLabel;

    writeIntArray( matrixFile, ar, len );

    fflush( matrixFile );
writeIntArrayFileLabel:
    fclose(matrixFile);
    return ret;
}
void DataOutputStream::writeArray(const osg::Array* a){
    switch(a->getType()){
        case osg::Array::IntArrayType:
            writeChar((char)0);
            writeIntArray(static_cast<const osg::IntArray*>(a));
            break;
        case osg::Array::UByteArrayType:
            writeChar((char)1);
            writeUByteArray(static_cast<const osg::UByteArray*>(a));
            break;
        case osg::Array::UShortArrayType:
            writeChar((char)2);
            writeUShortArray(static_cast<const osg::UShortArray*>(a));
            break;
        case osg::Array::UIntArrayType:
            writeChar((char)3);
            writeUIntArray(static_cast<const osg::UIntArray*>(a));
            break;
        case osg::Array::Vec4ubArrayType:
            writeChar((char)4);
            writeVec4ubArray(static_cast<const osg::Vec4ubArray*>(a));
            break;
        case osg::Array::FloatArrayType:
            writeChar((char)5);
            writeFloatArray(static_cast<const osg::FloatArray*>(a));
            break;
        case osg::Array::Vec2ArrayType:
            writeChar((char)6);
            writeVec2Array(static_cast<const osg::Vec2Array*>(a));
            break;
        case osg::Array::Vec3ArrayType:
            writeChar((char)7);
            writeVec3Array(static_cast<const osg::Vec3Array*>(a));
            break;
         case osg::Array::Vec4ArrayType:
            writeChar((char)8);
            writeVec4Array(static_cast<const osg::Vec4Array*>(a));
            break;
         case osg::Array::Vec2sArrayType:
             writeChar((char)9);
             writeVec2sArray(static_cast<const osg::Vec2sArray*>(a));
             break;
         case osg::Array::Vec3sArrayType:
             writeChar((char)10);
             writeVec3sArray(static_cast<const osg::Vec3sArray*>(a));
             break;
         case osg::Array::Vec4sArrayType:
             writeChar((char)11);
             writeVec4sArray(static_cast<const osg::Vec4sArray*>(a));
             break;
         case osg::Array::Vec2bArrayType:
             writeChar((char)12);
             writeVec2bArray(static_cast<const osg::Vec2bArray*>(a));
             break;
         case osg::Array::Vec3bArrayType:
             writeChar((char)13);
             writeVec3bArray(static_cast<const osg::Vec3bArray*>(a));
             break;
         case osg::Array::Vec4bArrayType:
             writeChar((char)14);
             writeVec4bArray(static_cast<const osg::Vec4bArray*>(a));
             break;
        default: throw Exception("Unknown array type in DataOutputStream::writeArray()");
    }
}