Beispiel #1
0
void KinectCalibration::updateTableRow(int row, int column, QVariant value) {
    switch(column) {
        case 0:
            storeNode (row, "node.selected", value);
            break;
        case 1:
            storeNode (row, "node.friendlyName", value);
            break;
        case 2:
            storeNode (row, "node.nodePath", value);
            break;
    }
}
Beispiel #2
0
        void MapReader::createEntity(const size_t line, const Model::EntityAttribute::List& attributes, const ExtraAttributes& extraAttributes) {
            Model::Entity* entity = m_factory->createEntity();
            entity->setAttributes(attributes);
            setExtraAttributes(entity, extraAttributes);

            const ParentInfo::Type parentType = storeNode(entity, attributes);
            stripParentAttributes(entity, parentType);
            
            m_currentNode = entity;
            m_brushParent = entity;
        }
Beispiel #3
0
 void MapReader::createGroup(const size_t line, const Model::EntityAttribute::List& attributes, const ExtraAttributes& extraAttributes) {
     const String& name = findAttribute(attributes, Model::AttributeNames::GroupName);
     if (StringUtils::isBlank(name)) {
         if (logger() != NULL)
             logger()->warn("Skipping group entity at line %u: missing name", static_cast<unsigned int>(line));
         return;
     }
     
     const String& idStr = findAttribute(attributes, Model::AttributeNames::GroupId);
     if (StringUtils::isBlank(idStr)) {
         if (logger() != NULL)
             logger()->warn("Skipping group entity at line %u: missing id", static_cast<unsigned int>(line));
         return;
     }
     
     const long rawId = std::atol(idStr.c_str());
     if (rawId <= 0) {
         if (logger() != NULL)
             logger()->warn("Skipping group entity at line %u: invalid id", static_cast<unsigned int>(line), name.c_str());
         return;
     }
     
     const Model::IdType groupId = static_cast<Model::IdType>(rawId);
     if (m_groups.count(groupId) > 0) {
         if (logger() != NULL)
             logger()->warn("Skipping group entity at line %u: a group with id '%s' already exists", static_cast<unsigned int>(line), idStr.c_str());
         return;
     }
     
     Model::Group* group = m_factory->createGroup(name);
     setExtraAttributes(group, extraAttributes);
     
     storeNode(group, attributes);
     m_groups.insert(std::make_pair(groupId, group));
     
     m_currentNode = group;
     m_brushParent = group;
 }
Beispiel #4
0
ManagedVector<Node> ResourceManager::parse(
    ParserContext &ctx, const std::string &path, const std::string &mimetype,
    const std::string &rel, const RttiSet &supportedTypes, ParseMode mode)
{
	// Some references used for convenience
	Registry &registry = ctx.getRegistry();
	Logger &logger = ctx.getLogger();
	ParserScope &scope = ctx.getScope();
	Resource relativeTo = getResource(ctx.getSourceId());

	// Locate the resource relative to the old resource, abort if this did not
	// work
	ResourceRequest req{path, mimetype, rel, supportedTypes, relativeTo};
	Resource resource;
	if (!req.deduce(registry, logger) ||
	    !req.locate(registry, logger, resource)) {
		return ManagedVector<Node>{};
	}

	// initialize the output vector.
	ManagedVector<Node> parsedNodes;

	// Allocate a new SourceId handle for this Resource
	bool newResource = false;
	SourceId sourceId = getSourceId(resource);
	if (sourceId == InvalidSourceId) {
		newResource = true;
		sourceId = allocateSourceId(resource);
	}
	// check for cycles.
	GuardedSetInsertion<SourceId> cycleDetection{currentlyParsing, sourceId};
	if (!cycleDetection.isSuccess()) {
		throw LoggableException{std::string("Detected cyclic parse of ") +
		                        resource.getLocation()};
	}

	if (!newResource && mode == ParseMode::IMPORT) {
		// if a already imported resource should be imported we just use the
		// cached node.
		parsedNodes.push_back(getNode(ctx.getManager(), sourceId));
	} else {
		// We can now try to parse the given file

		// Set the current source id in the logger instance. Note that this
		// modifies the logger instance -- the GuardedLogger is just used to
		// make sure the default location is popped from the stack again.
		GuardedLogger guardedLogger(logger, SourceLocation{sourceId});

		try {
			// Fetch the input stream and create a char reader
			std::unique_ptr<std::istream> is = resource.stream();
			CharReader reader(*is, sourceId);

			// Actually parse the input stream, distinguish the IMPORT and the
			// INCLUDE mode
			switch (mode) {
				case ParseMode::IMPORT: {
					// Create a new, empty parser scope instance and a new
					// parser
					// context with this instance in place
					ParserScope innerScope;
					ParserContext childCtx = ctx.clone(innerScope, sourceId);

					// Run the parser
					req.getParser()->parse(reader, childCtx);

					// Make sure the scope has been unwound and perform all
					// deferred resolutions
					innerScope.checkUnwound(logger);
					innerScope.performDeferredResolution(logger);

					// Fetch the nodes that were parsed by this parser instance
					// and
					// validate them
					parsedNodes = innerScope.getTopLevelNodes();
					for (auto parsedNode : parsedNodes) {
						parsedNode->validate(logger);
					}

					// Make sure the number of elements is exactly one -- we can
					// only store one element per top-level node.
					if (parsedNodes.empty()) {
						throw LoggableException{"Module is empty."};
					}
					if (parsedNodes.size() > 1) {
						throw LoggableException{
						    std::string(
						        "Expected exactly one top-level node but "
						        "got ") +
						    std::to_string(parsedNodes.size())};
					}

					// Store the parsed node along with the sourceId
					storeNode(sourceId, parsedNodes[0]);

					break;
				}
				case ParseMode::INCLUDE: {
					// Fork the scope instance and create a new parser context
					// with this instance in place
					ParserScope forkedScope = scope.fork();
					ParserContext childCtx = ctx.clone(forkedScope, sourceId);

					// Run the parser
					req.getParser()->parse(reader, childCtx);

					// Join the forked scope with the outer scope
					scope.join(forkedScope, logger);

					// Fetch the nodes that were parsed by this parser instance
					parsedNodes = forkedScope.getTopLevelNodes();

					break;
				}
			}
		}
		catch (LoggableException ex) {
			// Log the exception and return nullptr
			logger.log(ex);
			return ManagedVector<Node>{};
		}
	}

	// Make sure the parsed nodes fulfill the "supportedTypes" constraint,
	// remove nodes that do not the result
	for (auto it = parsedNodes.begin(); it != parsedNodes.end();) {
		const Rtti *type = (*it)->type();
		if (!type->isOneOf(supportedTypes)) {
			logger.error(std::string("Node of internal type ") + type->name +
			                 std::string(" not supported here"),
			             **it);
			it = parsedNodes.erase(it);
		} else {
			it++;
		}
	}

	return parsedNodes;
}