Exemplo n.º 1
0
bool OSExecutorModule::signal_event( BObjectImp* imp )
{
    INC_PROFILEVAR(events);

    if (blocked_ && (wait_type == WAIT_EVENT)) // already being waited for
    {
        /* Now, the tricky part.  The value to return on an error or
		   completion condition has already been pushed onto the value
		   stack - so, we need to replace it with the real result.
        */
        exec.ValueStack.top().set( new BObject( imp ) );
        /* This executor will get moved to the run queue at the
           next step_scripts(), where blocked is checked looking
           for timed out or completed operations. */

        revive();
    }
    else        // not being waited for, so queue for later.
    {
        if (events_.size() < max_eventqueue_size)
        {
            events_.push( imp );
        }
        else
        {
			if (config.discard_old_events)
			{
				BObject ob( events_.front() );
				events_.pop();
				events_.push( imp );
			}
			else
			{
				if (config.loglevel >= 11)
				{
					cout << "Event queue for " << exec.scriptname() << " is full, discarding event." << endl;
					ExecutorModule* em = exec.findModule( "npc" );
					if (em)
					{
						NPCExecutorModule* npcemod = static_cast<NPCExecutorModule*>(em);
						cout << "NPC Serial: " << hexint( npcemod->npc.serial ) <<
							" (" << npcemod->npc.x << " " << npcemod->npc.y << " " << (int) npcemod->npc.z << ")" << endl;
					}
					BObject ob( imp );
					cout << "Event: " << ob->getStringRep() << endl;
				}
				return false;
			}
        }
    }

	return true;
}
Exemplo n.º 2
0
Arquivo: timer.hpp Projeto: marayl/aug
 unsigned
 settimer(aug_timers_t timers, idref ref, unsigned ms, std::auto_ptr<T>& x)
 {
     boxptrptr ob(createboxptr(getmpool(aug_tlx), x));
     return verify(aug_settimer(timers, ref.get(), ms,
                                timermemcb<T>, ob.base()));
 }
Exemplo n.º 3
0
//--------------------------------------------------------------------------------------------
bool get_depth_2(const oct_bb_t& cv_a, const Vector3f& pos_a, const oct_bb_t& cv_b, const Vector3f& pos_b, bool break_out, oct_vec_v2_t& depth)
{
    // Translate the vector positions to octagonal vector positions.
    oct_vec_v2_t oa(pos_a), ob(pos_b);

    // calculate the depth
    bool valid = true;
    for (size_t i = 0; i < OCT_COUNT; ++i)
    {
        depth[i] = std::min(cv_b._maxs[i] + ob[i], cv_a._maxs[i] + oa[i]) -
                   std::max(cv_b._mins[i] + ob[i], cv_a._mins[i] + oa[i]);

        if (depth[i] <= 0.0f)
        {
            valid = false;
            if (break_out) return false;
        }
    }

    // scale the diagonal components so that they are actually distances
    depth[OCT_XY] *= Ego::Math::invSqrtTwo<float>();
    depth[OCT_YX] *= Ego::Math::invSqrtTwo<float>();

    return valid;
}
Exemplo n.º 4
0
void verify(T&c) {
  
  std::stringstream file;
  
  ROOT::Reflex::Type type = ROOT::Reflex::Type::ByTypeInfo(typeid(T));
  
  ROOT::Reflex::Object ob(type,&c);
  //  boost::archive::binary_oarchive oa(file);
  boost::archive::text_oarchive oa(file);
  
  oa << ob;
  
  T co;
  ROOT::Reflex::Object ib(type,&co);
  boost::archive::text_iarchive ia(file);
  ia >> ib;
  
  if (co!=c) std::cout << "Error" << std::endl;

  std::cout << file.str() << std::endl;

  
  std::ostringstream xfile;
  boost::archive::xml_oarchive ox(xfile);
  ox << boost::serialization::make_nvp("A",ob);
  std::cout << std::endl
	    << xfile.str() << std::endl;
  
}
void checkUpdate(int b, int N, int64 size, bool verbose = false) {
  if(verbose) cout << " Testing updates b = "<< b << " N = " << N << " size = " << size << endl;
  OlaBuffer< float > ob(b,N);
  cout << " beta (number of levels) = " << ob.levels(size) << endl;
  for(int64 k = 0 ; k < size ; ++k) {
    if(verbose) cout << " =======================" << endl;
    if(verbose) cout << " testing update of delta at k = " << k << " N = " << N << " size = " << size << endl;
    vector<float> data(size,0);
    data[k] = 1;// **
    if(verbose) cout << "k = " << k << endl;
    counted_ptr<vector<float> > buffer = ob.computeBuffer(data);
    ob.updateBuffer(*buffer,k,-1);
    for(int i = (int) buffer->size() -1 ; i >= 0 ; --i) {
      if(abs((*buffer)[i]) > 0.00001) {
        cout << " buffer should have gone to zero " << endl;
        for (int l = 0; l < (int) buffer->size() ; ++l) cout << (*buffer)[l] << " ";
        cout << endl;
        throw TestFailedException((*buffer)[i]);
      }
    }
    counted_ptr<vector<float> > newbuffer = ob.computeBuffer(data);
    ob.updateBuffer(*buffer,k,1.0f);
    for(int i = 0; i < (int) buffer->size(); ++i) {
       if(abs((*buffer)[i] - (*newbuffer)[i]) > 0.00001) { 
          cout << " updating should be the same as tranforming " << endl;
          for (int l = 0; l < (int) buffer->size() ; ++l) cout << (*buffer)[l] << " ";
          cout << endl;
          for (int l = 0; l < (int) newbuffer->size() ; ++l) cout << (*newbuffer)[l] << " ";
          cout << endl;
          throw TestFailedException((*buffer)[i] - (*newbuffer)[i]);
       }
    }
   }
  if(verbose) cout << "    *Test succesful* " << endl; 
  } 
/**
 *  This links the udo to the udo at the locator's position.
 *
 *  @param pLocator          The locator that has an item to link to.
 */
/*virtual*/ void UserDataObjectLinkProxy::createLinkAtPos(ToolLocatorPtr pLocator)
{
    UserDataObjectLinkLocator* locator =
        (UserDataObjectLinkLocator*)pLocator.getObject();
    ChunkItemPtr chunkItem = locator->chunkItem();
    if (chunkItem == NULL)
        return;

    // The linked udo
    EditorChunkItem* item = static_cast<EditorChunkItem*>( chunkItem.getObject() );
    if (!item->isEditorUserDataObject())
        return;
    EditorChunkUserDataObject* ecudo = static_cast<EditorChunkUserDataObject*>( item );

    if( !EditorChunkCache::instance( *ecudo->chunk() ).edIsWriteable() )
		return;

	PropertyIndex propIdx =
		linker_->propHelper()->propGetIdx(linkName_);
	if ( propIdx.empty() )
		//TODO: have a warning or error especially if its not a selection
		return;

	// Add a link from the linker to ecudo in property propIdx
	WorldManager::instance().linkerManager().addLink(
		linker_, ecudo->chunkItemLinker(), propIdx );
		
	// Update the property representation
	PyObjectPtr ob( linker_->propHelper()->propGetPy( propIdx ), PyObjectPtr::STEAL_REFERENCE );
	linkValue_ = UserDataObjectLinkDataType::asString( ob.getObject() );

	UndoRedo::instance().barrier(
		L( "WORLDEDITOR/WORLDEDITOR/PROPERTIES/STATION_NODE_LINK_PROXY/LINK_NODES" ), false);
}
Exemplo n.º 7
0
extern "C" int write_output_(char *out_filename, double *A, int *n)
{
  std::ofstream ofs(out_filename);
  OpenBabel::OBConversion ob(NULL, &ofs);
  OpenBabel::OBAtom atom;
  OpenBabel::OBMol mol;
  int i;

  ob.SetOutFormat("CML");

  /* Atom is Iridium */
  atom.SetAtomicNum(77);

  for (i = 0; i < *n; i++)
  {
    atom.SetVector(A[i*3], A[i*3+1], A[i*3+2]);
    mol.AddAtom(atom);
  }

  //for (i=0; i < *n; i++)
  //{
    //for (int j=i; j < *n; j++)
    //{
      //mol.AddBond(i+1, j+1, 0);
    //}
  //}

  ob.Write(&mol);
  ob.CloseOutFile();
}
void checkErrorRange(int b, int N, int64 size, bool verbose = true) {
  OlaBuffer< float > ob(b,N);
  int64 begin = 0;
  for(int64 end = begin + 1 ; end <= size;++end) {
     int64 lower = size; int64 higher = 0;
     cout << " testing range from " << begin << " to " << end << endl;
     RangedCubicPolynomial rcp(1.2,0.9,0,0,begin,end);
     cout << " rcp " << endl;
     for(int64 k = 0; k < size; ++k) cout << rcp(k) << " " ;
     cout << endl;
     cout << " interpolate " << endl;
     for(int64 k = 0; k < size; ++k) cout << ob.interpolate(k,1,rcp,size) << " " ;
     cout << endl;
      for(int64 k = 0; k < size ; ++k) {
       if(abs(ob.interpolate(k,1,rcp,size) - rcp(k)) > 0.0001) {
         if(k < lower) lower = k;
         if(k > higher) higher = k;
       }
     }  
     ++higher ;
     cout << " range = ["<<lower << " , " << higher << " ] ( b = "<< b <<", N = "<< N 
       << ", size = "<< size << " )" << endl;
     cout << endl;
     ob.testImperfectRange(end,1,size);
  }  
}
/**
 *  Create a copy of the EditorChunkUserDataObject that the UserDataObjectLinkProxy 
 *  is working on, link this copy to the original and return a MatrixProxyPtr 
 *  that can set the position/orientation etc of the copy.
 *
 *  @return		A proxy to set the position/orientation of the linked
 *              item.
 */
/*virtual*/ MatrixProxyPtr UserDataObjectLinkProxy::createCopyForLink()
{
	if ( linker_->chunkItem()->isEditorEntity() )
	{
		// Not supported in entities at the moment.
		return NULL;
	}

    // Create a copy of node_:
    EditorChunkUserDataObject *newNode = new EditorChunkUserDataObject();
    DataSectionPtr newSection = new XMLSection("copy");
    newSection->copy( linker_->chunkItem()->pOwnSect() );
	newSection->delChild( "guid" );
	newSection->delChild( "backLinks" );

	// delete the link property, or the whole array if it's an array of links
	DataSectionPtr propsSection = newSection->openSection( "properties" );
	std::string baseLinkName = linkName_;
	int pos = baseLinkName.find_first_of( "[" );
	if ( pos != std::string::npos )
		baseLinkName = baseLinkName.substr( 0, pos );
	if ( propsSection != NULL )
		propsSection->delChild( baseLinkName );

	// and load it.
    newNode->load( newSection, linker_->chunkItem()->chunk() );
    linker_->chunkItem()->chunk()->addStaticItem( newNode );
    newNode->edTransform( linker_->chunkItem()->edTransform(), false );

	// set the link in the current node to point to the newNode
	PropertyIndex propIdx =
		linker_->propHelper()->propGetIdx(linkName_);

	WorldManager::instance().linkerManager().addLink(
		linker_, newNode->chunkItemLinker(), propIdx );
	
	PyObjectPtr ob( linker_->propHelper()->propGetPy( propIdx ), PyObjectPtr::STEAL_REFERENCE );
	linkValue_ = UserDataObjectLinkDataType::asString( ob.getObject() );

    // Set the new node as the selection:
	
    std::vector<ChunkItemPtr> items;
    items.push_back( newNode );
    WorldManager::instance().setSelection( items );
	if(PropTable::table()->propertyList())//bobo edit
	{
		int curSel = PropTable::table()->propertyList()->GetCurSel();
		PropTable::table()->propertyList()->selectItem( curSel );
	}
	

	newNode->propHelper()->resetSelUpdate( true );

    // Return a ChunkItemMatrix for the new node so that its position can be
    // edited:
    ChunkItemMatrix *result = new ChunkItemMatrix( newNode );
    result->recordState();
    return result;
}
int main()
{
C3 ob(10);
ob.pisz();

ob.C1::pisz();

ob.pisz_wszystko();
}
/**
 *  This method returns true if the linker has links to the linker identified
 *	by "guid"/"chunkId".
 *
 *	@param guid		GUID of the linker to search in this linker's properties.
 *	@param chunkId	Chunk if the linker to search in this linker's properties.
 *  @return			true if this linker has links to "guid"
 */
bool EditorChunkItemLinkable::hasLinksTo(const UniqueID& guid, const std::string& chunkId)
{
	// look for more links to "guid"
	int propCounter = propHelper()->propCount();
	for (int i=0; i < propCounter; i++)
	{
		DataDescription* pDD = propHelper()->pType()->property( i );
		if (!pDD->editable())
			continue;

		// Is this property a user data object link
		if (propHelper()->isUserDataObjectLink( i ))
		{
			PyObjectPtr ob( propHelper()->propGetPy( i ), PyObjectPtr::STEAL_REFERENCE );

			std::string propId = PyString_AsString( PyTuple_GetItem( ob.getObject(), 0 ) );
			std::string propChunkId = PyString_AsString( PyTuple_GetItem( ob.getObject(), 1 ) );
			if ( propId == guid.toString() && propChunkId == chunkId )
				return true;
		}
		// Is this property an array of user data object links
		else if (propHelper()->isUserDataObjectLinkArray( i ))
		{
			PyObjectPtr ob(	propHelper()->propGetPy( i ), PyObjectPtr::STEAL_REFERENCE );

			SequenceDataType* dataType =
				static_cast<SequenceDataType*>( pDD->dataType() );
			ArrayPropertiesHelper propArray;
			propArray.init(this->chunkItem(),&(dataType->getElemType()), ob.getObject());

			// Iterate through the array of links
			for(int j = 0; j < propArray.propCount(); j++)
			{
				PyObjectPtr aob( propArray.propGetPy( j ), PyObjectPtr::STEAL_REFERENCE );
				std::string propId = PyString_AsString( PyTuple_GetItem( aob.getObject(), 0 ) );
				std::string propChunkId = PyString_AsString( PyTuple_GetItem( aob.getObject(), 1 ) );
				if ( propId == guid.toString() && propChunkId == chunkId )
					return true;
			}
		}
	}
	
	return false;
}
Exemplo n.º 12
0
int main()
{
 verybig ob(1);
 
 for(int i=1;i<=6;i++)
         ob.multiply(2);
 
 ob.display();
 getchar();
 return 0;
}
/**
 *  UserDataObjectLinkProxy constructor.
 *
 *  @param linkName	The id linked.
 *  @param linker	The linker object being linked.
 */
/*explicit*/ UserDataObjectLinkProxy::UserDataObjectLinkProxy(
		const std::string&		linkName,
		EditorChunkItemLinkable*	linker ) :
	linkName_(linkName),
	linker_(linker)
{
	PropertyIndex index =
		linker_->propHelper()->propGetIdx( linkName_ );
	PyObjectPtr ob( linker_->propHelper()->propGetPy( index ), PyObjectPtr::STEAL_REFERENCE );
	linkValue_ = UserDataObjectLinkDataType::asString( ob.getObject() );
}
void checkConstantInterpolation(int b, int N, int64 size, bool verbose = false) {
   OlaBuffer< float > ob(b,N);
   RangedCubicPolynomial rcp(1,0,0,0,0,size);
   for(int64 k = 0; k < size ; ++k) {
     if(abs(ob.interpolate(k,1,rcp,size)-1)> 0.00001) { 
       cout << "constant b = " << b << " N = "<< N << " size = " << size << endl;
       cout << "ob.interpolate("<< k<< ",b,rcp,size) = " << ob.interpolate(k,1,rcp,size) << endl;
       throw new TestFailedException(k);    
     }
   }
}
Exemplo n.º 15
0
utils::Buffer lElem2Buffer(const LabelElement& lElem)
{
    utils::Buffer ob(100);
    utils::OBufferStream os(ob);

    os << lElem.position() << ' ' << utils::String(lElem.text());

    os.flush();

    return ob;
}
/**
 *	This method sets the datasection form of a property.
 *
 *	@param	index	The index of the property in pType.
 *	@param	pTemp	The datasection form of property.
 *	@return	Boolean success or failure.
 */
bool PropertiesHelper::propSet( PropertyIndex index, DataSectionPtr pTemp )
{
	if ( pType_ == NULL || index.empty() )
		return false;

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

	if ( index.count() == 1 )
	{
		propUsingDefault( index.valueAt( 0 ), false );

		PyObjectPtr pNewVal = pDD->createFromSection( pTemp );
		if (!pNewVal)
		{
			PyErr_Clear();
			return false;
		}

		PyDict_SetItemString( pDict_,
			const_cast<char*>( pDD->name().c_str() ), &*pNewVal );
		Py_INCREF( &*pNewVal );
	}
	else
	{
		PyObjectPtr ob( propGetPy( index.valueAt(0) ), PyObjectPtr::STEAL_REFERENCE );
		if ( PySequence_Check( ob.getObject() ) )
		{
			SequenceDataType* dataType = static_cast<SequenceDataType*>( pDD->dataType() );
			ArrayPropertiesHelper propArray;
			propArray.init( pItem(), &(dataType->getElemType()), ob.getObject() );
			PropertyIndex arrayIndex = index.tail();
			if ( !propArray.propSet( arrayIndex, pTemp ) )
			{
				//ERROR_MSG( "PropertiesHelper::propSet: Failed to set value in array\n" );
				PyErr_Print();
				return false;
			}
		}
		else
		{
			//ERROR_MSG( "PropertiesHelper::propSet: Failed to set value in array (not a sequence)\n" );
			PyErr_Print();
			return false;
		}
	}

	if ( changedCallback_ != NULL )
		(*changedCallback_)( index.valueAt(0) );

	return true;
}
Exemplo n.º 17
0
MegaNatural operator %(const MegaInteger &ob1, const MegaInteger ob2)
{	
	if (ob2 == 0)
	{
		cout << "Error! Incorrect divisor in operation %.";
		return 0;
	}

	MegaNatural ob( ob1.abs.toMegaNatural() % ob2.abs.toMegaNatural() );
	if (ob1.isNegative)
		ob = ob2.abs - ob;
	return ob;
}
Exemplo n.º 18
0
bool call_script( const ScriptDef& script, 
                  BObjectImp* param0 )
{
    try
    {
        BObject ob(run_script_to_completion(script,param0));
        return ob.isTrue();
    }
    catch(std::exception&)//...
    {
        return false;
    }
}
Exemplo n.º 19
0
int main () {

	double vel0[3];
	double dt =1e-3;
	vel0[0]=vel0[1]=vel0[2]=1.0;
	double w0[3];
	w0[0]=w0[1]=w0[2]=0.0;
	w0[2]=1;
	Physics::Obliquous ob(Physics::Vector3D(), Physics::Vector3D(vel0), Physics::Vector3D(w0), 6e-3, 4e-4, dt);
	{
	ob.pos = Physics::Vector3D();
	ob.vel = Physics::Vector3D(vel0);
	std::ofstream saida("RK1.dat");

	while(ob.pos.GetElem(2) >= 0) {
		ob.RK1();
		saida << ob.pos << std::endl;
	}
	}
	{
	ob.pos = Physics::Vector3D();
	ob.vel = Physics::Vector3D(vel0);
	std::ofstream saida("RK2.dat");

	while(ob.pos.GetElem(2) >= 0) {
		ob.RK2();
		saida << ob.pos << std::endl;
	}
	}
	{
	ob.pos = Physics::Vector3D();
	ob.vel = Physics::Vector3D(vel0);
	std::ofstream saida("RK4.dat");

	while(ob.pos.GetElem(2) >= 0) {
		ob.RK4();
		saida << ob.pos << std::endl;
	}
	}
	{
	ob.pos = Physics::Vector3D();
	ob.vel = Physics::Vector3D(vel0);
	std::ofstream saida("VelocityVerlet.dat");

	while(ob.pos.GetElem(2) >= 0) {
		ob.VelocityVerlet();
		saida << ob.pos << std::endl;
	}
	}
}
void rangeSums(int b, int N, int64 size, bool verbose = false) {
  if(verbose) cout << " Testing range sums b = "<< b << " N = " << N << " size = " << size << endl;
  OlaBuffer< float > ob(b,N);
  if (ob.computeRecommendedPaddedLength(size)  != size) 
    cout << " Failure in recommendedPaddedLength size = "<< size 
      << " recommended = "<< ob.computeRecommendedPaddedLength(size)  << endl;
  for(int64 k = 0; k < size; ++k) {
    vector<float> data(size,0);
    data[k] = 1;// **
    if(verbose) cout << "k = " << k << endl;
    counted_ptr<vector<float> > buffer = ob.computeBuffer(data);
    if(verbose) {
      cout << "------------------" << endl;
      cout << "------------------" << endl;
    }
    if(verbose) {
      for(uint j = 0; j < buffer->size(); ++j) cout << "b["<<j<< "]=" << (*buffer)[j]<< " ";
      cout << endl;
    }
    for(int64 begin = 0; begin < size; ++begin) {
      for (int64 end = begin + 1 ; end <= size; ++end) {
        if(verbose) cout << endl << "======================="<< begin << " --> " << end << "(k="<< k 
          << " b="<< b<< " N="<< N<<", size = "<< size<<" )" << endl;
        RangedCubicPolynomial rcp(1,0,0,0,begin,end);
        if(verbose) {
          for(int64 j = begin; j < end; ++j) cout << " rcp(" << j<<") = " << rcp(j) ;
          cout << endl;
        }
        assert(rcp(begin) == 1.0); 
        float answer = ob.query(rcp , data , * buffer);
        if((begin <= k) && (k < end)) {
          if( abs(answer - 1.0f) > 0.00001f ) {
            cout << "k = "<< k << " is in range f("<<k << " ) = "<< rcp(k)<<endl;
            for(uint j = 0; j < buffer->size(); ++j) cout << "b["<<j<< "]=" << (*buffer)[j]<< " ";
            cout << endl;
            throw new TestFailedException(answer);    
          }
        } else {
          if( abs(answer ) > 0.00001f ) {
            cout << "k = "<< k << " is NOT in range f("<<k << " ) = "<< rcp(k)<<endl;
            for(uint j = 0; j < buffer->size(); ++j) cout << "b["<<j<< "]=" << (*buffer)[j]<< " ";
            cout << endl;
            throw new TestFailedException(answer);    
          }
        }
      }
    }
  } 
  if(verbose) cout << "    *Test succesful* " << endl; 
}
/**
 *	This method sets the PyObject form of a property.
 *
 *	@param	index	The index of the property in pType.
 *	@param	pObj	The PyObject of the property.
 *	@return	Boolean success or failure.
 */
bool PropertiesHelper::propSetPy( PropertyIndex index, PyObject * pObj )
{
	if ( pType_ == NULL || index.empty() )
		return false;

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

	if ( index.count() == 1 )
	{
		propUsingDefault( index.valueAt( 0 ), false );

		// requesting the top-level property directly, even if it's an array
		// (sequence), so set it directly.
		if (PyDict_SetItemString( pDict_,
			const_cast<char*>( pDD->name().c_str() ), pObj ) == -1)
		{
			//ERROR_MSG( "PropertiesHelper::propSetPy: Failed to set value\n" );
			PyErr_Print();
			return false;
		}
	}
	else
	{
		
		PyObjectPtr ob( propGetPy( index.valueAt(0) ), PyObjectPtr::STEAL_REFERENCE );
		if ( PySequence_Check( ob.getObject() ) )
		{
			SequenceDataType* dataType = static_cast<SequenceDataType*>( pDD->dataType() );
			ArrayPropertiesHelper propArray;
			propArray.init( pItem(), &(dataType->getElemType()), ob.getObject() );
			PropertyIndex arrayIndex = index.tail();
			if ( !propArray.propSetPy( arrayIndex, pObj ) )
			{
				//ERROR_MSG( "PropertiesHelper::propSetPy: Failed to set value in array\n" );
				PyErr_Print();
				return false;
			}
		}
		else
		{
			//ERROR_MSG( "PropertiesHelper::propSetPy: Failed to set value in array (not a sequence)\n" );
			PyErr_Print();
			return false;
		}
	}

	return true;
}
Exemplo n.º 22
0
TypWartosci& TADrzewo<TypKlucza, TypWartosci>::operator []
(const TypKlucza &k)
{
    try {
        Para<TypKlucza, TypWartosci> *cel =
            Tab.Dodaj(Para<TypKlucza, TypWartosci> (k));
        Rozmiar++;

        return cel->Wart;
    }
    catch (const logic_error &ex) {
        Para<TypKlucza, TypWartosci> ob(k);
        return (Tab.Znajdz(k))->elem.Wart;
    }
}
Exemplo n.º 23
0
/////////PUSH PART
void complex_stack::push(const complex new_el){
    if (new_sz == cur_sz)
    {
        int i;
        complex_stack ob(*this);
        delete []arr;
        new_sz += new_sz; // size*2
        arr = new complex[new_sz];
        for (i = 0; i < cur_sz; ++i){
            arr[i] = ob.arr[i];
        }
    }
    arr[cur_sz] = new_el;
    ++cur_sz;
}
Exemplo n.º 24
0
// _____________________________________________________________________________
vector<QueryPlanner::SubtreePlan> QueryPlanner::getOrderByRow(
    const ParsedQuery& pq,
    const vector<vector<SubtreePlan>>& dpTab) const {
  const vector<SubtreePlan>& previous = dpTab[dpTab.size() - 1];
  vector<SubtreePlan> added;
  added.reserve(previous.size());
  for (size_t i = 0; i < previous.size(); ++i) {
    if (pq._orderBy.size() == 1 && !pq._orderBy[0]._desc) {
      size_t col = previous[i]._qet.getVariableColumn(
          pq._orderBy[0]._key);
      if (col == previous[i]._qet.resultSortedOn()) {
        // Already sorted perfectly
        added.push_back(previous[i]);
      } else {
        QueryExecutionTree tree(_qec);
        Sort sort(_qec, previous[i]._qet, col);
        tree.setVariableColumns(
            previous[i]._qet.getVariableColumnMap());
        tree.setOperation(QueryExecutionTree::SORT, &sort);
        tree.setContextVars(previous[i]._qet.getContextVars());
        SubtreePlan plan(_qec);
        plan._qet = tree;
        plan._idsOfIncludedNodes = previous[i]._idsOfIncludedNodes;
        plan._idsOfIncludedFilters = previous[i]._idsOfIncludedFilters;
        added.push_back(plan);
      }
    } else {
      QueryExecutionTree tree(_qec);
      vector<pair<size_t, bool>> sortIndices;
      for (auto& ord : pq._orderBy) {
        sortIndices.emplace_back(
            pair<size_t, bool>{
                previous[i]._qet.getVariableColumn(ord._key),
                ord._desc});
      }
      OrderBy ob(_qec, previous[i]._qet, sortIndices);
      tree.setVariableColumns(previous[i]._qet.getVariableColumnMap());
      tree.setOperation(QueryExecutionTree::ORDER_BY, &ob);
      tree.setContextVars(previous[i]._qet.getContextVars());
      SubtreePlan plan(_qec);
      plan._qet = tree;
      plan._idsOfIncludedNodes = previous[i]._idsOfIncludedNodes;
      plan._idsOfIncludedFilters = previous[i]._idsOfIncludedFilters;
      added.push_back(plan);
    }
  }
  return added;
}
int main()
{
  int t;
    scanf("%d",&t);
    while(t--)
    {
              verybig ob(1);
              int n;
              scanf("%d",&n);
              for(int i=1;i<=n;i++)
                      ob.multiply(i);
 
             ob.display();
             printf("\n");
    }
    return 0;    
}
/**
 *	This method returns the index of the named property.
 *
 *	@param	name	The name of the property.
 *	@return	The index of the named property.
 */
PropertyIndex PropertiesHelper::propGetIdx( const std::string& name ) const
{
	// find brackets, in case it's an array element, and if so, extract the
	// type name from it.
	uint32 bracket = name.find_first_of( '[' );
	if ( bracket == std::string::npos )
		bracket = name.size();
	std::string typeName = name.substr( 0, bracket );

	// get the property
	PropertyIndex result;
	DataDescription* pDD = pType_->findProperty( typeName );
	if (pDD)
	{
		result.append( pDD->index() );
	}

	// if no brackets, we can return as it's not an array.
	if ( bracket == name.size() )
		return result;

	// find out if it's a valid python sequence
	PyObjectPtr ob( const_cast<PropertiesHelper*>(this)->propGetPy( result.valueAt(0) ),
		PyObjectPtr::STEAL_REFERENCE );

	if ( PySequence_Check( ob.getObject() ) )
	{
		// it's a sequence, so call propGetIdx in the array using the
		// ArrayPropertiesHelper, and append the return value to the result
		// PropertyIndex object.
		SequenceDataType* dataType = static_cast<SequenceDataType*>( pDD->dataType() );
		ArrayPropertiesHelper propArray;
		propArray.init( pItem(), &(dataType->getElemType()), ob.getObject() );
		PropertyIndex arrayResult = propArray.propGetIdx( name );
		if ( !arrayResult.empty() )
		{
			result.append( arrayResult );
		}
	}

	return result;
}
void transformDeltas(int b, int N, int64 size, bool verbose = false) {
  if(verbose) cout << " Testing deltas b = "<< b << " N = " << N << " size = " << size << endl;
  OlaBuffer< float > ob(b,N);
  for(int64 k = 0; k < size; ++k) {
    vector<float> data(size,0);
    data[k] = 1;
    if(verbose) cout << " k = " << k << " size = " << size << endl;
    counted_ptr<vector<float> > buffer = ob.computeBuffer(data);
    if(verbose) {
      for(uint j = 0; j < buffer->size(); ++j) cout << "b["<<j<< "]=" << (*buffer)[j]<< " ";
      cout << endl;
    }
    float total = 0.0;
    for (uint k = 0; k < buffer->size(); ++k)  {
      total += (*buffer)[k];
    }
    if( abs(total - 1.0f) > 0.00001f )  throw new TestFailedException(total);
  }
  if(verbose) cout << "    *Test succesful* " << endl; 
}
Exemplo n.º 28
0
//--------------------------------------------------------------------------------------------
bool test_interaction_2(const oct_bb_t& cv_a, const Vector3f& pos_a, const oct_bb_t& cv_b, const Vector3f& pos_b, int test_platform)
{
    // Convert the vector positions to octagonal vector positions.
    oct_vec_v2_t oa(pos_a), ob(pos_b);

    // calculate the depth
    float depth;
    for (size_t i = 0; i < OCT_Z; ++i)
    {
        depth  = std::min(cv_b._maxs[i] + ob[i], cv_a._maxs[i] + oa[i]) -
                 std::max(cv_b._mins[i] + ob[i], cv_a._mins[i] + oa[i]);

        if (depth <= 0.0f) return false;
    }

    // treat the z coordinate the same as always
    depth = std::min(cv_b._maxs[OCT_Z] + ob[OCT_Z], cv_a._maxs[OCT_Z] + oa[OCT_Z]) -
            std::max(cv_b._mins[OCT_Z] + ob[OCT_Z], cv_a._mins[OCT_Z] + oa[OCT_Z]);

    return TO_C_BOOL((0 != test_platform) ? (depth > -PLATTOLERANCE) : (depth > 0.0f));
}
Exemplo n.º 29
0
obvious::Matrix ThreadLocalize::tfToObviouslyMatrix3x3(const tf::Transform& tf)
{
  obvious::Matrix ob(3,3);
  ob.setIdentity();

  double theta = tf::getYaw(tf.getRotation());
  double x = tf.getOrigin().getX();
  double y = tf.getOrigin().getY();

  //sin() returns -0.0 -> avoid with +0.0
  ob(0,0 ) = cos(theta) + 0.0;
  ob(0,1 ) = -sin(theta) + 0.0;
  ob(0, 2) = x + 0.0;
  ob(1, 0) = sin(theta) + 0.0;
  ob(1, 1) = cos(theta) + 0.0;
  ob(1, 2) = y + 0.0;

  return ob;
}
/**
 *	This method returns the name of the property at the passed index.
 *
 *	@param	index	The index of the property in pType.
 *	@return	The name of the property at the passed index in pType.
 */
std::string PropertiesHelper::propName( PropertyIndex index )
{
	if ( pType_ == NULL || index.empty() )
		return "";

	MF_ASSERT( index.valueAt(0) < (int) pType_->propertyCount() );
	PyObjectPtr ob( propGetPy( index.valueAt(0) ), PyObjectPtr::STEAL_REFERENCE );
	DataDescription* pDD = pType_->property( index.valueAt(0) );

	std::string result = pDD->name();
	if ( PySequence_Check( ob.getObject() ) && index.count() > 1 )
	{
		SequenceDataType* dataType = static_cast<SequenceDataType*>( pDD->dataType() );
		ArrayPropertiesHelper propArray;
		propArray.init( pItem(), &(dataType->getElemType()), ob.getObject() );
		PropertyIndex arrayIndex = index.tail();
		result = result + propArray.propName( arrayIndex );
	}

	return result;
}