Exemplo n.º 1
0
template <typename Iter, typename Traits> NEXTWEB_INLINE typename StreamBuffer<Iter, Traits>::PosType
StreamBuffer<Iter, Traits>::seekoff(typename StreamBuffer<Iter, Traits>::OffType off, std::ios::seekdir dir, std::ios::openmode which) {
	
	if (!(which & std::ios::in)) {
		return BAD_POSITION;
	}		
	
	DistanceType size = std::distance(begin_, end_);
	DistanceType dist = static_cast<DistanceType>(off);
	DistanceType position = static_cast<DistanceType>(-1);
	
	if ((std::ios::beg == dir) && (dist >= 0) && (dist < size)) {
		position = dist;
	}
	else if ((std::ios::end == dir) && (dist >= 0) && (dist < size)) {
		position = size - dist;
	}
	else if (std::ios::cur == dir) {
		position = std::distance(begin_, current_) - static_cast<DistanceType>(egptr() - gptr()) + dist;
		if ((position < 0) || (position >= size)) {
			return BAD_POSITION;
		}
	}
	if (static_cast<DistanceType>(-1) != position) {
		current_ = begin_;
		std::advance(current_, position);
		fill();
		return static_cast<PosType>(position);
	}
	return BAD_POSITION;
}
Exemplo n.º 2
0
template <typename Iter, typename Traits> NEXTWEB_INLINE typename StreamBuffer<Iter, Traits>::IntType
StreamBuffer<Iter, Traits>::underflow() {
	assert(gptr() == egptr());
	if (end_ == current_) {
		return Traits::eof();
	}
	return fill();
}
Exemplo n.º 3
0
Instance MemoryDump::getInstanceAt(const QString& type, const size_t address,
        const QStringList& parentNames) const
{
    BaseType* t = getType(type);
	return t ?
	       t->toInstance(address, _vmem, "user", parentNames,
	               BaseType::trLexicalAndPointers) :
	       Instance();
}
Exemplo n.º 4
0
template <typename Iter, typename Traits> NEXTWEB_INLINE typename StreamBuffer<Iter, Traits>::IntType
StreamBuffer<Iter, Traits>::pbackfail(typename StreamBuffer<Iter, Traits>::IntType value) {
	assert(gptr() == eback());
	if (begin_ == current_) {
		return Traits::eof();
	}
	--current_;
	DistanceType dist = static_cast<DistanceType>(egptr() - eback());
	memmove(buffer_ + 1, buffer_, dist - 1);
	buffer_[0] = value;
	return Traits::to_int_type(value);
}
Exemplo n.º 5
0
Sequence *OGRDODSSequenceLayer::FindSuperSequence( BaseType *poChild )

{
    BaseType *poParent;

    for( poParent = poChild->get_parent(); 
         poParent != NULL; 
         poParent = poParent->get_parent() )
    {
        if( poParent->type() == dods_sequence_c )
        {
            return dynamic_cast<Sequence *>( poParent );
        }
    }

    return NULL;
}
Exemplo n.º 6
0
template <typename Iter, typename Traits> NEXTWEB_INLINE typename StreamBuffer<Iter, Traits>::IntType
StreamBuffer<Iter, Traits>::fill() {
	std::size_t size = 0;
	for (; end_ != current_ && size < BUFFER_SIZE; ++current_, ++size) {
		buffer_[size] = *current_;
	}
	setg(buffer_, buffer_, buffer_ + size);
	return Traits::to_int_type(buffer_[0]);
}
Exemplo n.º 7
0
 /**
  * Returns priority of outgoing transfers.
  * TODO: Make const.
  */
 TransferPriority getPriority()
 {
     // TODO probably TransferSender must be transformed into regular field?
     TransferSender* const ts = getTransferSender();
     if (ts != NULL)
     {
         return ts->getPriority();
     }
     else
     {
         return TransferPriorityNormal;  // This is default
     }
 }
Exemplo n.º 8
0
	void Painter::Render(D3D* d3d, Frustum* frustum, Viewport* viewport, 
		D3DXMATRIX world, D3DXMATRIX view, D3DXMATRIX projection, D3DXMATRIX ortho)
	{
		std::sort(z.begin(), z.end(), Compare);
		for( vector<BaseType*>::iterator p=z.begin(); p!=z.end(); ++p)
		{
			//process(*p); RENDER BACK TO FRONT

			//FRONT = negatives
			//BACK = positives
			//sort list greatest to least so back renders first

			BaseType* base = *p;
			int type = base->GetType();
			if (type == 1)
			{
				ModelType* model = (ModelType*)base;
				model->transform = &xforce(*model->transform, Rad);
				model->Render(d3d->GetDeviceContext(), frustum, viewport);
			}
			if (type == 2)
			{
				TextType* text = (TextType*)base;
				text->Render(d3d->GetDeviceContext(), viewport);
			}
			if (type == 3)
			{
				BitmapType* bitmap = (BitmapType*)base;
				bitmap->transform = &xforce(*bitmap->transform, Rad);
				bitmap->Render(d3d, viewport);
			}
			/*if (type == 4)
			{
				TransformType* transform = (TransformType*)base;
				transform->Render(d3d, world, view, projection, ortho);
			}*/
		}
		return;
	}
Exemplo n.º 9
0
bool DataStorePrivate::GetPositionInStorageForIndex(const BaseType& dataStorage, uint& lineNumber, uint& indexInLine, uint index)
{
    indexInLine = index;
    lineNumber = 0;

    uint dataStorageSize = dataStorage.size();
    uint lineSize = 0;
    while (lineNumber < dataStorageSize &&
            indexInLine >= (lineSize = dataStorage[lineNumber]->size()))
    {
        indexInLine -= lineSize;
        lineNumber++;
    }
    return lineNumber < dataStorageSize;
}
Exemplo n.º 10
0
Arquivo: TIL.cpp Projeto: google/ohmu
TIL_CastOpcode typeConvertable(BaseType Vt1, BaseType Vt2) {
  if (Vt1.isIntegral()) {
    if (Vt2.Base == Vt1.Base)
      if (Vt1.Size <= Vt2.Size)
        return CAST_extendNum;
    if (Vt2.Base == BaseType::BT_Float)
      if (static_cast<unsigned>(Vt1.Size) <= static_cast<unsigned>(Vt2.Size)-1)
        return CAST_extendToFloat;
  }
  else if (Vt1.Base == BaseType::BT_Float &&
           Vt2.Base == BaseType::BT_Float) {
    if (Vt1.Size <= Vt2.Size)
      return CAST_extendNum;
  }
  return CAST_none;
}
Exemplo n.º 11
0
	void Painter::AddToFront(BaseType& item)
	{
		item.ZOrder = 0;
		if (!z.empty())
		{
			BaseType* front;
			std::sort(z.begin(), z.end(), Compare);

			//z.BACK = FRONT

			front = z.back(); //z.front or z.back?
			float loc = front->ZOrder - 1;
			item.ZOrder = loc;
		}
		BaseType* base = item.Clone();
		//BaseType* base = dynamic_cast<BaseType*>((BaseType*)&model);
		z.push_back(base);
		return;
	}
Exemplo n.º 12
0
 /**
  * Allows to change the priority of outgoing transfers.
  * Note that only High, Normal and Low priorities can be used; Service priority is not available for messages.
  * Returns negative error code if priority cannot be set, non-negative on success.
  */
 int setPriority(const TransferPriority prio)
 {
     if (prio < NumTransferPriorities && prio != TransferPriorityService)
     {
         TransferSender* const ts = getTransferSender();  // TODO: Static TransferSender?
         if (ts != NULL)
         {
             ts->setPriority(prio);
             return 0;
         }
         else
         {
             return -ErrLogic;
         }
     }
     else
     {
         return -ErrInvalidParam;
     }
 }
Exemplo n.º 13
0
 FixedMap& operator=(std::initializer_list<value_type> init) {
   insert(init);
   return *this;
 }
Exemplo n.º 14
0
 FixedMap& operator=(const FixedMap& other) {
   insert(std::begin(other), std::end(other));
   return *this;
 }
Exemplo n.º 15
0
 FixedMap& operator=(FixedMap&& other) {
   insert(std::begin(other), std::end(other));
   other.clear();
   return *this;
 }
Exemplo n.º 16
0
 FixedMap(FixedMap&& other) : FixedMap() {
   insert(std::begin(other), std::end(other));
   other.clear();
 }
Exemplo n.º 17
0
 FixedMap(std::initializer_list<value_type> init) : FixedMap() {
   insert(init);
 }
Exemplo n.º 18
0
template <typename Iter, typename Traits> NEXTWEB_INLINE
StreamBuffer<Iter, Traits>::StreamBuffer(Iter begin, Iter end) :
	BaseType(), current_(begin), begin_(begin), end_(end)
{
	setg(buffer_, buffer_, buffer_);
}
Exemplo n.º 19
0
 FixedMap(const FixedMap& other) : FixedMap() {
   insert(std::begin(other), std::end(other));
 }
Exemplo n.º 20
0
 FixedMap& operator=(const std::map<KeyType, ValueType, Comp, Alloc>& other) {
   insert(std::begin(other), std::end(other));
   return *this;
 }
Exemplo n.º 21
0
 FixedMultiMap& operator=(
     std::multimap<KeyType, ValueType, Comp, Alloc>&& other) {
   insert(std::begin(other), std::end(other));
   other.clear();
   return *this;
 }
Exemplo n.º 22
0
OGRDODSGridLayer::OGRDODSGridLayer( OGRDODSDataSource *poDSIn,
                                    const char *pszTargetIn,
                                    AttrTable *poOGRLayerInfoIn ) :
    OGRDODSLayer( poDSIn, pszTargetIn, poOGRLayerInfoIn ),
    poTargetGrid(NULL),
    poTargetArray(NULL),
    nArrayRefCount(0),
    paoArrayRefs(NULL),
    nDimCount(0),
    paoDimensions(NULL),
    nMaxRawIndex(0)
{
/* -------------------------------------------------------------------- */
/*      What is the layer name?                                         */
/* -------------------------------------------------------------------- */
    string oLayerName;
    const char *pszLayerName = pszTargetIn;

    if( poOGRLayerInfo != NULL )
    {
        oLayerName = poOGRLayerInfo->get_attr( "layer_name" );
        if( strlen(oLayerName.c_str()) > 0 )
            pszLayerName = oLayerName.c_str();
    }

    poFeatureDefn = new OGRFeatureDefn( pszLayerName );
    poFeatureDefn->Reference();

/* -------------------------------------------------------------------- */
/*      Fetch the target variable.                                      */
/* -------------------------------------------------------------------- */
    BaseType *poTargVar = poDS->poDDS->var( pszTargetIn );

    if( poTargVar->type() == dods_grid_c )
    {
        poTargetGrid = dynamic_cast<Grid *>( poTargVar );
        poTargetArray = dynamic_cast<Array *>(poTargetGrid->array_var());
    }
    else if( poTargVar->type() == dods_array_c )
    {
        poTargetGrid = NULL;
        poTargetArray = dynamic_cast<Array *>( poTargVar );
    }
    else
    {
        CPLAssert( false );
        return;
    }

/* -------------------------------------------------------------------- */
/*      Count arrays in use.                                            */
/* -------------------------------------------------------------------- */
    AttrTable *poExtraContainers = NULL;
    nArrayRefCount = 1; // primary target.

    if( poOGRLayerInfo != NULL )
        poExtraContainers = poOGRLayerInfo->find_container("extra_containers");

    if( poExtraContainers != NULL )
    {
        AttrTable::Attr_iter dv_i;

        for( dv_i = poExtraContainers->attr_begin();
             dv_i != poExtraContainers->attr_end(); dv_i++ )
        {
            nArrayRefCount++;
        }
    }

/* -------------------------------------------------------------------- */
/*      Collect extra_containers.                                       */
/* -------------------------------------------------------------------- */
    paoArrayRefs = new OGRDODSArrayRef[nArrayRefCount];
    paoArrayRefs[0].pszName = CPLStrdup( pszTargetIn );
    paoArrayRefs[0].poArray = poTargetArray;

    nArrayRefCount = 1;

    if( poExtraContainers != NULL )
    {
        AttrTable::Attr_iter dv_i;

        for( dv_i = poExtraContainers->attr_begin();
             dv_i != poExtraContainers->attr_end(); dv_i++ )
        {
            const char *pszTargetName=poExtraContainers->get_attr(dv_i).c_str();
            BaseType *poExtraTarget = poDS->poDDS->var( pszTargetName );

            if( poExtraTarget == NULL )
            {
                CPLError( CE_Warning, CPLE_AppDefined,
                          "Unable to find extra_container '%s', skipping.",
                          pszTargetName );
                continue;
            }

            if( poExtraTarget->type() == dods_array_c )
                paoArrayRefs[nArrayRefCount].poArray =
                    dynamic_cast<Array *>( poExtraTarget );
            else if( poExtraTarget->type() == dods_grid_c )
            {
                Grid *poGrid = dynamic_cast<Grid *>( poExtraTarget );
                paoArrayRefs[nArrayRefCount].poArray =
                    dynamic_cast<Array *>( poGrid->array_var() );
            }
            else
            {
                CPLError( CE_Warning, CPLE_AppDefined,
                          "Target container '%s' is not grid or array, skipping.",
                          pszTargetName );
                continue;
            }

            paoArrayRefs[nArrayRefCount++].pszName = CPLStrdup(pszTargetName);
        }
    }

/* -------------------------------------------------------------------- */
/*      Collect dimension information.                                  */
/* -------------------------------------------------------------------- */
    int iDim;
    Array::Dim_iter iterDim;

    nDimCount = poTargetArray->dimensions();
    paoDimensions = new OGRDODSDim[nDimCount];
    nMaxRawIndex = 1;

    for( iterDim = poTargetArray->dim_begin(), iDim = 0;
         iterDim != poTargetArray->dim_end();
         iterDim++, iDim++ )
    {
        paoDimensions[iDim].pszDimName =
            CPLStrdup(poTargetArray->dimension_name(iterDim).c_str());
        paoDimensions[iDim].nDimStart =
            poTargetArray->dimension_start(iterDim);
        paoDimensions[iDim].nDimEnd =
            poTargetArray->dimension_stop(iterDim);
        paoDimensions[iDim].nDimStride =
            poTargetArray->dimension_stride(iterDim);
        paoDimensions[iDim].poMap = NULL;

        paoDimensions[iDim].nDimEntries =
            (paoDimensions[iDim].nDimEnd + 1 - paoDimensions[iDim].nDimStart
             + paoDimensions[iDim].nDimStride - 1)
            / paoDimensions[iDim].nDimStride;

        nMaxRawIndex *= paoDimensions[iDim].nDimEntries;
    }

/* -------------------------------------------------------------------- */
/*      If we are working with a grid, collect the maps.                */
/* -------------------------------------------------------------------- */
    if( poTargetGrid != NULL )
    {
        int iMap;
        Grid::Map_iter iterMap;

        for( iterMap = poTargetGrid->map_begin(), iMap = 0;
             iterMap != poTargetGrid->map_end();
             iterMap++, iMap++ )
        {
            paoDimensions[iMap].poMap = dynamic_cast<Array *>(*iterMap);
        }

        CPLAssert( iMap == nDimCount );
    }

/* -------------------------------------------------------------------- */
/*      Setup field definitions.  The first nDimCount will be the       */
/*      dimension attributes, and after that comes the actual target    */
/*      array.                                                          */
/* -------------------------------------------------------------------- */
    for( iDim = 0; iDim < nDimCount; iDim++ )
    {
        OGRFieldDefn oField( paoDimensions[iDim].pszDimName, OFTInteger );

        if( EQUAL(oField.GetNameRef(), poTargetArray->name().c_str()) )
            oField.SetName(CPLSPrintf("%s_i",paoDimensions[iDim].pszDimName));

        if( paoDimensions[iDim].poMap != NULL )
        {
            switch( paoDimensions[iDim].poMap->var()->type() )
            {
              case dods_byte_c:
              case dods_int16_c:
              case dods_uint16_c:
              case dods_int32_c:
              case dods_uint32_c:
                oField.SetType( OFTInteger );
                break;

              case dods_float32_c:
              case dods_float64_c:
                oField.SetType( OFTReal );
                break;

              case dods_str_c:
              case dods_url_c:
                oField.SetType( OFTString );
                break;

              default:
                // Ignore
                break;
            }
        }

        poFeatureDefn->AddFieldDefn( &oField );
    }

/* -------------------------------------------------------------------- */
/*      Setup the array attributes themselves.                          */
/* -------------------------------------------------------------------- */
    int iArray;
    for( iArray=0; iArray < nArrayRefCount; iArray++ )
    {
        OGRDODSArrayRef *poRef = paoArrayRefs + iArray;
        OGRFieldDefn oArrayField( poRef->poArray->name().c_str(), OFTInteger );

        switch( poRef->poArray->var()->type() )
        {
          case dods_byte_c:
          case dods_int16_c:
          case dods_uint16_c:
          case dods_int32_c:
          case dods_uint32_c:
            oArrayField.SetType( OFTInteger );
            break;

          case dods_float32_c:
          case dods_float64_c:
            oArrayField.SetType( OFTReal );
            break;

          case dods_str_c:
          case dods_url_c:
            oArrayField.SetType( OFTString );
            break;

          default:
            // Ignore
            break;
        }

        poFeatureDefn->AddFieldDefn( &oArrayField );
        poRef->iFieldIndex = poFeatureDefn->GetFieldCount() - 1;
    }

/* -------------------------------------------------------------------- */
/*      X/Y/Z fields.                                                   */
/* -------------------------------------------------------------------- */
    if( poOGRLayerInfo != NULL )
    {
        AttrTable *poField = poOGRLayerInfo->find_container("x_field");
        if( poField != NULL )
        {
            oXField.Initialize( poField );
            oXField.iFieldIndex =
                poFeatureDefn->GetFieldIndex( oXField.pszFieldName );
        }

        poField = poOGRLayerInfo->find_container("y_field");
        if( poField != NULL )
        {
            oYField.Initialize( poField );
            oYField.iFieldIndex =
                poFeatureDefn->GetFieldIndex( oYField.pszFieldName );
        }

        poField = poOGRLayerInfo->find_container("z_field");
        if( poField != NULL )
        {
            oZField.Initialize( poField );
            oZField.iFieldIndex =
                poFeatureDefn->GetFieldIndex( oZField.pszFieldName );
        }
    }

/* -------------------------------------------------------------------- */
/*      If we have no layerinfo, then check if there are obvious x/y    */
/*      fields.                                                         */
/* -------------------------------------------------------------------- */
    else
    {
        if( poFeatureDefn->GetFieldIndex( "lat" ) != -1
            && poFeatureDefn->GetFieldIndex( "lon" ) != -1 )
        {
            oXField.Initialize( "lon", "dds" );
            oXField.iFieldIndex = poFeatureDefn->GetFieldIndex( "lon" );
            oYField.Initialize( "lat", "dds" );
            oYField.iFieldIndex = poFeatureDefn->GetFieldIndex( "lat" );
        }
        else if( poFeatureDefn->GetFieldIndex( "latitude" ) != -1
                 && poFeatureDefn->GetFieldIndex( "longitude" ) != -1 )
        {
            oXField.Initialize( "longitude", "dds" );
            oXField.iFieldIndex = poFeatureDefn->GetFieldIndex( "longitude" );
            oYField.Initialize( "latitude", "dds" );
            oYField.iFieldIndex = poFeatureDefn->GetFieldIndex( "latitude" );
        }
    }

/* -------------------------------------------------------------------- */
/*      Set the layer geometry type if we have point inputs.            */
/* -------------------------------------------------------------------- */
    if( oZField.iFieldIndex >= 0 )
        poFeatureDefn->SetGeomType( wkbPoint25D );
    else if( oXField.iFieldIndex >= 0 && oYField.iFieldIndex >= 0 )
        poFeatureDefn->SetGeomType( wkbPoint );
    else
        poFeatureDefn->SetGeomType( wkbNone );
}
Exemplo n.º 23
0
OGRFeature *OGRDODSSequenceLayer::GetFeature( GIntBig nFeatureId )

{
/* -------------------------------------------------------------------- */
/*      Ensure we have the dataset.                                     */
/* -------------------------------------------------------------------- */
    if( !ProvideDataDDS() )
        return NULL;

    Sequence *seq = dynamic_cast<Sequence *>(poTargetVar);

/* -------------------------------------------------------------------- */
/*      Figure out what the super and subsequence number this           */
/*      feature will be, and validate it.  If there is not super        */
/*      sequence the feature id is the subsequence number.              */
/* -------------------------------------------------------------------- */
    int iSubSeq = -1;

    if( nFeatureId < 0 || nFeatureId >= nRecordCount )
        return NULL;

    if( poSuperSeq == NULL )
        iSubSeq = nFeatureId;
    else
    {
        int nSeqOffset = 0, iSuperSeq;

        // for now we just scan through till find find out what
        // super sequence this in.  In the long term we need a better (cached)
        // approach that doesn't involve this quadratic cost.
        for( iSuperSeq = 0; 
             iSuperSeq < nSuperSeqCount; 
             iSuperSeq++ )
        {
            if( nSeqOffset + panSubSeqSize[iSuperSeq] > nFeatureId )
            {
                iSubSeq = nFeatureId - nSeqOffset;
                break;
            }
            nSeqOffset += panSubSeqSize[iSuperSeq];
        }

        CPLAssert( iSubSeq != -1 );

        // Make sure we have the right target var ... the one 
        // corresponding to our current super sequence. 
        if( iSuperSeq != iLastSuperSeq )
        {
            iLastSuperSeq = iSuperSeq;
            poTargetVar = poSuperSeq->var_value( iSuperSeq, pszSubSeqPath );
            seq = dynamic_cast<Sequence *>(poTargetVar);
        }
    }

/* -------------------------------------------------------------------- */
/*      Create the feature being read.                                  */
/* -------------------------------------------------------------------- */
    OGRFeature *poFeature;

    poFeature = new OGRFeature( poFeatureDefn );
    poFeature->SetFID( nFeatureId );
    m_nFeaturesRead++;

/* -------------------------------------------------------------------- */
/*      Process all the regular data fields.                            */
/* -------------------------------------------------------------------- */
    int      iField;

    for( iField = 0; iField < poFeatureDefn->GetFieldCount(); iField++ )
    {
        if( papoFields[iField]->pszPathToSequence )
            continue;

        BaseType *poFieldVar = GetFieldValue( papoFields[iField], iSubSeq,
                                              NULL );

        if( poFieldVar == NULL )
            continue;

        switch( poFieldVar->type() )
        {
          case dods_byte_c:
          {
              signed char byVal;
              void *pValPtr = &byVal;
              
              poFieldVar->buf2val( &pValPtr );
              poFeature->SetField( iField, byVal );
          }
          break;

          case dods_int16_c:
          {
              GInt16 nIntVal;
              void *pValPtr = &nIntVal;
              
              poFieldVar->buf2val( &pValPtr );
              poFeature->SetField( iField, nIntVal );
          }
          break;

          case dods_uint16_c:
          {
              GUInt16 nIntVal;
              void *pValPtr = &nIntVal;
              
              poFieldVar->buf2val( &pValPtr );
              poFeature->SetField( iField, nIntVal );
          }
          break;

          case dods_int32_c:
          {
              GInt32 nIntVal;
              void *pValPtr = &nIntVal;
              
              poFieldVar->buf2val( &pValPtr );
              poFeature->SetField( iField, nIntVal );
          }
          break;

          case dods_uint32_c:
          {
              GUInt32 nIntVal;
              void *pValPtr = &nIntVal;
              
              poFieldVar->buf2val( &pValPtr );
              poFeature->SetField( iField, (int) nIntVal );
          }
          break;

          case dods_float32_c:
            poFeature->SetField( iField, 
                                 dynamic_cast<Float32 *>(poFieldVar)->value());
            break;

          case dods_float64_c:
            poFeature->SetField( iField, 
                                 dynamic_cast<Float64 *>(poFieldVar)->value());
            break;

          case dods_str_c:
          case dods_url_c:
          {
              string *poStrVal = NULL;
              poFieldVar->buf2val( (void **) &poStrVal );
              poFeature->SetField( iField, poStrVal->c_str() );
              delete poStrVal;
          }
          break;

          default:
            break;
        }
    }
    
/* -------------------------------------------------------------------- */
/*      Handle data nested in sequences.                                */
/* -------------------------------------------------------------------- */
    for( iField = 0; iField < poFeatureDefn->GetFieldCount(); iField++ )
    {
        OGRDODSFieldDefn *poFD = papoFields[iField];
        const char *pszPathFromSubSeq;

        if( poFD->pszPathToSequence == NULL )
            continue;

        CPLAssert( strlen(poFD->pszPathToSequence) 
                   < strlen(poFD->pszFieldName)-1 );

        if( strstr(poFD->pszFieldName,poFD->pszPathToSequence) != NULL )
            pszPathFromSubSeq = 
                strstr(poFD->pszFieldName,poFD->pszPathToSequence)
                + strlen(poFD->pszPathToSequence) + 1;
        else
            continue;

/* -------------------------------------------------------------------- */
/*      Get the sequence out of which this variable will be collected.  */
/* -------------------------------------------------------------------- */
        BaseType *poFieldVar = seq->var_value( iSubSeq, 
                                               poFD->pszPathToSequence );
        Sequence *poSubSeq;
        int nSubSeqCount;

        if( poFieldVar == NULL )
            continue;

        poSubSeq = dynamic_cast<Sequence *>( poFieldVar );
        if( poSubSeq == NULL )
            continue;

        nSubSeqCount = poSubSeq->number_of_rows();
            
/* -------------------------------------------------------------------- */
/*      Allocate array to put values into.                              */
/* -------------------------------------------------------------------- */
        OGRFieldDefn *poOFD = poFeature->GetFieldDefnRef( iField );
        int *panIntList = NULL;
        double *padfDblList = NULL;
        char **papszStrList = NULL;

        if( poOFD->GetType() == OFTIntegerList )
        {
            panIntList = (int *) CPLCalloc(sizeof(int),nSubSeqCount);
        }
        else if( poOFD->GetType() == OFTRealList )
        {
            padfDblList = (double *) CPLCalloc(sizeof(double),nSubSeqCount);
        }
        else if( poOFD->GetType() == OFTStringList )
        {
            papszStrList = (char **) CPLCalloc(sizeof(char*),nSubSeqCount+1);
        }
        else
            continue;

/* -------------------------------------------------------------------- */
/*      Loop, fetching subsequence values.                              */
/* -------------------------------------------------------------------- */
        int iSubIndex;
        for( iSubIndex = 0; iSubIndex < nSubSeqCount; iSubIndex++ )
        {
            poFieldVar = poSubSeq->var_value( iSubIndex, pszPathFromSubSeq );

            if( poFieldVar == NULL )
                continue;

            switch( poFieldVar->type() )
            {
              case dods_byte_c:
              {
                  signed char byVal;
                  void *pValPtr = &byVal;
                  
                  poFieldVar->buf2val( &pValPtr );
                  panIntList[iSubIndex] = byVal;
              }
              break;
              
              case dods_int16_c:
              {
                  GInt16 nIntVal;
                  void *pValPtr = &nIntVal;
                  
                  poFieldVar->buf2val( &pValPtr );
                  panIntList[iSubIndex] = nIntVal;
              }
              break;
              
              case dods_uint16_c:
              {
                  GUInt16 nIntVal;
                  void *pValPtr = &nIntVal;
                  
                  poFieldVar->buf2val( &pValPtr );
                  panIntList[iSubIndex] = nIntVal;
              }
              break;
              
              case dods_int32_c:
              {
                  GInt32 nIntVal;
                  void *pValPtr = &nIntVal;
                  
                  poFieldVar->buf2val( &pValPtr );
                  panIntList[iSubIndex] = nIntVal;
              }
              break;

              case dods_uint32_c:
              {
                  GUInt32 nIntVal;
                  void *pValPtr = &nIntVal;
              
                  poFieldVar->buf2val( &pValPtr );
                  panIntList[iSubIndex] = nIntVal;
              }
              break;

              case dods_float32_c:
                padfDblList[iSubIndex] = 
                    dynamic_cast<Float32 *>(poFieldVar)->value();
                break;

              case dods_float64_c:
                padfDblList[iSubIndex] = 
                    dynamic_cast<Float64 *>(poFieldVar)->value();
                break;

              case dods_str_c:
              case dods_url_c:
              {
                  string *poStrVal = NULL;
                  poFieldVar->buf2val( (void **) &poStrVal );
                  papszStrList[iSubIndex] = CPLStrdup( poStrVal->c_str() );
                  delete poStrVal;
              }
              break;

              default:
                break;
            }
        }

/* -------------------------------------------------------------------- */
/*      Apply back to feature.                                          */
/* -------------------------------------------------------------------- */
        if( poOFD->GetType() == OFTIntegerList )
        {
            poFeature->SetField( iField, nSubSeqCount, panIntList );
            CPLFree(panIntList);
        }
        else if( poOFD->GetType() == OFTRealList )
        {
            poFeature->SetField( iField, nSubSeqCount, padfDblList );
            CPLFree(padfDblList);
        }
        else if( poOFD->GetType() == OFTStringList )
        {
            poFeature->SetField( iField, papszStrList );
            CSLDestroy( papszStrList );
        }
    }
    
/* ==================================================================== */
/*      Fetch the geometry.                                             */
/* ==================================================================== */
    if( oXField.bValid && oYField.bValid )
    {
        int iXField = poFeature->GetFieldIndex( oXField.pszFieldName );
        int iYField = poFeature->GetFieldIndex( oYField.pszFieldName );
        int iZField = -1;

        if( oZField.bValid )
            iZField = poFeature->GetFieldIndex(oZField.pszFieldName);

/* -------------------------------------------------------------------- */
/*      If we can't find the values in attributes then use the more     */
/*      general mechanism to fetch the value.                           */
/* -------------------------------------------------------------------- */
        
        if( iXField == -1 || iYField == -1 
            || (oZField.bValid && iZField == -1) )
        {
            poFeature->SetGeometryDirectly( 
                new OGRPoint( GetFieldValueAsDouble( &oXField, iSubSeq ),
                              GetFieldValueAsDouble( &oYField, iSubSeq ),
                              GetFieldValueAsDouble( &oZField, iSubSeq ) ) );
        }
/* -------------------------------------------------------------------- */
/*      If the fields are list values, then build a linestring.         */
/* -------------------------------------------------------------------- */
        else if( poFeature->GetFieldDefnRef(iXField)->GetType() == OFTRealList
            && poFeature->GetFieldDefnRef(iYField)->GetType() == OFTRealList )
        {
            const double *padfX, *padfY, *padfZ = NULL;
            int nPointCount, i;
            OGRLineString *poLS = new OGRLineString();
            
            padfX = poFeature->GetFieldAsDoubleList( iXField, &nPointCount );
            padfY = poFeature->GetFieldAsDoubleList( iYField, &nPointCount );
            if( iZField != -1 )
                padfZ = poFeature->GetFieldAsDoubleList(iZField,&nPointCount);

            poLS->setPoints( nPointCount, (double *) padfX, (double *) padfY,
                             (double *) padfZ );

            // Make a pass clearing out NaN or Inf values. 
            for( i = 0; i < nPointCount; i++ )
            {
                double dfX = poLS->getX(i);
                double dfY = poLS->getY(i);
                double dfZ = poLS->getZ(i);
                int bReset = FALSE;

                if( OGRDODSIsDoubleInvalid( &dfX ) )
                {
                    dfX = 0.0;
                    bReset = TRUE;
                }
                if( OGRDODSIsDoubleInvalid( &dfY ) )
                {
                    dfY = 0.0;
                    bReset = TRUE;
                }
                if( OGRDODSIsDoubleInvalid( &dfZ ) )
                {
                    dfZ = 0.0;
                    bReset = TRUE;
                }

                if( bReset )
                    poLS->setPoint( i, dfX, dfY, dfZ );
            }

            poFeature->SetGeometryDirectly( poLS );
        }

/* -------------------------------------------------------------------- */
/*      Otherwise build a point.                                        */
/* -------------------------------------------------------------------- */
        else
        {
            poFeature->SetGeometryDirectly( 
                new OGRPoint( 
                    poFeature->GetFieldAsDouble( iXField ),
                    poFeature->GetFieldAsDouble( iYField ),
                    poFeature->GetFieldAsDouble( iZField ) ) );
        }
    }

    return poFeature;
}
Exemplo n.º 24
0
bool OGRDODSGridLayer::ProvideDataDDS()

{
    if( bDataLoaded )
        return poTargetVar != NULL;

    const bool  bResult = OGRDODSLayer::ProvideDataDDS();

    if( !bResult )
        return bResult;

    for( int iArray=0; iArray < nArrayRefCount; iArray++ )
    {
        OGRDODSArrayRef *poRef = paoArrayRefs + iArray;
        BaseType *poTarget = poDataDDS->var( poRef->pszName );

        // Reset ref array pointer to point in DataDDS result.
        if( poTarget->type() == dods_grid_c )
        {
            Grid *poGrid = dynamic_cast<Grid *>( poTarget );
            poRef->poArray = dynamic_cast<Array *>(poGrid->array_var());

            if( iArray == 0 )
                poTargetGrid = poGrid;
        }
        else if( poTarget->type() == dods_array_c )
        {
            poRef->poArray = dynamic_cast<Array *>( poTarget );
        }
        else
        {
            CPLAssert( false );
            return false;
        }

        if( iArray == 0 )
            poTargetArray = poRef->poArray;

        // Allocate appropriate raw data array, and pull out data into it.
        poRef->pRawData = CPLMalloc( poRef->poArray->width() );
        poRef->poArray->buf2val( &(poRef->pRawData) );
    }

    // Setup pointers to each of the map objects.
    if( poTargetGrid != NULL )
    {
        int iMap = 0;
        Grid::Map_iter iterMap;

        for( iterMap = poTargetGrid->map_begin();
             iterMap != poTargetGrid->map_end();
             iterMap++, iMap++ )
        {
            paoDimensions[iMap].poMap = dynamic_cast<Array *>(*iterMap);
            if( paoDimensions[iMap].poMap == NULL )
                return false;
            paoDimensions[iMap].pRawData =
                CPLMalloc( paoDimensions[iMap].poMap->width() );
            paoDimensions[iMap].poMap->buf2val( &(paoDimensions[iMap].pRawData) );
        }
    }

    return bResult;
}
Exemplo n.º 25
0
Instance MemoryDump::getNextInstance(const QString& component,
									 const Instance& instance,
									 KnowledgeSources src) const
{
	Instance result;
	QString typeString, symbol, offsetString, candidate, arrayIndexString;
	bool okay;
//    quint32 compatibleCnt = 0;

	// A component should have the form (symbol(-offset)?)?symbol(<candidate>)?([index])?
#define SYMBOL "[A-Za-z0-9_]+"
#define NUMBER "\\d+"
	QRegExp re(
				"^\\s*(?:"
					"\\(\\s*"
						"(" SYMBOL ")"
						"(?:"
							"\\s*-\\s*(" SYMBOL ")"
						")?"
					"\\s*\\)"
				")?"
				"\\s*(" SYMBOL ")\\s*"
				"(?:<\\s*(" NUMBER ")\\s*>\\s*)?"
				"((?:\\[\\s*" NUMBER "\\s*\\]\\s*)*)\\s*");
	 
	if (!re.exactMatch(component)) {
		queryError(QString("Could not parse a part of the query string: %1")
		            .arg(component));
    }
	
	// Set variables according to the matching
	typeString = re.cap(1);
	offsetString = re.cap(2).trimmed();
	symbol = re.cap(3);
	candidate = re.cap(4);
	arrayIndexString = re.cap(5).trimmed();

	int candidateIndex = candidate.isEmpty() ? -1 : candidate.toInt();

//	debugmsg(QString("1: %1, 2: %2, 3: %3, 4: %4, 5: %5")
//			 .arg(re.cap(1))
//			 .arg(re.cap(2))
//			 .arg(re.cap(3))
//			 .arg(re.cap(4))
//			 .arg(re.cap(5)));

	// A candidate index of 0 means to ignore the alternative types
	if (candidateIndex == 0)
		src = static_cast<KnowledgeSources>(src|ksNoAltTypes);

	// If the given instance is Null, we interpret this as the first component
	// in the query string and will therefore try to resolve the variable.
	if (!instance.isValid()) {
		 Variable* v = _factory->findVarByName(symbol);

		if (!v)
			queryError(QString("Variable does not exist: %1").arg(symbol));

		if (candidateIndex > 0) {
			if (v->altRefTypeCount() < candidateIndex)
				queryError(QString("Variable \"%1\" does not have a candidate "
								   "with index %2")
							.arg(symbol)
							.arg(candidateIndex));
			result = v->altRefTypeInstance(_vmem, candidateIndex - 1);
		}
		else {
			result = v->toInstance(_vmem, BaseType::trLexical, src);
		}
	}
	else {
		// Dereference any pointers/arrays first
		result = instance.dereference(BaseType::trAnyNonNull);

		// Did we get a null instance?
		if (!(result.type()->type() & StructOrUnion) &&
			(result.isNull() || !result.toPointer()))
			queryError(QString("Member \"%1\" is null")
					   .arg(result.fullName()));
		// We have a instance therefore we resolve the member
		if (!(result.type()->type() & StructOrUnion))
            queryError(QString("Member \"%1\" is not a struct or union")
                        .arg(result.fullName()));

        if (!result.memberExists(symbol))
            queryError(QString("Struct \"%1\" has no member named \"%2\"")
                        .arg(result.typeName())
                        .arg(symbol));

        // Do we have a candidate index?
        if (candidateIndex > 0) {
            if (result.memberCandidatesCount(symbol) < candidateIndex)
                queryError(QString("Member \"%1\" does not have a candidate "
                                   "with index %2")
                            .arg(symbol)
                            .arg(candidateIndex));
            result = result.memberCandidate(symbol, candidateIndex - 1);
        }
        else {
            result = result.member(symbol, BaseType::trLexical, 0, src);
        }
	}

	if (!result.isValid())
		return result;
	
	// Cast the instance if necessary
	if (!typeString.isEmpty()) {
		quint32 offset = 0;
		// Is a offset given?
		if (!offsetString.isEmpty()) {
			// Is the offset given as string or as int?
			offset = offsetString.toUInt(&okay, 10);
			
			if (!okay) {
				// String.
				BaseType* type = getType(typeString);
				
				if (!type ||
					!(type->type() & StructOrUnion))
					queryError(QString("The given type \"%1\" is not a struct "
					            "or union and therefore has no offset")
					            .arg(typeString));
				
				Structured* structd = dynamic_cast<Structured *>(type);
				
				if (!structd->memberExists(offsetString)) {
					queryError(QString("Struct of type \"%1\" has no member "
					            "named \"%2\"")
								.arg(typeString)
								.arg(offsetString));
				}
				else {
					StructuredMember* structdMember =
							structd->member(offsetString);
					offset = structdMember->offset();
				}
			}
		}

		// Get address
		size_t address;
		if (result.type()->type() & (rtPointer))
			address = (size_t)result.toPointer() - offset;
		else
			address = result.address() - offset;
		
		result = getInstanceAt(typeString, address, result.fullNameComponents());
	}
	
	// Add array index
	if (!arrayIndexString.isEmpty()) {
		QRegExp reArrayIndex("\\[\\s*(" NUMBER ")\\s*\\]\\s*");
		QStringList matches;
		int strpos = 0;
		while (strpos < arrayIndexString.size() &&
			   (strpos = arrayIndexString.indexOf(reArrayIndex, strpos)) >= 0)
		{
			matches.append(reArrayIndex.cap(1));
			strpos += reArrayIndex.cap(0).size();
		}

		for (int i = 0; i < matches.count(); ++i) {
			quint32 arrayIndex = matches[i].toUInt(&okay, 10);

			if (okay) {
				// Is the result already an instance list?
				if (result.isList()) {
					InstanceList list(result.toList());
					if (arrayIndex < (quint32)list.size())
						result = list[arrayIndex];
					else
						queryError(QString("Given array index %1 is out of bounds.")
								   .arg(arrayIndex));
				}
				else {
					// Is this a pointer or an array type?
					Instance tmp = result.arrayElem(arrayIndex);
					if (!tmp.isNull())
						result = tmp.dereference(BaseType::trLexical);
					// Manually update the address
					else {
						result.addToAddress(arrayIndex * result.type()->size());
						result.setName(QString("%1[%2]").arg(result.name()).arg(arrayIndex));
					}
				}
			}
			else {
				queryError(QString("Given array index %1 could not be converted "
								   "to a number.")
						   .arg(matches[i]));
			}
		}
		
	}
	// Try to dereference this instance as deep as possible
	return result.dereference(BaseType::trLexicalAndPointers);
}
Exemplo n.º 26
0
        void init(const Wells* wells, const State& state, const PrevState& prevState, const PhaseUsage& pu)
        {
            // call init on base class
            BaseType :: init(wells, state, prevState);

            // if there are no well, do nothing in init
            if (wells == 0) {
                return;
            }

            const int nw = wells->number_of_wells;
            if( nw == 0 ) return ;

            const int np = wells->number_of_phases;

            well_solutions_.clear();
            well_solutions_.resize(nw * np, 0.0);
            std::vector<double> g = {1.0,1.0,0.01};
            for (int w = 0; w < nw; ++w) {
                WellControls* wc = wells->ctrls[w];

                // The current control in the well state overrides
                // the current control set in the Wells struct, which
                // is instead treated as a default.
                const int current = currentControls()[w];
                well_controls_set_current( wc, current);
                const WellType& well_type = wells->type[w];

                switch (well_controls_iget_type(wc, current)) {
                case THP: // Intentional fall-through
                case BHP:
                {
                    if (well_type == INJECTOR) {
                        for (int p = 0; p < np; ++p)  {
                            well_solutions_[w] += wellRates()[np*w + p] * wells->comp_frac[np*w + p];
                        }
                    } else {
                        for (int p = 0; p < np; ++p) {
                            well_solutions_[w] += g[p] * wellRates()[np*w + p];
                        }
                    }
                }
                    break;


                case RESERVOIR_RATE: // Intentional fall-through
                case SURFACE_RATE:
                {
                    wellSolutions()[w] = bhp()[w];

                }
                    break;
                }

                double total_rates = 0.0;
                for (int p = 0; p < np; ++p)  {
                    total_rates += g[p] * wellRates()[np*w + p];
                }

                const int waterpos = pu.phase_pos[Water];
                const int gaspos = pu.phase_pos[Gas];

                assert(np == 3 || (np == 2 && !pu.phase_used[Gas]));
                // assumes the gas fractions are stored after water fractions
                if(std::abs(total_rates) > 0) {
                    if( pu.phase_used[Water] ) {
                        wellSolutions()[nw + w] = g[Water] * wellRates()[np*w + waterpos] / total_rates;
                    }
                    if( pu.phase_used[Gas] ) {
                        wellSolutions()[2*nw + w] = g[Gas] * wellRates()[np*w + gaspos] / total_rates ;
                    }
                } else {
                    if( pu.phase_used[Water] ) {
                        wellSolutions()[nw + w] = wells->comp_frac[np*w + waterpos];
                    }
                    if( pu.phase_used[Gas] ) {
                        wellSolutions()[2*nw + w] = wells->comp_frac[np*w + gaspos];
                    }
                }
            }


            // intialize wells that have been there before
            // order may change so the mapping is based on the well name
            if( ! prevState.wellMap().empty() )
            {
                typedef typename WellMapType :: const_iterator const_iterator;
                const_iterator end = prevState.wellMap().end();
                int nw_old = prevState.bhp().size();
                for (int w = 0; w < nw; ++w) {
                    std::string name( wells->name[ w ] );
                    const_iterator it = prevState.wellMap().find( name );
                    if( it != end )
                    {
                        const int oldIndex = (*it).second[ 0 ];
                        const int newIndex = w;

                        // wellSolutions
                        for( int i = 0;  i < np; ++i)
                        {
                            wellSolutions()[ i*nw + newIndex ] = prevState.wellSolutions()[i * nw_old + oldIndex ];
                        }

                    }
                }
            }
        }
Exemplo n.º 27
0
 FixedMap(const std::map<KeyType, ValueType, Comp, Alloc>& other)
     : FixedMap() {
   insert(std::begin(other), std::end(other));
 }
Exemplo n.º 28
0
 FixedMap(InputIterator first, InputIterator last,
          const Compare& comp = Compare())
     : FixedMap(comp) {
   insert(first, last);
 }
Exemplo n.º 29
0
 FixedMap(std::map<KeyType, ValueType, Comp, Alloc>&& other)
     : FixedMap() {
   insert(std::begin(other), std::end(other));
   other.clear();
 }
Exemplo n.º 30
0
template <typename Iter, typename Traits> NEXTWEB_INLINE std::streamsize
StreamBuffer<Iter, Traits>::showmanyc() {
	assert(gptr() == egptr());
	DistanceType dist = std::distance(current_, end_);
	return (0 == dist) ? static_cast<std::streamsize>(-1) : static_cast<std::streamsize>(dist);
}