Пример #1
0
struct token *expand(struct token *original)
{
    const struct token *list;
    struct token *res;

    /* Do nothing if there is nothing to expand. */
    if (!needs_expansion(original))
        return original;

    list = original;
    res = calloc(1, sizeof(*res));
    res[0] = token_end;
    while (list->token != END) {
        const struct macro *def = definition(*list);
        struct token **args;

        /* Only expand function-like macros if they appear as function
         * invocations, beginning with an open paranthesis. */
        if (def && !is_macro_expanded(def) &&
            (def->type != FUNCTION_LIKE || peek_next(list + 1) == '('))
        {
            args = read_args(list + 1, &list, def);
            res = concat(res, expand_macro(def, args));
        } else {
            res = append(res, *list++);
        }
    }

    free(original);
    return res;
}
Пример #2
0
void CSensor::load()
{
  if (m_handle)
  {
    char *error; error = nullptr;
    TFGetStatistics       getStatistics;
    TFGetFrameAvialable   getFrameAvialable;
    MON_IMPORT(TFInitSensor         , initSensor         );
    MON_IMPORT(TFGetName            , getName            );
    MON_IMPORT(TFGetDefinition      , getDefinition      );
    MON_IMPORT(TFGetDefinitionLength, getDefinitionLength);
    MON_IMPORT(TFGetStatistics      , getStatistics      );
    MON_IMPORT(TFGetFrameAvialable  , getFrameAvialable  );
    initSensor(MON_ST_LOGGER, MON_ST_CONFIG->folder("sensors")->folder(name()));
    setDefinition(getDefinition());
    if(name().compare(getName()) != 0)
    {
      MON_LOG_ERR("Detected try to load sensor " << getName() << ", renamed to " << name());
    }
    for(auto &frame : definition()->frames())
    {
      m_frames[frame] = new CFrame(this, getStatistics, getFrameAvialable, frame);
    }
  }
}
Пример #3
0
object_t *eval(object_t *exp, object_t *env) { 
  object_t *ret = NULL;
  
  if (evaluate_to_self(exp)) {
    ret = exp;
  }
  else if (quoted(exp)) {
    ret = car(cdr(exp));
  }
  else if (definition(exp)) {
    object_t *symb = car(cdr(exp)),
      *val = car(cdr(cdr(exp)));
    
    if (val == NULL) {
      create_new_variable(symb, get_nil(), env);
    } else {
      create_new_variable(symb,
			  eval(val, env),
			  env);
    }
    ret = symb;
  }
  else if (is_symbol(exp)) {
    //printf("\nfound symbol: %s\n\n", exp->values.symbol.value);
    ret = find_variable_value(exp, env);
  }
  else if (function(exp)) {
    object_t *arguments = make_arguments(cdr(exp), env);
    object_t *func = eval(car(exp), env);

    if (func == NULL || func == get_nil() ||
	func->type != t_primitive) {
      fprintf(stderr, "func: %d\n", (unsigned int)func);
      //fprintf(stderr, "type: %d\n", func->type);
      die("Not a primitive!\n");
    } else {
      ret = (func->values.primitive.function)(arguments);
    }
  } else if (maybe_eval_to_function(exp)) {
    object_t *c = car(exp);
    object_t *func = eval(c, env);
    if (!(func == NULL || nilp(func))) {
      object_t *arguments = make_arguments(cdr(exp), env);
      ret = (func->values.primitive.function)(arguments);
    }
    else {
      die("Not a function!\n");
    }
  }
  else {
    die("Can't eval!\n");
  }
  
  return ret;
}
Пример #4
0
void UmlUseCaseDiagram::write_it(FileOut & out) {
  const char * k = ((_uml_20) ? "ownedMember" : "packagedElement");
  UmlUseCaseDiagramDefinition * def = definition();
  const Q3PtrVector<UmlUseCaseAssociation> & assocs = def->associations();
  int n = (int) assocs.size();
  
  for (int rank = 0; rank != n; rank += 1)
    assocs.at(rank)->write(out, this, rank, k);
 
  unload(); 
}
 bool all_children_closed(func_decl * f) const {
     func_decl_set * def = definition(f);
     if (!def)
         return true;
     func_decl_set::iterator it  = def->begin();
     func_decl_set::iterator end = def->end();
     for (; it != end; ++it) {
         if (get_color(*it) != CLOSED)
             return false;
     }
     return true;
 }
 bool visit_children(func_decl * f) {
     func_decl_set * def = definition(f);
     if (!def)
         return true;
     bool visited = true;
     func_decl_set::iterator it  = def->begin();
     func_decl_set::iterator end = def->end();
     for (; it != end; ++it) {
         visit(*it, visited);
     }
     return visited;
 }
Пример #7
0
void PlusProtocol::translate(const igtl::ImageMessage::Pointer body)
{
    CX_LOG_DEBUG() << "Image incoming to plusprotocol";
    //DIMENSION
    int x = 0;
    int y = 1;
    int z = 2;

    //There seems to be a bug in the received images spacing from the plusserver
    /*
    float wrong_spacing[3];
    body->GetSpacing(wrong_spacing);
    float right_spacing[3];
    right_spacing[x] = wrong_spacing[x];
    right_spacing[y] = wrong_spacing[z];
    right_spacing[z] = 1;
    body->SetSpacing(right_spacing);
    */

    int dimensions_p[3];
    body->GetDimensions(dimensions_p);
    float spacing[3];
    body->GetSpacing(spacing);
    int extent_p[3];
    extent_p[x] = dimensions_p[x]-1;
    extent_p[y] = dimensions_p[y]-1;
    extent_p[z] = dimensions_p[z]-1;

    //IMAGE
    IGTLinkConversion converter;
    ImagePtr theImage = converter.decode(body);

	IGTLinkConversionBase baseConverter;
	double timestamp_ms = baseConverter.decode_timestamp(body).toMSecsSinceEpoch();
	timestamp_ms = this->getSyncedTimestampForTransformsAndImages(timestamp_ms);
    theImage->setAcquisitionTime(QDateTime::fromMSecsSinceEpoch(timestamp_ms));
    emit image(theImage);

    //PROBEDEFINITION
    ProbeDefinitionPtr definition(new ProbeDefinition);
    definition->setUseDigitalVideo(true);
    definition->setType(ProbeDefinition::tLINEAR);
    definition->setSpacing(Vector3D(spacing[x], spacing[y], spacing[z]));
    definition->setSize(QSize(dimensions_p[x], dimensions_p[y]));
    definition->setOrigin_p(Vector3D(dimensions_p[x]/2, 0, 0));
    double depthstart_mm = 0;
    double depthend_mm = extent_p[y]*spacing[y];
    double width_mm = extent_p[x]*spacing[x];
    definition->setSector(depthstart_mm, depthend_mm, width_mm);
    definition->setClipRect_p(DoubleBoundingBox3D(0, extent_p[x], 0, extent_p[y], 0, extent_p[z]));

    emit probedefinition(mProbeToTrackerName, definition);
}
Пример #8
0
VectorFont::Glyph::Glyph( const std::string &hershey_glyph_definition, const double word_space_percentage, const double character_space_percentage )
{
	m_word_space_percentage = word_space_percentage;
	m_character_space_percentage = character_space_percentage;

	std::string definition(hershey_glyph_definition);

	if (definition.size() >= 2)
	{
	    double left_edge = PointToMM(double(definition[0] - 'R'));
	    double right_edge = PointToMM(double( definition[1] - 'R'));
	    definition.erase(0,2);

        m_bounding_box.Insert( left_edge, 0, 0 );
        m_bounding_box.Insert( right_edge, 0, 0 );

		if (definition.size() >= 2)
		{
			double x = double(definition[0] - 'R');
			double y = double(definition[1] - 'R') * -1.0;
			definition.erase(0,2);

			while (definition.size() > 0)
			{
				if (definition.size() >= 2)
				{
					if ((definition[0] == ' ') && (definition[1] == 'R'))
					{
						// This is a 'pen up' item.  Set the new coordinates but don't draw anything.
						definition.erase(0,2);
						x = double(definition[0] - 'R');
						y = double(definition[1] - 'R') * -1.0;
					}
					else
					{
						double to_x = double(definition[0] - 'R');
						double to_y = double(definition[1] - 'R') * -1.0;

						GlyphLine *line = new GlyphLine( PointToMM(x), PointToMM(y), PointToMM(to_x), PointToMM(to_y) );
						m_graphics_list.push_back( line );
						m_bounding_box.Insert( line->BoundingBox() );
						x = to_x;
						y = to_y;
					}

				}

				definition.erase(0,2);
			}
		}
	} // End if - then
} // End constructor
OptionalModelObject ReverseTranslator::translateInternalMass( const WorkspaceObject & workspaceObject )
{
  if( workspaceObject.iddObject().type() != IddObjectType::InternalMass ){
    LOG(Error, "WorkspaceObject is not IddObjectType: InternalMass");
    return boost::none;
  }

  // create the definition
  openstudio::model::InternalMassDefinition definition(m_model);
  
  OptionalString s = workspaceObject.name();
  if(s){
    definition.setName(*s + " Definition");
  }

  OptionalWorkspaceObject target = workspaceObject.getTarget(openstudio::InternalMassFields::ConstructionName);
  if (target){
    OptionalModelObject modelObject = translateAndMapWorkspaceObject(*target);
    if (modelObject){
      if (modelObject->optionalCast<ConstructionBase>()){
        definition.setConstruction(modelObject->cast<ConstructionBase>());
      }
    }
  }

  OptionalDouble d = workspaceObject.getDouble(openstudio::InternalMassFields::SurfaceArea);
  if(d){
    definition.setSurfaceArea(*d);
  }

  // create the instance
  InternalMass internalMass(definition);

  s = workspaceObject.name();
  if(s){
    internalMass.setName(*s);
  }

  target = workspaceObject.getTarget(openstudio::InternalMassFields::ZoneName);
  if (target){
    OptionalModelObject modelObject = translateAndMapWorkspaceObject(*target);
    if (modelObject){
      if (modelObject->optionalCast<Space>()){
        internalMass.setSpace(modelObject->cast<Space>());
      }else if (modelObject->optionalCast<SpaceType>()){
        internalMass.setSpaceType(modelObject->cast<SpaceType>());
      }
    }
  }

  return internalMass;
}
Пример #10
0
static int needs_expansion(const struct token *list)
{
    const struct macro *def;

    while (list->token != END) {
        def = definition(*list);
        if (def && !is_macro_expanded(def))
            return 1;
        list++;
    }

    return 0;
}
Пример #11
0
QStringList CheckConstraint::create() const {
	QStringList ret;
	QStringList checks;
	QStringList cols = columnNames();
	for (QStringList::const_iterator i = cols.begin(); i != cols.end(); i++) {
		checks.append(QString("%1 %2").arg((*i), definition()));
	}
	ret.append(QString("ALTER TABLE %1 ADD CONSTRAINT %2 CHECK (%3);")
			.arg(table()->qualifiedName())
			.arg(name())
			.arg(checks.join(" AND ")));
	return ret;
}
Пример #12
0
precedence * mk_precedence(ast_manager & m, order_params const & params) {
    if (params.m_order_precedence_gen.empty())
        return mk_default_precedence(m, params);

    symbol user("user");
    symbol definition("definition");
    symbol interpreted("interpreted");
    symbol frequency("frequency");
    symbol arity("arity");
    symbol arbitrary("arbitrary");
    symbol inv("-");

    ptr_buffer<precedence> ps;

    svector<symbol>::const_iterator it  =  params.m_order_precedence_gen.begin();
    svector<symbol>::const_iterator end =  params.m_order_precedence_gen.end();
    bool prev_inv = false;
    for (; it != end; ++it) {
        symbol curr = *it;
        if (curr == user) {
            if (params.m_order_precedence.empty())
                ps.push_back(mk_inv_precedence(prev_inv, alloc(user_precedence, m, params.m_order_precedence.size(), params.m_order_precedence.c_ptr())));
        }
        else if (curr == definition) {
            warning_msg("definition precedence was not implement yet.");
        }
        else if (curr == interpreted) {
            ps.push_back(mk_inv_precedence(prev_inv, alloc(interpreted_precedence)));
        }
        else if (curr == frequency) {
            warning_msg("frequency precedence was not implement yet.");
        }
        else if (curr == arity) {
            ps.push_back(mk_inv_precedence(prev_inv, alloc(arity_precedence)));
        }
        else if (curr == arbitrary) {
            ps.push_back(mk_inv_precedence(prev_inv, alloc(arbitrary_precedence)));
            // it is pointless to continue, arbitrary_precedence is a total order
            return mk_lex_precedence(ps);
        }
        else if (curr == inv) {
            prev_inv = true;
        }
        else {
            warning_msg("invalid precedence generator: ignoring atom '%s'.", curr.bare_str());
        }
    }
    
    return mk_lex_precedence(ps);
}
void generate_literal_chain_comparison(ast::tree& ast, ast::node* root, ast::node* atom, formatter& output)
{
    ast::node* arg_0 = atom->first_child;
    plnnrc_assert(arg_0 && ast::is_term_variable(arg_0));
    ast::node* arg_1 = arg_0->next_sibling;
    plnnrc_assert(arg_1 && ast::is_term_variable(arg_1) && !arg_1->next_sibling);

    plnnrc_assert(definition(arg_0) && definition(arg_1));

    const char* comparison_op = atom->s_expr->token;

    int var_index_0 = ast::annotation<ast::term_ann>(arg_0)->var_index;
    int var_index_1 = ast::annotation<ast::term_ann>(arg_1)->var_index;

    if (ast::is_op_not(root))
    {
        output.writeln("if (!(state._%d %s state._%d))", var_index_0, comparison_op, var_index_1);
    }
    else
    {
        output.writeln("if (state._%d %s state._%d)", var_index_0, comparison_op, var_index_1);
    }

    {
        scope s(output, root->next_sibling != 0);

        if (root->next_sibling)
        {
            generate_literal_chain(ast, root->next_sibling, output);
        }
        else
        {
            output.writeln("PLNNR_COROUTINE_YIELD(state);");
        }
    }
}
Пример #14
0
void SpawnSystem::AddSpawn(Lua::LuaRef function, const glm::vec4& area, float minDelay, float maxDelay)
{
    // Validate function.
    if(!function.isFunction())
        return;

    // Create a spawn definition.
    SpawnDefinition definition(function, area, minDelay, maxDelay);

    // Roll the initial delay.
    definition.currentDelay = std::uniform_real<float>(minDelay, maxDelay)(spawnRandom);

    // Add a definition to the list.
    m_spawnList.push_back(definition);
}
QString JsScriptingComponent::getStartedScriptFromAgrs() const
{
    // TODO: Handle optional argument ... may be it should be one more extension
    QStringList args = definition()->arguments();
    auto it = std::find(args.cbegin(), args.cend(), "--start-script");
    if (it == args.cend())
        return QString();

    ++it;
    if (it == args.cend()) {
        Log.e("Wrong parameters. Usage [--start-script <scriptFilePath>]");
        return QString();
    }

    return *it;
}
Пример #16
0
int
main(int argc, char **argv)
{
	char buf[20];

	signal(SIGFPE, fpecatch);
	cmdname = argv[0];
	while (argc > 1 && *argv[1] == '-') {
		switch (argv[1][1]) {
		case 'd':
			dbg = atoi(&argv[1][2]);
			if (dbg == 0)
				dbg = 1;
			fprintf(stderr, "%s\n", version);
			break;
		}
		argc--;
		argv++;
	}
	setdefaults();
	objlist = (obj **) grow((char *)objlist, "objlist", nobjlist += 1000, sizeof(obj *));
	text = (Text *) grow((char *)text, "text", ntextlist += 1000, sizeof(Text));
	attr = (Attr *) grow((char *)attr, "attr", nattrlist += 100, sizeof(Attr));

	sprintf(buf, "/%d/", getpid());
	pushsrc(String, buf);
	definition("pid");

	curfile = infile;
	pushsrc(File, curfile->fname);
	if (argc <= 1) {
		curfile->fin = stdin;
		curfile->fname = tostring("-");
		getdata();
	} else
		while (argc-- > 1) {
			if ((curfile->fin = fopen(*++argv, "r")) == NULL) {
				fprintf(stderr, "%s: can't open %s\n", cmdname, *argv);
				exit(1);
			}
			curfile->fname = tostring(*argv);
			getdata();
			fclose(curfile->fin);
			free(curfile->fname);
		}
	return anyerr;
}
Пример #17
0
ToolBarsManager::ToolBarDefinition ToolBarsManager::getToolBarDefinition(int identifier)
{
	if (m_definitions.isEmpty())
	{
		getToolBarDefinitions();
	}

	if (identifier >= 0 && identifier < m_definitions.count())
	{
		ToolBarDefinition definition(m_definitions[identifier]);
		definition.identifier = identifier;

		return definition;
	}

	return ToolBarDefinition();
}
Пример #18
0
void ToolBarsManager::resetToolBar(int identifier)
{
	QAction *action(qobject_cast<QAction*>(sender()));

	if (action && identifier < 0)
	{
		identifier = action->data().toInt();
	}

	if (identifier >= 0 && identifier < OtherToolBar && QMessageBox::question(NULL, tr("Reset Toolbar"), tr("Do you really want to reset this toolbar to default configuration?"), (QMessageBox::Yes | QMessageBox::Cancel)) == QMessageBox::Yes)
	{
		const QHash<QString, ToolBarDefinition> defaultDefinitions(loadToolBars(SessionsManager::getReadableDataPath(QLatin1String("toolBars.json"), true), true));
		ToolBarDefinition definition(defaultDefinitions.value(getToolBarName(identifier)));
		definition.identifier = identifier;

		setToolBar(definition);
	}
}
Пример #19
0
void EdWidget::Save(	const char* xmlFilename,
						KrConsole* console,
						const std::string& surfaceName,
						int nTrans,
						const KrRGBA* trans )
{
	TiXmlDocument doc;
	doc.SetValue( xmlFilename );

	TiXmlElement definition( "Definition" );
	definition.SetAttribute( "filename", surfaceName.c_str() );

	for( int i=0; i<nTrans; i++ )
	{
		char key[256];
		char value[256];
		sprintf( key, "Transparent%d", i );
		sprintf( value, "#%02x%02x%02x", trans[i].c.red, trans[i].c.green, trans[i].c.blue );

		definition.SetAttribute( key, value );
	}

	GlSListIterator< EdWidget* > it( children );
	for( it.Begin(); !it.Done(); it.Next() )
		it.Current()->BuildXML( &definition );

	doc.InsertEndChild( definition );
	doc.SaveFile();
	if ( doc.Error() )
	{
		console->Print( "Error saving XML. '%s'\n", doc.ErrorDesc() );
	}
	else
	{
		console->Print( "XML file '%s' saved.\n", xmlFilename );
	}
}
Пример #20
0
 boost::optional<ModelObject> SpaceLoadInstance_Impl::definitionAsModelObject() const {
   OptionalModelObject result = definition();
   return result;
 }
void generate_literal_chain(ast::tree& ast, ast::node* root, formatter& output)
{
    plnnrc_assert(ast::is_op_not(root) || ast::is_term_call(root) || is_atom(root) || is_comparison_op(root));

    ast::node* atom = root;

    if (ast::is_op_not(root))
    {
        atom = root->first_child;
    }

    if (ast::is_comparison_op(atom))
    {
        generate_literal_chain_comparison(ast, root, atom, output);
        return;
    }

    if (ast::is_term_call(atom))
    {
        generate_literal_chain_call_term(ast, root, atom, output);
        return;
    }

    const char* atom_id = atom->s_expr->token;
    int atom_index = ast::annotation<ast::atom_ann>(atom)->index;

    if (ast::is_op_not(root) && all_unbound(atom))
    {
        output.writeln("if (!tuple_list::head<%i_tuple>(world.atoms[atom_%i]))", atom_id, atom_id);
        {
            scope s(output);

            if (root->next_sibling)
            {
                generate_literal_chain(ast, root->next_sibling, output);
            }
            else
            {
                output.writeln("PLNNR_COROUTINE_YIELD(state);");
            }
        }
    }
    else if (ast::is_op_not(root) && all_bound(atom))
    {
        output.writeln("for (state.%i_%d = tuple_list::head<%i_tuple>(world.atoms[atom_%i]); state.%i_%d != 0; state.%i_%d = state.%i_%d->next)",
            atom_id, atom_index,
            atom_id,
            atom_id,
            atom_id, atom_index,
            atom_id, atom_index,
            atom_id, atom_index);
        {
            scope s(output);

            int atom_param_index = 0;

            for (ast::node* term = atom->first_child; term != 0; term = term->next_sibling)
            {
                if (ast::is_term_variable(term))
                {
                    int var_index = ast::annotation<ast::term_ann>(term)->var_index;

                    output.writeln("if (state.%i_%d->_%d == state._%d)", atom_id, atom_index, atom_param_index, var_index);
                    {
                        scope s(output, !is_last(term));
                        output.writeln("break;");
                    }
                }

                if (ast::is_term_call(term))
                {
                    paste_precondition_function_call paste(term, "state._");

                    output.writeln("if (state.%i_%d->_%d == world.%p)", atom_id, atom_index, atom_param_index, &paste);
                    {
                        scope s(output, !is_last(term));
                        output.writeln("break;");
                    }
                }

                ++atom_param_index;
            }
        }

        output.writeln("if (state.%i_%d == 0)", atom_id, atom_index);
        {
            scope s(output, is_first(root));

            if (root->next_sibling)
            {
                generate_literal_chain(ast, root->next_sibling, output);
            }
            else
            {
                output.writeln("PLNNR_COROUTINE_YIELD(state);");
            }
        }
    }
    else
    {
        output.writeln("for (state.%i_%d = tuple_list::head<%i_tuple>(world.atoms[atom_%i]); state.%i_%d != 0; state.%i_%d = state.%i_%d->next)",
            atom_id, atom_index,
            atom_id,
            atom_id,
            atom_id, atom_index,
            atom_id, atom_index,
            atom_id, atom_index);
        {
            scope s(output, is_first(root));

            const char* comparison_op = "!=";

            if (ast::is_op_not(root))
            {
                comparison_op = "==";
            }

            int atom_param_index = 0;

            for (ast::node* term = atom->first_child; term != 0; term = term->next_sibling)
            {
                if (ast::is_term_variable(term) && definition(term))
                {
                    int var_index = ast::annotation<ast::term_ann>(term)->var_index;

                    output.writeln("if (state.%i_%d->_%d %s state._%d)", atom_id, atom_index, atom_param_index, comparison_op, var_index);
                    {
                        scope s(output);
                        output.writeln("continue;");
                    }
                }

                if (ast::is_term_call(term))
                {
                    paste_precondition_function_call paste(term, "state._");

                    output.writeln("if (state.%i_%d->_%d %s world.%p)", atom_id, atom_index, atom_param_index, comparison_op, &paste);
                    {
                        scope s(output);
                        output.writeln("continue;");
                    }
                }

                ++atom_param_index;
            }

            atom_param_index = 0;

            for (ast::node* term = atom->first_child; term != 0; term = term->next_sibling)
            {
                if (ast::is_term_variable(term) && !definition(term))
                {
                    int var_index = ast::annotation<ast::term_ann>(term)->var_index;
                    output.writeln("state._%d = state.%i_%d->_%d;", var_index, atom_id, atom_index, atom_param_index);
                    output.newline();
                }

                ++atom_param_index;
            }

            if (root->next_sibling)
            {
                generate_literal_chain(ast, root->next_sibling, output);
            }
            else
            {
                output.writeln("PLNNR_COROUTINE_YIELD(state);");
            }
        }
    }
}
Пример #22
0
 void operator()(const T& definition) const {
   definition(function_template_);
 }
Пример #23
0
 OtherEquipmentDefinition OtherEquipment_Impl::otherEquipmentDefinition() const {
   return definition().cast<OtherEquipmentDefinition>();
 }
boost::optional<model::ModelObject> ReverseTranslator::translateExteriorLights(
    const WorkspaceObject& workspaceObject)
{
  if (workspaceObject.iddObject().type() != IddObjectType::Exterior_Lights) {
    LOG(Error,"WorkspaceObject " << workspaceObject.briefDescription()
        << " is not of IddObjectType::Exterior_Lights.");
    return boost::none;
  }

  model::ExteriorLightsDefinition definition(m_model);

  OptionalString s;
  OptionalDouble d;

  if ((s = workspaceObject.name())) {
    definition.setName(*s + " Definition");
  }

  if ((d = workspaceObject.getDouble(Exterior_LightsFields::DesignLevel))){
    definition.setDesignLevel(*d);
  }

  model::OptionalExteriorLights exteriorLights;
  model::OptionalSchedule schedule;

  if (OptionalWorkspaceObject target = workspaceObject.getTarget(Exterior_LightsFields::ScheduleName))
  {
    if (model::OptionalModelObject modelObject = translateAndMapWorkspaceObject(*target)) {
      schedule = modelObject->optionalCast<model::Schedule>();
    }
  }

  if (schedule) {
    try {
      exteriorLights = model::ExteriorLights(definition,*schedule);
    }
    catch (std::exception& e) {
      LOG(Warn,"Could not reverse translate " << workspaceObject.briefDescription()
          << " in full, because " << e.what() << ".");
    }
  }
  if (!exteriorLights) {
    exteriorLights = model::ExteriorLights(definition);
  }

  OS_ASSERT(exteriorLights);

  if ((s = workspaceObject.name())) {
    exteriorLights->setName(*s);
  }

  if ((s = workspaceObject.getString(Exterior_LightsFields::ControlOption,false,true))) {
    exteriorLights->setControlOption(*s);
  }

  if ((s = workspaceObject.getString(Exterior_LightsFields::EndUseSubcategory,false,true))) {
    exteriorLights->setEndUseSubcategory(*s);
  }

  return *exteriorLights;
}
SteamEquipmentDefinition SteamEquipment_Impl::steamEquipmentDefinition() const {
    return definition().cast<SteamEquipmentDefinition>();
}
Пример #26
0
 WaterUseEquipmentDefinition WaterUseEquipment_Impl::waterUseEquipmentDefinition() const
 {
   return definition().cast<WaterUseEquipmentDefinition>();
 }
boost::optional<model::ModelObject> ReverseTranslator::translateExteriorFuelEquipment(
    const WorkspaceObject& workspaceObject)
{
  if (workspaceObject.iddObject().type() != IddObjectType::Exterior_FuelEquipment) {
    LOG(Error,"WorkspaceObject " << workspaceObject.briefDescription()
        << " is not of IddObjectType::Exterior_FuelEquipment.");
    return boost::none;
  }

  // Create an EquipmentDefinition to hold the Design Level
  model::ExteriorFuelEquipmentDefinition definition(m_model);

  OptionalString s;
  OptionalDouble d;

  if ((s = workspaceObject.name())) {
    definition.setName(*s + " Definition");
  }

  if ((d = workspaceObject.getDouble(Exterior_FuelEquipmentFields::DesignLevel))){
    definition.setDesignLevel(*d);
  }

  model::OptionalExteriorFuelEquipment exteriorFuelEquipment;
  model::OptionalSchedule schedule;

  if (OptionalWorkspaceObject target = workspaceObject.getTarget(Exterior_FuelEquipmentFields::ScheduleName))
  {
    if (model::OptionalModelObject modelObject = translateAndMapWorkspaceObject(*target)) {
      schedule = modelObject->optionalCast<model::Schedule>();
    }
  }

  if (schedule) {
    try {
      exteriorFuelEquipment = model::ExteriorFuelEquipment(definition,*schedule);
    }
    catch (std::exception& e) {
      LOG(Warn,"Could not reverse translate " << workspaceObject.briefDescription()
          << " in full, because " << e.what() << ".");
    }
  }
  if (!exteriorFuelEquipment) {
    exteriorFuelEquipment = model::ExteriorFuelEquipment(definition);
  }

  OS_ASSERT(exteriorFuelEquipment);

  if ((s = workspaceObject.name())) {
    exteriorFuelEquipment->setName(*s);
  }

  if ((s = workspaceObject.getString(Exterior_FuelEquipmentFields::FuelUseType,false,true))) {
    exteriorFuelEquipment->setFuelType(*s);
  } else {
    LOG(Warn, "The Fuel Use Type (required) isn't set for " << workspaceObject.briefDescription() <<
              " while it is a required field with no default... Will default to Electricity")
    exteriorFuelEquipment->setFuelType("Electricity");
  }

  if ((s = workspaceObject.getString(Exterior_FuelEquipmentFields::EndUseSubcategory,false,true))) {
    exteriorFuelEquipment->setEndUseSubcategory(*s);
  }

  return *exteriorFuelEquipment;
}
OptionalModelObject ReverseTranslator::translateGasEquipment( const WorkspaceObject & workspaceObject )
{
  if( workspaceObject.iddObject().type() != IddObjectType::GasEquipment ){
    LOG(Error, "WorkspaceObject is not IddObjectType: GasEquipment");
    return boost::none;
  }

  // create the definition
  openstudio::model::GasEquipmentDefinition definition(m_model);
  
  OptionalString s = workspaceObject.name();
  if(s){
    definition.setName(*s + " Definition");
  }

  s = workspaceObject.getString(openstudio::GasEquipmentFields::DesignLevelCalculationMethod, true);
  OS_ASSERT(s);
 
  OptionalDouble d;
  if (istringEqual("EquipmentLevel", *s)){
    d = workspaceObject.getDouble(openstudio::GasEquipmentFields::DesignLevel);
    if (d){
      definition.setDesignLevel(*d);
    }else{
      LOG(Error, "EquipmentLevel value not found for workspace object " << workspaceObject);
    }
  }else if(istringEqual("Watts/Area", *s)){
    d = workspaceObject.getDouble(openstudio::GasEquipmentFields::PowerperZoneFloorArea);
    if (d){
      definition.setWattsperSpaceFloorArea(*d);
    }else{
      LOG(Error, "Watts/Area value not found for workspace object " << workspaceObject);
    }
  }else if(istringEqual("Watts/Person", *s)){
    d = workspaceObject.getDouble(openstudio::GasEquipmentFields::PowerperPerson);
    if (d){
      definition.setWattsperPerson(*d);
    }else{
      LOG(Error, "Watts/Person value not found for workspace object " << workspaceObject);
    }
  }else{
    LOG(Error, "Unknown DesignLevelCalculationMethod value for workspace object" << workspaceObject);
  }

  d = workspaceObject.getDouble(openstudio::GasEquipmentFields::FractionLatent);
  if (d){
    definition.setFractionLatent(*d);
  }

  d = workspaceObject.getDouble(openstudio::GasEquipmentFields::FractionRadiant);
  if (d){
    definition.setFractionRadiant(*d);
  }

  d = workspaceObject.getDouble(openstudio::GasEquipmentFields::FractionLost);
  if (d){
    definition.setFractionLost(*d);
  }

  d = workspaceObject.getDouble(openstudio::GasEquipmentFields::CarbonDioxideGenerationRate);
  if (d){
    definition.setCarbonDioxideGenerationRate(*d);
  }

  // create the instance
  GasEquipment gasEquipment(definition);

  s = workspaceObject.name();
  if(s){
    gasEquipment.setName(*s);
  }

  OptionalWorkspaceObject target = workspaceObject.getTarget(openstudio::GasEquipmentFields::ZoneorZoneListName);
  if (target){
    OptionalModelObject modelObject = translateAndMapWorkspaceObject(*target);
    if (modelObject){
      if (modelObject->optionalCast<Space>()){
        gasEquipment.setSpace(modelObject->cast<Space>());
      }else if (modelObject->optionalCast<SpaceType>()){
        gasEquipment.setSpaceType(modelObject->cast<SpaceType>());
      }
    }
  }

  target = workspaceObject.getTarget(openstudio::GasEquipmentFields::ScheduleName);
  if (target){
    OptionalModelObject modelObject = translateAndMapWorkspaceObject(*target);
    if (modelObject){
      if (OptionalSchedule intermediate = modelObject->optionalCast<Schedule>()){
        Schedule schedule(*intermediate);
        gasEquipment.setSchedule(schedule);
      }
    }
  }

  s = workspaceObject.getString(openstudio::GasEquipmentFields::EndUseSubcategory);
  if(s){
    gasEquipment.setEndUseSubcategory(*s);
  }
       
  return gasEquipment;
}
Пример #29
0
 EntityDefinition* EntityDefinitionManager::definition(const Model::AttributableNode* attributable) const {
     ensure(attributable != nullptr, "attributable is null");
     return definition(attributable->attribute(Model::AttributeNames::Classname));
 }
    void testSymbolVersionDefinitions()
    {
        ElfFileSet set;
        set.addFile(QStringLiteral(LIBDIR "libversioned-symbols.so"));
        QVERIFY(set.size() > 1);

        auto f = set.file(0);
        QVERIFY(f);

        const auto symDefIndex = f->indexOfSection(".gnu.version_d");
        const auto symbolVersionDefs = f->section<ElfGNUSymbolVersionDefinitionsSection>(symDefIndex);
        QVERIFY(symbolVersionDefs);
        QCOMPARE(symbolVersionDefs->entryCount(), 3u);

        ElfGNUSymbolVersionDefinition *defV1 = nullptr, *defV2 = nullptr;
        auto def = symbolVersionDefs->definition(1);
        QVERIFY(def);
        QCOMPARE(def->versionIndex(), (uint16_t)2);
        QCOMPARE(symbolVersionDefs->definitionForVersionIndex(2), def);
        if (def->auxiliarySize() == 1)
            defV1 = def;
        else
            defV2 = def;

        def = symbolVersionDefs->definition(2);
        QVERIFY(def);
        QCOMPARE(def->versionIndex(), (uint16_t)3);
        QCOMPARE(symbolVersionDefs->definitionForVersionIndex(3), def);
        if (def->auxiliarySize() == 1)
            defV1 = def;
        else
            defV2 = def;

        QVERIFY(defV1);
        QVERIFY(defV2);

        QCOMPARE(defV2->auxiliarySize(), (uint16_t)2);
        auto defEntry = defV2->auxiliaryEntry(0);
        QVERIFY(defEntry);
        QCOMPARE(defEntry->name(), "VER2");
        defEntry = defV2->auxiliaryEntry(1);
        QVERIFY(defEntry);
        QCOMPARE(defEntry->name(), "VER1");

        QCOMPARE(defV1->auxiliarySize(), (uint16_t)1);
        defEntry = defV1->auxiliaryEntry(0);
        QVERIFY(defEntry);
        QCOMPARE(defEntry->name(), "VER1");

        const auto symVerIndex = f->indexOfSection(".gnu.version");
        const auto symbolVersionTable = f->section<ElfGNUSymbolVersionTable>(symVerIndex);
        QVERIFY(symbolVersionTable);

        const auto dynTabIndex = f->indexOfSection(".dynsym");
        QVERIFY(dynTabIndex > 0);
        const auto symTab = f->section<ElfSymbolTableSection>(dynTabIndex);
        QVERIFY(symTab);
        QCOMPARE(symTab->header()->entryCount(), symbolVersionTable->header()->entryCount());

        ElfSymbolTableEntry *f1 = nullptr, *f2 = nullptr, *f_ver1 = nullptr, *f_ver2 = nullptr;
        for (uint i = 0; i < symTab->header()->entryCount(); ++i) {
            auto sym = symTab->entry(i);
            QVERIFY(sym);
            if (strcmp(sym->name(), "function1") == 0)
                f1 = sym;
            else if (strcmp(sym->name(), "function2") == 0)
                f2 = sym;
            else if (strcmp(sym->name(), "function") == 0) {
                qDebug() << symbolVersionTable->versionIndex(i);
                if (symbolVersionTable->versionIndex(i) == defV2->versionIndex())
                    f_ver2 = sym;
                else if (symbolVersionTable->versionIndex(i) == defV1->versionIndex())
                    f_ver1 = sym;
            }
        }

        QVERIFY(f1);
        QVERIFY(f2);
        QVERIFY(f_ver1);
        QVERIFY(f_ver2);
        QCOMPARE(f1->value(), f_ver1->value());
        QCOMPARE(f2->value(), f_ver2->value());
    }