void FgfUtil::WriteCurveSegment(FdoICurveSegmentAbstract* curveSeg, FdoByteArray ** outputStream) { /* * Note: This function **doesn't** write the first position * of the segment being written. This is to make it compatible with * memory layout of CurveString FGF. */ if ( (NULL == curveSeg) || (NULL == outputStream) ) throw FdoException::Create(FdoException::NLSGetMessage(FDO_NLSID(FDO_1_INVALID_INPUT_ON_CLASS_FUNCTION), L"FgfUtil::WriteCurveSegment", L"curveSeg/outputStream")); FdoGeometryComponentType geomType = curveSeg->GetDerivedType(); // Geometry type FGFUTIL_WRITE_INT32(outputStream, geomType); switch (geomType) { case FdoGeometryComponentType_CircularArcSegment: { // Positions, will be three, but only two // will be written (mid and end) because start pos is either // stored as member of CurveString or as end point of // previous segment FdoPtr<FdoIDirectPosition> midPos = ((FdoICircularArcSegment*)curveSeg)->GetMidPoint(); FdoPtr<FdoIDirectPosition> endPos = ((FdoICircularArcSegment*)curveSeg)->GetEndPosition(); WriteDirectPosition(outputStream, midPos); WriteDirectPosition(outputStream, endPos); break; } case FdoGeometryComponentType_LineStringSegment: { // Although this segment has numPositions positions, // we will write numPositions-1 because its start position // has already been written as end point of previous segment // and we will be writing numPosition-1 positions in fgf buffer FdoILineStringSegment * lss = (FdoILineStringSegment*)curveSeg; FdoInt32 dimensionality = lss->GetDimensionality(); FdoInt32 numPositions = lss->GetCount(); FGFUTIL_WRITE_INT32(outputStream, numPositions-1); FdoInt32 numOrdsPerPos = GeometryUtility::DimensionalityToNumOrdinates(dimensionality); FdoInt32 numOrds = (numPositions-1) * numOrdsPerPos; const double * ordinates = lss->GetOrdinates(); ordinates += numOrdsPerPos; FGFUTIL_WRITE_DOUBLES(outputStream, numOrds, ordinates); break; } default: { throw FdoException::Create(FdoException::NLSGetMessage(FDO_NLSID(FDO_1_UNKNOWN_GEOMETRY_COMPONENT_TYPE), L"FgfUtil::WriteCurveSegment", geomType)); } } // of switch }
void FgfUtil::WriteRing(FdoIRing* ring, FdoByteArray ** outputStream) { if ( (NULL == ring) || (NULL == outputStream) ) throw FdoException::Create(FdoException::NLSGetMessage(FDO_NLSID(FDO_1_INVALID_INPUT_ON_CLASS_FUNCTION), L"FgfUtil::WriteRing", L"ring/outputSream")); // StartPoint FdoPtr<FdoICurveSegmentAbstract> curveSeg = ring->GetItem(0); FdoPtr<FdoIDirectPosition> startPos = curveSeg->GetStartPosition(); WriteDirectPosition(outputStream, startPos); // NumElements (segments) FdoInt32 numCurveSegs = ring->GetCount(); FGFUTIL_WRITE_INT32(outputStream, numCurveSegs); // CurveSegs for (FdoInt32 i=0; i<numCurveSegs; i++) { FdoPtr<FdoICurveSegmentAbstract> curveSeg = ring->GetItem(i); WriteCurveSegment(curveSeg, outputStream); } }
/// <summary>Opens a feature connection with the settings specified by the /// ConnectionString attribute of the provider-specific feature connection /// object.</summary> /// <returns>Returns nothing</returns> FdoConnectionState SuperMapConnection::Open () { TRACE(_T("调用 SuperMapConnection::Open ...\n")); if (GetConnectionState() == FdoConnectionState_Open) throw FdoException::Create(FdoException::NLSGetMessage(FDO_NLSID(FDO_103_CONNECTION_ALREADY_OPEN))); // Disconnect if currently 'partially' connected (but not if already 'fully' connected): if (GetConnectionState() == FdoConnectionState_Pending) Close(); /* DEL ***************************************** FdoPtr<ConnectionProperty> datastoreProperty = dictionary->FindProperty(CONNECTIONPROPERTY_DATASTORE); // Create an enum list with a single "Default Datastore" entry: wchar_t **enumArray = new wchar_t*[1]; enumArray[0] = new wchar_t[wcslen(L"测试")+1]; wcscpy(enumArray[0], L"测试"); datastoreProperty->UpdateEnumerableProperties(1, (const wchar_t**)enumArray); if (FdoConnectionState_Pending == GetConnectionState ()) datastoreProperty->SetIsPropertyRequired (true); ************************************************/ m_strConnectionSession = SuperMapConnectionPool::GetInstance()->GetConnectionInfo(this); if (m_strConnectionSession != "") m_ConnectionState = FdoConnectionState_Open; else m_ConnectionState = FdoConnectionState_Closed; return (GetConnectionState ()); }
int FdoCommonOSUtil::ismbslead(const unsigned char *string, const unsigned char *current) { #ifdef _WIN32 return _ismbslead(string, current); #else // _WIN32 mbstate_t pstate; int i = 0; int curPos = 0; int inquiryPos = (int)(current - string); int ret = 0; memset(&pstate, 0, sizeof(pstate)); do { if (inquiryPos == curPos) { ret = -1; break; } i = mbrlen((const char*)(string + curPos), MB_CUR_MAX, &pstate); if (i < 0) throw FdoException::Create(FdoException::NLSGetMessage(FDO_NLSID(FDO_1_INVALID_INPUT_ON_CLASS_FUNCTION), L"FdoCommonOSUtil::ismbslead", L"string")); if (i > 0) curPos += i; } while (i > 0); return ret; #endif }
void FdoXmlSpatialContextReader::ThrowOnNotRead( FdoString* function ) { if ( mSCHandler->mSCName.GetLength() == 0 ) // No currently read spatial context, so throw an error. throw FdoException::Create( FdoException::NLSGetMessage( FDO_NLSID(SC_4_XMLNOREAD), function ) ); }
int FdoCommonOSUtil::ismbcalpha(const unsigned char *string, long stringLength, const unsigned char *current) { wchar_t wBuffer; mbstate_t pstate; memset(&pstate, 0, sizeof(pstate)); size_t lStatus = mbrtowc(&wBuffer, (const char*)current, stringLength - (current-string), &pstate); if (lStatus<0) throw FdoException::Create(FdoException::NLSGetMessage(FDO_NLSID(FDO_1_INVALID_INPUT_ON_CLASS_FUNCTION), L"FdoCommonOSUtil::ismbcalpha", L"string/current")); return iswalpha(wBuffer) ? -1 : 0; }
FdoSize FdoIoMemoryStream::Read( FdoByte* buffer, FdoSize count ) { // Validate the parameters. if ( !buffer ) throw FdoException::Create( FdoException::NLSGetMessage( FDO_NLSID(FDO_30_BADPARAM), L"buffer", L"(NULL)", L"FdoIoMemoryStream::Read" ) ); // The data to read can include parts of or complete buffers. It can also // span buffers. // Create a temporary buffer for reading the data from each internal buffer. FdoIoBufferStreamP bufIter = FdoIoBufferStream::Create( buffer, count ); FdoSize bufNum = 0; FdoSize bufOffset = 0; // Given the current position, get the corresponding internal buffer and // offset with the buffer. Reading will start in this buffer. GetBufPosn( bufNum, bufOffset ); // Read until end of this stream is reached or we have enough bytes. while ( (bufNum < ((FdoSize) mBuffers->GetCount())) && (bufIter->GetIndex() < bufIter->GetLength() ) ) { // Get the current internal buffer. FdoIoBufferStreamP intBuf = mBuffers->GetItem(bufNum); // Position the buffer to the current offset. intBuf->Reset(); intBuf->Skip( bufOffset ); // Write the remainder of the internal buffer to the temporary buffer or // the number of bytes left to read, whichever is less. bufIter->Write( intBuf, (FdoSize)(bufIter->GetLength() - bufIter->GetIndex()) ); // Increment to read from the next internal buffer. bufNum++; bufOffset = 0; } // Update the current position. mPos += bufIter->GetIndex(); return (FdoSize) bufIter->GetIndex(); }
FdoIoTextWriter* FdoIoTextWriter::Create( FdoIoStream* stream ) { if ( !stream ) throw FdoException::Create( FdoException::NLSGetMessage( FDO_NLSID(FDO_30_BADPARAM), L"stream", L"(NULL)", L"FdoIoTextWriter::Create" ) ); return( new FdoIoTextWriter(stream) ); }
void FdoIoMemoryStream::Write( FdoByte* buffer, FdoSize count ) { if ( !buffer ) throw FdoException::Create( FdoException::NLSGetMessage( FDO_NLSID(FDO_30_BADPARAM), L"buffer", L"(NULL)", L"FdoIoMemoryStream::Write" ) ); // Wrap a stream around the buffer and delegate to write from stream. FdoIoBufferStreamP bufStream = FdoIoBufferStream::Create( buffer, count ); Write( bufStream, 0 ); }
FdoXmlSpatialContextReader* FdoXmlSpatialContextReader::Create( FdoXmlReader* reader, FdoXmlSpatialContextFlags* flags ) { if ( !reader ) throw FdoException::Create( FdoException::NLSGetMessage( FDO_NLSID(FDO_30_BADPARAM), L"reader", L"(NULL)", L"FdoXmlSpatialContextReader::Create" ) ); return new FdoXmlSpatialContextReader( reader, flags ); }
void FdoPropertyDefinition::Set( FdoPropertyDefinition* pProperty, FdoSchemaMergeContext* pContext ) { if ( GetPropertyType() != pProperty->GetPropertyType() ) { pContext->AddError( FdoSchemaExceptionP( FdoSchemaException::Create( FdoException::NLSGetMessage( FDO_NLSID(SCHEMA_25_PROPERTYTYPECONFLICT), (FdoString*) GetQualifiedName() ) ) ) ); return; } FdoSchemaElement::Set(pProperty, pContext); }
FdoIGeometry* FgfUtil::ReadGeometryFromAggregate(FdoFgfGeometryFactory * factory, FdoInt32 Index, FdoGeometryType expectedGeometryType, const FdoByte ** inputStream, const FdoByte * streamEnd) { FGFUTIL_SKIP_INT32S(inputStream, streamEnd, 1); // Skip over geomtype FdoInt32 numSubGeometries = FgfUtil::ReadInt32(inputStream, streamEnd); if ( (Index >= numSubGeometries) || (Index < 0) ) throw FdoException::Create(FdoException::NLSGetMessage(FDO_NLSID(FDO_1_INDEXOUTOFBOUNDS))); // Skip sub-geometries that precede the desired one. for (FdoInt32 i=0; i<Index; i++) { FgfUtil::SkipGeometry(inputStream, streamEnd); } FdoPtr<FdoIGeometry> geometry = FgfUtil::ReadGeometry(factory, expectedGeometryType, inputStream, streamEnd); return FDO_SAFE_ADDREF(geometry.p); }
FdoFgfCurveString::FdoFgfCurveString( FdoFgfGeometryFactory * factory, FdoFgfGeometryPools * pools, FdoCurveSegmentCollection* curveSegs ) : FdoFgfGeometryImpl<FdoICurveString>(factory, pools) { if ( (NULL == curveSegs) || (0 == curveSegs->GetCount()) ) throw FdoException::Create(FdoException::NLSGetMessage(FDO_NLSID(FDO_1_INVALID_INPUT_ON_CLASS_CREATION), L"FdoFgfCurveString", L"curveSegs/factory")); FdoByteArray * newByteArray = FgfUtil::GetPoolsNoRef(m_pools)->GetByteArray(); // Geometrytype FGFUTIL_WRITE_INT32(&newByteArray, FdoGeometryType_CurveString); // Coordtype - from 1st element in curveSegs array FdoPtr<FdoICurveSegmentAbstract> firstCurve = curveSegs->GetItem(0); FdoInt32 dimensionality = firstCurve->GetDimensionality(); FGFUTIL_WRITE_INT32(&newByteArray, dimensionality); // Startpoint - from 1st element in curveSegs array FdoPtr<FdoIDirectPosition> startPos = firstCurve->GetStartPosition(); FgfUtil::WriteDirectPosition(&newByteArray, startPos); // Number of curveSegs FGFUTIL_WRITE_INT32(&newByteArray, curveSegs->GetCount()); // CurveSegs for (FdoInt32 i=0; i<curveSegs->GetCount(); i++) { FdoPtr<FdoICurveSegmentAbstract> curveSeg = curveSegs->GetItem(i); FgfUtil::WriteCurveSegment(curveSeg, &newByteArray); } SetFgf(newByteArray, NULL, 0); FDO_SAFE_RELEASE(newByteArray); }
void FgfUtil::SkipCurveSegments( FdoInt32 numSegs, FdoInt32 dimensionality, const FdoByte ** inputStream, const FdoByte * streamEnd) { if (0 == numSegs) return; FdoInt32 numOrdsPerPos = GeometryUtility::DimensionalityToNumOrdinates(dimensionality); for (FdoInt32 i=0; i<numSegs; i++) { // FdoGeometryType FdoGeometryComponentType geomType = (FdoGeometryComponentType)ReadInt32(inputStream, streamEnd); FdoInt32 numPositions = 0; switch(geomType) { case FdoGeometryComponentType_CircularArcSegment: { numPositions = 2; break; } case FdoGeometryComponentType_LineStringSegment: { numPositions = ReadInt32(inputStream, streamEnd); break; } default: throw FdoException::Create(FdoException::NLSGetMessage(FDO_NLSID(FDO_1_UNKNOWN_GEOMETRY_COMPONENT_TYPE), L"FgfUtil::SkipCurveSegments", geomType)); } // of switch FGFUTIL_SKIP_DIRECTPOSITIONS(inputStream, streamEnd, numOrdsPerPos, numPositions); } // of for }
FdoIGeometry * FgfUtil::ReadGeometry(FdoFgfGeometryFactory * factory, FdoGeometryType expectedGeometryType, const FdoByte ** inputStream, const FdoByte * streamEnd) { FdoPtr<FdoIGeometry> geometry; const FdoByte * streamStartOfGeometry = *inputStream; FgfUtil::SkipGeometry(inputStream, streamEnd); const FdoByte * streamEndOfGeometry = *inputStream; FdoInt32 streamSizeOfGeometry = (FdoInt32)(streamEndOfGeometry - streamStartOfGeometry); // Copy the FGF data to a new (possibly pooled) byte array. // Don't use "FdoPtr" smart pointer while the array is being updated. FdoByteArray * newByteArray = factory->GetByteArray(); newByteArray = FdoByteArray::Append(newByteArray, streamSizeOfGeometry, (FdoByte *)streamStartOfGeometry); // Create a new (possibly pooled) geometry from the byte array. geometry = factory->CreateGeometryFromFgf(newByteArray); if (FdoGeometryType_None != expectedGeometryType && expectedGeometryType != geometry->GetDerivedType()) throw FdoException::Create(FdoException::NLSGetMessage(FDO_NLSID(FDO_7_INVALIDFGF))); FDO_SAFE_RELEASE(newByteArray); return FDO_SAFE_ADDREF(geometry.p); }
void FdoPropertyDefinition::InitFromXml(FdoSchemaXmlContext* pContext, FdoXmlAttributeCollection* attrs) { FdoSchemaXmlContext* fdoContext = (FdoSchemaXmlContext*) pContext; FdoSchemaElement::InitFromXml(pContext, attrs ); // If property already exists, make sure type change is not attempted. if (FdoSchemaElementP (GetParent())) { FdoClassDefinitionP pOldClass = fdoContext->GetMergeContext()->FindClass( FdoFeatureSchemasP( fdoContext->GetMergeContext()->GetSchemas() ), FdoFeatureSchemaP(GetFeatureSchema())->GetName(), FdoSchemaElementP(GetParent())->GetName() ); if ( pOldClass != NULL ) { FdoPropertyP pOldProp = FdoPropertiesP( pOldClass->GetProperties() )->FindItem( GetName() ); if ( pOldProp && (pOldProp->GetPropertyType() != GetPropertyType()) ) { pContext->AddError( FdoSchemaExceptionP( FdoSchemaException::Create( FdoException::NLSGetMessage( FDO_NLSID(SCHEMA_25_PROPERTYTYPECONFLICT), (FdoString*) GetQualifiedName() ) ) ) ); return; } } } }
// Converts the filter expression to it's well defined text representation. FdoString* FdoComparisonCondition::ToStringInternal( FdoIdentifierCollection *pIdCol ) { FdoStringUtility::ClearString(m_toString); FdoExpression* pRight = GetRightExpression(); FdoExpression* pLeft = GetLeftExpression(); if (pRight == NULL || pLeft == NULL) { FDO_SAFE_RELEASE(pRight); FDO_SAFE_RELEASE(pLeft); FdoFilterException* pExcept = FdoFilterException::Create(FdoException::NLSGetMessage(FDO_NLSID(FILTER_2_INCOMPLETECOMPARISONCONDITION))); throw pExcept; } const wchar_t* szOp; switch (GetOperation()) { default: case FdoComparisonOperations_EqualTo: szOp = L" = "; break; case FdoComparisonOperations_NotEqualTo: szOp = L" <> "; break; case FdoComparisonOperations_GreaterThan: szOp = L" > "; break; case FdoComparisonOperations_GreaterThanOrEqualTo: szOp = L" >= "; break; case FdoComparisonOperations_LessThan: szOp = L" < "; break; case FdoComparisonOperations_LessThanOrEqualTo: szOp = L" <= "; break; case FdoComparisonOperations_Like: szOp = L" LIKE "; break; } try { m_toString = FdoStringUtility::MakeString(pLeft->ToStringInternal( pIdCol ), szOp, pRight->ToStringInternal( pIdCol )); } catch (FdoException* pExcept) { FDO_SAFE_RELEASE(pRight); FDO_SAFE_RELEASE(pLeft); throw pExcept; } pLeft->Release(); pRight->Release(); return m_toString; }
// Returns the well defined text representation of this expression. FdoString* FdoParameter::ToString() { FdoStringUtility::ClearString(m_toString); // if NULL string or no quotes or spaces, then don't quote. if (GetName() == NULL) { FdoExpressionException* pExcept = FdoExpressionException::Create(FdoException::NLSGetMessage(FDO_NLSID(EXPRESSION_10_INCOMPLETEPARAMETER))); throw pExcept; } if (FdoStringUtility::FindCharacter(GetName(), L' ') == NULL && FdoStringUtility::FindCharacter(GetName(), L'\'') == NULL) m_toString = FdoStringUtility::MakeString(L":", GetName()); else { wchar_t* pszTemp = FdoStringUtility::QuoteString(GetName(), L'\''); m_toString = FdoStringUtility::MakeString(L":", pszTemp); FdoStringUtility::ClearString(pszTemp); } return m_toString; }
// Gets the DataValue as a 64 bit integer. FdoInt64 FdoInt64Value::GetInt64() { if (IsNull()) { FdoExpressionException* pExcept = FdoExpressionException::Create(FdoException::NLSGetMessage(FDO_NLSID(EXPRESSION_14_INT64VALUENULL))); throw pExcept; } return m_data; }
FdoInt64Value* FdoInt64Value::Create( FdoDataValue* src, FdoBoolean nullIfIncompatible, FdoBoolean shift, FdoBoolean truncate ) { FdoInt64Value* ret = NULL; FdoDouble int64DblMax = (pow((FdoDouble)2, (FdoDouble)52) - 1) * pow((FdoDouble)2, (FdoDouble)11); FdoFloat int64SglMax = (pow((FdoFloat)2, (FdoFloat)23) - 1) * pow((FdoFloat)2, (FdoFloat)40); if ( !src->IsNull() ) { switch ( src->GetDataType() ) { case FdoDataType_Boolean: // Convert to numeric ret = FdoInt64Value::Create( static_cast<FdoBooleanValue*>(src)->GetBoolean() ? 1 : 0 ); break; case FdoDataType_Byte: // copy without truncation or shifting ret = FdoInt64Value::Create( (FdoInt64)(static_cast<FdoByteValue*>(src)->GetByte()) ); break; case FdoDataType_Decimal: // Copy with possible truncation and rounding { FdoDecimalValue* src2 = static_cast<FdoDecimalValue*>(src); ret = Convert<FdoDecimalValue, FdoInt64Value, FdoDouble, FdoInt64>( src2, src2->GetDecimal(), FdoInt64Min, FdoInt64Max, pow((double)2, (double)63), 0.5, nullIfIncompatible, shift, truncate, FdoDataTypeMapper::Type2String(FdoDataType_Int64) ); } break; case FdoDataType_Double: // Copy with possible truncation and rounding { FdoDoubleValue* src2 = static_cast<FdoDoubleValue*>(src); ret = Convert<FdoDoubleValue, FdoInt64Value, FdoDouble, FdoInt64>( src2, src2->GetDouble(), FdoInt64Min, FdoInt64Max, pow((double)2, (double)63), 0.5, nullIfIncompatible, shift, truncate, FdoDataTypeMapper::Type2String(FdoDataType_Int64) ); } break; case FdoDataType_Int16: // copy without truncation or shifting ret = FdoInt64Value::Create( (FdoInt64)(static_cast<FdoInt16Value*>(src)->GetInt16()) ); break; case FdoDataType_Int32: // copy without truncation or shifting ret = FdoInt64Value::Create( (FdoInt64)(static_cast<FdoInt32Value*>(src)->GetInt32()) ); break; case FdoDataType_Int64: // Same types, simple copy. ret = FdoInt64Value::Create( static_cast<FdoInt64Value*>(src)->GetInt64() ); break; case FdoDataType_Single: // Copy with possible truncation and rounding { FdoSingleValue* src2 = static_cast<FdoSingleValue*>(src); ret = Convert<FdoSingleValue, FdoInt64Value, FdoFloat, FdoInt64>( src2, src2->GetSingle(), FdoInt64Min, FdoInt64Max, (FdoFloat)pow((double)2, (double)63), (FdoFloat) 0.5, nullIfIncompatible, shift, truncate, FdoDataTypeMapper::Type2String(FdoDataType_Int64) ); } break; case FdoDataType_String: // convert to numeric with possible truncation and rounding. ret = static_cast<FdoStringValue*>(src)->ConvertFrom<FdoInt64Value> ( nullIfIncompatible, shift, truncate, FdoDataTypeMapper::Type2String(FdoDataType_Int64) ); break; default: // src and dest types incompatible if ( !nullIfIncompatible ) throw FdoExpressionException::Create( FdoException::NLSGetMessage( FDO_NLSID(EXPRESSION_22_INCOMPATIBLEDATATYPES), src->ToString(), (FdoString*) FdoDataTypeMapper::Type2String(src->GetDataType()), (FdoString*) FdoDataTypeMapper::Type2String(FdoDataType_Int64) ) ); // else return null value break; } } if ( !ret ) // return null data value instead of NULL pointer. ret = FdoInt64Value::Create(); return ret; }
// Converts the filter expression to it's well defined text representation. FdoString* FdoBinaryLogicalOperator::ToStringInternal( FdoIdentifierCollection *pIdCol ) { FdoStringUtility::ClearString(m_toString); FdoFilter* pRight = GetRightOperand(); FdoFilter* pLeft = GetLeftOperand(); if (pRight == NULL || pLeft == NULL) { FDO_SAFE_RELEASE(pRight); FDO_SAFE_RELEASE(pLeft); FdoFilterException* pExcept = FdoFilterException::Create(FdoException::NLSGetMessage(FDO_NLSID(FILTER_1_INCOMPLETEBINARYOPERATOR))); throw pExcept; } bool bParenRight = false; bool bParenLeft = false; FdoString* pszRight = NULL; FdoString* pszLeft = NULL; try { pszRight = pRight->ToStringInternal( pIdCol ); pszLeft = pLeft->ToStringInternal( pIdCol ); } catch (FdoException* pExcept) { FDO_SAFE_RELEASE(pRight); FDO_SAFE_RELEASE(pLeft); throw pExcept; } if (GetOperation() == FdoBinaryLogicalOperations_And) { FdoBinaryLogicalOperator* pBLO = dynamic_cast<FdoBinaryLogicalOperator*>(pRight); if (pBLO != NULL && pBLO->GetOperation() == FdoBinaryLogicalOperations_Or) { bParenRight = true; pszRight = FdoStringUtility::MakeString(L"(", pszRight, L")"); } pBLO = dynamic_cast<FdoBinaryLogicalOperator*>(pLeft); if (pBLO != NULL && pBLO->GetOperation() == FdoBinaryLogicalOperations_Or) { bParenLeft = true; pszLeft = FdoStringUtility::MakeString(L"(", pszLeft, L")"); } } const wchar_t* szOp; switch (GetOperation()) { default: case FdoBinaryLogicalOperations_And: szOp = L" AND "; break; case FdoBinaryLogicalOperations_Or: szOp = L" OR "; break; } m_toString = FdoStringUtility::MakeString(pszLeft, szOp, pszRight); if (bParenLeft) delete [] pszLeft; if (bParenRight) delete [] pszRight; pLeft->Release(); pRight->Release(); return m_toString; }
FdoICurveSegmentAbstract* FdoFgfCurveString::GetItem(FdoInt32 Index) const { FdoInt32 numSegs = this->GetCount(); if ( (Index >= numSegs) || (Index < 0) ) throw FdoException::Create(FdoException::NLSGetMessage(FDO_NLSID(FDO_1_INDEXOUTOFBOUNDS))); FdoPtr<FdoFgfGeometryFactory> gf = GetFactory(); /* * Note: The first position for the segment to be returned is * stored as part of last position of immediately previous segment. * In case the segment to be returned is the 1st segment, its * start position is stored as StartPoint member of CurveString */ FdoPtr<FdoIDirectPosition> startPos; FdoInt32 dimensionality = this->GetDimensionality(); FdoInt32 numOrdsPerPos = GeometryUtility::DimensionalityToNumOrdinates(dimensionality); // Read start position if (0 == Index) { startPos = this->GetStartPosition(); // Skip to beginning of first segment m_streamPtr = m_data; // Skip over geomtype, dimensionality FGFUTIL_SKIP_INT32S(&m_streamPtr, m_streamEnd, 2); // Skip over startpoint FGFUTIL_SKIP_DIRECTPOSITIONS(&m_streamPtr, m_streamEnd, numOrdsPerPos, 1); // Skip over numElements FGFUTIL_SKIP_INT32S(&m_streamPtr, m_streamEnd, 1); } else { // Skip over geomtype and dimtype m_streamPtr = m_data; FGFUTIL_SKIP_INT32S(&m_streamPtr, m_streamEnd, 2); // Read Startpos of curvesegment FdoPtr<FdoIDirectPosition> startPosPrevSeg = FgfUtil::ReadDirectPosition(gf, dimensionality, &m_streamPtr, m_streamEnd); // Skip numSegments FGFUTIL_SKIP_INT32S(&m_streamPtr, m_streamEnd, 1); // Skip to curve segment just before the one that we need FgfUtil::SkipCurveSegments(Index-1, dimensionality, &m_streamPtr, m_streamEnd); FdoPtr<FdoICurveSegmentAbstract> prevCurveSeg = FgfUtil::ReadCurveSegment(gf, dimensionality, startPosPrevSeg, &m_streamPtr, m_streamEnd); // And Read its last position // which will be startPos for the segment // we'll return startPos = prevCurveSeg->GetEndPosition(); } // Read the CurveSegment we are interested in // We are already pointing at it FdoPtr<FdoICurveSegmentAbstract> thisCurveSeg = FgfUtil::ReadCurveSegment(gf, dimensionality, startPos, &m_streamPtr, m_streamEnd); return FDO_SAFE_ADDREF(thisCurveSeg.p); }
void FgfUtil::SkipGeometry(const FdoByte ** inputStream, const FdoByte * streamEnd) { FdoPtr<FdoIGeometry> geometry; FdoInt32 dimensionality = 0; FdoInt32 numPositions = 0; FdoInt32 numOrdsPerPos = 0; FdoInt32 numRings = 0; FdoInt32 numSubGeometries = 0; FdoInt32 numCurveSegments = 0; FdoInt32 i; FdoInt32 geometryType = FgfUtil::ReadInt32(inputStream, streamEnd); switch (geometryType) { case FdoGeometryType_LineString: dimensionality = FgfUtil::ReadInt32(inputStream, streamEnd); numPositions = FgfUtil::ReadInt32(inputStream, streamEnd); numOrdsPerPos = GeometryUtility::DimensionalityToNumOrdinates(dimensionality); FGFUTIL_SKIP_DIRECTPOSITIONS(inputStream, streamEnd, numOrdsPerPos, numPositions); break; case FdoGeometryType_Point: dimensionality = FgfUtil::ReadInt32(inputStream, streamEnd); numOrdsPerPos = GeometryUtility::DimensionalityToNumOrdinates(dimensionality); FGFUTIL_SKIP_DIRECTPOSITIONS(inputStream, streamEnd, numOrdsPerPos, 1); break; case FdoGeometryType_Polygon: dimensionality = FgfUtil::ReadInt32(inputStream, streamEnd); numOrdsPerPos = GeometryUtility::DimensionalityToNumOrdinates(dimensionality); numRings = FgfUtil::ReadInt32(inputStream, streamEnd); for (i=0; i<numRings; i++) { numPositions = FgfUtil::ReadInt32(inputStream, streamEnd); FGFUTIL_SKIP_DIRECTPOSITIONS(inputStream, streamEnd, numOrdsPerPos, numPositions); } break; case FdoGeometryType_CurveString: dimensionality = FgfUtil::ReadInt32(inputStream, streamEnd); numOrdsPerPos = GeometryUtility::DimensionalityToNumOrdinates(dimensionality); FGFUTIL_SKIP_DIRECTPOSITIONS(inputStream, streamEnd, numOrdsPerPos, 1); // Start position. numCurveSegments = FgfUtil::ReadInt32(inputStream, streamEnd); FgfUtil::SkipCurveSegments(numCurveSegments, dimensionality, inputStream, streamEnd); break; case FdoGeometryType_CurvePolygon: dimensionality = FgfUtil::ReadInt32(inputStream, streamEnd); numOrdsPerPos = GeometryUtility::DimensionalityToNumOrdinates(dimensionality); numRings = FgfUtil::ReadInt32(inputStream, streamEnd); FgfUtil::SkipRings(numRings, dimensionality, inputStream, streamEnd); break; case FdoGeometryType_MultiPoint: case FdoGeometryType_MultiLineString: case FdoGeometryType_MultiPolygon: case FdoGeometryType_MultiCurveString: case FdoGeometryType_MultiCurvePolygon: case FdoGeometryType_MultiGeometry: numSubGeometries = FgfUtil::ReadInt32(inputStream, streamEnd); for (i=0; i<numSubGeometries; i++) { FgfUtil::SkipGeometry(inputStream, streamEnd); // Recurse. } break; default: throw FdoException::Create(FdoException::NLSGetMessage(FDO_NLSID(FDO_1_UNKNOWN_GEOMETRY_TYPE), L"FgfUtil::SkipGeometry", geometryType)); } }
void FgfUtil::WriteGeometry(FdoIGeometry* geometry, FdoByteArray ** outputStream) { FdoInt32 dimensionality = 0; FdoInt32 numPositions = 0; FdoInt32 numOrdsPerPos = 0; FdoInt32 numOrds = 0; const double * ordinates = NULL; FdoInt32 numRings = 0; FdoInt32 numSubGeometries = 0; FdoInt32 numCurveSegments = 0; FdoPtr<FdoIRing> ring; FdoPtr<FdoILinearRing> lRing; FdoPtr<FdoIDirectPosition> pos; FdoILineString * ls; FdoIPoint * pt; FdoIPolygon * poly; FdoIMultiPoint * mpt; FdoIMultiLineString * mls; FdoIMultiPolygon * mpoly; FdoICurveString * cs; FdoIMultiCurveString * mcs; FdoICurvePolygon * cpoly; FdoIMultiCurvePolygon * mcpoly; FdoIMultiGeometry * mgeom; FdoInt32 i; FdoGeometryType geometryType = geometry->GetDerivedType(); FGFUTIL_WRITE_INT32(outputStream, geometryType); switch (geometryType) { case FdoGeometryType_LineString: ls = static_cast<FdoILineString *>(geometry); dimensionality = ls->GetDimensionality(); numPositions = ls->GetCount(); FGFUTIL_WRITE_INT32(outputStream, dimensionality); FGFUTIL_WRITE_INT32(outputStream, numPositions); numOrdsPerPos = GeometryUtility::DimensionalityToNumOrdinates(dimensionality); numOrds = numPositions * numOrdsPerPos; ordinates = ls->GetOrdinates(); FGFUTIL_WRITE_DOUBLES(outputStream, numOrds, ordinates); break; case FdoGeometryType_Point: pt = static_cast<FdoIPoint *>(geometry); dimensionality = pt->GetDimensionality(); numPositions = 1; FGFUTIL_WRITE_INT32(outputStream, dimensionality); numOrdsPerPos = GeometryUtility::DimensionalityToNumOrdinates(dimensionality); numOrds = numPositions * numOrdsPerPos; ordinates = pt->GetOrdinates(); FGFUTIL_WRITE_DOUBLES(outputStream, numOrds, ordinates); break; case FdoGeometryType_Polygon: poly = static_cast<FdoIPolygon *>(geometry); dimensionality = poly->GetDimensionality(); FGFUTIL_WRITE_INT32(outputStream, dimensionality); numRings = poly->GetInteriorRingCount(); FGFUTIL_WRITE_INT32(outputStream, numRings+1); // Include exterior ring in count lRing = poly->GetExteriorRing(); FgfUtil::WriteLinearRing(lRing, outputStream); for (i=0; i<numRings; i++) { lRing = poly->GetInteriorRing(i); FgfUtil::WriteLinearRing(lRing, outputStream); } break; case FdoGeometryType_MultiPoint: mpt = static_cast<FdoIMultiPoint *>(geometry); numSubGeometries = mpt->GetCount(); FGFUTIL_WRITE_INT32(outputStream, numSubGeometries); for (i=0; i<numSubGeometries; i++) { FdoPtr<FdoIPoint> pnt = mpt->GetItem(i); WriteGeometry(pnt, outputStream); } break; case FdoGeometryType_MultiLineString: mls = static_cast<FdoIMultiLineString *>(geometry); numSubGeometries = mls->GetCount(); FGFUTIL_WRITE_INT32(outputStream, numSubGeometries); for (i=0; i<numSubGeometries; i++) { FdoPtr<FdoILineString> lineString = mls->GetItem(i); WriteGeometry(lineString, outputStream); } break; case FdoGeometryType_MultiPolygon: mpoly = static_cast<FdoIMultiPolygon *>(geometry); numSubGeometries = mpoly->GetCount(); FGFUTIL_WRITE_INT32(outputStream, numSubGeometries); for (i=0; i<numSubGeometries; i++) { FdoPtr<FdoIPolygon> polygon = mpoly->GetItem(i); WriteGeometry(polygon, outputStream); } break; case FdoGeometryType_CurveString: cs = static_cast<FdoICurveString *>(geometry); dimensionality = cs->GetDimensionality(); FGFUTIL_WRITE_INT32(outputStream, dimensionality); pos = cs->GetStartPosition(); WriteDirectPosition(outputStream, pos); numCurveSegments = cs->GetCount(); FGFUTIL_WRITE_INT32(outputStream, numCurveSegments); for (i=0; i<numCurveSegments; i++) { FdoPtr<FdoICurveSegmentAbstract> curveSeg = cs->GetItem(i); WriteCurveSegment(curveSeg, outputStream); } break; case FdoGeometryType_MultiCurveString: mcs = static_cast<FdoIMultiCurveString *>(geometry); numSubGeometries = mcs->GetCount(); FGFUTIL_WRITE_INT32(outputStream, numSubGeometries); for (i=0; i<numSubGeometries; i++) { FdoPtr<FdoICurveString> curveString = mcs->GetItem(i); WriteGeometry(curveString, outputStream); } break; case FdoGeometryType_CurvePolygon: cpoly = static_cast<FdoICurvePolygon *>(geometry); dimensionality = cpoly->GetDimensionality(); FGFUTIL_WRITE_INT32(outputStream, dimensionality); numRings = cpoly->GetInteriorRingCount(); FGFUTIL_WRITE_INT32(outputStream, numRings + 1); // Include exterior ring ring = cpoly->GetExteriorRing(); FgfUtil::WriteRing(ring, outputStream); // Interior rings for (i=0; i<numRings; i++) { ring = cpoly->GetInteriorRing(i); FgfUtil::WriteRing(ring, outputStream); } break; case FdoGeometryType_MultiCurvePolygon: mcpoly = static_cast<FdoIMultiCurvePolygon *>(geometry); numSubGeometries = mcpoly->GetCount(); FGFUTIL_WRITE_INT32(outputStream, numSubGeometries); for (i=0; i<numSubGeometries; i++) { FdoPtr<FdoICurvePolygon> curvePolygon = mcpoly->GetItem(i); WriteGeometry(curvePolygon, outputStream); } break; case FdoGeometryType_MultiGeometry: mgeom = static_cast<FdoIMultiGeometry *>(geometry); numSubGeometries = mgeom->GetCount(); FGFUTIL_WRITE_INT32(outputStream, numSubGeometries); for (i=0; i<numSubGeometries; i++) { FdoPtr<FdoIGeometry> geom = mgeom->GetItem(i); WriteGeometry(geom, outputStream); } break; default: throw FdoException::Create(FdoException::NLSGetMessage(FDO_NLSID(FDO_1_UNKNOWN_GEOMETRY_TYPE), L"FgfUtil::WriteGeometry", geometryType)); } }
void FdoIoMemoryStream::Write( FdoIoStream* stream, FdoSize count ) { // Validate the parameters. if ( !stream ) throw FdoException::Create( FdoException::NLSGetMessage( FDO_NLSID(FDO_30_BADPARAM), L"stream", L"(NULL)", L"FdoIoMemoryStream::Write" ) ); // Find out how many bytes are after the input streams position. FdoInt64 streamRemaining = stream->GetLength() - stream->GetIndex(); // Amount to write is the lesser of the remaining bytes and the given limit. FdoInt64 lCount = (count > streamRemaining || count == 0) ? streamRemaining : count; FdoSize bufNum = 0; FdoSize bufOffset = 0; // Convert this stream's position to position in the right internal buffer. GetBufPosn( bufNum, bufOffset ); // Write the data to this internal and its following buffers, until all bytes // have been written. while ( lCount > 0 ) { // Our buffer array can't have more than INT_MAX members if ( bufNum >= INT_MAX ) throw FdoException::Create( FdoException::NLSGetMessage( FDO_NLSID(FDO_34_MEMORYSTREAMOVERFLOW), L"FdoIoMemoryStream::Write", L"FdoIoMemoryStream", mBufferSize ) ); // Create another internal buffer if at end of this stream. while ( bufNum >= ((FdoSize) mBuffers->GetCount()) ) { FdoIoBufferStreamP buffer = FdoIoBufferStream::Create( mBufferSize ); mBuffers->Add( buffer ); bufOffset = 0; } // Get the current internal buffer FdoIoBufferStreamP buffer = mBuffers->GetItem(bufNum); // Position buffer at its offset. buffer->Reset(); buffer->Skip( bufOffset ); // figure out the amount to write to this internal buffer. // lessor of amount remaining to write and amount remaining in this buffer. FdoSize writeCount = mBufferSize - bufOffset; writeCount = (lCount < writeCount) ? ((FdoSize)lCount) : writeCount; // Write to the internal buffer buffer->Write( stream, writeCount ); // Bump down bytes remaining to write by amount written lCount -= writeCount; // Update current stream position mPos += writeCount; // Move on to the next internal buffer. bufNum++; bufOffset = 0; } // Update the total stream length. mLength = (mPos > mLength) ? mPos : mLength; }
FdoICurveSegmentAbstract* FgfUtil::ReadCurveSegment( FdoFgfGeometryFactory * factory, FdoInt32 dimensionality, FdoIDirectPosition* startPos, const FdoByte ** inputStream, const FdoByte * streamEnd) { // // Reads CurveSegment positions and creates a new // CurveString using the startPos passed followed by positions // read from the reader. In this manner it creates and returns a // complete curveSeg with all of its positions (unlike its fgf // counterpart that has its startPos stored as last position of // immediately previous curveSeg. // // It is assumed that reader is currently pointing at beginning // of CurveSeg. // FdoGeometryComponentType geomType = (FdoGeometryComponentType)ReadInt32(inputStream, streamEnd); FdoPtr<FdoICurveSegmentAbstract> curveSeg; switch (geomType) { case FdoGeometryComponentType_CircularArcSegment: { FdoPtr<FdoIDirectPosition> midPos = ReadDirectPosition(factory, dimensionality, inputStream, streamEnd); FdoPtr<FdoIDirectPosition> endPos = ReadDirectPosition(factory, dimensionality, inputStream, streamEnd); curveSeg = factory->CreateCircularArcSegment(startPos, midPos, endPos); break; } case FdoGeometryComponentType_LineStringSegment: { FdoInt32 numPositions = ReadInt32(inputStream, streamEnd); FdoInt32 numOrdsPerPos = GeometryUtility::DimensionalityToNumOrdinates(dimensionality); FdoInt32 numOrds = (numPositions+1) * numOrdsPerPos; FdoPtr<FdoDoubleArray> da = FdoDoubleArray::Create(numOrds); double * ordinates = da->GetData(); double * currentOrdinates = ordinates; const double * positionOrdinates = startPos->GetOrdinates(); // add the startPos for (FdoInt32 i=0; i < numOrdsPerPos; i++) *currentOrdinates++ = *positionOrdinates++; // Now add remaining positions numOrds -= numOrdsPerPos; // Adjust for already having start position. FGFUTIL_STREAM_CHECK(inputStream, streamEnd, numOrds * sizeof(double)); positionOrdinates = (const double *) *inputStream; for (FdoInt32 i=0; i < numOrds; i++) *currentOrdinates++ = *positionOrdinates++; *inputStream += numOrds * sizeof(double); numOrds += numOrdsPerPos; // Adjust for start position + remaining ones. curveSeg = factory->CreateLineStringSegment(dimensionality, numOrds, ordinates); break; } default: { throw FdoException::Create(FdoException::NLSGetMessage(FDO_NLSID(FDO_1_UNKNOWN_GEOMETRY_COMPONENT_TYPE), L"FgfUtil::ReadCurveSegment", geomType)); } } // of switch return FDO_SAFE_ADDREF(curveSeg.p); }
void FdoXslTransformerXalan::Transform() { // Reading from a stream at EOF is a common client error. // Therefore trap this particular problem. FdoIoStreamP stream = FdoXmlReaderP(GetInDoc())->GetStream(); FdoInt64 streamLen = stream->GetLength(); if ( (streamLen >= 0) && (stream->GetIndex() >= streamLen) ) throw FdoXmlException::Create( FdoException::NLSGetMessage( FDO_NLSID(FDO_55_XSLINPUTEOF) ) ); stream = FdoXmlReaderP(GetStylesheet())->GetStream(); streamLen = stream->GetLength(); if ( (streamLen >= 0) && (stream->GetIndex() >= streamLen) ) throw FdoXmlException::Create( FdoException::NLSGetMessage( FDO_NLSID(FDO_56_XSLSTYLESHEETEOF) ) ); // Create the Xalan transformer XALAN_CPP_NAMESPACE::XalanTransformer transformer; // Attach the in document to it FdoXmlReaderP readerP = GetInDoc(); InputSource inSource( readerP ); // Attach the stylesheet to it. readerP = GetStylesheet(); InputSource sheetSource( readerP ); sheetSource.setSystemId((const XMLCh*) L"sheet"); try { FdoDictionaryP params = GetParameters(); FdoInt32 i; // Give Xalan all the parameters for ( i = 0; i < params->GetCount(); i++ ) { FdoDictionaryElementP param = params->GetItem(i); if ( param->GetValue() ) transformer.setStylesheetParam( XALAN_CPP_NAMESPACE::XalanDOMString( (const char*) FdoStringP(param->GetName()) ), XALAN_CPP_NAMESPACE::XalanDOMString( (const char*) FdoStringP(param->GetValue()) ) ); } // Listen to messages, warnings, and errors: transformer.setProblemListener(this); // Do the transformation. if ( transformer.transform( inSource, sheetSource, (void*) this, (XalanOutputHandlerType) outputHandler, (XalanFlushHandlerType) flushHandler ) ) { const char* lastError = transformer.getLastError(); size_t i = strlen ( lastError ) + 1; wchar_t* wstrLastError = (wchar_t*)alloca (i * sizeof (wchar_t)); //#ifdef _WIN32 // i = MultiByteToWideChar ( CP_THREAD_ACP, 0,lastError,(int)i, wstrLastError,(int)i); //#else i = mbstowcs (wstrLastError, lastError, i); //#endif if( i == 0 ) wstrLastError[0] = 0; throw FdoXmlException::Create( FdoException::NLSGetMessage( FDO_NLSID(FDO_42_GENERICCHAR), wstrLastError ) ); } } catch ( const XALAN_CPP_NAMESPACE::XSLException& ex ) { throw FdoXmlException::Create( FdoException::NLSGetMessage( FDO_NLSID(FDO_43_XSLERROR), ex.getLineNumber(), ex.getColumnNumber(), (FdoString*)XalanDomStringToUnicode(ex.getMessage()) ) ); } }