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


C++ contains函数代码示例

本文整理汇总了C++中contains函数的典型用法代码示例。如果您正苦于以下问题:C++ contains函数的具体用法?C++ contains怎么用?C++ contains使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: invert

 Element Group::invert(const Element& x) const {
#ifdef GROUP_CHECKS_MEMBERSHIP
  if (!contains(x)) throw group_mismatch("Group::invert");
#endif
  return Element(this, inverses[x.val]);
 }
开发者ID:foadnh,项目名称:groups,代码行数:6,代码来源:Group.cpp

示例2: assert

inline Breakpoint* BreakpointTable::get_breakpoint(int32_t location)
{
	assert(contains(location));
	return &(_breakpoints.find(location)->second);
}
开发者ID:zapster,项目名称:cacao-travis,代码行数:5,代码来源:breakpoint.hpp

示例3: in

/**
 * The DAT format contains "datasets" and each dataset has N-outputs. One output
 * represents data for all vertices/faces for one timestep
 *
 * In MDAL we convert one output to one MDAL dataset;
 *
 */
void MDAL::LoaderAsciiDat::load( MDAL::Mesh *mesh, MDAL_Status *status )
{
  if ( status ) *status = MDAL_Status::None;

  if ( !MDAL::fileExists( mDatFile ) )
  {
    if ( status ) *status = MDAL_Status::Err_FileNotFound;
    return;
  }

  std::ifstream in( mDatFile, std::ifstream::in );
  std::string line;
  if ( !std::getline( in, line ) )
  {
    if ( status ) *status = MDAL_Status::Err_UnknownFormat;
    return;
  }
  line = trim( line );

  // http://www.xmswiki.com/xms/SMS:ASCII_Dataset_Files_*.dat
  // Apart from the format specified above, there is an older supported format used in BASEMENT (and SMS?)
  // which is simpler (has only one dataset in one file, no status flags etc)
  bool oldFormat;
  bool isVector = false;

  std::shared_ptr<DatasetGroup> group; // DAT outputs data
  std::string name( MDAL::baseName( mDatFile ) );

  if ( line == "DATASET" )
    oldFormat = false;
  else if ( line == "SCALAR" || line == "VECTOR" )
  {
    oldFormat = true;
    isVector = ( line == "VECTOR" );

    group.reset( new DatasetGroup() );
    group->uri = mDatFile;
    group->setName( name );
    group->isScalar = !isVector;
  }
  else
    EXIT_WITH_ERROR( MDAL_Status::Err_UnknownFormat );

  // see if it contains face-centered results - supported by BASEMENT
  bool faceCentered = false;
  if ( !oldFormat && contains( name, "_els_" ) )
    faceCentered = true;

  if ( group )
    group->isOnVertices = !faceCentered;

  while ( std::getline( in, line ) )
  {
    std::vector<std::string> items = split( line,  " ", SplitBehaviour::SkipEmptyParts );
    if ( items.size() < 1 )
      continue; // empty line?? let's skip it

    std::string cardType = items[0];
    if ( cardType == "ND" && items.size() >= 2 )
    {
      size_t fileNodeCount = toSizeT( items[1] );
      if ( mesh->vertexIDtoIndex.size() != fileNodeCount )
        EXIT_WITH_ERROR( MDAL_Status::Err_IncompatibleMesh );
    }
    else if ( !oldFormat && cardType == "NC" && items.size() >= 2 )
    {
      size_t fileElemCount = toSizeT( items[1] );
      if ( mesh->faceIDtoIndex.size() != fileElemCount )
        EXIT_WITH_ERROR( MDAL_Status::Err_IncompatibleMesh );
    }
    else if ( !oldFormat && cardType == "OBJTYPE" )
    {
      if ( items[1] != "mesh2d" && items[1] != "\"mesh2d\"" )
        EXIT_WITH_ERROR( MDAL_Status::Err_UnknownFormat );
    }
    else if ( !oldFormat && ( cardType == "BEGSCL" || cardType == "BEGVEC" ) )
    {
      if ( group )
      {
        debug( "New dataset while previous one is still active!" );
        EXIT_WITH_ERROR( MDAL_Status::Err_UnknownFormat );
      }
      isVector = cardType == "BEGVEC";

      group.reset( new DatasetGroup() );
      group->uri = mDatFile;
      group->setName( name );
      group->isScalar = !isVector;
      group->isOnVertices = !faceCentered;
    }
    else if ( !oldFormat && cardType == "ENDDS" )
    {
      if ( !group )
//.........这里部分代码省略.........
开发者ID:borysiasty,项目名称:QGIS,代码行数:101,代码来源:mdal_ascii_dat.cpp

示例4: contains

bool Rectangle::contains( const Point3d& p3d ) const
{
    return contains(p3d.to_point());
}
开发者ID:anylonen,项目名称:abura-tan,代码行数:4,代码来源:rectangle.cpp

示例5: make_astar_node

std::vector<int> Pathfinder::getPathFrom(int start) const
{
    if (goal_(start)) return {start};

    // Record shortest path costs for every node we examine.
    std::unordered_map<int, AstarNodePtr> nodes;
    // Maintain a heap of nodes to consider.
    std::vector<int> open;
    int goalLoc = -1;
    AstarNodePtr goalNode;

    // The heap functions confusingly use operator< to build a heap with the
    // *largest* element on top.  We want to get the node with the *least* cost,
    // so we have to order nodes in the opposite way.
    auto orderByCost = [&] (int lhs, int rhs)
    {
        return nodes[lhs]->estTotalCost > nodes[rhs]->estTotalCost;
    };

    nodes.emplace(start, make_astar_node(-1, 0, 0));
    open.push_back(start);

    // A* algorithm.  Decays to Dijkstra's if estimate function is always 0.
    while (!open.empty()) {
        auto loc = open.front();
        pop_heap(std::begin(open), std::end(open), orderByCost);
        open.pop_back();
        if (goal_(loc)) {
            goalLoc = loc;
            goalNode = nodes[loc];
            break;
        }

        auto &curNode = nodes[loc];
        curNode->visited = true;
        for (auto n : neighbors_(loc)) {
            auto nIter = nodes.find(n);
            auto step = stepCost_(loc, n);

            if (nIter != nodes.end()) {
                auto &nNode = nIter->second;
                if (nNode->visited) {
                    continue;
                }

                // Are we on a shorter path to the neighbor node than what
                // we've already seen?  If so, update the neighbor's node data.
                if (curNode->costSoFar + step < nNode->costSoFar) {
                    nNode->prev = loc;
                    nNode->costSoFar = curNode->costSoFar + step;
                    nNode->estTotalCost = nNode->costSoFar + estimate_(n);
                    make_heap(std::begin(open), std::end(open), orderByCost);
                }
            }
            else {
                // We haven't seen this node before.  Add it to the open list.
                nodes.emplace(n, make_astar_node(loc, curNode->costSoFar + step, 
                    curNode->costSoFar + step + estimate_(n)));
                open.push_back(n);
                push_heap(std::begin(open), std::end(open), orderByCost);
            }
        }
    }

    if (!goalNode) {
        return {};
    }

    // Build the path from the chain of nodes leading to the goal.
    std::vector<int> path = {goalLoc};
    auto n = goalNode;
    while (n->prev != -1) {
        path.push_back(n->prev);
        n = nodes[n->prev];
    }
    reverse(std::begin(path), std::end(path));
    assert(contains(path, start));
    return path;
}
开发者ID:CraigularB,项目名称:battle-sim,代码行数:79,代码来源:Pathfinder.cpp

示例6: do_tokenizing

void do_tokenizing(char *orig, char *source) {
  //printf("***tokenizing...\n------------------------\n%s\n----------------------\n", orig);
  char *str = strdup(orig);

  char *curr, *new_str, *word;
  char *saveptr1, *saveptr2;


  while( (curr = strstr(str, "link:")) != NULL) {
    new_str = strdup(curr+1);

    if(curr == str || (curr > str && is_blank_space(*(curr-1)))) {

      curr = strtok_r(curr, " \n", &saveptr1);
      assert(curr != NULL);

      word = strtok_r(curr, ":", &saveptr2);
      word = strtok_r(NULL, ":", &saveptr2);

      //printf("found word: %s\n", word);
      assert(word != NULL);

      edge_fn(source, word);

      // check hash set and, if not present, add
      // link producer
      Mutex_lock(&l_m);
      while(link_count == max_link) {
	// wait
	Cond_wait(&l_empty, &l_m);
      }
    
      if(!contains(table, word)) {
	// do pushing
	printf("PUSH link: %s\n", word);
	links = push(NULL, strdup(word), links);
	link_count++;
      
	Mutex_lock(&done_m);
	total_work++;
	Mutex_unlock(&done_m);

	printf("--> new link_count: %d\n", link_count);
	printf("--> curr page_count: %d\n", page_count);
	// update table
	add(table, word);
      }
    
      Cond_signal(&l_fill);
      Mutex_unlock(&l_m);

    }

    free(str);
    str = new_str;
  }

  free(str);

  return;
}
开发者ID:wkfunk,项目名称:cs,代码行数:61,代码来源:crawler.c

示例7: node

	std::shared_ptr<ILoadableObject> ObjLoader::load(AssetManager *assetMgr, AssetInfo &asset)
	{
		shared_ptr<Node> node(new Node());

		std::string currentDir = std::string(asset.getFilePath());
		std::string nodeFileName = currentDir.substr(currentDir.find_last_of("\\/")+1);
		nodeFileName = nodeFileName.substr(0, nodeFileName.find_first_of(".")); // trim extension

		node->setName(nodeFileName);

		std::string line;
		while (std::getline(*asset.getStream(), line))
		{
			vector<string> tokens = split(line, ' ');
			tokens = removeEmptyStrings(tokens);

			if (tokens.size() == 0 || strcmp(tokens[0].c_str(), "#") == 0)
			{
			}
			else if (strcmp(tokens[0].c_str(), "v") == 0)
			{
				float x = parse<float>(tokens[1]);
				float y = parse<float>(tokens[2]);
				float z = parse<float>(tokens[3]);
				Vector3f vec(x, y, z);
				positions.push_back(vec);
			}
			else if (strcmp(tokens[0].c_str(), "vn") == 0)
			{
				float x = parse<float>(tokens[1]);
				float y = parse<float>(tokens[2]);
				float z = parse<float>(tokens[3]);
				Vector3f vec(x, y, z);
				normals.push_back(vec);
			}
			else if (strcmp(tokens[0].c_str(), "vt") == 0)
			{
				float x = parse<float>(tokens[1]);
				float y = parse<float>(tokens[2]);
				Vector2f vec(x, y);
				texCoords.push_back(vec);
			}
			else if (strcmp(tokens[0].c_str(), "f") == 0)
			{
				vector<ObjIndex> *c_idx = currentList();
				for (int i = 0; i < tokens.size() - 3; i++)
				{
					c_idx->push_back(parseObjIndex(tokens[1]));
					c_idx->push_back(parseObjIndex(tokens[2 + i]));
					c_idx->push_back(parseObjIndex(tokens[3 + i]));
				}
			}
			else if (strcmp(tokens[0].c_str(), "mtllib") == 0)
			{
				string libLoc = tokens[1];

				std::string currentDir = std::string(asset.getFilePath());
				currentDir = currentDir.substr(0, currentDir.find_last_of("\\/"));

				if (!contains(currentDir, "/") && !contains(currentDir, "\\"))	// the file path is just current file name,															   
				{																// so just make the string empty
					currentDir = "";
				}

				currentDir += "/" + libLoc;

				std::shared_ptr<MaterialList> mtlList = assetMgr->loadAs<MaterialList>(currentDir.c_str());
				this->mtlList = *mtlList.get();
			}
			else if (strcmp(tokens[0].c_str(), "usemtl") == 0)
			{
				string matname = tokens[1];
				newMesh(matname);
			}
		}

		for (int i = 0; i < objIndices.size(); i++)
		{
			vector<ObjIndex> *c_idx = objIndices[i];
			vector<Vertex> vertices;

			for (int j = 0; j < c_idx->size(); j++)
			{
				Vertex vert(positions[(*c_idx)[j].vertex_idx],
						   (hasTexCoords ? texCoords[(*c_idx)[j].texcoord_idx] : Vector2f()),
						   (hasNormals ? normals[(*c_idx)[j].normal_idx] : Vector3f()));

				vertices.push_back(vert);
			}

			shared_ptr<Mesh> mesh(new Mesh());
			mesh->setVertices(vertices);

			if (hasNormals)
				mesh->getAttributes().setAttribute(VertexAttributes::NORMALS);
			if (hasTexCoords)
				mesh->getAttributes().setAttribute(VertexAttributes::TEXCOORDS0);

			shared_ptr<Geometry> geom(new Geometry());
			geom->setName(names[i]);
//.........这里部分代码省略.........
开发者ID:ajmd17,项目名称:apexengine,代码行数:101,代码来源:objloader.cpp

示例8: traverse

//Traverse a directory tree with root given by 'path'
void traverse(char* path, char* str, int log_out, int grep_out, list* checked){
	DIR *pDir;
	struct dirent *pDirent;
	struct stat s;
	pid_t child;
	int status;
	int text;

	pDir = opendir(path);
	//Iterate through the contents of the current directory
	while((pDirent = readdir(pDir)) != NULL){
		char* current_path;
		char* current;

		if((current_path = malloc(512*sizeof(char))) == NULL){
			fprintf(stderr, "ERROR: malloc() error\n");
			exit(0);
		}
		//Construct the path string
		current = pDirent->d_name;
		strcpy(current_path, path);
		strcat(current_path, "/");
		strcat(current_path, current);
		//Ignore '.' and '..' directories
		if(!strcmp(current, ".") || !strcmp(current, "..")){
			continue;
		}
		//Write paths to log.txt
		write(log_out, current_path, strlen(current_path));
		write(log_out, "\n", 1);
		//Check for redundant links
		if(lstat(current_path, &s) != 0){
			fprintf(stderr, "ERROR: lstat() failure\n");
		}
		else if(!contains(checked, (int)s.st_ino)){
			insert(checked, (int)s.st_ino);
		}
		else{
			continue;
		}

		//Check if the current file is a directory
		if(S_ISDIR(s.st_mode)){
				traverse(current_path, str, log_out, grep_out, checked);				
		}//If not, fork
		else{
			int pp[2];
			int size = s.st_size;
			char buf[size];

			if(pipe(pp) == -1){//Create a pipe
				fprintf(stderr, "ERROR: pipe() failure\n");
			}
			dup2(grep_out, 1);
			dup2(pp[0], 0);
			
			child = fork();
			if(child == -1){
				fprintf(stderr, "ERROR: fork() failure\n");
				exit(0);
			}

			if(child == 0){//The child executes grep
				close(pp[1]);
				char* array[3] = {"grep", str, NULL};
				execvp(array[0], array);
			}
			else{//The parent pipes the text to the child
				close(pp[0]);
				text = open(current_path, O_RDONLY);
				read(text, buf, size);
				write(pp[1], buf, size);
				close(pp[1]);
				wait(NULL);
			}
		}
		free(current_path);
	}
	closedir(pDir);
}
开发者ID:soleusrex,项目名称:4061,代码行数:81,代码来源:main.c

示例9: assert

inline address ThreadCodeBuffer::compute_adjusted_pc(address pc) {
  assert(contains(pc), "pc must point into codebuffer") 
  pc = real_pc() + (pc - code_begin());
  assert(method()->contains(pc), "result must be in nmethod");      
  return pc;
}
开发者ID:fatman2021,项目名称:myforthprocessor,代码行数:6,代码来源:threadCodeBuffer.hpp

示例10: main

int main(int argc, char *argv[])
{
    int size,tmpdec,i,fd, nread, fp, ntemp, tmpi,colons, uid,tmpflag;
    double tmpsize;
    long long int giga,mega,kilo;
    giga=1024*1024*1024;
    mega=1024*1024;
    kilo=1024;
    char buf[BUF_SIZE];
    char user[50];
    char buffer[50000],linkval[500];
    char line[1000];
    struct linux_dirent *d;
    int bpos,isalink;
    int flag=0,hasfile=0;
    char d_type;
    int l=0,a=0,h=0;
    struct stat fileStat,tmpStat;
    char file[100],tmpfile[100];
    if(argc==2||argc==3)
    {
        if(compare(argv[1],"-l")||compare(argv[1],"-a")||compare(argv[1],"-h")||compare(argv[1],"-lah")||compare(argv[1],"-lha")||compare(argv[1],"-ahl")||compare(argv[1],"-alh")||compare(argv[1],"-hla")||compare(argv[1],"-hal")||compare(argv[1],"-la")||compare(argv[1],"-ah")||compare(argv[1],"-hl")||compare(argv[1],"-al")||compare(argv[1],"-ha")||compare(argv[1],"-lh"))
        {
            flag=1;
            if(argc>2)
                hasfile=1;
            if(contains(argv[1],'l'))
                l=1;
            if(contains(argv[1],'a'))
            {
                if(l==0)
                    flag=0;
                if(argc==3)
                    hasfile=1;
                a=1;
            }
            if(contains(argv[1],'h'))
            {
                h=1;
                if(l==0)
                    flag=0;
                if(argc==3)
                    hasfile=1;
            }
        }
        else if(argc==2)
            hasfile=1;
    }
    if(argc==3)
    {
        if(compare(argv[2],"-l")||compare(argv[2],"-a")||compare(argv[2],"-h")||compare(argv[2],"-lah")||compare(argv[2],"-lha")||compare(argv[2],"-ahl")||compare(argv[2],"-alh")||compare(argv[2],"-hla")||compare(argv[2],"-hal")||compare(argv[2],"-la")||compare(argv[2],"-ah")||compare(argv[2],"-hl")||compare(argv[2],"-al")||compare(argv[2],"-ha")||compare(argv[2],"-lh"))
        {
            flag=2;
            hasfile=1;
            if(contains(argv[2],'l'))
                l=1;
            if(contains(argv[2],'a'))
            {
                a=1;
                if(l==0)
                    flag=0;
            }
            if(contains(argv[2],'h'))
            {
                h=1;
                if(l==0)
                    flag=0;
            }
        }
    }
    //	printf("%d %d %d %d %d %d\n" ,l,a,h,hasfile,flag, argc);
    if((!flag&&a&!l)||(!flag&&h&!l)||!a&!l&!h||(!flag&&a&h))
    {
        if(argc>1)
        {
            file[0]='\0';
            if(!a&&!h)
            {
                fd = open(argv[1], O_RDONLY | O_DIRECTORY);
                concat(file,argv[1]);
                //printf("%s",file);
            }
            else if(a|h)
            {
                if(hasfile)
                {
                    if(compare(argv[1],"-a")||compare(argv[1],"-h")||compare(argv[1],"-ah")||compare(argv[1],"-ha"))
                    {
                        fd = open(argv[2], O_RDONLY | O_DIRECTORY);
                        concat(file,argv[2]);
                    }
                    else if(compare(argv[2],"-a")||compare(argv[2],"-h")||compare(argv[2],"-ah")||compare(argv[2],"-ha"))
                    {
                        fd = open(argv[1], O_RDONLY | O_DIRECTORY);
                        concat(file,argv[1]);
                    }
                    //fd = open(".", O_RDONLY | O_DIRECTORY);
                }
                else
                {
//.........这里部分代码省略.........
开发者ID:raj454raj,项目名称:myls,代码行数:101,代码来源:myls.c

示例11: handleEvent

void Joystick::handleEvent(sf::Event const& event, const sf::Vector2f& position)
{
	if ((event.type == sf::Event::TouchBegan || (event.type == sf::Event::MouseButtonPressed && event.mouseButton.button == sf::Mouse::Left)) && contains(position))
    {
        mHeld = true;
		if (ke::isMobile())
		{
			mFingerId = event.touch.finger;
		}
        mButton.setPosition(0,0);
    }
    if ((event.type == sf::Event::MouseButtonReleased && event.mouseButton.button == sf::Mouse::Left) || (event.type == sf::Event::TouchEnded && event.touch.finger == mFingerId))
    {
        mHeld = false;
        mButton.setPosition(0,0);
    }
    if ((event.type == sf::Event::MouseMoved || (event.type == sf::Event::TouchMoved && event.touch.finger == mFingerId)) && mHeld)
    {
        sf::Vector2f p = position - getPosition();
		if (mBlockHorizontal)
		{
			p.x = 0.f;
		}
		if (mBlockVertical)
		{
			p.y = 0.f;
		}
        float r = std::sqrt(p.x * p.x + p.y * p.y);
        if (r >= mDeltaMax)
        {
            mButton.setPosition(mDeltaMax * sf::Vector2f(p.x/r,p.y/r));
        }
        else
        {
            mButton.setPosition(p);
        }
    }
}
开发者ID:Cmdu76,项目名称:Keengine,代码行数:38,代码来源:Joystick.cpp

示例12: contains

bool
Interval::contains(const Interval* interval) const
{
    return contains(interval->min, interval->max);
}
开发者ID:libgeos,项目名称:libgeos,代码行数:5,代码来源:Interval.cpp

示例13: showElem

 string Group::showElem(const Element& x) const {
#ifdef GROUP_CHECKS_MEMBERSHIP
  if (!contains(x)) throw group_mismatch("Group::showElem");
#endif
  return strs[x.val];
 }
开发者ID:foadnh,项目名称:groups,代码行数:6,代码来源:Group.cpp

示例14: order

 int Group::order(const Element& x) const {
#ifdef GROUP_CHECKS_MEMBERSHIP
  if (!contains(x)) throw group_mismatch("Group::order");
#endif
  return orders[x.val];
 }
开发者ID:foadnh,项目名称:groups,代码行数:6,代码来源:Group.cpp

示例15: get

 bool get(const K & k, V & v) {
   if(contains(k)) {
     v = kvdct.at(k);
     return true;
   } else { return false; }
 }
开发者ID:lqshixinlei,项目名称:paracel,代码行数:6,代码来源:kv.hpp


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