Beispiel #1
0
//==================================================================================
//Return the value for a given column for the current record
QVariant PostgresqlCursor::value(int pos)
{
    if (pos < m_fieldCount)
        return pValue(pos);
    else
        return QVariant();
}
Beispiel #2
0
//==================================================================================
//Store the current record in [data]
bool PostgresqlCursor::drv_storeCurrentRecord(KDbRecordData* data) const
{
// postgresqlDebug() << "POSITION IS" << (long)m_at;
    for (int i = 0; i < m_fieldsToStoreInRecord; i++)
        (*data)[i] = pValue(i);
    return true;
}
//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
GroupMemberDataMap::pFutureGroupMemberDomainObject_type
GroupMemberDataMap::getByKey(boost::uint64_t _primaryKeyValue)
{
    // Start a transaction
    Zen::Database::I_DatabaseConnection::pDatabaseTransaction_type 
        pTransaction = getDatabaseConnection()->beginTransaction();

    // Create a query
    Zen::Database::I_DatabaseTransaction::pStaticQuery_type 
        pQuery = pTransaction->createStaticQuery();

	const boost::uint64_t primaryKeyValue(_primaryKeyValue);

    // Get a record from the GroupMember.
    std::stringstream query;
    query << "SELECT * FROM GroupMember WHERE memberId = " << primaryKeyValue;

    pQuery->setQuery(query.str());
    
	pFutureGroupMemberDomainObject_type pReturnValue(new FutureGroupMemberDomainObject_type);
    pGroupMemberDomainObject_type pValue(new GroupMemberDomainObject, &destroyObject);

    // Create a result handler to handle the execution results
    Zen::Database::I_DatabaseTransaction::pQueryResultHandler_type pResultHandler(new ResultHandler(pTransaction, pReturnValue, pValue));

    // Execute the query.  
    pTransaction->executeQuery(pQuery, pResultHandler);
    
    return pReturnValue;
}
Beispiel #4
0
//--------------------------------------------------------------
//Draw should always be as fast as possible, so any heavy computations
// should be done in update.
//-----
void testApp::draw(){
    //Draw the two matrices
    drawMatrix(5,5+24+5+24+5,260,260,randCounts, 0, experimentsDone/26);
    drawMatrix(260+10,5+24+5+24+5,260,260,shuffleCounts,0,experimentsDone/26);
    
    //Draw info about how long we have been running
    //Draw text in black
    ofSetColor(0);
    ostringstream stringBuilder;
    stringBuilder << experimentsDone << " experiments done" << flush;
    double strWidth = arial24.stringWidth(stringBuilder.str());
    double strX = (ofGetWidth() - strWidth)/2;
    arial24.drawString(stringBuilder.str(), strX, 260+5+24+5+24+24+5);
    
    //Clear out the string buffer for re-use
    stringBuilder.clear();
    stringBuilder.str("");
    
    //Calculate the p value for true random, and print it
    stringBuilder << "p < " << pValue(randCounts) << flush;
    strWidth = arial24.stringWidth(stringBuilder.str());
    strX = 5 + (260 - strWidth)/2;
    arial24.drawString(stringBuilder.str(), strX, 130+5+24+5+24+24+5);
    
    //Clear out the string buffer for re-use
    stringBuilder.clear();
    stringBuilder.str("");
    
    //Calculate the p value for shuffle, and print it
    stringBuilder << "p < " << pValue(shuffleCounts) << flush;
    strWidth = arial24.stringWidth(stringBuilder.str());
    strX = 10 + 260 + (260 - strWidth)/2;
    arial24.drawString(stringBuilder.str(), strX, 130+5+24+5+24+24+5);
    
    //Clear out the string buffer for re-use
    stringBuilder.clear();
    stringBuilder.str("");
    
    //Calculate the p value for shuffle, and print it
    stringBuilder << "If shuffle is truly random, what is chance\nof this outcome? (small is bad)" << flush;
    strWidth = arial24.stringWidth(stringBuilder.str());
    strX = (ofGetWidth() - strWidth)/2;
    arial24.drawString(stringBuilder.str(), strX, 24);
}
void CScript_HostPseudoModel::OpenList(CFXJSE_Arguments* pArguments) {
  if (!m_pDocument->GetScriptContext()->IsRunAtClient()) {
    return;
  }
  int32_t iLength = pArguments->GetLength();
  if (iLength != 1) {
    ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"openList");
    return;
  }
  CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
  if (!pNotify) {
    return;
  }
  CXFA_Node* pNode = nullptr;
  if (iLength >= 1) {
    std::unique_ptr<CFXJSE_Value> pValue(pArguments->GetValue(0));
    if (pValue->IsObject()) {
      pNode = ToNode(pValue.get(), nullptr);
    } else if (pValue->IsString()) {
      CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
      if (!pScriptContext)
        return;

      CXFA_Object* pObject = pScriptContext->GetThisObject();
      if (!pObject)
        return;

      uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Parent |
                        XFA_RESOLVENODE_Siblings;
      XFA_RESOLVENODE_RS resoveNodeRS;
      int32_t iRet = pScriptContext->ResolveObjects(
          pObject, pValue->ToWideString().AsStringC(), resoveNodeRS, dwFlag);
      if (iRet < 1 || !resoveNodeRS.nodes[0]->IsNode())
        return;

      pNode = resoveNodeRS.nodes[0]->AsNode();
    }
  }
  CXFA_LayoutProcessor* pDocLayout = m_pDocument->GetDocLayout();
  if (!pDocLayout) {
    return;
  }
  CXFA_FFWidget* hWidget =
      pNotify->GetHWidget(pDocLayout->GetLayoutItem(pNode));
  if (!hWidget) {
    return;
  }
  pNotify->GetDocEnvironment()->SetFocusWidget(pNotify->GetHDOC(), hWidget);
  pNotify->OpenDropDownList(hWidget);
}
Beispiel #6
0
    Document::Document(BSONObj *pBsonObj):
        vFieldName(),
        vpValue() {
        BSONObjIterator bsonIterator(pBsonObj->begin());
        while(bsonIterator.more()) {
            BSONElement bsonElement(bsonIterator.next());
            string fieldName(bsonElement.fieldName());
	    intrusive_ptr<const Value> pValue(
                Value::createFromBsonElement(&bsonElement));

            vFieldName.push_back(fieldName);
            vpValue.push_back(pValue);
        }
    }
    intrusive_ptr<Document> DocumentSourceGroup::makeDocument(
        const GroupsType::iterator &rIter) {
        vector<intrusive_ptr<Accumulator> > *pGroup = &rIter->second;
        const size_t n = vFieldName.size();
        intrusive_ptr<Document> pResult(Document::create(1 + n));

        /* add the _id field */
        pResult->addField(Document::idName, rIter->first);

        /* add the rest of the fields */
        for(size_t i = 0; i < n; ++i) {
	    intrusive_ptr<const Value> pValue((*pGroup)[i]->getValue());
	    if (pValue->getType() != Undefined)
		pResult->addField(vFieldName[i], pValue);
	}

        return pResult;
    }
Beispiel #8
0
char* pAmount(My402ListElem *elem, char *amt)
{
    ListEntry *Entry;
    
    /*
     * 14 for amount along with brackets
     * 1 for null
     */
    char temp[15];


    Entry = (ListEntry *)elem->obj;
    if(Entry->trans_amt >= 1000000000){
        if(Entry->trans_type[0] == '+'){
            strncpy(amt,"?,???,???.?? ", 15);
        }else {
            strncpy(amt, "(?,???,???.??", 15);
            strcat(amt, ")");
        }
        return amt;
    }
    snprintf(temp, 15, "%03d", Entry->trans_amt);

    /*
     * number of spaces to be given
     */
    amt = pValue(amt, temp);
    if(Entry->trans_type[0] == '+'){
        memset(temp, 0, 15);
        strncpy(temp, amt, 15);
        memset(amt, 0, 15);
        snprintf(amt, 15, "%13s",temp);
        strncat(amt, " ", 15);
    } else{
        memset(temp, 0, 15);
        strncpy(temp, amt, 15);
        memset(amt, 0, 15);
        snprintf(amt, 15, "(%12s",temp);
        strncat(amt, ")", 15);
    }
    return amt;
}
Beispiel #9
0
bool set_chanel_freq_rate (uint8_t channel, uint8_t band,uint8_t bitrate){

  printf("Channel amoutn %d, chanel %d",chanelAmount(band, bitrate),channel);
  if (channel >= chanelAmount(band, bitrate)) {
    //errstate invalid_chanel_freq_rate;
    return false;
  }

  //Program registers R, P, S and Synthesize the RF
   PHY_STORAGE.channel=channel;
   PHY_STORAGE.band=band;
   PHY_STORAGE.bitrate=bitrate;
   
   
   D_PHY printf("Chanel %d band %d bitrate %d\n", channel, band, bitrate);

  set_register(R1CNTREG, rValue());
  set_register(P1CNTREG, pValue(band, channel, bitrate));
  set_register(S1CNTREG, sValue(band, channel, bitrate));
  
  return true;
}
/**
 *	This method returns the property in datasection form.
 *
 *	@param	index	The index of the property in pType.
 *	@return	The property in datasection form.
 */
DataSectionPtr PropertiesHelper::propGet( PropertyIndex index )
{
	if ( pType_ == NULL || index.empty() )
		return NULL;

	MF_ASSERT( index.valueAt(0) < (int) pType_->propertyCount() );
	DataDescription * pDD = pType_->property( index.valueAt(0) );

	PyObjectPtr pValue( propGetPy( index ), PyObjectPtr::STEAL_REFERENCE );

	if (pValue == NULL)
	{
		PyErr_Clear();

		PyObject * pStr = PyObject_Str( pDict_ );
		Py_XDECREF( pStr );

		return NULL;
	}

	DataSectionPtr pTemp = new XMLSection( "temp" );

	if ( index.count() > 1 )
	{
		PyObjectPtr ob( propGetPy( index.valueAt(0) ), PyObjectPtr::STEAL_REFERENCE );
		if ( PySequence_Check( ob.getObject() ) )
		{
			// requesting and array item, so return it.
			SequenceDataType* dataType = static_cast<SequenceDataType*>( pDD->dataType() );
			dataType->getElemType().addToSection( pValue.getObject(), pTemp );
			return pTemp;
		}
	}
	
	pDD->addToSection( pValue.getObject(), pTemp );

	return pTemp;
}
    Document DocumentSourceGroup::makeDocument(
        const GroupsType::iterator &rIter) {
        vector<intrusive_ptr<Accumulator> > *pGroup = &rIter->second;
        const size_t n = vFieldName.size();
        MutableDocument out (1 + n);

        /* add the _id field */
        out.addField("_id", rIter->first);

        /* add the rest of the fields */
        for(size_t i = 0; i < n; ++i) {
            Value pValue((*pGroup)[i]->getValue());
            if (pValue.missing()) {
                // we return undefined in this case so return objects are predictable
                out.addField(vFieldName[i], Value(BSONUndefined));
            }
            else {
                out.addField(vFieldName[i], pValue);
            }
        }

        return out.freeze();
    }
intrusive_ptr<DocumentSource> DocumentSourceGroup::createFromBson(
    BSONElement *pBsonElement,
    const intrusive_ptr<ExpressionContext> &pCtx) {
    assert(pBsonElement->type() == Object); // CW TODO must be an object

    intrusive_ptr<DocumentSourceGroup> pGroup(
        DocumentSourceGroup::create(pCtx));
    bool idSet = false;

    BSONObj groupObj(pBsonElement->Obj());
    BSONObjIterator groupIterator(groupObj);
    while(groupIterator.more()) {
        BSONElement groupField(groupIterator.next());
        const char *pFieldName = groupField.fieldName();

        if (strcmp(pFieldName, Document::idName.c_str()) == 0) {
            assert(!idSet); // CW TODO _id specified multiple times

            BSONType groupType = groupField.type();

            if (groupType == Object) {
                /*
                  Use the projection-like set of field paths to create the
                  group-by key.
                */
                Expression::ObjectCtx oCtx(
                    Expression::ObjectCtx::DOCUMENT_OK);
                intrusive_ptr<Expression> pId(
                    Expression::parseObject(&groupField, &oCtx));

                pGroup->setIdExpression(pId);
                idSet = true;
            }
            else if (groupType == String) {
                string groupString(groupField.String());
                const char *pGroupString = groupString.c_str();
                if ((groupString.length() == 0) ||
                        (pGroupString[0] != '$'))
                    goto StringConstantId;

                string pathString(
                    Expression::removeFieldPrefix(groupString));
                intrusive_ptr<ExpressionFieldPath> pFieldPath(
                    ExpressionFieldPath::create(pathString));
                pGroup->setIdExpression(pFieldPath);
                idSet = true;
            }
            else {
                /* pick out the constant types that are allowed */
                switch(groupType) {
                case NumberDouble:
                case String:
                case Object:
                case Array:
                case jstOID:
                case Bool:
                case Date:
                case NumberInt:
                case Timestamp:
                case NumberLong:
                case jstNULL:
StringConstantId: // from string case above
                    {
                        intrusive_ptr<const Value> pValue(
                            Value::createFromBsonElement(&groupField));
                        intrusive_ptr<ExpressionConstant> pConstant(
                            ExpressionConstant::create(pValue));
                        pGroup->setIdExpression(pConstant);
                        idSet = true;
                        break;
                    }

                default:
                    assert(false);
                    // CW TODO disallowed constant group key
                }
            }
        }
        else {
            /*
              Treat as a projection field with the additional ability to
              add aggregation operators.
            */
            assert(*pFieldName != '$');
            // CW TODO error: field name can't be an operator
            assert(groupField.type() == Object);
            // CW TODO error: must be an operator expression

            BSONObj subField(groupField.Obj());
            BSONObjIterator subIterator(subField);
            size_t subCount = 0;
            for(; subIterator.more(); ++subCount) {
                BSONElement subElement(subIterator.next());

                /* look for the specified operator */
                GroupOpDesc key;
                key.pName = subElement.fieldName();
                const GroupOpDesc *pOp =
                    (const GroupOpDesc *)bsearch(
                        &key, GroupOpTable, NGroupOp, sizeof(GroupOpDesc),
                        GroupOpDescCmp);

                assert(pOp); // CW TODO error: operator not found

                intrusive_ptr<Expression> pGroupExpr;

                BSONType elementType = subElement.type();
                if (elementType == Object) {
                    Expression::ObjectCtx oCtx(
                        Expression::ObjectCtx::DOCUMENT_OK);
                    pGroupExpr = Expression::parseObject(
                                     &subElement, &oCtx);
                }
                else if (elementType == Array) {
                    assert(false); // CW TODO group operators are unary
                }
                else { /* assume its an atomic single operand */
                    pGroupExpr = Expression::parseOperand(&subElement);
                }

                pGroup->addAccumulator(
                    pFieldName, pOp->pFactory, pGroupExpr);
            }

            assert(subCount == 1);
            // CW TODO error: only one operator allowed
        }
    }

    assert(idSet); // CW TODO error: missing _id specification

    return pGroup;
}
bool DocumentSourceFilter::accept(
    const intrusive_ptr<Document> &pDocument) const {
    intrusive_ptr<const Value> pValue(pFilter->evaluate(pDocument));
    return pValue->coerceToBool();
}
int32_t CXFA_ScriptContext::ResolveObjects(CXFA_Object* refNode,
                                           const CFX_WideStringC& wsExpression,
                                           XFA_RESOLVENODE_RS& resolveNodeRS,
                                           uint32_t dwStyles,
                                           CXFA_Node* bindNode) {
  if (wsExpression.IsEmpty()) {
    return 0;
  }
  if (m_eScriptType != XFA_SCRIPTLANGTYPE_Formcalc ||
      (dwStyles & (XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings))) {
    m_upObjectArray.RemoveAll();
  }
  if (refNode && refNode->IsNode() &&
      (dwStyles & (XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings))) {
    m_upObjectArray.Add(refNode->AsNode());
  }
  FX_BOOL bNextCreate = FALSE;
  if (dwStyles & XFA_RESOLVENODE_CreateNode) {
    m_ResolveProcessor->GetNodeHelper()->SetCreateNodeType(bindNode);
  }
  m_ResolveProcessor->GetNodeHelper()->m_pCreateParent = nullptr;
  m_ResolveProcessor->GetNodeHelper()->m_iCurAllStart = -1;
  CXFA_ResolveNodesData rndFind;
  int32_t nStart = 0;
  int32_t nLevel = 0;
  int32_t nRet = -1;
  rndFind.m_pSC = this;
  CXFA_ObjArray findNodes;
  findNodes.Add(refNode ? refNode : m_pDocument->GetRoot());
  int32_t nNodes = 0;
  while (TRUE) {
    nNodes = findNodes.GetSize();
    int32_t i = 0;
    rndFind.m_dwStyles = dwStyles;
    m_ResolveProcessor->SetCurStart(nStart);
    nStart = m_ResolveProcessor->GetFilter(wsExpression, nStart, rndFind);
    if (nStart < 1) {
      if ((dwStyles & XFA_RESOLVENODE_CreateNode) && !bNextCreate) {
        CXFA_Node* pDataNode = nullptr;
        nStart = m_ResolveProcessor->GetNodeHelper()->m_iCurAllStart;
        if (nStart != -1) {
          pDataNode = m_pDocument->GetNotBindNode(findNodes);
          if (pDataNode) {
            findNodes.RemoveAll();
            findNodes.Add(pDataNode);
            break;
          }
        } else {
          pDataNode = findNodes[0]->AsNode();
          findNodes.RemoveAll();
          findNodes.Add(pDataNode);
          break;
        }
        dwStyles |= XFA_RESOLVENODE_Bind;
        findNodes.RemoveAll();
        findNodes.Add(m_ResolveProcessor->GetNodeHelper()->m_pAllStartParent);
        continue;
      } else {
        break;
      }
    }
    if (bNextCreate) {
      FX_BOOL bCreate =
          m_ResolveProcessor->GetNodeHelper()->ResolveNodes_CreateNode(
              rndFind.m_wsName, rndFind.m_wsCondition,
              nStart == wsExpression.GetLength(), this);
      if (bCreate) {
        continue;
      } else {
        break;
      }
    }
    CXFA_ObjArray retNodes;
    while (i < nNodes) {
      FX_BOOL bDataBind = FALSE;
      if (((dwStyles & XFA_RESOLVENODE_Bind) ||
           (dwStyles & XFA_RESOLVENODE_CreateNode)) &&
          nNodes > 1) {
        CXFA_ResolveNodesData rndBind;
        m_ResolveProcessor->GetFilter(wsExpression, nStart, rndBind);
        m_ResolveProcessor->SetIndexDataBind(rndBind.m_wsCondition, i, nNodes);
        bDataBind = TRUE;
      }
      rndFind.m_CurNode = findNodes[i++];
      rndFind.m_nLevel = nLevel;
      rndFind.m_dwFlag = XFA_RESOVENODE_RSTYPE_Nodes;
      nRet = m_ResolveProcessor->Resolve(rndFind);
      if (nRet < 1) {
        continue;
      }
      if (rndFind.m_dwFlag == XFA_RESOVENODE_RSTYPE_Attribute &&
          rndFind.m_pScriptAttribute && nStart < wsExpression.GetLength()) {
        std::unique_ptr<CFXJSE_Value> pValue(new CFXJSE_Value(m_pIsolate));
        (rndFind.m_Nodes[0]->*(rndFind.m_pScriptAttribute->lpfnCallback))(
            pValue.get(), FALSE,
            (XFA_ATTRIBUTE)rndFind.m_pScriptAttribute->eAttribute);
        rndFind.m_Nodes.SetAt(0, ToObject(pValue.get(), nullptr));
      }
      int32_t iSize = m_upObjectArray.GetSize();
      if (iSize) {
        m_upObjectArray.RemoveAt(iSize - 1);
      }
      retNodes.Append(rndFind.m_Nodes);
      rndFind.m_Nodes.RemoveAll();
      if (bDataBind) {
        break;
      }
    }
    findNodes.RemoveAll();
    nNodes = retNodes.GetSize();
    if (nNodes < 1) {
      if (dwStyles & XFA_RESOLVENODE_CreateNode) {
        bNextCreate = TRUE;
        if (!m_ResolveProcessor->GetNodeHelper()->m_pCreateParent) {
          m_ResolveProcessor->GetNodeHelper()->m_pCreateParent =
              ToNode(rndFind.m_CurNode);
          m_ResolveProcessor->GetNodeHelper()->m_iCreateCount = 1;
        }
        FX_BOOL bCreate =
            m_ResolveProcessor->GetNodeHelper()->ResolveNodes_CreateNode(
                rndFind.m_wsName, rndFind.m_wsCondition,
                nStart == wsExpression.GetLength(), this);
        if (bCreate) {
          continue;
        } else {
          break;
        }
      } else {
        break;
      }
    }
    findNodes.Copy(retNodes);
    rndFind.m_Nodes.RemoveAll();
    if (nLevel == 0) {
      dwStyles &= ~(XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings);
    }
    nLevel++;
  }
  if (!bNextCreate) {
    resolveNodeRS.dwFlags = rndFind.m_dwFlag;
    if (nNodes > 0) {
      resolveNodeRS.nodes.Append(findNodes);
    }
    if (rndFind.m_dwFlag == XFA_RESOVENODE_RSTYPE_Attribute) {
      resolveNodeRS.pScriptAttribute = rndFind.m_pScriptAttribute;
      return 1;
    }
  }
  if (dwStyles & (XFA_RESOLVENODE_CreateNode | XFA_RESOLVENODE_Bind |
                  XFA_RESOLVENODE_BindNew)) {
    m_ResolveProcessor->SetResultCreateNode(resolveNodeRS,
                                            rndFind.m_wsCondition);
    if (!bNextCreate && (dwStyles & XFA_RESOLVENODE_CreateNode)) {
      resolveNodeRS.dwFlags = XFA_RESOVENODE_RSTYPE_ExistNodes;
    }
    return resolveNodeRS.nodes.GetSize();
  }
  return nNodes;
}
    intrusive_ptr<DocumentSource> DocumentSourceGroup::createFromBson(
	BSONElement *pBsonElement,
	const intrusive_ptr<ExpressionContext> &pCtx) {
	uassert(15947, "a group's fields must be specified in an object",
		pBsonElement->type() == Object);

        intrusive_ptr<DocumentSourceGroup> pGroup(
	    DocumentSourceGroup::create(pCtx));
        bool idSet = false;

        BSONObj groupObj(pBsonElement->Obj());
        BSONObjIterator groupIterator(groupObj);
        while(groupIterator.more()) {
            BSONElement groupField(groupIterator.next());
            const char *pFieldName = groupField.fieldName();

            if (strcmp(pFieldName, Document::idName.c_str()) == 0) {
		uassert(15948, "a group's _id may only be specified once",
			!idSet);

		BSONType groupType = groupField.type();

		if (groupType == Object) {
		    /*
		      Use the projection-like set of field paths to create the
		      group-by key.
		    */
		    Expression::ObjectCtx oCtx(
			Expression::ObjectCtx::DOCUMENT_OK);
		    intrusive_ptr<Expression> pId(
			Expression::parseObject(&groupField, &oCtx));

		    pGroup->setIdExpression(pId);
		    idSet = true;
		}
		else if (groupType == String) {
		    string groupString(groupField.String());
		    const char *pGroupString = groupString.c_str();
		    if ((groupString.length() == 0) ||
			(pGroupString[0] != '$'))
			goto StringConstantId;

		    string pathString(
			Expression::removeFieldPrefix(groupString));
		    intrusive_ptr<ExpressionFieldPath> pFieldPath(
			ExpressionFieldPath::create(pathString));
		    pGroup->setIdExpression(pFieldPath);
		    idSet = true;
		}
		else {
		    /* pick out the constant types that are allowed */
		    switch(groupType) {
		    case NumberDouble:
		    case String:
		    case Object:
		    case Array:
		    case jstOID:
		    case Bool:
		    case Date:
		    case NumberInt:
		    case Timestamp:
		    case NumberLong:
		    case jstNULL:
		    StringConstantId: // from string case above
		    {
			intrusive_ptr<const Value> pValue(
			    Value::createFromBsonElement(&groupField));
			intrusive_ptr<ExpressionConstant> pConstant(
			    ExpressionConstant::create(pValue));
			pGroup->setIdExpression(pConstant);
			idSet = true;
			break;
		    }

		    default:
			uassert(15949, str::stream() <<
				"a group's _id may not include fields of BSON type " << groupType,
				false);
		    }
		}
            }
            else {
                /*
                  Treat as a projection field with the additional ability to
                  add aggregation operators.
                */
		uassert(15950, str::stream() <<
			"the group aggregate field name " <<
			*pFieldName << " cannot be an operator name",
			*pFieldName != '$');

		uassert(15951, str::stream() << 
			"the group aggregate field " << *pFieldName <<
			"must be defined as an expression inside an object",
			groupField.type() == Object);

                BSONObj subField(groupField.Obj());
                BSONObjIterator subIterator(subField);
                size_t subCount = 0;
                for(; subIterator.more(); ++subCount) {
                    BSONElement subElement(subIterator.next());

                    /* look for the specified operator */
                    GroupOpDesc key;
                    key.pName = subElement.fieldName();
                    const GroupOpDesc *pOp =
			(const GroupOpDesc *)bsearch(
                              &key, GroupOpTable, NGroupOp, sizeof(GroupOpDesc),
                                      GroupOpDescCmp);

		    uassert(15952, str::stream() <<
			    "unknown group operator \"" <<
			    key.pName << "\"",
			    pOp);

                    intrusive_ptr<Expression> pGroupExpr;

                    BSONType elementType = subElement.type();
                    if (elementType == Object) {
			Expression::ObjectCtx oCtx(
			    Expression::ObjectCtx::DOCUMENT_OK);
                        pGroupExpr = Expression::parseObject(
			    &subElement, &oCtx);
		    }
                    else if (elementType == Array) {
			uassert(15953, str::stream() <<
				"aggregating group operators are unary (" <<
				key.pName << ")", false);
                    }
                    else { /* assume its an atomic single operand */
                        pGroupExpr = Expression::parseOperand(&subElement);
                    }

                    pGroup->addAccumulator(
                        pFieldName, pOp->pFactory, pGroupExpr);
                }

		uassert(15954, str::stream() <<
			"the computed aggregate \"" <<
			pFieldName << "\" must specify exactly one operator",
			subCount == 1);
            }
        }

	uassert(15955, "a group specification must include an _id", idSet);

        return pGroup;
    }
Beispiel #16
0
    void BlackoilCo2PVT::generateBlackOilTables(double temperature)
    {
        std::cout << "\n Generating pvt tables for the eclipse black oil formulation\n using the oil component as brine and the gas component as co_2." << std::endl;
        if (std::fabs(temperature-400.) > 100.0) {
            std::cout << "T=" << temperature << " is outside the allowed range [300,500] Kelvin" << std::endl;
            exit(-1);
        }

        temperature_ = temperature;

        CompVec z;
        z[Water] = 0.0;
        z[Oil] = 1.0;
        z[Gas] = 1.0e6;

        std::ofstream black("blackoil_pvt");
        black.precision(8);
        black << std::fixed << std::showpoint;

        const double pMin=150.e5;
        const double pMax=400.e5;
        const unsigned int np=11;
        std::vector<double> pValue(np+1,0.0);
        std::vector<double> rs(np+1,0.0);

        pValue[0] = 101330.0;
        rs[0] = 0.0;

        // Buble points 
        z[Gas] = 1.0e4;
        for (unsigned int i=0; i<np; ++i) {
            pValue[i+1] = pMin + i*(pMax-pMin)/(np-1);
            rs[i+1] = R(pValue[i+1], z, Liquid);       
        }

        const unsigned int np_fill_in = 10;
        const double dr = (rs[1] - rs[0])/(np_fill_in+1);
        const double dp = (pValue[1] - pValue[0])/(np_fill_in+1);
        rs.insert(rs.begin()+1,np_fill_in,0.0);
        pValue.insert(pValue.begin()+1,np_fill_in,0.0);
        for (unsigned int i=1; i<=np_fill_in; ++i) {
           rs[i] = rs[i-1] + dr;
           pValue[i] = pValue[i-1] + dp;
        }

        // Brine with dissolved co_2 ("live oil")
        black << "PVTO\n";
        black << "--     Rs       Pbub        Bo          Vo\n";
        black << "--  sm3/sm3     barsa       rm3/sm3     cP\n";

        // Undersaturated
        for (unsigned int i=0; i<np+np_fill_in; ++i) {
            z[Gas] = rs[i];
            black << std::setw(14) << rs[i];
            for (unsigned int j=i; j<np+1+np_fill_in; ++j) {
                if (j<=np_fill_in) {
                   if (j==i) black << std::setw(14) << pValue[j]*1.e-5 << std::setw(14) << 1.0-j*0.001 << std::setw(14) << 1.06499;
                   continue; 
                }
                if (j>i) black << std::endl << std::setw(14) << ' ';
                black << std::setw(14) << pValue[j]*1.e-5
                      << std::setw(14) << B(pValue[j], z, Liquid)
                      << std::setw(14) << getViscosity(pValue[j], z, Liquid)*1.e3;     
            }
            black << " /" <<  std::endl;
        }
        black << "/ " <<  std::endl;

        // We provide tables for co_2 both with and without dissolved water:

        // Co_2 neglecting dissolved water ("dry gas")
        black << "\nPVDG\n";
        black << "--    Pg          Bg            Vg\n";
        black << "--   barsa        rm3/sm3       cP\n";
 
        for (unsigned int i=0; i<np; ++i) {
            z[Oil] = 0.0;
            z[Gas] = 1.0;
            black << std::setw(14) << pValue[i+np_fill_in+1]*1.e-5
                  << std::setw(14) << B(pValue[i+np_fill_in+1], z, Vapour)
                  << std::setw(14) << getViscosity(pValue[i+np_fill_in+1], z, Vapour)*1.e3
                  << std::endl;     
        }
        black << "/ " <<  std::endl;

        // Co_2 with dissolved water ("wet gas")
        black << "\nPVTG\n";
        black << "--    Pg          Rv            Bg            Vg\n";
        black << "--   barsa        sm3/sm3       rm3/sm3       cP\n";
        for (unsigned int i=0; i<np; ++i) {
            z[Oil] = 1000.0;
            z[Gas] = 1.0;
            black << std::setw(14) << pValue[i+np_fill_in+1]*1.e-5
                  << std::setw(14) << R(pValue[i+np_fill_in+1], z, Vapour)
                  << std::setw(14) << B(pValue[i+np_fill_in+1], z, Vapour)
                  << std::setw(14) << getViscosity(pValue[i+np_fill_in+1], z, Vapour)*1.e3
                  << std::endl;
            z[Oil] = 0.0;
            black << std::setw(14) << ' '
                  << std::setw(14) << R(pValue[i+np_fill_in+1], z, Vapour)
                  << std::setw(14) << B(pValue[i+np_fill_in+1], z, Vapour)
                  << std::setw(14) << getViscosity(pValue[i+np_fill_in+1], z, Vapour)*1.e3
                  << " /" << std::endl;          
        }
        black << "/ " <<  std::endl;
        black << std::endl;
        std::cout << " Pvt tables for temperature=" << temperature << " Kelvin is written to file blackoil_pvt. " << std::endl;
        std::cout << " NOTE that the file contains tables for both PVDG (dry gas) and PVTG (wet gas)." << std::endl;
    }
Beispiel #17
0
char* pBalance(My402List *list, My402ListElem *elem, char *bal)
{
    int balance = 0;
    char temp[15];

    /*
     * 14 characters for balance including "(", ")"
     * 1 extra for the null character
     */

    ListEntry* Entry = NULL, *prevEntry = NULL;
    Entry = (ListEntry *)elem->obj;
    if(My402ListPrev(list, elem)){
        prevEntry = (ListEntry *)elem->prev->obj;
    }
    if(Entry->trans_type[0] == '+') {
        if(prevEntry) {
            Entry->balance =  prevEntry->balance + Entry->trans_amt;
        }else {
            Entry->balance = Entry->trans_amt;
        }
    }else{
        if(prevEntry) {
            Entry->balance = prevEntry->balance - Entry->trans_amt;
        }else {
            Entry->balance = (Entry->trans_amt) * (-1);
        }
    }

    if(Entry->balance < 0){
        balance = (Entry->balance) * (-1);
        if(balance >= 1000000000) {
            strncpy(bal, "(?,???,???.??", 15);
            strcat(bal, ")");
            return bal;
        }
        snprintf(temp, 15, "%d", balance);

        bal = pValue(bal, temp);
        strncpy(temp, bal, 15);
        memset(bal, 0, 15);
        snprintf(bal, 15, "(%12s",temp);

        strncat(bal,")", 15);
    } else{
        balance = Entry->balance;
        if(balance >= 1000000000) {
            strncpy(bal, "?,???,???.?? ", 15);
            return bal;
        }
        snprintf(temp, 15, "%d", balance);

        bal = pValue(bal, temp);
        memset(temp, 0 , 15);
        strncpy(temp, bal, 15);
        memset(bal, 0, 15);
        snprintf(bal, 15, "%13s",temp);
        strncat(bal," ", 15);
    }
    return bal;
}
 bool DocumentSourceFilter::accept(const Document& pDocument) const {
     Value pValue(pFilter->evaluate(pDocument));
     return pValue.coerceToBool();
 }