当前位置: 首页>>代码示例>>C++>>正文


C++ Node::size方法代码示例

本文整理汇总了C++中yaml::Node::size方法的典型用法代码示例。如果您正苦于以下问题:C++ Node::size方法的具体用法?C++ Node::size怎么用?C++ Node::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在yaml::Node的用法示例。


在下文中一共展示了Node::size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: SimpleAlias

		bool SimpleAlias()
		{
			std::string input = "- &alias test\n- *alias";
			
			std::stringstream stream(input);
			YAML::Parser parser(stream);
			YAML::Node doc;
			parser.GetNextDocument(doc);
			
			std::string output;
			doc[0] >> output;
			if(output != "test")
				return false;
			
			doc[1] >> output;
			if(output != "test")
				return false;
			
			if(doc.size() != 2)
				return false;
			
			return true;
		}
开发者ID:LazerTrace,项目名称:LazerTrace,代码行数:23,代码来源:parsertests.cpp

示例2: matrix

// Test conversion to and from yaml node
TYPED_TEST(AllMatrixTests, YamlConvert)
{
	typedef typename TestFixture::Matrix Matrix;
	typedef typename TestFixture::Scalar T;

	// This array has more elements than we will need.
	// The element type must match the matrix!
	const T inputArray[18]  =
	{
		0.01f,  1.02f,  2.03f,  3.04f,  4.05f,  5.06f,  6.07f,  7.08f,  8.09f,
		9.10f, 10.11f, 11.12f, 12.13f, 13.14f, 14.15f, 15.16f, 16.17f, 17.18f
	};

	Matrix matrix(inputArray);

	YAML::Node node;

	ASSERT_NO_THROW(node = matrix);

	EXPECT_TRUE(node.IsSequence());
	EXPECT_EQ(matrix.rows(), node.size());

	ASSERT_NO_THROW({Matrix expected = node.as<Matrix>();});
开发者ID:ricortiz,项目名称:opensurgsim,代码行数:24,代码来源:MatrixTests.cpp

示例3: initializeDepth

bool DepthObstacleGrid::initializeDepth(const std::string &filename, double depth_variance){
    std::ifstream fin(filename.c_str());
    if(fin.fail()) {
        std::cerr << "Could not open input stream from file" << filename.c_str() << std::endl;
        return false;
    }
    
    YAML::Parser parser(fin);
    YAML::Node doc;
    Eigen::Vector3d vec;
    Eigen::Vector3d last_vec(NAN, NAN, NAN);

    std::cout << "Read yml" << std::endl;
    
    while(parser.GetNextDocument(doc)) {
      std::cout << "Doc size: " << doc.size() << std::endl;
      
        for(int i = 0; i < doc.size(); i++){
      
          //const YAML::Node& node = doc["values"];
          doc[i]["position"] >> vec;
          std::cout << "Vec: " << vec.transpose() << std::endl;
          
          if(vec.y() == last_vec.y() && vec.x() - last_vec.x() > resolution ){
            
            for(double x = last_vec.x() ; x < vec.x(); x += resolution){
              setDepth(x, vec.y(), last_vec.z(), depth_variance);
            }          
            
          }
          
          if(vec.y() != last_vec.y() && last_vec.x() < ( - position.x()) + span.x() ){
            
            for(double x = last_vec.x() + resolution; x <= (- position.x()) + span.x() ; x += resolution){
              setDepth( x, last_vec.y(), last_vec.z(), depth_variance);
            }
            
          }
          
          if(vec.y() != last_vec.y() && vec.x() > ( - position.x())){
            
            for(double x = -position.x() ; x < vec.x() ; x += resolution){
              setDepth( x, vec.y(), last_vec.z(), depth_variance);
            }
            
          }
          
          
          if(vec.y() - last_vec.y() > resolution){ 
          
            for( double y = last_vec.y() + resolution; y < vec.y(); y+= resolution){
            
              for( double x = - position.x(); x < (- position.x()) + span.x() ; x += resolution){
                
                setDepth(x, y, last_vec.z(), depth_variance);
                
              }
              
            }       
            
          
          }
          
          setDepth(vec.x(), vec.y(), vec.z(), depth_variance);
          
          
          
          last_vec = vec;
        
        }
     
    }

    return true;
    
}
开发者ID:auv-avalon,项目名称:uw_localization,代码行数:76,代码来源:depth_obstacle_grid.cpp

示例4: readFile

void MidiRouter::readFile(QString fileName) {
  clear();

  QFile file(fileName);
  if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
    emit(mappingError("cannot open file: " + fileName));
    return;
  }
  QTextStream in(&file);
  YAML::Node root = YAML::Load(in.readAll().toStdString());
  if (!root.IsMap()) {
    emit(mappingError("mapping is not a map in " + fileName));
    return;
  }

  for (auto kv: std::map<QString, int>({{"master", -1}, {"player0", 0}, {"player1", 1}})) {
    const QString key = kv.first;
    const int player = kv.second;

    if (!root[key])
      continue;
    YAML::Node parent = root[key];
    if (!parent.IsSequence())
      emit(mappingError(key + " is not a sequence in " + fileName));

    for (unsigned int i = 0; i < parent.size(); i++) {
      YAML::Node node = parent[i];
      MidiMapPtr mmap = QSharedPointer<MidiMap>::create();
      mmap->player_index = player;
      try {
        if (node["trigger"]) {
          mmap->signal_name = node["trigger"].as<QString>();
          mmap->mapping_type = TRIGGER;
          try {
            if (!find_midi(node, mmap, yamls_trigger_map))
              emit(mappingError(key + " could not find trigger mapping in element " + QString::number(i)));
          } catch (std::runtime_error& e) {
            emit(mappingError(key + QString::fromStdString(e.what()) + " in element " + QString::number(i)));
          }
        } else if (node["continuous"]) {
          mmap->signal_name = node["continuous"].as<QString>();
          mmap->mapping_type = CONTINUOUS;
          try {
            if (!find_midi(node, mmap, yamls_cc_map))
              emit(mappingError(key + " could not find cc mapping in element " + QString::number(i)));
          } catch (std::runtime_error& e) {
            emit(mappingError(key + QString::fromStdString(e.what()) + " in element " + QString::number(i)));
          }
        } else if (node["twos_complement"]) {
          mmap->signal_name = node["twos_complement"].as<QString>();
          mmap->mapping_type = TWOS_COMPLEMENT;
          try {
            if (!find_midi(node, mmap, yamls_cc_map))
              emit(mappingError(key + " could not find trigger mapping in element " + QString::number(i)));
          } catch (std::runtime_error& e) {
            emit(mappingError(key + QString::fromStdString(e.what()) + " in element " + QString::number(i)));
          }
        } else {
          emit(mappingError(key + " no supported mapping found in midi mapping element " + QString::number(i)));
          return;
        }

        if (node["mult"])
          mmap->multiplier = node["mult"].as<double>();
        if (node["offset"])
          mmap->offset = node["offset"].as<double>();

        //XXX search for conflicting maps and warn
        mMappings.push_back(mmap);
      } catch (YAML::Exception& e) {
        emit(mappingError(key + " exception processing midi mapping element " + QString::number(i) + " " + QString(e.what())));
        return;
      } catch(...) {
        emit(mappingError(key + " exception processing midi mapping element " + QString::number(i)));
        return;
      }
    }
  }
}
开发者ID:hypercycle,项目名称:datajockey,代码行数:79,代码来源:midirouter.cpp

示例5:

bool Article::ArticleData::ParseYaml(const ArticleData& defaultValues)
{
	YAML::Node config = YAML::Load(m_RawYaml);

	if (config.size() <= 0)
		return false;

	if (config["m_Ignore"] != NULL)
		m_Ignore = config["m_Ignore"].as<bool>();
	else
		m_Ignore = defaultValues.m_Ignore;

	if (config["m_Hidden"] != NULL)
		m_Hidden = config["m_Hidden"].as<bool>();
	else
		m_Hidden = defaultValues.m_Hidden;

	if (config["m_Order"] != NULL)
		m_Order = config["m_Order"].as<int>();
	else
		m_Order = defaultValues.m_Order;

	if (config["m_IsHomepage"] != NULL)
		m_IsHomepage = config["m_IsHomepage"].as<bool>();
	else
		m_IsHomepage = defaultValues.m_IsHomepage;

	if (config["m_Title"] != NULL)
		m_Title = config["m_Title"].as<std::string>();
	else
		m_Title = defaultValues.m_Title;

	if (config["m_Language"] != NULL)
		m_Language = config["m_Language"].as<std::string>();
	else
		m_Language = defaultValues.m_Language;

	if (config["m_Link"] != NULL)
		m_Link = config["m_Link"].as<std::string>();
	else
		m_Link = defaultValues.m_Link;

	m_ExternalLink = m_Link.find("http://") != std::string::npos;

	if (config["m_Date"] != NULL)
	{
		std::string dateString = config["m_Date"].as<std::string>();
		m_Date = boost::gregorian::from_string(dateString);
	}
	else
		m_Date = defaultValues.m_Date;

	YAML::Node tags = config["m_Tags"];
	if (tags != NULL)
	{

		for (unsigned i = 0; i < tags.size(); i++) {
			std::string tag = tags[i].as<std::string>();
			bool tagFound = false;
			for (auto it = m_Tags.begin(); it != m_Tags.end(); ++it)
			{
				if (*it == tag)
				{
					tagFound = true;
					break;
				}
			}

			if (!tagFound)
				m_Tags.push_back(tag);
		}
	}
	else
		m_Tags = defaultValues.m_Tags;

	if (m_Content.empty())
		m_Content = defaultValues.m_Content;

	return true;
}
开发者ID:beuiot,项目名称:mown,代码行数:80,代码来源:article.cpp

示例6: GenerateReportData

    void GenerateReportData(const Game& game,
        std::list<Message>& messages,
        const std::list<Plugin>& plugins,
        const std::string& masterlistVersion,
        const std::string& masterlistDate,
        const bool masterlistUpdateEnabled) {

        YAML::Node oldDetails;
        GetOldReportDetails(game.ReportDataPath(), oldDetails);
        
        //Need to output YAML as a JSON Javascript variable.
        YAML::Emitter yout;
        yout.SetOutputCharset(YAML::EscapeNonAscii);
        yout.SetStringFormat(YAML::DoubleQuoted);
        yout.SetBoolFormat(YAML::TrueFalseBool);
        yout.SetSeqFormat(YAML::Flow);
        yout.SetMapFormat(YAML::Flow);

        BOOST_LOG_TRIVIAL(debug) << "Generating JSON report data.";

        yout << YAML::BeginMap;

        yout << YAML::Key << "lootVersion"
            << YAML::Value << IntToString(g_version_major) + "." + IntToString(g_version_minor) + "." + IntToString(g_version_patch);

        yout << YAML::Key << "masterlist"
            << YAML::BeginMap
            << YAML::Key << "updaterEnabled"
            << YAML::Value;

        if (masterlistUpdateEnabled)
            yout << boost::locale::translate("Enabled").str();
        else
            yout << boost::locale::translate("Disabled").str();

        yout << YAML::Key << "revision"
            << YAML::Value << masterlistVersion
            << YAML::Key << "date"
            << YAML::Value << masterlistDate
            << YAML::EndMap;

        if (!plugins.empty()) {
            BOOST_LOG_TRIVIAL(debug) << "Generating JSON plugin data.";
            YAML::Emitter tempout;
            tempout.SetOutputCharset(YAML::EscapeNonAscii);
            tempout.SetStringFormat(YAML::DoubleQuoted);
            tempout.SetBoolFormat(YAML::TrueFalseBool);
            tempout.SetSeqFormat(YAML::Flow);
            tempout.SetMapFormat(YAML::Flow);

            tempout << YAML::BeginSeq;
            for (std::list<Plugin>::const_iterator it = plugins.begin(), endit = plugins.end(); it != endit; ++it) {
                WritePlugin(tempout, *it, game);
            }
            tempout << YAML::EndSeq;

            YAML::Node node = YAML::Load(tempout.c_str());

            if (AreDetailsEqual(node, oldDetails))
                messages.push_front(loot::Message(loot::Message::say, boost::locale::translate("There have been no changes in the Details tab since LOOT was last run for this game.").str()));
                
            //Need to generate output twice because passing the node causes !<!> to be written before every key and value for some reason.
            yout << YAML::Key << "plugins"
                << YAML::Value << YAML::BeginSeq;
            for (std::list<Plugin>::const_iterator it = plugins.begin(), endit = plugins.end(); it != endit; ++it) {
                WritePlugin(yout, *it, game);
            }
            yout << YAML::EndSeq;
        }
        else if (oldDetails.size() == 0)
            messages.push_front(loot::Message(loot::Message::say, boost::locale::translate("There have been no changes in the Details tab since LOOT was last run for this game.").str()));

        if (!messages.empty()) {
            BOOST_LOG_TRIVIAL(debug) << "Generating JSON general message data.";
            yout << YAML::Key << "globalMessages"
                << YAML::Value << YAML::BeginSeq;
            for (std::list<Message>::const_iterator it = messages.begin(), endit = messages.end(); it != endit; ++it) {
                WriteMessage(yout, *it);
            }
            yout << YAML::EndSeq;
        }

        BOOST_LOG_TRIVIAL(debug) << "Generating text translations.";
        yout << YAML::Key << "l10n"
            << YAML::BeginMap

            << YAML::Key << "txtSummarySec"
            << YAML::Value << boost::locale::translate("Summary").str()

            << YAML::Key << "txtSummary"
            << YAML::Value << boost::locale::translate("Summary").str()

            << YAML::Key << "txtLootVersion"
            << YAML::Value << boost::locale::translate("LOOT Version").str()

            << YAML::Key << "txtMasterlistRevision"
            << YAML::Value << boost::locale::translate("Masterlist Revision").str()

            << YAML::Key << "txtMasterlistDate"
            << YAML::Value << boost::locale::translate("Masterlist Date").str()
//.........这里部分代码省略.........
开发者ID:dbb,项目名称:loot,代码行数:101,代码来源:generators.cpp

示例7: printf

View::View(node_id_t node_id, std::string cf) 
  : node_id_(node_id), master_id_(0), period_(500) {

  LOG_INFO("loading config file %s ...", cf.c_str());
	
	YAML::Node config;

  if (cf.empty()) {
    // default only one node
	  config = YAML::LoadFile("config/localhost-1.yaml");
    node_id_ = 0;
  } else {
	  config = YAML::LoadFile(cf);
  }
  if (config == NULL) {
    printf("cannot open config file: %s.", cf.c_str());
  }

	YAML::Node nodes = config["host"];
  YAML::Node lease = config["lease"];

  for (std::size_t i = 0; i < nodes.size(); i++) {

		YAML::Node node = nodes[i];

		std::string name = node["name"].as<std::string>();
		std::string addr = node["addr"].as<std::string>();
    uint32_t port = node["port"].as<int>();
    // set a node in view
    host_info_t host_info = host_info_t(name, addr, port);
    host_nodes_.push_back(host_info);
  }
    
  size_ = host_nodes_.size();

  if (lease) {
    master_id_ = lease["master_id"].as<int>();
    period_ = lease["period"].as<int>();
  } else {
    LOG_INFO("No lease Node Found, using default master_id/0 period/500");
  }
  
  #if MODE_TYPE == 1
  YAML::Node rs = config["rs"];
  if (rs) {
    rs_x_ = rs["x"].as<int>();
    rs_n_ = rs["n"].as<int>();
    rs_qr_ = rs["qr"].as<int>();
    rs_qw_ = rs["qw"].as<int>();
    rs_f_ = rs["f"].as<int>();
  } else {
    LOG_INFO("No RS Node Found!!, using Default function to compute");
    rs_n_ = size_;
    if (rs_n_ == 1) {
      rs_x_ = 1;
    } else {
      if (rs_n_ % 2 == 0) {
        rs_x_ = 2;
      } else {
        rs_x_ = 3;
      } 
    }
    rs_qr_ = (rs_n_ + rs_x_) / 2;
    rs_qw_ = rs_qr_;
    rs_f_ = rs_n_ - rs_qr_;
  }  
  #endif


  if (node_id_ >= size_) {
    std::cout << "Node_Id " << node_id_ << " > host_nodes_.size " << size_ << "Invalid!" << std::endl;
    std::cout << "Set Node_Id = 0" << std::endl;
    node_id_ = 0;
  }
  LOG_INFO("config file loaded");
 
}
开发者ID:tempbottle,项目名称:PurePaxos,代码行数:77,代码来源:view.cpp

示例8: parseWatcher

void Config::parseWatcher(const YAML::Node& node)
{
	size_t asterisk_count;
	if(node.size() >= 1 && node.IsMap())
		for (YAML::const_iterator iter=node.begin();iter!=node.end();++iter) {
			std::string key = iter->first.as<std::string>();
			YAML::Node value = iter->second;
			Util::lowercase(key);
			if(key == "filter")
			{
				if(!value.IsSequence())
					std::cerr << "ERROR!\n";
				for(YAML::const_iterator filter_iter=value.begin();
						filter_iter!=value.end();
						++filter_iter)
				{
					asterisk_count = 0;
					std::string val = filter_iter->as<std::string>();
					for(size_t i = 0; i < val.length(); i++)
						if(val[i] == '*')
							asterisk_count++;
					LOG(logger, DEBUG, "Filter: %s", val.c_str());
					if(asterisk_count > 1)
						throw std::runtime_error("Could not open file");
					mWatch.filters.push_back(val);
				}
			}
			else if(key == "include")
			{
				if(!value.IsSequence() && !value.IsScalar())
					std::cerr << "ERROR!\n";
				if(value.IsSequence())
				{
					for(YAML::const_iterator filter_iter=value.begin();
							filter_iter!=value.end();
							++filter_iter)
					{
						LOG(logger, DEBUG, "Include: %s", filter_iter->as<std::string>().c_str());
						mWatch.include.push_back(filter_iter->as<std::string>());
					}
				}
				else if(value.IsScalar())
				{
					LOG(logger, DEBUG, "Include: %s", value.as<std::string>().c_str());
					mWatch.include.push_back(value.as<std::string>());
				}
			}
			else if(key == "exclude")
			{
				if(!value.IsSequence() && !value.IsScalar())
					std::cerr << "ERROR!\n";
				if(value.IsSequence())
				{
					for(YAML::const_iterator filter_iter=value.begin();
							filter_iter!=value.end();
							++filter_iter)
					{
						LOG(logger, DEBUG, "Exclude: %s", filter_iter->as<std::string>().c_str());
						mWatch.exclude.push_back(filter_iter->as<std::string>());
					}
				}
				else if(value.IsScalar())
				{
					LOG(logger, DEBUG, "Exclude: %s", value.as<std::string>().c_str());
					mWatch.exclude.push_back(value.as<std::string>());
				}
			}
			else
				LOG(logger, DEBUG, "Value: %s\n", value.as<std::string>().c_str());
		}
}
开发者ID:frostyfrog,项目名称:Renzoku,代码行数:71,代码来源:config.cpp

示例9: yaml_traverse

static void yaml_traverse(struct VMGlobals* g, const YAML::Node & node, PyrObject *parent, PyrSlot *slot) {
	YAML::NodeType::value type = node.Type();
	string out;
	PyrObject *result = NULL;

	switch (type)
	{
		case YAML::NodeType::Scalar:
			node >> out;
			result = (PyrObject*)newPyrString(g->gc, out.c_str(), 0, true);
			SetObject(slot, result);
			if(parent) g->gc->GCWriteNew(parent, result); // we know result is white so we can use GCWriteNew
			break;

		case YAML::NodeType::Sequence:
			result = newPyrArray(g->gc, node.size(), 0, true);
			SetObject(slot, result);
			if(parent) g->gc->GCWriteNew(parent, result); // we know result is white so we can use GCWriteNew
			for (unsigned int i = 0; i < node.size(); i++) {
				const YAML::Node & subnode = node[i];
				result->size++;
				yaml_traverse(g, subnode, result, result->slots+i);
			}
			break;

		case YAML::NodeType::Map:
		{
			result = instantiateObject( g->gc, s_dictionary->u.classobj, 0, false, true );
			SetObject(slot, result);
			if(parent) g->gc->GCWriteNew(parent, result); // we know result is white so we can use GCWriteNew

			PyrObject *array = newPyrArray(g->gc, node.size()*2, 0, true);
			result->size = 2;
			SetObject(result->slots, array);      // array
			SetInt(result->slots+1, node.size()); // size
			g->gc->GCWriteNew(result, array); // we know array is white so we can use GCWriteNew

			int j = 0;
			for (YAML::Iterator i = node.begin(); i != node.end(); ++i) {
				const YAML::Node & key   = i.first();
				const YAML::Node & value = i.second();
				key >> out;
				PyrObject *pkey = (PyrObject*)newPyrString(g->gc, out.c_str(), 0, true);
				SetObject(array->slots+j, pkey);
				array->size++;
				g->gc->GCWriteNew(array, pkey); // we know pkey is white so we can use GCWriteNew

				array->size++;
				yaml_traverse(g, value, array, array->slots+j+1);

				j += 2;
			}
			break;
		}

		case YAML::NodeType::Null:
			SetNil(slot);
			break;

		default:
			postfl("WARNING: yaml_traverse(): unknown/unsupported node type\n");
			SetNil(slot);
	}
}
开发者ID:kulicuu,项目名称:supercollider,代码行数:64,代码来源:PyrStringPrim.cpp

示例10:

// Safely gets the YAML value from the sequence of YAML values. If provided
// index is out-of-bounds we return a null value.
inline const YAML::Node safe_get_value(const YAML::Node& seq, std::size_t idx)
{
    static const auto null_value = YAML::Node{};
    return idx >= seq.size() ? null_value : seq[idx];
}
开发者ID:k0zmo,项目名称:kl,代码行数:7,代码来源:yaml.hpp

示例11: reflectable_from_yaml

Reflectable reflectable_from_yaml(const YAML::Node& value)
{
    Reflectable refl{};

    if (value.IsMap())
    {
        ctti::reflect(refl, [&value](auto fi) {
            using field_type = typename decltype(fi)::type;

            try
            {
                const auto& query = value[fi.name()];
                if (query)
                    fi.get() = yaml::deserialize<field_type>(query);
                else
                    fi.get() = yaml::deserialize<field_type>({});
            }
            catch (deserialize_error& ex)
            {
                std::string msg =
                    "error when deserializing field " + std::string(fi.name());
                ex.add(msg.c_str());
                throw;
            }
        });
    }
    else if (value.IsSequence())
    {
        if (value.size() > ctti::total_num_fields<Reflectable>())
        {
            throw deserialize_error{"sequence size is greater than "
                                    "declared struct's field "
                                    "count"};
        }
        ctti::reflect(refl, [&value, index = 0U](auto fi) mutable {
            using field_type = typename decltype(fi)::type;

            try
            {
                if (index < value.size())
                    fi.get() = yaml::deserialize<field_type>(value[index]);
                else
                    fi.get() = yaml::deserialize<field_type>({});
                ++index;
            }
            catch (deserialize_error& ex)
            {
                std::string msg =
                    "error when deserializing element " + std::to_string(index);
                ex.add(msg.c_str());
                throw;
            }
        });
    }
    else
    {
        throw deserialize_error{"type must be a sequence or map but is " +
                                yaml_type_name(value)};
    }

    return refl;
}
开发者ID:k0zmo,项目名称:kl,代码行数:62,代码来源:yaml.hpp

示例12: eMesh

STKUNIT_UNIT_TEST(nodeRegistry, test_parallel_1_0)
{
  EXCEPTWATCH;
  MPI_Barrier( MPI_COMM_WORLD );

  // start_demo_nodeRegistry_test_parallel_1

  percept::PerceptMesh eMesh(3u);

  unsigned p_size = eMesh.get_parallel_size();
  unsigned p_rank = eMesh.get_rank();
  Util::setRank(eMesh.get_rank());

  eMesh.new_mesh(percept::GMeshSpec(std::string("1x1x")+toString(p_size)+std::string("|bbox:0,0,0,1,1,1")));

  // prepare for adding some quadratic elements
  mesh::Part& block_hex_20 = eMesh.get_fem_meta_data()->declare_part("block_hex_20", eMesh.element_rank());
  /// set cell topology for the part block_hex_20
  mesh::fem::set_cell_topology< shards::Hexahedron<20>  >( block_hex_20 );
  stk_classic::io::put_io_part_attribute(block_hex_20);

  eMesh.commit();
  eMesh.print_info();
  eMesh.save_as("./cube1x1x2_hex-20-orig.e");

  mesh::Part* block_hex_8 = const_cast<mesh::Part *>(eMesh.getPart("block_1"));

  NodeRegistry nodeRegistry(eMesh);
  nodeRegistry.initialize();

  if (p_size <= 2)
  {
    // pick an element on the processor boundary
    unsigned elem_num_local = 1;
    unsigned elem_num_ghost = 2;
    if (p_size == 1)
      elem_num_ghost = 1;

    stk_classic::mesh::Entity* element_local_p = eMesh.get_bulk_data()->get_entity(eMesh.element_rank(), elem_num_local);
    stk_classic::mesh::Entity* element_ghost_p = eMesh.get_bulk_data()->get_entity(eMesh.element_rank(), elem_num_ghost);
    if (p_rank == 1)
    {
      element_local_p = eMesh.get_bulk_data()->get_entity(eMesh.element_rank(), elem_num_ghost);
      element_ghost_p = eMesh.get_bulk_data()->get_entity(eMesh.element_rank(), elem_num_local);
    }

    dw() << "P["<<p_rank<<"] elem_num_local = " << elem_num_local << DWENDL;
    dw() << "P["<<p_rank<<"] elem_num_ghost = " << elem_num_ghost << DWENDL;

    stk_classic::mesh::Entity& element_local = *element_local_p;
    stk_classic::mesh::Entity& element_ghost = *element_ghost_p;

    std::cout << "P["<<p_rank<<"] element_local = " << element_local << std::endl;
    std::cout << "P["<<p_rank<<"] element_ghost = " << element_ghost << std::endl;

    // choose edges to be used for new node locations (i.e., this would model a serendipity-like element with only edge Lagrange nodes)
    stk_classic::mesh::EntityRank stk_mesh_Edge = 1;
    NeededEntityType needed_entity_rank( stk_mesh_Edge, 1u);
    std::vector<NeededEntityType> needed_entity_ranks(1, needed_entity_rank);

    /*
     * 1st of three steps to create and associate new nodes - register need for new nodes, then check if node is remote, then get
     *   from remote proc if necessary; finally, the local node database is ready to be queried
     *
     * The pattern is to begin the step, loop over all elements (including ghosts) and invoke the local operation
     * The method doForAllSubEntities is a utility for performing the operation on all the sub entities.
     * If more granularity is desired, the member functions can be invoked directly for a particular sub-entity.
     */
    nodeRegistry.beginRegistration();
    nodeRegistry.doForAllSubEntities(&NodeRegistry::registerNeedNewNode, element_local, needed_entity_ranks);
    nodeRegistry.doForAllSubEntities(&NodeRegistry::registerNeedNewNode, element_ghost, needed_entity_ranks);
    nodeRegistry.endRegistration();

    std::cout << "P["<<p_rank<<"] nodeRegistry size  = " << nodeRegistry.total_size() << std::endl;
    std::cout << "P["<<p_rank<<"] nodeRegistry lsize = " << nodeRegistry.local_size() << std::endl;

    dw() << "P["<<p_rank<<"] nodeRegistry size       = " << nodeRegistry.total_size() << DWENDL;
    dw() << "P["<<p_rank<<"] nodeRegistry lsize      = " << nodeRegistry.local_size() << DWENDL;

    // could do local create of elements here
    nodeRegistry.beginLocalMeshMods();
    nodeRegistry.endLocalMeshMods();

    // check if the newly requested nodes are local or remote
    nodeRegistry.beginCheckForRemote();
    nodeRegistry.doForAllSubEntities(&NodeRegistry::checkForRemote, element_local, needed_entity_ranks);
    nodeRegistry.doForAllSubEntities(&NodeRegistry::checkForRemote, element_ghost, needed_entity_ranks);
    nodeRegistry.endCheckForRemote();

    // get the new nodes from other procs if they are nonlocal
    nodeRegistry.beginGetFromRemote();
    nodeRegistry.doForAllSubEntities(&NodeRegistry::getFromRemote, element_local, needed_entity_ranks);
    nodeRegistry.doForAllSubEntities(&NodeRegistry::getFromRemote, element_ghost, needed_entity_ranks);
    nodeRegistry.endGetFromRemote();

    // now we can get the new node's id and entity
    unsigned iSubDimOrd = 4u;
    if (p_rank)
    {
      iSubDimOrd = 0u;
//.........这里部分代码省略.........
开发者ID:00liujj,项目名称:trilinos,代码行数:101,代码来源:UnitTestNodeRegistry.cpp

示例13: parse_yaml

int parse_yaml(std::string config_file)
{
    rect_t matrix_rect = {0, 0, 0, 0};

    simulator_ptr sim = NULL;
    surface_ptr surf = NULL;
    output_ptr out = NULL;

    YAML::Node config = YAML::LoadFile(config_file);
    if(config.size() == 0 || !(config))
    {
        fprintf(stderr,
                "config file incomplete or empty!. exiting\n");
        return -1;
    }
    for(YAML::const_iterator j = config.begin();j != config.end(); ++j) {
        YAML::Node pattern_node = config[j->first.as<std::string>()];
        YAML::Node matrix = pattern_node["matrix"].as<YAML::Node>();
        YAML::Node matrixsim = pattern_node["matrixsim"].as<YAML::Node>();
        YAML::Node protocol = pattern_node["protocol"].as<YAML::Node>();
        YAML::Node pattern = pattern_node["pattern"].as<YAML::Node>();
        
        // a first test to see if pattern exist nothing else matters if it doesn't
        // exist.
        std::string pname;
        if(pattern)
        {
            pname = pattern["job"].as<std::string>();
        }
        else
        {
            fprintf(stderr,
                    "exiting because no pattern exist/selected. \n"
                    "config-node: %s\n",
                    j->first.as<std::string>().c_str());
            return -1;
        }

        if(matrix)
        {
            matrix_rect.x = matrix["x"].as<int>();
            matrix_rect.y = matrix["y"].as<int>();
            matrix_rect.width = matrix["width"].as<int>();
            matrix_rect.height = matrix["height"].as<int>();
        }
        else
        {
            fprintf(stderr,
                    "%s: no valid dimensions found. exiting.\n"
                    "config-node: %s\n",
                    pname.c_str(),
                    j->first.as<std::string>().c_str());
            return -1;
        }

        if(matrixsim)
        {
            int pixelsize = matrixsim["pixelsize"].as<int>();
            bool fullscreen = false;
            if(matrixsim["fullscreen"])
                fullscreen = matrixsim["fullscreen"].as<bool>();
            /* there is a small leak here, probably due to SDL */
            sim = simulator_ptr(new MatrixSimulator(matrix_rect, pixelsize, fullscreen));
        }
        else
        {
            fprintf(stderr,
                    "%s: running pattern without simulator.\n"
                    "config-node: %s\n",
                    pname.c_str(),
                    j->first.as<std::string>().c_str());
        }

        if(protocol)
        {
            std::string type = protocol["type"].as<std::string>();
            out = builder.protocol_builder(type, protocol);
            if(out == NULL)
            {
                fprintf(stderr,
                        "%s couldn't be created. not sending.\n",
                        type.c_str());
            }
        }
        else
        {
            fprintf(stderr,
                    "%s: no protocol found. not sending.\n"
                    "config-node: %s\n",
                    pname.c_str(),
                    j->first.as<std::string>().c_str());
        }

        // after all this we are sure pattern exist.
        // because we did a test for that earlier.
        std::string name = pattern["job"].as<std::string>().c_str();
        surf = builder.surface_builder(name, matrix_rect, pattern);
        if(surf == NULL)
        {
            fprintf(stderr,
//.........这里部分代码省略.........
开发者ID:TkkrLab,项目名称:ledart,代码行数:101,代码来源:argparse.cpp

示例14: InvalidNode

void
NodeSerialization::decode(const YAML::Node& node)
{
    if (!node.IsMap()) {
        throw YAML::InvalidNode();
    }


    _pluginID = node["PluginID"].as<std::string>();

    if (node["PresetName"]) {
        _encodeType = eNodeSerializationTypePresets;

        // This is a presets or pyplug
        _presetsIdentifierLabel = node["PresetName"].as<std::string>();
        if (node["PresetIcon"]) {
            _presetsIconFilePath = node["PresetIcon"].as<std::string>();
        }
        if (node["PresetShortcutKey"]) {
            _presetShortcutSymbol = node["PresetShortcutKey"].as<int>();
        }
        if (node["PresetShortcutModifiers"]) {
            _presetShortcutPresetModifiers = node["PresetShortcutModifiers"].as<int>();
        }
    }

    if (node["Name"]) {
        _nodeScriptName = node["Name"].as<std::string>();
    }
    
    if (node["Label"]) {
        _nodeLabel = node["Label"].as<std::string>();
    } else {
        _nodeLabel = _nodeScriptName;
    }

    if (node["Version"]) {
        YAML::Node versionNode = node["Version"];
        if (versionNode.size() != 2) {
            throw YAML::InvalidNode();
        }
        _pluginMajorVersion = versionNode[0].as<int>();
        _pluginMinorVersion = versionNode[1].as<int>();
    }

    tryDecodeInputsMap(node, "Inputs", &_inputs);
    tryDecodeInputsMap(node, "Masks", &_masks);

    
    if (node["Params"]) {
        YAML::Node paramsNode = node["Params"];
        for (std::size_t i = 0; i < paramsNode.size(); ++i) {
            KnobSerializationPtr s(new KnobSerialization);
            s->decode(paramsNode[i]);
            _knobsValues.push_back(s);
        }
    }
    if (node["UserPages"]) {
        YAML::Node pagesNode = node["UserPages"];
        for (std::size_t i = 0; i < pagesNode.size(); ++i) {
            GroupKnobSerializationPtr s(new GroupKnobSerialization);
            s->decode(pagesNode[i]);
            _userPages.push_back(s);
        }
    }
    if (node["PagesOrder"]) {
        YAML::Node pagesOrder = node["PagesOrder"];
        for (std::size_t i = 0; i < pagesOrder.size(); ++i) {
            _pagesIndexes.push_back(pagesOrder[i].as<std::string>());
        }
    }
    if (node["Children"]) {
        YAML::Node childrenNode = node["Children"];
        for (std::size_t i = 0; i < childrenNode.size(); ++i) {
            NodeSerializationPtr s(new NodeSerialization);
            s->decode(childrenNode[i]);
            _children.push_back(s);
        }
    }
    if (node["TableItems"]) {
        _tableModel.reset(new KnobItemsTableSerialization);
        _tableModel->decode(node["TableItems"]);
    }
    
    if (node["Preset"]) {
        _presetInstanceLabel = node["Preset"].as<std::string>();
    }
    
    if (node["NewLayers"]) {
        YAML::Node layersNode = node["NewLayers"];
        for (std::size_t i = 0; i < layersNode.size(); ++i) {
            ImagePlaneDescSerialization s;
            s.decode(layersNode[i]);
            _userComponents.push_back(s);
        }
    }
    if (node["Pos"]) {
        YAML::Node posNode = node["Pos"];
        if (posNode.size() != 2) {
            throw YAML::InvalidNode();
//.........这里部分代码省略.........
开发者ID:kcotugno,项目名称:Natron,代码行数:101,代码来源:NodeSerialization.cpp

示例15: switch

void
CurveSerialization::decode(const YAML::Node& node)
{
    if (!node.IsSequence()) {
        return;
    }
    if (node.size() == 0) {
        return;
    }
    CurveDecodeStateEnum state = eCurveDecodeStateMayExpectInterpolation;
    std::string interpolation;
    KeyFrameSerialization keyframe;
    bool pushKeyFrame = false;
    for (std::size_t i = 0; i < node.size(); ++i) {

        YAML::Node keyNode = node[i];

        switch (state) {
            case eCurveDecodeStateMayExpectInterpolation:
                if (pushKeyFrame) {
                    keys.push_back(keyframe);

                    // Reset keyframe
                    keyframe.interpolation.clear();
                    keyframe.time = keyframe.value = keyframe.leftDerivative = keyframe.rightDerivative = 0.;

                }
                try {
                    // First try to get a time. Conversion of a string to double always fails but string to double does not
                    keyframe.time = keyNode.as<double>();

                    // OK we read a valid time, assume the interpolation is the same as the previous

                    // No interpolation, use the interpolation set previously.
                    // If interpolation is not set, set interpolation to linear
                    if (interpolation.empty()) {
                        interpolation = kKeyframeSerializationTypeLinear;
                    }
                    keyframe.interpolation = interpolation;
                    state = eCurveDecodeStateExpectValue;
                } catch (const YAML::BadConversion& /*e*/) {
                    // OK we read an interpolation and set the curve interpolation so far if needed
                    keyframe.interpolation = keyNode.as<std::string>();
                    // No interpolation, use the interpolation set previously.
                    // If interpolation is not set, set interpolation to linear
                    if (interpolation.empty()) {
                        interpolation = keyframe.interpolation;
                    }
                    state = eCurveDecodeStateExpectTime;
                }

                break;
            case eCurveDecodeStateExpectTime:
                keyframe.time = keyNode.as<double>();
                state  = eCurveDecodeStateExpectValue;
                break;
            case eCurveDecodeStateExpectValue:
                keyframe.value = keyNode.as<double>();
                // Depending on interpolation we may expect derivatives
                if (keyframe.interpolation == kKeyframeSerializationTypeFree || keyframe.interpolation == kKeyframeSerializationTypeBroken) {
                    state = eCurveDecodeStateMayExpectRightDerivative;
                } else {
                    state = eCurveDecodeStateMayExpectInterpolation;
                }
                break;
            case eCurveDecodeStateMayExpectRightDerivative:
                keyframe.rightDerivative = keyNode.as<double>();
                if (keyframe.interpolation == kKeyframeSerializationTypeBroken) {
                    state = eCurveDecodeStateMayExpectLeftDerivative;
                } else {
                    state = eCurveDecodeStateMayExpectInterpolation;
                }
                break;
            case eCurveDecodeStateMayExpectLeftDerivative:
                keyframe.leftDerivative = keyNode.as<double>();
                state = eCurveDecodeStateMayExpectInterpolation;
                break;
        }
        pushKeyFrame = true;
    }
    if (pushKeyFrame) {
        keys.push_back(keyframe);
    }
}
开发者ID:azerupi,项目名称:Natron,代码行数:84,代码来源:CurveSerialization.cpp


注:本文中的yaml::Node::size方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。