void JsonStringifier::stringifyObject(std::stringstream & ss, Object & object, Class & clazz, bool allowMissingAttributes) {
			std::vector<std::string> & attribNames = clazz.getAttributeNames();

			ss << "{\n";
			mIndentation++;
			mIndentation++;

			for (std::vector<std::string>::iterator attribName = attribNames.begin(); attribName != attribNames.end(); ++attribName) {
				if (!allowMissingAttributes && !object.hasValue(*attribName))
					throw std::runtime_error("object is missing value, name=" + *attribName);

				if (object.hasValue(*attribName)) {
					std::shared_ptr<Object> attribValue = object.get(*attribName);
					Type & attribType = clazz.getAttributeType(*attribName);

					mIndentation--;
					indent(ss);

					ss << "\"" << *attribName << "\"" << " :\n";

					mIndentation++;
					indent(ss);

					if (attribType.isBuiltIn()) {
						if (attribType.isSimpleArray())
							stringifyArray(ss, *attribValue, attribType);
						else if (attribType.isObjectArray())
							stringifyObjectArray(ss, *attribValue, attribType, allowMissingAttributes);
						else
							stringifyPrimitive(ss, *attribValue, attribType);
					}
					else {
						Class * attribClass = dynamic_cast<Class *>(&attribType);

						if (attribClass)
							stringifyObject(ss, *attribValue, *attribClass, allowMissingAttributes);
						else
							throw std::runtime_error("attempt to convert a non-class to a class, type=" + attribType.name);
					}

					if (attribName + 1 != attribNames.end())
						ss << ",\n";
				}
			}

			ss << "\n";

			mIndentation--;
			mIndentation--;
			indent(ss);
			ss << "}";
		}
示例#2
0
void PRMDisplay::RBNToGraph(const double attributeWeight, const double FKWeight) {
	Class aClass;
	VertexDescriptor vd;
	std::map<std::string, VertexDescriptor> container;
	positionMap = boost::get(&VertexProperties::point, graph);
	vertexIdPropertyMap = boost::get(&VertexProperties::index, graph);
	WeightPropertyMap weightPropertyMap = boost::get(&EdgeProperty::weight, graph);
	RelationalSchema schema = rbn->getSchema();
	std::vector<std::string> classnames = schema.getClassNames();
	for(std::vector<std::string>::iterator it = classnames.begin(); it != classnames.end(); ++it)
	{
		std::string classname = *it;

		aClass = schema.getClass(classname);
		std::vector<std::string> attributesName = aClass.getAttributeNames();
		//std::vector<std::string>::iterator it2 = attributesName.begin();

		//pour chaque attribut, ajout d'un nouveau sommet aux coordonnée (1,1)
		for(std::vector<std::string>::iterator it1 = attributesName.begin(); it1!=attributesName.end(); it1++)
		{
			std::stringstream ss;
			ss << classname << "." << *it1;

			vd = boost::add_vertex(graph);

			vertexIdPropertyMap[vd] = ss.str();
			container[ss.str()] = vd;
			positionMap[vd][0]=1;
			positionMap[vd][1]=1;
			// si l'itérateur est différent de begin, alors on itere pour ajouter une arête jusqu'à l'itérateur it1 actuel
			if(attributesName.begin() != it1)
			{
				//Ajout d'arête entre le nouveau sommet et ceux du graphe qui appartiennent à la même classe. Le poid est de 2
				for(std::vector<std::string>::iterator it3 = attributesName.begin(); it3 != it1; it3++)
				{
					std::stringstream ss2;
					ss2 << classname << "." << *it3;
					boost::add_edge(container[ss.str()], container[ss2.str()], EdgeProperty(attributeWeight), graph);
				}
			}
		} 
	}
	
	/***** ajout d'arête pour chaque clé étrangère ****/
	RefSlotsMultimap foreignKeys = schema.getRefSlots();
	std::string attPK;
	std::string classPK;
	std::string classFK;
	for(RefSlotsMultimap::iterator rb = foreignKeys.begin(); rb != foreignKeys.end(); ++rb){
		classPK=rb->second.second->getName().c_str();
		attPK= rbn->getSchema().getClass(classPK).getPK().front();
		classPK.append(".");
		classPK.append(attPK);
		//std::cout << "\t primaryKey "<<classPK;
		classFK=rb->first.c_str();;
		classFK.append(".");
		classFK.append(rb->second.first.getName());
		//std::cout << "\t foriegnKey "<<classFK;
		boost::add_edge(container[classFK], container[classPK], EdgeProperty(FKWeight), graph);
	}
}