コード例 #1
0
ファイル: console.cpp プロジェクト: Liag/shmup-base-engine
    void Console::exec(std::string cmd)
    {
        StrVec args;

        if(cmd.find(' ') != std::string::npos)
        {
            args.push_back(cmd.substr(cmd.find(' ') + 1, cmd.size() - cmd.find(' ')));
            cmd = cmd.substr(0, cmd.find(' '));

            while(args.back().find(' ') != std::string::npos)
            {
                args.push_back(args.back().substr(args.back().find(' ') + 1 , args.size() - args.back().find(' ')));
                args.at(args.size() - 1) = args.at(args.size() - 1).substr(0, args.at(args.size() - 1).find(' ') - 1);
            }
        }

        if(commands.find(cmd) == commands.end())
        {
            addString("Command '" + cmd + "' not found");
            return;
        }

        if(!commands[cmd].exec(args)) addString("Wrong number of arguments for command '" + cmd + "'.");

    }
コード例 #2
0
ファイル: CorbaNotifyUtils.cpp プロジェクト: diegorz/ACS
void CorbaNotifyUtils::getORBOptions(const std::string &appName,const std::string &orbOptions,
		int &orbArgc,ACE_TCHAR*** orbArgv)
{
	StrVec ORBOptionsVec;
	size_t ini = orbOptions.find_first_not_of(" \t");
	size_t end;

	while(ini != std::string::npos)
	{
		end = orbOptions.find_first_of(" \t", ini + 1);
		if(end != std::string::npos)
		{
			ORBOptionsVec.push_back(orbOptions.substr(ini, end - ini));
			ini = orbOptions.find_first_not_of(" \t", end);
		} else {
			ORBOptionsVec.push_back(orbOptions.substr(ini));
			ini = std::string::npos;
		}
	}

	int i = 1;
	orbArgc = ORBOptionsVec.size() + 1;
	*orbArgv = new ACE_TCHAR*[orbArgc];
	(*orbArgv)[0] = new ACE_TCHAR[appName.size() + 1];
	strncpy((*orbArgv)[0], appName.c_str(), appName.size());
	(*orbArgv)[0][appName.size()] = '\0';
	for(StrVec::const_iterator it = ORBOptionsVec.begin();
			it != ORBOptionsVec.end(); ++it, ++i)
	{
		(*orbArgv)[i] = new ACE_TCHAR[it->size() + 1];
		strncpy((*orbArgv)[i], it->c_str(), it->size());
		(*orbArgv)[i][it->size()] = '\0';
		ACE_DEBUG((LM_INFO, "%T ORB option: %s\n", (*orbArgv)[i]));
	}
}
コード例 #3
0
int main() {
  StrVec sv;
  print(sv);

  sv.push_back("s1"); print(sv);
  sv.push_back("s2"); print(sv);
  sv.push_back("s3"); print(sv);
  sv.push_back("s4"); print(sv);
  sv.push_back("s5"); print(sv);

  {
    StrVec sv2(sv); print(sv2);
    sv2.push_back("s6"); print(sv); print(sv2);
    sv.pop_back(); print(sv); print(sv2);
    sv = sv2; print(sv); print(sv2);
  }

  sv.reserve(sv.capacity() / 2); print(sv);
  sv.reserve(sv.capacity() * 2); print(sv);

  sv.resize(sv.size() + 2); print(sv);
  sv.resize(sv.size() + 2, "s7"); print(sv);
  sv.resize(sv.size() - 2); print(sv);
  sv.resize(sv.size() - 2, "s7"); print(sv);

  return 0;
}
コード例 #4
0
ファイル: main.cpp プロジェクト: SnakeSolidNL/tools
void ParseBufVC(char* buf, const string& filter_modules, const string& filter_disabled, const string& filter_headers)
{
    static bool ignore_files=false;
    string line(buf);
    switch(BufState)
    {
    case 0: // expect filter start (set state to 1) or just a line (state =0)
    {
        if(line.find("<Filter")!=-1) BufState++;
        ProjLines.push_back(line);
        break;
    }
    case 1: // found filter, read the name and maybe start ignoring files, state++
    {
        int from=line.find("\"")+1;
        int to=line.find("\"",from);
        string name=line.substr(from,to-from);
        if(name==filter_modules || name==filter_headers || name==filter_disabled)
        {
            ProjAssoc[ProjLines.size()+4]=name;
            ignore_files=true;
        }
        BufState++;
        ProjLines.push_back(line);
        break;
    }
    case 2: // state++
    case 3: // state++
    case 4: // state++
    {
        BufState++;
        ProjLines.push_back(line);
        break;
    }
    case 5: // expect file or end of filter (back to 0, stop ignoring files)
    {
        // end of filter?
        if(line.find("</Filter>")!=-1)
        {
            BufState=0;
            ignore_files=false;
            ProjLines.push_back(line);
            break;
        }
        // file, pass
    }
    case 6: // state++
    case 7: // state++
    case 8: // state++
    {
        if(!ignore_files) ProjLines.push_back(line);
        BufState++;
        if(BufState>8) BufState=5;
        break;
    }
    default:
        ;
    }
}
コード例 #5
0
ファイル: main.cpp プロジェクト: keyu-lai/cpp-exercise
int main()
{
	StrVec str;
	str.push_back("adf");
	str.push_back("sdfd");
	for (auto i = str.begin(); i != str.end(); ++i)
		cout << *i << ends;
	cout << endl;
	return 0;
}
コード例 #6
0
ファイル: main.cpp プロジェクト: RustonOoOo/cpp_note
int main() {
    StrVec words;
    words.push_back("ss");
    words.push_back("sb");
    words.push_back("asf");
    words.push_back("safasfd");
    words.push_back("asfas");
    std::cout<<words.size()<<std::endl;
    //words = StrVec();
    //words = words;
    std::cout<<"cap "<<words.capacity()<<std::endl;
    std::cout<<"sz "<<words.size()<<std::endl;
    for_each(words.begin(), words.end(), [](const std::string &s){std::cout<<s<<std::endl;});
    std::cout<<"exit"<<std::endl;
}
コード例 #7
0
ファイル: cGRASS.cpp プロジェクト: roeland-frans/q-rap
void cGRASS::breakDir(string Dir)
{
	StrVec Vec;
	Vec.clear();
	char dir[255];
	strcpy(dir,Dir.c_str());
	char * t;
	string temp;
	printf ("Splitting string \"%s\" into tokens:\n",dir);
	t = strtok (dir,"/");
	while (t != NULL)
	{
		temp = t;
		Vec.push_back(temp);
  		t = strtok (NULL, "/");
	}
	MapSet = Vec[Vec.size()-1];
	Location = Vec[Vec.size()-2];
	GDBase = "";
	for (uint i = 0; i < Vec.size()-2; i++)
	{
		GDBase = GDBase + "/" + Vec[i];
	}
//	printf(MapSet);
//	printf(Location);
//	printf(GDBase);
}
コード例 #8
0
template<> StrVec
GncDbiProviderImpl<DbType::DBI_MYSQL>::get_index_list (dbi_conn conn)
{
    StrVec retval;
    const char* errmsg;
    auto tables = get_table_list(conn, "");
    for (auto table_name : tables)
    {
        auto result = dbi_conn_queryf (conn,
                                       "SHOW INDEXES IN %s WHERE Key_name != 'PRIMARY'",
                                       table_name.c_str());
        if (dbi_conn_error (conn, &errmsg) != DBI_ERROR_NONE)
        {
            PWARN ("Index Table Retrieval Error: %s on table %s\n",
                   errmsg, table_name.c_str());
            continue;
        }

        while (dbi_result_next_row (result) != 0)
        {
            std::string index_name {dbi_result_get_string_idx (result, 3)};
            retval.push_back(index_name + " " + table_name);
        }
        dbi_result_free (result);
    }

    return retval;
}
コード例 #9
0
ファイル: fileutils.cpp プロジェクト: Lingrui/TS
StrVec split_path (const char* path)
{
    StrVec rv;
    std::string pstr = path;
    std::string::size_type pos, ppos = 0;
    while ((pos = pstr.find (PATH_SEPARATOR, ppos)) != std::string::npos)
    {
        if (pos != ppos || ppos == 0)
            rv.push_back (pstr.substr (ppos, pos - ppos));
        ppos = pos + 1;
    }
    if (ppos < pstr.length ())
        rv.push_back (pstr.substr (ppos, pstr.length () - ppos));

    return rv;
}
コード例 #10
0
ファイル: string_util.cpp プロジェクト: Acidburn0zzz/code
extern StrVec string_util::split(const string &source,const string &split)
{
  string::size_type number=count_occur(source,split);
  if(number==0)
    {
      StrVec result;
      result.push_back(source);
      return result;
    }

  vector<string> result;
  string::size_type start=0;
  string::size_type stop=0;
  string inner;
  while(true)
    {
      stop=source.find(split,start);
      if(stop==string::npos)
        {
          result.push_back(source.substr(start));
          break;
        }
      else
        {
          result.push_back(source.substr(start,stop-start));
          start=stop+split.size();
        }
    }
  return result;
}
コード例 #11
0
ファイル: Exer13_43.cpp プロジェクト: chihyang/CPP_Primer
int main()
{
	StrVec v = {"Gone", "with", "the"};
	v.push_back("winds");
	for_each(v.begin(), v.end(), [](const string &s) {cout << s << " ";});
	cout << endl;
	return 0;
}
コード例 #12
0
StrVec getVec(istream &is)
{
	StrVec svec;
	string s;
	while (is >> s)
		svec.push_back(s);
	return svec;
}
コード例 #13
0
ファイル: SLData.cpp プロジェクト: clagv/sl
 size_t Data::newEntry(const std::string& key, const SLStore& dv)
 {
     KeyIdx ki(key, m_keyIdx.size());
     KeyIdxVec::iterator it = std::upper_bound(m_keyIdx.begin(), m_keyIdx.end(), ki, key_less);
     m_keys.push_back(key);
     m_varData.push_back(dv);
     m_keyIdx.insert(it, ki);
     return ki.second;
 }
コード例 #14
0
ファイル: main.cpp プロジェクト: LvChong/My_Primer
int main()
{
	StrVec vec = { "aaa", "bbb", "ccc" };
	cout << vec.size() << " " << vec.capacity() << endl;
	vec.push_back("ddd");
	vec.print();
	system("pause");
	return 0;
}
コード例 #15
0
ファイル: t_ex_strvec.cpp プロジェクト: keitee/kb
StrVec getVec(std::istream &is)
{
    StrVec svec;
    std::string s;

    while (is >> s)
        svec.push_back(s);

    // this is where move is necessary
    return svec;
}
コード例 #16
0
int main()
{
	string temp[] = {"one", "two", "three"};
	StrVec sv(temp, temp + sizeof(temp)/sizeof(*temp));

	// run the string empty funciton on the first element in sv
	if (!sv[0].empty()) 
		sv[0] = "None"; // assign a new value to the first string 

	// we'll call getVec a couple of times
	// and will read the same file each time
	ifstream in("data/storyDataFile");
	StrVec svec = getVec(in);
	print(svec);
	in.close();

	cout << "copy " << svec.size() << endl;
	StrVec svec2 = svec;
	print(svec2);

	cout << "assign" << endl;
	StrVec svec3;
	svec3 = svec2;
	print(svec3);

	StrVec v1, v2;
	v1 = v2;                   // v2 is an lvalue; copy assignment

	in.open("data/storyDataFile");
	v2 = getVec(in);          // getVec(in) is an rvalue; move assignment
	in.close();

	StrVec vec;  // empty StrVec
	string s = "some string or another";
	vec.push_back(s);      // calls push_back(const string&)
	vec.push_back("done"); // calls push_back(string&&)

	return 0;
}
コード例 #17
0
ファイル: class.cpp プロジェクト: whr4935/C_plus_plus_primer
static void test_strVec()
{
    StrVec v;
    v.push_back("wang");
    v.push_back("hou");
    v.push_back("ren");
#if __cplusplus > 201103L
    for_each(v.begin(), v.end(), [](auto &it) {cout << it << " "; }), cout << endl;
#endif
    StrVec v2 = std::move(v);
    #if __cplusplus > 201103L
    for_each(v2.begin(), v2.end(), [](auto &it) {cout << it << " "; }), cout << endl;
#endif
    {
        v2 = std::move(v2);
    }

    v = v2;
    StrVec v3 = v;
//	v.operator=(v2);
//	StrVec().operator=(v2);
}
コード例 #18
0
ファイル: tfidf.hpp プロジェクト: herumi/cybozulib
	void append(const std::string& word)
	{
		std::string lower;
		cybozu::ToLower(lower, word);
		std::pair<Str2Int::iterator, bool> ret = word2id_.insert(Str2Int::value_type(lower, (int)id2word_.size()));
//printf("word=%s, id=%d, ret=%d\n", ret.first->first.c_str(), ret.first->second, ret.second);
		if (ret.second) {
			id2word_.push_back(lower);
			df_.resize(id2word_.size());
		}
		if (set_.insert(word).second) {
			df_[ret.first->second]++;
		}
	}
コード例 #19
0
void EventsGenerator::desiresCB(const hbba_msgs::DesiresSet::ConstPtr& msg)
{
	typedef std::vector<std::string> StrVec;
	typedef std::list<std::string> StrList;
	typedef std::vector<hbba_msgs::Desire> DesVec;
	typedef std::map<std::string,std::string> TypeMap;
	const DesVec& desires = msg->desires;
	TypeMap typeMap;
	StrVec ids;
	ids.reserve(desires.size());
	for (DesVec::const_iterator d = desires.begin(); d != desires.end(); ++d)
	{
		ids.push_back(d->id);
		typeMap[d->id] = d->type;
	}

    // First, remove desires not in it the current desires set.
    StrList del;
    for (Model::const_iterator i = model_.begin(); i != model_.end(); ++i)
    {
        const std::string& id = i->first;
        if (std::find(ids.begin(), ids.end(), id) == ids.end())
            del.push_back(id);
    }
    for (StrList::const_iterator i = del.begin(); i != del.end(); ++i)
    {
        const std::string& id = *i;
	
        event(id, model_[id].type, hbba_msgs::Event::DES_OFF);
        if (model_[id].flags & FLAG_INT)
            event(id, model_[id].type, hbba_msgs::Event::INT_OFF);
        if (model_[id].flags & FLAG_EXP)
            event(id, model_[id].type, hbba_msgs::Event::EXP_OFF);

        model_.erase(id);
    }

	// Then, generate events for new desires.
	for (StrVec::const_iterator i = ids.begin(); i != ids.end(); ++i)
	{
		const std::string& id = *i;
		if (model_.find(id) == model_.end())
		{
			model_[id].flags = FLAG_NONE;
			model_[id].type = typeMap[id]; //set type in the model
			event(id, model_[id].type, hbba_msgs::Event::DES_ON);
		}
	}

}
コード例 #20
0
static StrVec
conn_get_table_list (dbi_conn conn, const std::string& dbname,
                     const std::string& table)
{
    StrVec retval;
    const char* tableptr = (table.empty() ? nullptr : table.c_str());
    auto tables = dbi_conn_get_table_list (conn, dbname.c_str(), tableptr);
    while (dbi_result_next_row (tables) != 0)
    {
        std::string table_name {dbi_result_get_string_idx (tables, 1)};
        retval.push_back(table_name);
    }
    dbi_result_free (tables);
    return retval;
}
コード例 #21
0
ファイル: Applic.cpp プロジェクト: PIfagor/AliceGame
void App::loadSearthPaths(const rapidjson::Document & doc)
{
	StrVec paths;
	std::string prefix;

	// slave paths depend on resolution, so we need to add prefix
	if (_resolution == Resolution::REGULAR_RES) {
		paths.push_back(REGULAR_RESOLUTION_PATH);
		prefix = REGULAR_RESOLUTION_PATH + "/";
	}
	else {
		paths.push_back(RETINA_RESOLUTION_PATH);
		prefix = RETINA_RESOLUTION_PATH + "/";
	}

	const rapidjson::Value & genPathArr = doc["generalSearchPaths"];
	for (rapidjson::SizeType i = 0; i < genPathArr.Size(); ++i) {
		std::string path = genPathArr[i].GetString();
		paths.push_back(path);
	}

	const rapidjson::Value & slavePathArr = doc["slaveSearchPaths"];
	for (rapidjson::SizeType i = 0; i < slavePathArr.Size(); ++i) {
		std::string path = prefix + slavePathArr[i].GetString();
		paths.push_back(path);
	}

	for (auto it = paths.begin(); it != paths.end(); ++it) {
		std::stringstream ss;
		ss << "Path added: " << *it;
		CCLOG(ss.str().c_str());
	}


	FileUtils::getInstance()->setSearchPaths(paths);
}
コード例 #22
0
ファイル: main.cpp プロジェクト: SnakeSolidNL/tools
int strsplit_slash(string& st, StrVec& vec)
{
    vec.clear();
    int last_pos=0;
    int pos=0;
    int max_pos=st.size();
    while(pos<max_pos)
    {
        last_pos=pos;
        while(st[pos]!='/' && pos<max_pos) pos++;
        vec.push_back(st.substr(last_pos,pos-last_pos));
        while(st[pos]=='/' && pos<max_pos) pos++;
    }
    return vec.size();
}
コード例 #23
0
ファイル: attack.cpp プロジェクト: herumi/msoffice
	Option(int argc, const char *const argv[])
	{
		cybozu::Option opt;
		std::string charSetFile;
		std::string dicFile;
		bool debug;
		opt.appendOpt(&charSetFile, "", "cf", "char set file");
		opt.appendOpt(&threadNum, 4, "t", "thread num");
		opt.appendOpt(&dicFile, "", "d", "dictionary file");
		opt.appendOpt(&passLen, 0, "l", "length of pass");
		opt.appendBoolOpt(&debug, "v", "verbose message");
		opt.appendHelp("h");
		opt.appendParam(&encFile, "encrypted file");
		if (!opt.parse(argc, argv)) {
			opt.usage();
			exit(1);
		}
		if (debug) ms::setDebug(1);
		if (charSetFile.empty()) {
			charSet = "abcdefghijklmnopqrstuvwxyz"
			          "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
					  "0123456789-_";
		} else {
			std::ifstream ifs(charSetFile.c_str(), std::ios::binary);
			if (!std::getline(ifs, charSet)) {
				fprintf(stderr, "can't read char set file [%s]\n", charSetFile.c_str());
				exit(1);
			}
			trim(charSet);
		}
		if (!dicFile.empty()) {
			std::ifstream ifs(dicFile.c_str(), std::ios::binary);
			std::string line;
			while (std::getline(ifs, line)) {
				trim(line);
				toUtf8(line);
				passSet.push_back(line);
			}
			if (passSet.empty()) {
				fprintf(stderr, "can't read dicFile [%s]\n", dicFile.c_str());
				exit(1);
			}
			std::sort(passSet.begin(), passSet.end(), &lessByLength);
		}
		if (ms::isDebug()) {
			opt.put();
		}
	}
コード例 #24
0
int main()
{
    StrVec vec;
    vec.reserve(6);
    std::cout << "capacity(reserve to 6): " << vec.capacity() << std::endl;

    vec.reserve(4);
    std::cout << "capacity(reserve to 4): " << vec.capacity() << std::endl;

    vec.push_back("hello");
    vec.push_back("world");

    vec.resize(4);

    for (auto i = vec.begin(); i != vec.end(); ++i)
        std::cout << *i << std::endl;
    std::cout << "-EOF-" << std::endl;

    vec.resize(1);

    for (auto i = vec.begin(); i != vec.end(); ++i)
        std::cout << *i << std::endl;
    std::cout << "-EOF-" << std::endl;

    StrVec vec_list{ "hello", "world", "pezy" };

    for (auto i = vec_list.begin(); i != vec_list.end(); ++i)
        std::cout << *i << " ";
    std::cout << std::endl;

    // Test operator==

    const StrVec const_vec_list{ "hello", "world", "pezy" };
    if (vec_list == const_vec_list)
        for (const auto &str : const_vec_list)
            std::cout << str << " ";
    std::cout << std::endl;

    // Test operator<
    const StrVec const_vec_list_small{ "hello", "pezy", "ok" };
    std::cout << (const_vec_list_small < const_vec_list) << std::endl;

    // Test []
    std::cout << const_vec_list_small[1] << std::endl;
}
コード例 #25
0
ファイル: fileutils.cpp プロジェクト: Lingrui/TS
StrVec read_list (const char* fname)
{
    StrVec rv;
    LineReader rd (fname);
    char *l, *lc;
    while ((l = rd.nextLine ()))
    {
        // find first token and add to rv
        while (*l && isspace (*l)) l ++;
        if (!*l) continue;
        lc = l + 1;
        while (*lc && !isspace (*lc)) lc ++;
        *lc = 0;
        rv.push_back (l);
    }
    rd.close ();
    return rv;
}
コード例 #26
0
ファイル: RedisClient.cpp プロジェクト: cchd0001/gld_work
StrVec RedisClient::SMembers(const std::string& key){
    StrVec vec;
    if(key.empty()) 
        return vec;
    std::stringstream sm;
    sm << "SMEMBERS " << key;
    redisReply *redis_reply = RedoCommand(sm.str(),REDIS_REPLY_ARRAY);
    if ( redis_reply ) {
        for (size_t i=0; i<redis_reply->elements; ++i) {
            auto reply = redis_reply->element[i];
            if (reply->type == REDIS_REPLY_STRING) {
                vec.push_back(reply->str);
            }
        }
    }
    freeReplyObject_Safe(redis_reply);
    return vec;
}
コード例 #27
0
ファイル: RedisClient.cpp プロジェクト: cchd0001/gld_work
StrVec RedisClient::HKeys(const std::string & hask_name){
    StrVec vec;
    if(hask_name.empty())
        return vec;
    std::stringstream sm;
    sm << "HKEYS " << hask_name;
    redisReply *redis_reply = RedoCommand(sm.str(),REDIS_REPLY_ARRAY);
    if ( redis_reply ) {
        for (size_t i=0; i<redis_reply->elements; ++i) {
            auto reply = redis_reply->element[i];
            if (reply->type == REDIS_REPLY_STRING) {
                vec.push_back(reply->str);
            }
        }
    }
    freeReplyObject_Safe(redis_reply);
    return vec;
}
コード例 #28
0
ファイル: RedisClient.cpp プロジェクト: cchd0001/gld_work
StrVec RedisClient::ZRevrange(const std::string& key, const int start, const int stop){
    StrVec vec;
    if(key.empty())
        return vec;
    std::stringstream sm;
    sm << "ZREVRANGE " << key << " " << start << " " << stop;
    redisReply *redis_reply = RedoCommand(sm.str(),REDIS_REPLY_ARRAY);
    if ( redis_reply ) {
        for (uint32_t i=0 ; i<redis_reply->elements; i++ ) {
            auto reply = redis_reply->element[i];
            if (reply!=NULL && reply->type==REDIS_REPLY_STRING) {
                vec.push_back(reply->str);
            }
        }
    }
    freeReplyObject_Safe(redis_reply);
    return vec;
}
コード例 #29
0
template<> StrVec
GncDbiProviderImpl<DbType::DBI_SQLITE>::get_index_list (dbi_conn conn)
{
    StrVec retval;
    const char* errmsg;
    dbi_result result = dbi_conn_query (conn,
                                        "SELECT name FROM sqlite_master WHERE type = 'index' AND name NOT LIKE 'sqlite_autoindex%'");
    if (dbi_conn_error (conn, &errmsg) != DBI_ERROR_NONE)
    {
        PWARN ("Index Table Retrieval Error: %s\n", errmsg);
        return retval;
    }
    while (dbi_result_next_row (result) != 0)
    {
        std::string index_name {dbi_result_get_string_idx (result, 1)};
        retval.push_back(index_name);
    }
    dbi_result_free (result);
    return retval;
}
コード例 #30
0
ファイル: tfidf.hpp プロジェクト: herumi/cybozulib
	bool loadKeywordFile(const std::string& keyFile)
	{
		std::ifstream ifs(keyFile.c_str(), std::ios::binary);
		if (!ifs) return false;
		std::string word;
		while (std::getline(ifs, word)) {
			size_t pos = word.find('\t');
			if (pos == std::string::npos) break;
			word.resize(pos);
			std::pair<Str2Int::iterator, bool> ret = word2id_.insert(Str2Int::value_type(word, (int)id2word_.size()));
			if (ret.second) {
				id2word_.push_back(word);
			} else {
				fprintf(stderr, "ERR already set %s\n", word.c_str());
			}
		}
		df_.resize(id2word_.size());
		fprintf(stderr, "#word = %d\n", (int)df_.size());
		return true;
	}