示例#1
0
int ActiveSystem::init(const InactiveSystem& data)
{
    m_borders.width = std::stof(getConstant("SystemSizeX"));
    m_borders.height = std::stof(getConstant("SystemSizeY"));
    m_borders.left = m_borders.width * -0.5f;
    m_borders.top = m_borders.height * -0.5f;

    if(m_collisionMgr.init(m_borders) != 0)
        return 1;

    m_minAsteroidCount = static_cast<unsigned int>(std::stoi(getConstant("AsteroidCount")));
    float maxAsteroidSpeed = std::stof(getConstant("AsteroidMaxSpeed"));
    m_asteroids.clear();
    for(unsigned int i = 0; i < m_minAsteroidCount; i++)
    {
        m_asteroids.emplace_back();
        m_asteroids.back().init(sf::Vector2f(m_borders.left + static_cast <float> (rand()) /( static_cast <float> (RAND_MAX/(m_borders.width))),
                                             m_borders.top + static_cast <float> (rand()) /( static_cast <float> (RAND_MAX/(m_borders.height)))));
        m_asteroids.back().setMovement(sf::Vector2f(-maxAsteroidSpeed + static_cast <float> (rand()) /( static_cast <float> (RAND_MAX/(maxAsteroidSpeed*2.0f))),
                                                    -maxAsteroidSpeed + static_cast <float> (rand()) /( static_cast <float> (RAND_MAX/(maxAsteroidSpeed*2.0f)))));
        m_collisionMgr.addObject(&m_asteroids.back());
    }
    m_collisionMgr.refresh();
    return 0;
}
void preROTATE(string &line, RawSource *) {
    string nr;
    int val,rot,max;
    if (!ParseExpression(line,val)) {
        error1("Expression expected");
        return;
    }
    if (labelnotfound) {
        error1("Forward reference");
        return;
    }
    nr=macnumtab.getrepl(ROTATE);
    if (nr.empty()) {
        error1("use of rotate not allowed outside macro");
        return;
    }
    if (!getConstant(nr,rot)) error1("preROTATE",ERRINTERNAL);
    nr=macnumtab.getrepl(0);
    if (nr.empty()) {
        error1("use of rotate not allowed outside macro");
        return;
    }
    if (!getConstant(nr,max)) error1("preROTATE",ERRINTERNAL);
    rot=rot+val;
    while (rot<0) rot=rot+max;
    macnumtab.replace(ROTATE,tostr(rot));
}
示例#3
0
Joystick::JoystickInput Joystick::getGamepadMapping(const GamepadInput &input) const
{
	Joystick::JoystickInput jinput;
	jinput.type = INPUT_TYPE_MAX_ENUM;

	if (!isGamepad())
		return jinput;

	SDL_GameControllerButtonBind sdlbind = {};
	sdlbind.bindType = SDL_CONTROLLER_BINDTYPE_NONE;

	SDL_GameControllerButton sdlbutton;
	SDL_GameControllerAxis sdlaxis;

	switch (input.type)
	{
	case INPUT_TYPE_BUTTON:
		if (getConstant(input.button, sdlbutton))
			sdlbind = SDL_GameControllerGetBindForButton(controller, sdlbutton);
		break;
	case INPUT_TYPE_AXIS:
		if (getConstant(input.axis, sdlaxis))
			sdlbind = SDL_GameControllerGetBindForAxis(controller, sdlaxis);
		break;
	default:
		break;
	}

	switch (sdlbind.bindType)
	{
	case SDL_CONTROLLER_BINDTYPE_BUTTON:
		jinput.type = INPUT_TYPE_BUTTON;
		jinput.button = sdlbind.value.button;
		break;
	case SDL_CONTROLLER_BINDTYPE_AXIS:
		jinput.type = INPUT_TYPE_AXIS;
		jinput.axis = sdlbind.value.axis;
		break;
	case SDL_CONTROLLER_BINDTYPE_HAT:
		if (getConstant(sdlbind.value.hat.hat_mask, jinput.hat.value))
		{
			jinput.type = INPUT_TYPE_HAT;
			jinput.hat.index = sdlbind.value.hat.hat;
		}
		break;
	case SDL_CONTROLLER_BINDTYPE_NONE:
	default:
		break;
	}

	return jinput;
}
示例#4
0
void ActiveSystem::update(float fTime)
{
    for(std::list<Asteroid>::iterator i = m_asteroids.begin(); i != m_asteroids.end();)
    {
        i->update(fTime);
        if(!m_borders.contains(i->getPosition()))
        {
            m_collisionMgr.removeObject(&(*i));
            m_asteroids.erase(i++);
        }
        else
            i++;
    }

    m_collisionMgr.update(fTime);

    while(m_asteroids.size() < m_minAsteroidCount)
    {
        float maxAsteroidSpeed = std::stof(getConstant("AsteroidMaxSpeed"));
        m_asteroids.emplace_back();
        m_asteroids.back().init(sf::Vector2f(m_borders.left + static_cast <float> (rand()) /( static_cast <float> (RAND_MAX/(m_borders.width))),
                                             m_borders.top + static_cast <float> (rand()) /( static_cast <float> (RAND_MAX/(m_borders.height)))));
        m_asteroids.back().setMovement(sf::Vector2f(-maxAsteroidSpeed + static_cast <float> (rand()) /( static_cast <float> (RAND_MAX/(maxAsteroidSpeed*2.0f))),
                                                    -maxAsteroidSpeed + static_cast <float> (rand()) /( static_cast <float> (RAND_MAX/(maxAsteroidSpeed*2.0f)))));
        m_collisionMgr.addObject(&m_asteroids.back());
    }
}
示例#5
0
void IRGenerator::accept(MatchStmt& stmt)
{
    FNTRACE();

    Value* cond = codegen(stmt.condition());
    BasicBlock* contBlock = createBlock("match.cont");
    MatchInstr* matchInstr = createMatch(stmt.op(), cond);

    for (const MatchCase& one: stmt.cases()) {
        BasicBlock* bb = createBlock("match.case");
        setInsertPoint(bb);
        codegen(one.second.get());
        createBr(contBlock);

        for (auto& labelNode: one.first) {
            Constant* label = getConstant(labelNode.get());
            matchInstr->addCase(label, bb);
        }
    }

    if (stmt.elseStmt()) {
        BasicBlock* elseBlock = createBlock("match.else");
        setInsertPoint(elseBlock);
        codegen(stmt.elseStmt());
        createBr(contBlock);

        matchInstr->setElseBlock(elseBlock);
    }

    setInsertPoint(contBlock);
}
示例#6
0
Token Lexer::getOperandToken(const std::string & str, Machine & machine)
{
    Token returnToken;
    if (str.size() < 2)
    {
        if (isdigit(str[0])) getHeapLocation(str, 0, returnToken, machine);
        else if (isalpha(str[0])) getLabel(str, 0, returnToken);
        return returnToken;
    }
    switch (str[0])
    {
    case '#': getConstant(str, 1, returnToken); break;
    case '@': getPointer(str, 1, returnToken, machine); break;
    case '$': getDataType(str, 1, returnToken); break;
    case '?': getComparisonFlagId(str, 1, returnToken); break;
    case 'n':
        if ((str.size() == 3) && (str[1] == 'i') && (str[2] == 'l'))
        {
            returnToken.type = Token::T_OPERAND_NIL;
            break;
        } // else fall into default
    default:  getLocation(str, 0, returnToken, machine);
    }
    return returnToken;
}
示例#7
0
unsigned UnlinkedCodeBlock::addOrFindConstant(JSValue v)
{
    unsigned numberOfConstants = numberOfConstantRegisters();
    for (unsigned i = 0; i < numberOfConstants; ++i) {
        if (getConstant(FirstConstantRegisterIndex + i) == v)
            return i;
    }
    return addConstant(v);
}
示例#8
0
Joystick::Hat Joystick::getHat(int hatindex) const
{
	Hat h = HAT_INVALID;

	if (!isConnected() || hatindex < 0 || hatindex >= getHatCount())
		return h;

	getConstant(SDL_JoystickGetHat(joyhandle, hatindex), h);

	return h;
}
void ifIFNUM(string &line, void(*push)(bool)) {
    skipblanks(line);
    if (isdigit(line[0]) || (line[0]=='#' && isalnum(line[1])) || (line[0]=='$' && isalnum(line[1])) || line[0]=='%' && isdigit(line[1])) {
        int nval;
        getConstant(line,nval);
        (*push)(true);
    } else {
        line.clear();
        (*push)(false);
    }
}
示例#10
0
float Joystick::getGamepadAxis(love::joystick::Joystick::GamepadAxis axis) const
{
	if (!isConnected() || !isGamepad())
		return 0.f;

	SDL_GameControllerAxis sdlaxis;
	if (!getConstant(axis, sdlaxis))
		return 0.f;

	Sint16 value = SDL_GameControllerGetAxis(controller, sdlaxis);

	return clampval((float) value / 32768.0f);
}
示例#11
0
love::filesystem::FileData *ImageData::encode(EncodedFormat format, const char *filename)
{
	FormatHandler *encoder = nullptr;
	FormatHandler::EncodedImage encodedimage;
	FormatHandler::DecodedImage rawimage;

	rawimage.width = width;
	rawimage.height = height;
	rawimage.size = width*height*sizeof(pixel);
	rawimage.data = data;

	for (FormatHandler *handler : formatHandlers)
	{
		if (handler->canEncode(format))
		{
			encoder = handler;
			break;
		}
	}

	if (encoder != nullptr)
	{
		thread::Lock lock(mutex);
		encodedimage = encoder->encode(rawimage, format);
	}

	if (encoder == nullptr || encodedimage.data == nullptr)
	{
		const char *fname = "unknown";
		getConstant(format, fname);
		throw love::Exception("No suitable image encoder for %s format.", fname);
	}

	love::filesystem::FileData *filedata = nullptr;

	try
	{
		filedata = new love::filesystem::FileData(encodedimage.size, filename);
	}
	catch (love::Exception &)
	{
		encoder->free(encodedimage.data);
		throw;
	}

	memcpy(filedata->getData(), encodedimage.data, encodedimage.size);
	encoder->free(encodedimage.data);

	return filedata;
}
示例#12
0
int Space::init()
{
    int xResolution = std::stoi(getConstant("SystemCountX"));
    int yResolution = std::stoi(getConstant("SystemCountY"));
    m_inactiveSystems.clear();
    for(int x = 0; x < xResolution; x++)
    {
        m_inactiveSystems.emplace_back();
        for(int y = 0; y < yResolution; y++)
        {
            m_inactiveSystems.back().emplace_back();
            m_inactiveSystems.back().back().init();
        }
    }

    m_activeIndex.x = static_cast<std::size_t>(std::stoi(getConstant("DefaultSystemX")));
    m_activeIndex.y = static_cast<std::size_t>(std::stoi(getConstant("DefaultSystemY")));

    m_activeSystem.init(m_inactiveSystems[m_activeIndex.x][m_activeIndex.y]);
    m_inactiveUpdateTimer = 0;
    m_inactiveUpdateDelay = std::stof(getConstant("InactiveSystemUpdateDelay"));

    return 0;
}
示例#13
0
static VALUE getClass(const char *name)
{
   VALUE klass = getConstant(name, Qnil);

   if(klass != Qnil)
   {
      VALUE type = rb_funcall(klass, rb_intern("class"), 0);

      if(type != rb_cClass)
      {
         klass = Qnil;
      }
   }

   return(klass);
}
示例#14
0
bool Joystick::isGamepadDown(const std::vector<GamepadButton> &blist) const
{
	if (!isConnected() || !isGamepad())
		return false;

	SDL_GameControllerButton sdlbutton;

	for (GamepadButton button : blist)
	{
		if (!getConstant(button, sdlbutton))
			continue;

		if (SDL_GameControllerGetButton(controller, sdlbutton) == 1)
			return true;
	}

	return false;
}
示例#15
0
  int CodeGenerator::addSparsity(const Sparsity& sp) {
    // Get the current number of patterns before looking for it
    size_t num_patterns_before = added_sparsities_.size();

    // Get index of the pattern
    const void* h = static_cast<const void*>(sp.get());
    int& ind = added_sparsities_[h];

    // Generate it if it does not exist
    if (added_sparsities_.size() > num_patterns_before) {

      // Compact version of the sparsity pattern
      std::vector<int> sp_compact = sp.compress();

      // Codegen vector
      ind = getConstant(sp_compact, true);
    }

    return ind;
  }
示例#16
0
void cpCommonLDC(u2 constantPoolIndex) {
	// Look up value (int, float or String) from within const pool:
	constantDef constant;
	getConstant(constantPoolIndex, &constant);
	if (constant.type == CONSTANT_INTEGER) {
		operandStackPushJavaInt(constant.value.jrenameint);
	} else if (constant.type == CONSTANT_LONG) {
		operandStackPushJavaLong(constant.value.jlong);
	} else if (constant.type == CONSTANT_STRING) {
		//		consout("%s:%d ldc string: %d\n", __FILE__, __LINE__, constantPoolIndex);
		jobject str = NewString(constant.value.string);
		operandStackPushObjectRef(str);
	} else if (constant.type == CONSTANT_CLASS) {
		//registerNatives skal bygge det Class[], der skal foretages lookup i:
		jclass jc = getJavaLangClass(constant.value.classId);
		operandStackPushObjectRef(jc);
	} else {
		// TODO Support float
		consout("Unsupported type: %d\n", constant.type);
		jvmexit(1);
	}
}
示例#17
0
// makeToken {{{
int CLexer::makeToken()
{
    //if(isEOF()) return ILexer::RET_EOF;
    
    CToken* token=NULL;
    int ret = ILexer::RET_NORMAL; 
    // トークンの作成
    while(token == NULL)
    {
        skipBlanks();
        if(isComment())
        {
            skipLine();
            continue;
        }

        if( (token = getEOF()) != NULL){ret = ILexer::RET_EOF; break;}
        if( (token = getEOL()) != NULL){ret = ILexer::RET_EOL; nowLine_++;break;}
        
        // トークン取得開始
        if( (token = getKeyword())    != NULL) break; 
        if( (token = getOperator())   != NULL) break;
        if( (token = getIdentifier()) != NULL) break;
		if( (token = getLiteral('\'',false)) != NULL) break;
        if( (token = getLiteral('"',true))   != NULL) break;
        if( (token = getConstant())   != NULL) break;
        if( (token = getSeparator())  != NULL) break;

        // エラー処理
		onAnalyzeError();
        
    }
    
    topToken_ = token;
    makeTokenRet_ = ret;
    
    return ret;
}
示例#18
0
	void FlatZincSpace::newIntVar(IntVarSpec* vs) {
		if (vs->alias) {
			iv[intVarCount++] = iv[vs->i];
		} else {
			IntVar* v = NULL;
			if (vs->assigned) v = getConstant(vs->i);
			else if (vs->domain()) {
				AST::SetLit* sl = vs->domain.some();
				if (sl->interval) v = ::newIntVar(sl->min, sl->max);
				else {
					vec<int> d;
					for (unsigned int i = 0; i < sl->s.size(); i++) d.push(sl->s[i]);
					sort((int*) d, (int*) d + d.size());
					v = ::newIntVar(d[0], d.last());
					if (!v->allowSet(d)) TL_FAIL();
				}
			} else {
				v = ::newIntVar();
			}
			iv[intVarCount++] = v;
		}
		iv_introduced[intVarCount-1] = vs->introduced;
	}
bool AttributeAttractRepelParticleAffector::affect(ParticleSystemRefPtr System, Int32 ParticleIndex, const Time& elps)
{
    if(System != NULL)
    {
        Vec3f Displacement(System->getSecPosition(ParticleIndex) - System->getPosition(ParticleIndex) );

        Real32 Distance(Displacement.squareLength());

        if((Distance > getMinDistance()*getMinDistance()) &&
           (Distance < getMaxDistance()*getMaxDistance()))
        {
            Distance = osgSqrt(Distance);
            Displacement.normalize();

            Real32 t((getQuadratic() * (Distance*Distance) + getLinear() * Distance + getConstant())*elps);
            if(t > Distance)
            {
                t=Distance;
            }

            System->setPosition(System->getPosition(ParticleIndex) + (Displacement * t),ParticleIndex) ;
        }
    }
    return false;
}
示例#20
0
namespace H5 {
#endif

#ifndef DOXYGEN_SHOULD_SKIP_THIS
// This DOXYGEN_SHOULD_SKIP_THIS block is a work-around approach to control
// the order of creation and deletion of the global constants.  See Design Notes
// in "H5PredType.cpp" for information.

// Initialize a pointer for the constant
DSetMemXferPropList* DSetMemXferPropList::DEFAULT_ = 0;

//--------------------------------------------------------------------------
// Function:    DSetMemXferPropList::getConstant
//              Creates a DSetMemXferPropList object representing the HDF5
//              constant H5P_DATASET_XFER, pointed to by
//		DSetMemXferPropList::DEFAULT_
// exception    H5::PropListIException
// Description
//              If DSetMemXferPropList::DEFAULT_ already points to an allocated
//              object, throw a PropListIException.  This scenario should not
//              happen.
// Programmer   Binh-Minh Ribler - 2015
//--------------------------------------------------------------------------
DSetMemXferPropList* DSetMemXferPropList::getConstant()
{
    // Tell the C library not to clean up, H5Library::termH5cpp will call
    // H5close - more dependency if use H5Library::dontAtExit()
    if (!IdComponent::H5dontAtexit_called)
    {
        (void) H5dont_atexit();
        IdComponent::H5dontAtexit_called = true;
    }

    // If the constant pointer is not allocated, allocate it. Otherwise,
    // throw because it shouldn't be.
    if (DEFAULT_ == 0)
        DEFAULT_ = new DSetMemXferPropList(H5P_DATASET_XFER);
    else
        throw PropListIException("DSetMemXferPropList::getConstant", "DSetMemXferPropList::getConstant is being invoked on an allocated DEFAULT_");
    return(DEFAULT_);
}

//--------------------------------------------------------------------------
// Function:    DSetMemXferPropList::deleteConstants
// Purpose:     Deletes the constant object that DSetMemXferPropList::DEFAULT_
//              points to.
// Programmer   Binh-Minh Ribler - 2015
//--------------------------------------------------------------------------
void DSetMemXferPropList::deleteConstants()
{
    if (DEFAULT_ != 0)
        delete DEFAULT_;
}

//--------------------------------------------------------------------------
// Purpose	Constant for default dataset memory and transfer property list.
//--------------------------------------------------------------------------
const DSetMemXferPropList& DSetMemXferPropList::DEFAULT = *getConstant();

#endif // DOXYGEN_SHOULD_SKIP_THIS

//--------------------------------------------------------------------------
// Function	DSetMemXferPropList default constructor
///\brief	Default constructor: creates a stub dataset memory and
///		transfer property list object.
// Programmer:	Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
DSetMemXferPropList::DSetMemXferPropList() : PropList(H5P_DATASET_XFER) {}

//--------------------------------------------------------------------------
// Function	DSetMemXferPropList constructor
///\brief	Creates a dataset transfer property list with transform
///		expression.
// Programmer:	Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
DSetMemXferPropList::DSetMemXferPropList(const char* exp) : PropList(H5P_DATASET_XFER)
{
    setDataTransform(exp);
}

//--------------------------------------------------------------------------
// Function	DSetMemXferPropList copy constructor
///\brief	Copy constructor: makes a copy of the original
///		DSetMemXferPropList object
///\param	original - IN: Original dataset memory and transfer property
///				list object to copy
// Programmer:	Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
DSetMemXferPropList::DSetMemXferPropList(const DSetMemXferPropList& original ) : PropList( original ) {}

//--------------------------------------------------------------------------
// Function	DSetMemXferPropList overloaded constructor
///\brief	Creates a DSetMemXferPropList object using the id of an
///		existing DSetMemXferPropList.
///\param	plist_id - IN: Id of an existing dataset memory and transfer
///				property list
// Programmer:	Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
DSetMemXferPropList::DSetMemXferPropList(const hid_t plist_id) : PropList(plist_id) {}

//--------------------------------------------------------------------------
// Function:	DSetMemXferPropList::setBuffer
///\brief	Sets type conversion and background buffers.
///\param	size  - IN: Size, in bytes, of the type conversion and background buffers
///\param	tconv - IN: Pointer to application-allocated type conversion buffer
///\param	bkg   - IN: Pointer to application-allocated background buffer
///\exception	H5::PropListIException
// Programmer:	Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
void DSetMemXferPropList::setBuffer( size_t size, void* tconv, void* bkg ) const
{
   herr_t ret_value = H5Pset_buffer( id, size, tconv, bkg );
   if( ret_value < 0 )
   {
      throw PropListIException("DSetMemXferPropList::setBuffer",
		"H5Pset_buffer failed");
   }
}

//--------------------------------------------------------------------------
// Function:	DSetMemXferPropList::getBuffer
///\brief	Reads buffer settings.
///\param	tconv - IN: Pointer to application-allocated type conversion buffer
///\param	bkg   - IN: Pointer to application-allocated background buffer
///\return	Buffer size, in bytes
///\exception	H5::PropListIException
// Programmer:	Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------

size_t DSetMemXferPropList::getBuffer( void** tconv, void** bkg ) const
{
   size_t buffer_size = H5Pget_buffer( id, tconv, bkg );
   if( buffer_size == 0 )
   {
      throw PropListIException("DSetMemXferPropList::getBuffer",
		"H5Pget_buffer returned 0 for buffer size - failure");
   }
   return( buffer_size );
}

//--------------------------------------------------------------------------
// Function:	DSetMemXferPropList::setPreserve
///\brief	Sets the dataset transfer property list status to true or false.
///\param	status - IN: Status to set, true or false
///\exception	H5::PropListIException
// Programmer:	Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
void DSetMemXferPropList::setPreserve( bool status ) const
{
   herr_t ret_value = H5Pset_preserve( id, (hbool_t) status );
   if( ret_value < 0 )
   {
      throw PropListIException("DSetMemXferPropList::setPreserve",
		"H5Pset_preserve failed");
   }
}

//--------------------------------------------------------------------------
// Function:	DSetMemXferPropList::getPreserve
///\brief	Checks status of the dataset transfer property list.
///\return	Status of the dataset transfer property list
///\exception	H5::PropListIException
// Programmer:	Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
bool DSetMemXferPropList::getPreserve() const
{
   int ret_value = H5Pget_preserve( id );
   if( ret_value > 0 )
      return true;
   else if( ret_value == 0 )
      return false;
   else
   {
      throw PropListIException("DSetMemXferPropList::getPreserve",
		"H5Pget_preserve returned negative value for status");
   }
}

//--------------------------------------------------------------------------
// Function:	DSetMemXferPropList::setBtreeRatios
///\brief	Sets B-tree split ratios for a dataset transfer property list.
///\param	left   - IN: B-tree split ratio for left-most nodes
///\param	middle - IN: B-tree split ratio for right-most nodes and lone nodes
///\param	right  - IN: B-tree split ratio for all other nodes
///\exception	H5::PropListIException
// Programmer:	Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
void DSetMemXferPropList::setBtreeRatios( double left, double middle, double right ) const
{
   herr_t ret_value = H5Pset_btree_ratios( id, left, middle, right );
   if( ret_value < 0 )
   {
      throw PropListIException("DSetMemXferPropList::setBtreeRatios",
		"H5Pset_btree_ratios failed");
   }
}

//--------------------------------------------------------------------------
// Function:	DSetMemXferPropList::getBtreeRatios
///\brief	Gets B-tree split ratios for a dataset transfer property list.
///\param	left   - OUT: B-tree split ratio for left-most nodes
///\param	middle - OUT: B-tree split ratio for right-most nodes and lone nodes
///\param	right  - OUT: B-tree split ratio for all other nodes
///\exception	H5::PropListIException
// Programmer:	Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
void DSetMemXferPropList::getBtreeRatios( double& left, double& middle, double& right ) const
{
   herr_t ret_value = H5Pget_btree_ratios( id, &left, &middle, &right );
   if( ret_value < 0 )
   {
      throw PropListIException("DSetMemXferPropList::getBtreeRatios",
		"H5Pget_btree_ratios failed");
   }
}

//--------------------------------------------------------------------------
// Function:	DSetMemXferPropList::setDataTransform
///\brief	Sets data transform expression.
///\param	expression - IN: null-terminated data transform expression (char*)
///\exception	H5::PropListIException
// Programmer:	Binh-Minh Ribler - Mar, 2014
//--------------------------------------------------------------------------
void DSetMemXferPropList::setDataTransform(const char* expression) const
{
   herr_t ret_value = H5Pset_data_transform( id, expression);
   if( ret_value < 0 )
   {
      throw PropListIException("DSetMemXferPropList::setDataTransform",
		"H5Pset_data_transform failed");
   }
}

//--------------------------------------------------------------------------
// Function:	DSetMemXferPropList::setDataTransform
///\brief	This is an overloaded member function, provided for convenience.
///		It takes a reference to a \c H5std_string for the expression.
///\param	expression - IN: H5std_string data transform expression
///\exception	H5::PropListIException
// Programmer:	Binh-Minh Ribler - Mar, 2014
//--------------------------------------------------------------------------
void DSetMemXferPropList::setDataTransform(const H5std_string& expression) const
{
    setDataTransform(expression.c_str());
}

//--------------------------------------------------------------------------
// Function:	DSetMemXferPropList::getDataTransform
///\brief	Sets data transform expression.
///\param	exp - OUT: buffer for data transform expression (char*)
///\param	buf_size   - IN: size of buffer for expression, including the
///				 null terminator
///\exception	H5::PropListIException
// Programmer:	Binh-Minh Ribler - Mar, 2014
//--------------------------------------------------------------------------
ssize_t DSetMemXferPropList::getDataTransform(char* exp, size_t buf_size) const
{
    // H5Pget_data_transform will get buf_size characters of the expression
    // including the null terminator
    ssize_t exp_len;
    exp_len = H5Pget_data_transform(id, exp, buf_size);

    // H5Pget_data_transform returns a negative value, raise an exception
    if (exp_len < 0)
    {
	throw PropListIException("DSetMemXferPropList::getDataTransform",
		"H5Pget_data_transform failed");
    }

    // H5Pget_data_transform will put a null terminator at the end of the
    // expression or at [buf_size-1] if the expression is at least the size
    // of the buffer.

    // Return the expression length, which might be different from buf_size
    return(exp_len);
}

//--------------------------------------------------------------------------
// Function:	DSetMemXferPropList::getDataTransform
///\brief	This is an overloaded member function, provided for convenience.
///		It takes no parameter and returns a \c H5std_string for the expression.
///
///\exception	H5::PropListIException
// Programmer:	Binh-Minh Ribler - Mar, 2014
//--------------------------------------------------------------------------
H5std_string DSetMemXferPropList::getDataTransform() const
{
    // Initialize string to "", so that if there is no expression, the returned
    // string will be empty
    H5std_string expression("");

    // Preliminary call to get the expression's length
    ssize_t exp_len = H5Pget_data_transform(id, NULL, (size_t)0);

    // If H5Pget_data_transform returns a negative value, raise an exception
    if (exp_len < 0)
    {
        throw PropListIException("DSetMemXferPropList::getDataTransform", "H5Pget_data_transform failed");
    }

    // If expression exists, calls C routine again to get it
    else if (exp_len > 0)
    {
        // Temporary buffer for char* expression
        char* exp_C = new char[exp_len+1];
        HDmemset(exp_C, 0, exp_len+1); // clear buffer

        // Used overloaded function
        exp_len = getDataTransform(exp_C, exp_len+1);

        // Convert the C expression to return
        expression = exp_C;

        // Clean up resource
        delete []exp_C;
    }
    // Return the string expression
    return(expression);
}

//--------------------------------------------------------------------------
// Function:	DSetMemXferPropList::getTypeConvCB
///\brief	Sets an exception handling callback for datatype conversion
///		for a dataset transfer property list.
///\param	op        - IN: User's function
///\param	user_data - IN: User's data
///\exception	H5::PropListIException
// Programmer:	Binh-Minh Ribler - April, 2004
//--------------------------------------------------------------------------
void DSetMemXferPropList::setTypeConvCB( H5T_conv_except_func_t op, void *user_data) const
{
   herr_t ret_value = H5Pset_type_conv_cb( id, op, user_data);
   if( ret_value < 0 )
   {
      throw PropListIException("DSetMemXferPropList::setTypeConvCB",
		"H5Pset_type_conv_cb failed");
   }
}

//--------------------------------------------------------------------------
// Function:	DSetMemXferPropList::getTypeConvCB
///\brief	Gets the exception handling callback function and data.
///\param	op        - IN: Retrieved user function
///\param	user_data - IN: Retrieved user data
///\exception	H5::PropListIException
// Programmer:	Binh-Minh Ribler - April, 2004
//--------------------------------------------------------------------------
void DSetMemXferPropList::getTypeConvCB( H5T_conv_except_func_t *op, void **user_data) const
{
   herr_t ret_value = H5Pget_type_conv_cb( id, op, user_data);
   if( ret_value < 0 )
   {
      throw PropListIException("DSetMemXferPropList::getTypeConvCB",
		"H5Pget_type_conv_cb failed");
   }
}

//--------------------------------------------------------------------------
// Function:	DSetMemXferPropList::setVlenMemManager
///\brief	Sets the memory manager for variable-length datatype allocation.
///\param	alloc_func - IN: User's allocate routine
///\param	alloc_info - IN: User's allocation parameters
///\param	free_func  - IN: User's free routine
///\param	free_info  - IN: User's free parameters
///\exception	H5::PropListIException
// Programmer:	Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
void DSetMemXferPropList::setVlenMemManager( H5MM_allocate_t alloc_func, void* alloc_info, H5MM_free_t free_func, void* free_info ) const
{
   herr_t ret_value = H5Pset_vlen_mem_manager( id, alloc_func, alloc_info,
						free_func, free_info );
   if( ret_value < 0 )
   {
      throw PropListIException("DSetMemXferPropList::setVlenMemManager",
		"H5Pset_vlen_mem_manager failed");
   }
}

//--------------------------------------------------------------------------
// Function:	DSetMemXferPropList::setVlenMemManager
///\brief	Sets the memory manager for variable-length datatype
///		allocation - system \c malloc and \c free will be used.
///
///\exception	H5::PropListIException
// Programmer:	Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
void DSetMemXferPropList::setVlenMemManager() const
{
   setVlenMemManager( NULL, NULL, NULL, NULL );
}

//--------------------------------------------------------------------------
// Function:	DSetMemXferPropList::getVlenMemManager
///\brief	Gets the memory manager for variable-length datatype allocation
///\param	alloc_func - OUT: User's allocate routine
///\param	alloc_info - OUT: User's allocation parameters
///\param	free_func  - OUT: User's free routine
///\param	free_info  - OUT: User's free parameters
///\exception	H5::PropListIException
// Programmer:	Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
void DSetMemXferPropList::getVlenMemManager( H5MM_allocate_t& alloc_func, void** alloc_info, H5MM_free_t& free_func, void** free_info ) const
{
   herr_t ret_value = H5Pget_vlen_mem_manager( id, &alloc_func, alloc_info, &free_func, free_info );
   if( ret_value < 0 )
   {
      throw PropListIException("DSetMemXferPropList::getVlenMemManager",
		"H5Pget_vlen_mem_manager failed");
   }
}

//--------------------------------------------------------------------------
// Function:	DSetMemXferPropList::setSmallDataBlockSize
///\brief	Sets the size of a contiguous block reserved for small data.
///\param	size - IN: Maximum size, in bytes, of the small data block.
///\exception	H5::PropListIException
///\par Description
///		For detail, please refer to the C layer Reference Manual at:
/// http://www.hdfgroup.org/HDF5/doc/RM/RM_H5P.html#Property-SetSmallData
// Programmer:	Binh-Minh Ribler - April, 2004
//--------------------------------------------------------------------------
void DSetMemXferPropList::setSmallDataBlockSize(hsize_t size)
{
   herr_t ret_value = H5Pset_small_data_block_size(id, size);
   if (ret_value < 0)
   {
      throw PropListIException("DSetMemXferPropList::setSmallDataBlockSize",
		"H5Pset_small_data_block_size failed");
   }
}

//--------------------------------------------------------------------------
// Function:	DSetMemXferPropList::getSmallDataBlockSize
///\brief	Returns the current small data block size setting.
///\return	Size of the small data block, in bytes
///\exception	H5::PropListIException
// Programmer:	Binh-Minh Ribler - April, 2004
//--------------------------------------------------------------------------
hsize_t DSetMemXferPropList::getSmallDataBlockSize()
{
   hsize_t size;
   herr_t ret_value = H5Pget_small_data_block_size(id, &size);
   if (ret_value < 0)
   {
      throw PropListIException("DSetMemXferPropList::getSmallDataBlockSize",
		"H5Pget_small_data_block_size failed");
   }
   return(size);
}

//--------------------------------------------------------------------------
// Function:	DSetMemXferPropList::setHyperVectorSize
///\brief	Sets number of I/O vectors to be read/written in hyperslab I/O.
///
///\exception	H5::PropListIException
///\par Description
///		For information, please refer to the C layer Reference
///		Manual at:
/// http://www.hdfgroup.org/HDF5/doc/RM/RM_H5P.html#Property-SetHyperVectorSize
// Programmer:	Binh-Minh Ribler - April, 2004
//--------------------------------------------------------------------------
void DSetMemXferPropList::setHyperVectorSize(size_t vector_size)
{
   herr_t ret_value = H5Pset_hyper_vector_size(id, vector_size);
   if (ret_value < 0)
   {
      throw PropListIException("DSetMemXferPropList::setHyperVectorSize",
		"H5Pset_hyper_vector_size failed");
   }
}

//--------------------------------------------------------------------------
// Function:	DSetMemXferPropList::getHyperVectorSize
///\brief	Returns the number of I/O vectors to be read/written in
///		hyperslab I/O.
///\return	Number of I/O vectors
///\exception	H5::PropListIException
// Programmer:	Binh-Minh Ribler - April, 2004
//--------------------------------------------------------------------------
size_t DSetMemXferPropList::getHyperVectorSize()
{
   size_t vector_size;
   herr_t ret_value = H5Pget_hyper_vector_size(id, &vector_size);
   if (ret_value < 0)
   {
      throw PropListIException("DSetMemXferPropList::getHyperVectorSize",
		"H5Pget_hyper_vector_size failed");
   }
   return(vector_size);
}

//--------------------------------------------------------------------------
// Function:	DSetMemXferPropList::setEDCCheck
///\brief	Enables or disables error-detecting for a dataset reading
///		process.
///\param	check - IN: Specifies whether error detection is enabled or
///				disabled
///\exception	H5::PropListIException
///\par Description
///		The error detection algorithm used is the algorithm previously
///		specified in the corresponding dataset creation property
///		list.  This function does not affect the use of error
///		detection in the writing process.
///\par
///		Valid values are as follows:
///		\li \c H5Z_ENABLE_EDC   (default)
///		\li \c H5Z_DISABLE_EDC
// Programmer:	Binh-Minh Ribler - April, 2004
//--------------------------------------------------------------------------
void DSetMemXferPropList::setEDCCheck(H5Z_EDC_t check)
{
   herr_t ret_value = H5Pset_edc_check(id, check);
   if (ret_value < 0)
   {
      throw PropListIException("DSetMemXferPropList::setEDCCheck",
		"H5Pset_edc_check failed");
   }
}

//--------------------------------------------------------------------------
// Function:	DSetMemXferPropList::getEDCCheck
///\brief	Determines whether error-detection is enabled for dataset reads.
///\return	\c H5Z_ENABLE_EDC or \c H5Z_DISABLE_EDC
///\exception	H5::PropListIException
// Programmer:	Binh-Minh Ribler - April, 2004
//--------------------------------------------------------------------------
H5Z_EDC_t DSetMemXferPropList::getEDCCheck()
{
   H5Z_EDC_t check = H5Pget_edc_check(id);
   if (check < 0)
   {
      throw PropListIException("DSetMemXferPropList::getEDCCheck",
		"H5Pget_edc_check failed");
   }
   return(check);
}

//--------------------------------------------------------------------------
// Function:	DSetMemXferPropList destructor
///\brief	Noop destructor.
// Programmer	Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
DSetMemXferPropList::~DSetMemXferPropList() {}

#ifndef H5_NO_NAMESPACE
} // end namespace
osg::Real32 ConstantAnimationAdvancer::getValue(void) const
{
   return getConstant();
}
示例#22
0
int pregetmacro(string &line, bool icase, RawSource *rs, bool list, bool recursive) {
    Macro mac;
    mac._list=list;
    mac._recursive=recursive;
    string d,name=getid(line);
    if (name.empty()) {
        error1("Illegal macroname");
        return 0;
    }
    while('>') {
        skipblanks(line);
        if (!line[0]) break;
        if (isalpha(line[0])) {
            d=getid(line);
            mac._namParam.push_back(d);
            if (sbcneed(line,'+')) mac._greedy=true;
            if (sbcneed(line,':')) {
                d=getargument(line,mac._greedy);
            } else d="\01";
            mac._namDefaults.push_back(d);
            if (mac._greedy) break;
            if (comma(line)) continue;
            break;
        }
        if (isdigit(line[0])) {
            if (!getConstant(line,mac._minnum)) {
                error1("constant expected");
                return 0;
            }
            if (need(line,"..")) {
                skipblanks(line);
                if (sbcneed(line,'*'))
                    mac._maxnum=BIGVALUE;
                else {
                    if (!getConstant(line,mac._maxnum)) {
                        error1("constant expected");
                        return 0;
                    }
                }
            } else mac._maxnum=mac._minnum;
            if (mac._minnum<0 || mac._maxnum<mac._minnum) {
                error1("Illegal parameter");
                return 0;
            }
            if (sbcneed(line,'+'))
                if (mac._maxnum<BIGVALUE) mac._greedy=true;
                else error1("No greedy stars allowed!");
            break;
        }
        if (sbcneed(line,'*')) {
            mac._minnum=0;
            mac._maxnum=BIGVALUE;
            if (sbcneed(line,'+')) error1("No greedy stars allowed!");
            break;
        }
        error1("Syntax error");
        break;
    }
    if (mac._maxnum>mac._minnum && line[0]) {
        int i=mac._maxnum-mac._minnum;
        bool gr=false;
        while (i--) {
            if (!line[0]) break;
            if (!i) gr=mac._greedy;
            d=getargument(line,gr);
            mac._numDefaults.push_back(d);
        }
    }
    if (mac._minnum)
        mac._minparam=(int)mac._namParam.size()+mac._minnum;
    else {
        int i=(int)mac._namParam.size();
        mac._minparam=0;
        while (i--) if (mac._namDefaults[i]=="\01") {
                mac._minparam=i+1;
                break;
            }
    }
    if (mac._greedy || mac._maxnum==BIGVALUE) mac._maxparam=BIGVALUE;
    else mac._maxparam=(int)mac._namParam.size()+mac._maxnum;
    if (listopt._macroname.empty()) mac._line=curlin;
    else mac._line=listopt._macrocurlin;
    mac._filename=listopt._filename;
    mac._body=rs->ReadUntil(macronl,macroel,"macro");
    if (!listopt._macroname.empty()) listopt._macrocurlin+=(int)mac._body.size()+1;
    mactab.add(name,icase,mac);
    return 1;
}
示例#23
0
QVariant Engine::getValue(QString n) const
{
	if(hasConstant(n))return getConstant(n);
	if(hasVariable(n))return getVariable(n);
	return QVariant();
}
示例#24
0
文件: MetaLexer.cpp 项目: ellert/root
 bool Token::getConstantAsBool() const {
   assert(kind == tok::constant && "Not a constant");
   return getConstant() != 0;
 }
示例#25
0
文件: assign.hpp 项目: abduld/cena
 void toCCode_(ostringstream &o) override { o << getConstant(); }
示例#26
0
文件: Plane.hpp 项目: hhsaez/crimild
		PRECISION signedDistanceToPoint( const VectorImpl &point ) const
		{
			return getNormal() * point + getConstant();
		}
示例#27
0
string ReplaceDefines(string s) {
    string nid,nr,res("");
    int pos;
    for(;;) {
        pos=frepdef.find(s);
        if (pos) res+=s.substr(0,pos);
        if (pos==string::npos) break;
        s=s.substr(pos);
        if (s[0]=='_' || isalpha(s[0])) {
            nid=getid(s);
            nr=defargtab.getrepl(nid);
            if (nr.empty()) nr=deftab.getrepl(nid,s);
            if (nr.empty() && nid[0]=='_') nr=getbuildindefine(nid,s);
            if (nr.empty()) nr=nid;
            res+=nr;
        } else if (s[0]=='\'' || s[0]=='"') {
            pos=getstringlength(s);
            res+=s.substr(0,pos);
            s=s.substr(pos);
        } else {
            if (s[0]!='@') error1("ReplaceDefines",ERRINTERNAL);
            int skip=-1;
            while (cneed(s,'@')) ++skip;
            if (s[0]=='\'' || s[0]=='"') {
                pos=getstringlength(s);
                res+=s[0]+ReplaceDefines(s.substr(1,pos-2))+s[pos-1];
                s=s.substr(pos);
            } else if (isdigit(s[0])) {
                int max,num,rot;
                if (!getConstant(s,num)) error1("ReplaceDefines",ERRINTERNAL);
                nr=macnumtab.getrepl(0,skip);
                if (nr.empty()) {
                    error1("Use of @num not allowed outside macro");
                    continue;
                }
                if (num) {
                    if (!getConstant(nr,max)) error1("ReplaceDefines",ERRINTERNAL);
                    if (num>max) nr="";
                    else {
                        nr=macnumtab.getrepl(ROTATE,skip);
                        if (nr.empty()) error1("ReplaceDefines",ERRINTERNAL);
                        if (!getConstant(nr,rot)) error1("ReplaceDefines",ERRINTERNAL);
                        num-=1;
                        num=(num+rot)%max;
                        num+=1;
                        nr=macnumtab.getrepl(num,skip);
                        if (nr.empty()) error1("ReplaceDefines",ERRINTERNAL);
                    }
                }
                res+=nr;
            } else if (cneed(s,'#')) {
                nr=macnumtab.getrepl(ITERATION,skip);
                if (nr.empty()) {
                    nr="0";
                    error1("Use of @# not allowed outside loops");
                }
                res+=nr;
            } else if (cneed(s,'*')) {
                res+=tostr(unieknummer++);
            } else {
                ++skip;
                while (skip--) res+='@';
            }
        }
    }

    s=res;
    res.clear();
    nr.clear();
    for(;;) {
        pos=fmacfun.find(s);
        if (pos) res+=s.substr(0,pos);
        if (pos==string::npos) break;
        s=s.substr(pos);
        nid=getid(s);
        if (s[0]=='(') nr=getmacrofun(nid,s);
        if (nr.empty()) res+=nid;
        else {
            res+=nr;
            nr.clear();
        }
    }

    string r;
    for(;;) {
        pos=(int)res.find_first_of("'\">");
        if (pos) r+=res.substr(0,pos);
        if (pos==string::npos) break;
        res=res.substr(pos);
        if (res[0]=='\'' || res[0]=='"') {
            pos=getstringlength(res);
            r+=res.substr(0,pos);
            res=res.substr(pos);
        } else if (res[0]=='>' && res[1]=='<') {
            pos=(int)r.find_last_not_of(' ');
            if (pos!=string::npos) r.erase(pos+1);
            res=res.substr(2);
            skipblanks(res);
        } else {
            r+='>';
            res.erase(0,1);
        }
    }
    return r;
}
示例#28
0
namespace H5 {

#ifndef DOXYGEN_SHOULD_SKIP_THIS
// This DOXYGEN_SHOULD_SKIP_THIS block is a work-around approach to control
// the order of creation and deletion of the global constants.  See Design Notes
// in "H5PredType.cpp" for information.

// Initialize a pointer for the constant
LinkAccPropList* LinkAccPropList::DEFAULT_ = 0;

//--------------------------------------------------------------------------
// Function:    LinkAccPropList::getConstant
//              Creates a LinkAccPropList object representing the HDF5 constant
//              H5P_LINK_ACCESS, pointed to by LinkAccPropList::DEFAULT_
// exception    H5::PropListIException
// Description
//              If LinkAccPropList::DEFAULT_ already points to an allocated
//              object, throw a PropListIException.  This scenario should not
//              happen.
// Programmer   Binh-Minh Ribler - December, 2016
//--------------------------------------------------------------------------
LinkAccPropList* LinkAccPropList::getConstant()
{
    // Tell the C library not to clean up, H5Library::termH5cpp will call
    // H5close - more dependency if use H5Library::dontAtExit()
    if (!IdComponent::H5dontAtexit_called)
     {
        (void) H5dont_atexit();
        IdComponent::H5dontAtexit_called = true;
    }

    // If the constant pointer is not allocated, allocate it. Otherwise,
    // throw because it shouldn't be.
    if (DEFAULT_ == 0)
        DEFAULT_ = new LinkAccPropList(H5P_LINK_ACCESS);
    else
        throw PropListIException("LinkAccPropList::getConstant", "LinkAccPropList::getConstant is being invoked on an allocated DEFAULT_");
    return(DEFAULT_);
}

//--------------------------------------------------------------------------
// Function:    LinkAccPropList::deleteConstants
// Purpose:     Deletes the constant object that LinkAccPropList::DEFAULT_
//              points to.
// exception    H5::PropListIException
// Programmer   Binh-Minh Ribler - December, 2016
//--------------------------------------------------------------------------
void LinkAccPropList::deleteConstants()
{
    if (DEFAULT_ != 0)
        delete DEFAULT_;
}

//--------------------------------------------------------------------------
// Purpose:     Constant for default property
//--------------------------------------------------------------------------
const LinkAccPropList& LinkAccPropList::DEFAULT = *getConstant();

#endif // DOXYGEN_SHOULD_SKIP_THIS

//--------------------------------------------------------------------------
// Function:    Default Constructor
///\brief       Creates a file access property list
// Programmer   Binh-Minh Ribler - December, 2016
//--------------------------------------------------------------------------
LinkAccPropList::LinkAccPropList() : PropList(H5P_LINK_ACCESS) {}

//--------------------------------------------------------------------------
// Function:    LinkAccPropList copy constructor
///\brief       Copy Constructor: same HDF5 object as \a original
///\param       original - IN: LinkAccPropList instance to copy
// Programmer   Binh-Minh Ribler - December, 2016
//--------------------------------------------------------------------------
LinkAccPropList::LinkAccPropList(const LinkAccPropList& original) : PropList(original) {}

//--------------------------------------------------------------------------
// Function:    LinkAccPropList overloaded constructor
///\brief       Creates a file access property list using the id of an
///             existing one.
// Programmer   Binh-Minh Ribler - December, 2016
//--------------------------------------------------------------------------
LinkAccPropList::LinkAccPropList(const hid_t plist_id) : PropList(plist_id) {}

//--------------------------------------------------------------------------
// Function:    LinkAccPropList::setNumLinks
///\brief       Set the number of soft or user-defined link traversals allowed
///             before the library assumes it has found a cycle and aborts the
///             traversal.
///
///\exception   H5::PropListIException
// Programmer   Binh-Minh Ribler - March 1, 2017
//--------------------------------------------------------------------------
void LinkAccPropList::setNumLinks(size_t nlinks) const
{
    herr_t ret_value = H5Pset_nlinks(id, nlinks);
    // Throw exception if H5Pset_nlinks returns failure
    if (ret_value < 0)
    {
        throw PropListIException("setNumLinks", "H5Pset_nlinks failed");
    }
}

//--------------------------------------------------------------------------
// Function:    LinkAccPropList::getNumLinks
///\brief       Gets the number of soft or user-defined links that can be
///             traversed before a failure occurs.
///
///\exception   H5::PropListIException
// Programmer   Binh-Minh Ribler - March 1, 2017
//--------------------------------------------------------------------------
size_t LinkAccPropList::getNumLinks() const
{
    size_t nlinks = 0;
    herr_t ret_value = H5Pget_nlinks(id, &nlinks);
    // Throw exception if H5Pget_nlinks returns failure
    if (ret_value < 0)
    {
        throw PropListIException("getNumLinks", "H5Pget_nlinks failed");
    }
    return(nlinks);
}

//--------------------------------------------------------------------------
// Function:    LinkAccPropList destructor
///\brief       Noop destructor
// Programmer   Binh-Minh Ribler - December, 2016
//--------------------------------------------------------------------------
LinkAccPropList::~LinkAccPropList() {}

} // end namespace
示例#29
0
namespace H5 {
#endif

#ifndef DOXYGEN_SHOULD_SKIP_THIS
// This DOXYGEN_SHOULD_SKIP_THIS block is a work-around approach to control
// the order of creation and deletion of the global constants.  See Design Notes
// in "H5PredType.cpp" for information.

// Initialize a pointer for the constant
ObjCreatPropList* ObjCreatPropList::DEFAULT_ = 0;

//--------------------------------------------------------------------------
// Function:    ObjCreatPropList::getConstant
//              Creates a ObjCreatPropList object representing the HDF5 constant
//              H5P_FILE_ACCESS, pointed to by ObjCreatPropList::DEFAULT_
// exception    H5::PropListIException
// Description
//              If ObjCreatPropList::DEFAULT_ already points to an allocated
//              object, throw a PropListIException.  This scenario should not
//              happen.
// Programmer   Binh-Minh Ribler - 2015
//--------------------------------------------------------------------------
ObjCreatPropList* ObjCreatPropList::getConstant()
{
    // Tell the C library not to clean up, H5Library::termH5cpp will call
    // H5close - more dependency if use H5Library::dontAtExit()
    if (!IdComponent::H5dontAtexit_called)
    {
        (void) H5dont_atexit();
        IdComponent::H5dontAtexit_called = true;
    }

    // If the constant pointer is not allocated, allocate it. Otherwise,
    // throw because it shouldn't be.
    if (DEFAULT_ == 0)
        DEFAULT_ = new ObjCreatPropList(H5P_OBJECT_CREATE);
    else
        throw PropListIException("ObjCreatPropList::getConstant", "ObjCreatPropList::getConstant is being invoked on an allocated DEFAULT_");
    return(DEFAULT_);
}

//--------------------------------------------------------------------------
// Function:    ObjCreatPropList::deleteConstants
// Purpose:     Deletes the constant object that ObjCreatPropList::DEFAULT_
//              points to.
// exception    H5::PropListIException
// Programmer   Binh-Minh Ribler - 2015
//--------------------------------------------------------------------------
void ObjCreatPropList::deleteConstants()
{
    if (DEFAULT_ != 0)
        delete DEFAULT_;
}

//--------------------------------------------------------------------------
// Purpose:	Constant for default property
//--------------------------------------------------------------------------
const ObjCreatPropList& ObjCreatPropList::DEFAULT = *getConstant();

#endif // DOXYGEN_SHOULD_SKIP_THIS

//--------------------------------------------------------------------------
// Function:	Default Constructor
///\brief	Creates a file access property list
// Programmer:	Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
ObjCreatPropList::ObjCreatPropList() : PropList(H5P_OBJECT_CREATE) {}

//--------------------------------------------------------------------------
// Function:	ObjCreatPropList copy constructor
///\brief	Copy Constructor: makes a copy of the original
///\param	original - IN: ObjCreatPropList instance to copy
// Programmer:	Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
ObjCreatPropList::ObjCreatPropList(const ObjCreatPropList& original) : PropList(original) {}

//--------------------------------------------------------------------------
// Function:	ObjCreatPropList overloaded constructor
///\brief	Creates a file access property list using the id of an
///		existing one.
// Programmer:  Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
ObjCreatPropList::ObjCreatPropList(const hid_t plist_id) : PropList(plist_id) {}

//--------------------------------------------------------------------------
// Function:	ObjCreatPropList::setAttrPhaseChange
///\brief	Sets attribute storage phase change thresholds.
///\param	max_compact - IN: Maximum number of attributes to be stored in
///				  compact storage.  Default to 8
///\param	min_dense   - IN: Minimum number of attributes to be stored in
///				  dense storage.  Default to 6
///\exception	H5::PropListIException
///\par Description
///		If \c max_compact is set to 0, dense storage will be used.
///		For more detail about on attribute storage, please refer to the
///		C layer Reference Manual at:
/// https://www.hdfgroup.org/HDF5/doc/RM/RM_H5P.html#Property-SetAttrPhaseChange
// Programmer:  Binh-Minh Ribler - September 2015
//--------------------------------------------------------------------------
void ObjCreatPropList::setAttrPhaseChange(unsigned max_compact, unsigned min_dense) const
{
    herr_t ret_value = H5Pset_attr_phase_change(id, max_compact, min_dense);
    if (ret_value < 0)
    {
        throw PropListIException("ObjCreatPropList::setAttrPhaseChange", "H5Pset_attr_phase_change failed");
    }
}

//--------------------------------------------------------------------------
// Function:	ObjCreatPropList::getAttrPhaseChange
///\brief	Gets attribute storage phase change thresholds.
///\param	max_compact - OUT: Maximum number of attributes to be stored in
///				  compact storage.
///\param	min_dense   - OUT: Minimum number of attributes to be stored in
///				  dense storage.
///\exception	H5::PropListIException
///\par Description
///		If \c max_compact is set to 0, dense storage will be used.
///		For more detail about on attribute storage, please refer to the
///		C layer Reference Manual at:
/// https://www.hdfgroup.org/HDF5/doc/RM/RM_H5P.html#Property-GetAttrPhaseChange
// Programmer:  Binh-Minh Ribler - September 2015
//--------------------------------------------------------------------------
void ObjCreatPropList::getAttrPhaseChange(unsigned& max_compact, unsigned& min_dense) const
{
    herr_t ret_value;
    ret_value = H5Pget_attr_phase_change(id, &max_compact, &min_dense);
    if (ret_value < 0)
    {
        throw PropListIException("ObjCreatPropList::getAttrPhaseChange", "H5Pget_attr_phase_change failed");
    }
}

//--------------------------------------------------------------------------
// Function:	ObjCreatPropList::setAttrCrtOrder
///\brief	Sets tracking and indexing of attribute creation order.
///\param	crt_order_flags  - IN: Flags specifying whether to track and
///			index attribute creation order.  Default: No flag set
///\exception	H5::PropListIException
///\par Description
///		Valid flags are:
///		\li \c H5P_CRT_ORDER_TRACKED - Attribute creation order is tracked
///		\li \c H5P_CRT_ORDER_INDEXED - Attribute creation order is
///				 indexed (requires H5P_CRT_ORDER_TRACKED).
///		When no flag is set, attribute creation order is neither
///		tracked not indexed.  Note that HDF5 currently provides no
///		mechanism to turn on attribute creation order tracking at object
///		creation time and to build the index later.
///		The C layer Reference Manual at can be found at:
/// https://www.hdfgroup.org/HDF5/doc/RM/RM_H5P.html#Property-SetAttrCreationOrder
// Programmer:  Binh-Minh Ribler - September 2015
//--------------------------------------------------------------------------
void ObjCreatPropList::setAttrCrtOrder(unsigned crt_order_flags) const
{
    herr_t ret_value = H5Pset_attr_creation_order(id, crt_order_flags);
    if (ret_value < 0)
    {
        throw PropListIException("ObjCreatPropList::setAttrCrtOrder", "H5Pset_attr_creation_order failed");
    }
}

//--------------------------------------------------------------------------
// Function:	ObjCreatPropList::getAttrCrtOrder
///\brief	Gets tracking and indexing settings for attribute
///		creation order.
///\return	Attribute creation order
///\exception	H5::PropListIException
///\par Description
///		When no flag is set, i.e. crt_order_flags = 0, attribute
///		creation order is neither tracked not indexed.
///		The C layer Reference Manual at can be found at:
/// https://www.hdfgroup.org/HDF5/doc/RM/RM_H5P.html#Property-GetAttrCreationOrder
// Programmer:  Binh-Minh Ribler - September 2015
//--------------------------------------------------------------------------
unsigned ObjCreatPropList::getAttrCrtOrder() const
{
    herr_t ret_value;
    unsigned crt_order_flags = 0;
    ret_value = H5Pget_attr_creation_order(id, &crt_order_flags);
    if (ret_value < 0)
    {
        throw PropListIException("ObjCreatPropList::getAttrCrtOrder", "H5Pget_attr_creation_order failed");
    }
    return(crt_order_flags);
}

//--------------------------------------------------------------------------
// Function:	ObjCreatPropList destructor
///\brief	Noop destructor
// Programmer	Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
ObjCreatPropList::~ObjCreatPropList() {}

#ifndef H5_NO_NAMESPACE
} // end namespace
示例#30
0
bool CubicSpline::intersects(const CubicSpline &rt, VectorF ignoreAxis) const
{
#if 1
    vector<VectorF> path1 = getSplinePoints(*this);
    vector<VectorF> path2 = getSplinePoints(rt);
    for(size_t i = 1; i < path1.size(); i++)
    {
        for(size_t j = 1; j < path2.size(); j++)
        {
            if(linesIntersect(path1[i - 1], path1[i], path2[j - 1], path2[j], 0))
                return true;
        }
    }
    return false;
#else
    const int splitCount = 50; // number of line segments to split spline into
    ignoreAxis = normalize(ignoreAxis);

    for(int segmentNumber = 0; segmentNumber < splitCount; segmentNumber++)
    {
        float startT = (float)(segmentNumber) / splitCount;
        float endT = (float)(segmentNumber + 1) / splitCount;
        VectorF startP = rt.evaluate(startT);
        startP -= ignoreAxis * dot(ignoreAxis, startP); // move to plane normal to ignoreAxis
        VectorF endP = rt.evaluate(endT);
        endP -= ignoreAxis * dot(ignoreAxis, endP); // move to plane normal to ignoreAxis
        VectorF delta = endP - startP;

        if(absSquared(delta) < eps * eps) // if delta is too small
        {
            continue;
        }

        // solve dot(evaluate(t), cross(ignoreAxis, delta)) == 0 and it intersects if dot(evaluate(t) - startP, delta) / dot(delta, delta) is in [0, 1] and t is in [0, 1]
        VectorF normal = cross(ignoreAxis, delta);
        float cubic = dot(getCubic(), normal);
        float quadratic = dot(getQuadratic(), normal);
        float linear = dot(getLinear(), normal);
        float constant = dot(getConstant(), normal);
        float intersections[3];
        int intersectionCount = solveCubic(constant, linear, quadratic, cubic, intersections);

        for(int i = 0; i < intersectionCount; i++)
        {
            float t = intersections[i];

            if(t < 0 || t > 1)
            {
                continue;
            }

            float v = dot(evaluate(t) - startP, delta) / dot(delta, delta);

            if(v < 0 || v > 1)
            {
                continue;
            }

            return true;
        }
    }

    return false;
#endif
}