Esempio n. 1
0
string trimmedName(string& s)
{
    //printf("splitting %s\n",s.c_str());
    StrVec vec;
    int n=strsplit_slash(s, vec);

    //for(int i=0;i<n;i++) printf("  '%s'\n",vec[i].c_str());

    unsigned int i=0;
    while(i<vec.size())
    {
        if(i>0)
        {
            if(vec[i]==".." && vec[i-1]!="..")
            {
                i--;
                vec.erase(vec.begin()+i,vec.begin()+i+2);
                continue;
            }
        }

        i++;
    }
    if(!vec.size()) return "";
    string ret="";
    for(unsigned int i=0; i<vec.size(); i++)
    {
        ret+=vec[i];
        if(i+1!=vec.size()) ret+="/";
    }
    return ret;
}
Esempio n. 2
0
bool operator>=(const StrVec &lhs, const StrVec &rhs)
{
	auto sz = lhs.size() < rhs.size() ? lhs.size() : rhs.size();
	auto pl = lhs.begin(), pr = rhs.begin();
	while (sz-- && *pl == *pr)
		++pl, ++pr;
	return sz ? *pl >= *pr : pr == rhs.end();
}
Esempio n. 3
0
bool operator==(const StrVec &lhs, const StrVec &rhs)
{
	if (lhs.size() != rhs.size())
		return false;
	for (auto pl = lhs.begin(), pr = rhs.begin(); pl != lhs.end(); )
		if (*pl != *pr)
			return false;
	return true;
}
Esempio n. 4
0
StrVec read_lists (const StrVec& fnames)
{
    StrVec rv;
    StrVec::const_iterator itr = fnames.begin ();
    while (itr != fnames.end ())
    {
        StrVec vals = read_list (*itr);
        std::copy (vals.begin (), vals.end (), std::back_inserter (rv));
        itr ++;
    }
    return rv;
}
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);
		}
	}

}
bool operator==(const StrVec& lhs, const StrVec& rhs)
{
    if(lhs.size() != rhs.size())
    {
        return false;
    }
    for(auto itrL=lhs.begin(), itrR=rhs.begin(); itrL!=lhs.end(), itrR!=rhs.end(); itrL++, itrR++)
    {
        if(itrL != itrR)
        {
            return false;
        }
    }
    return true;
}
Esempio n. 7
0
bool TestPathops::process ()
{
#ifdef _MSC_VER
    const char* paths [] = {"\\kokos\\banan", "d:\\Encyclopedia\\Data\\Genomes\\E.coli.K12\\proteins\\fasta\\", "", "\\", "\\ananas\\", NULL};
#else
    const char* paths [] = {"/kokos/banan", "~/Encyclopedia/Data/Genomes/E.coli.K12/proteins/fasta/", "", "/", "/ananas/", NULL};
#endif
    const char** path = paths;
    for (; *path != NULL; path ++)
    {
        o_ << "Path " << *path << std::endl;
        StrVec comps = split_path (*path);
        o_ << "path " << *path << ", " << comps.size () << " components" << std::endl;
        StrVec::const_iterator i = comps.begin ();
        for (;i < comps.end (); i ++)
            o_ << "  '" << (*i).c_str () << "'" << std::endl;
        std::string rejoined = join_path (comps);
        o_ << "  Rejoined: " << rejoined.c_str () << std::endl;
    }

    std::string jp = join_path ("kokos", "banan", "ananas", "yabloko", NULL);
    o_ << jp.c_str () << std::endl;
    jp = join_path ("", "kokos", NULL);
    o_ << jp.c_str () << std::endl;
    jp = join_path ("", NULL);
    o_ << jp.c_str () << std::endl;
    jp = join_path ("kokos", NULL);
    o_ << jp.c_str () << std::endl;
    jp = join_path (NULL);
    o_ << jp.c_str () << std::endl;
    return true;
}
Esempio n. 8
0
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]));
	}
}
Esempio n. 9
0
StrVec::StrVec(const StrVec &s)
{
	using namespace std;
	auto newdata = alloc_n_copy(s.begin(), s.end());
	elements = newdata.first;
	first_free = cap = newdata.second;
}
Esempio n. 10
0
void display(const StrVec &s)
{
	for (auto p = s.begin(); p != s.end(); ++p)
	{
		std::cout << *p << " ";
	}
	std::cout << std::endl;
}
Esempio n. 11
0
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;
}
Esempio n. 12
0
StrVec::StrVec(const StrVec& orig) 
{	
	// call alloc_n_copy to allocate space and copy data
	auto newData = alloc_n_copy(orig.begin(), orig.end());
	// update pointers
	elements = newData.first;
	first_free = cap = newData.second;
}
Esempio n. 13
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;
}
Esempio n. 14
0
std::string join_path (StrVec components)
{
    std::string rv = EMPTY_STR;
    StrVec::const_iterator itr = components.begin ();
    int prevlen = 0;
    bool firstcomp = true;
    for (;itr != components.end (); itr ++)
    {
        if (prevlen || (itr != components.begin () && firstcomp))
            rv += PATH_SEPARATOR;
        rv += *itr;
        prevlen = (*itr).length ();
        if (itr != components.begin ())
            firstcomp = false;
    }
    if (!rv.length ())
        rv += PATH_SEPARATOR;
    return rv;
}
Esempio n. 15
0
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;
}
Esempio n. 16
0
std::string make_temp_fname (const char* tmpdir, const char* prefix)
{
    // if directory not passed in, guess one
    std::string tn = temp_dir (tmpdir);;

    // if prefix not passed in, use default
    if (!prefix) prefix = DEFAULT_TEMP_FILE_PREFIX;

    // get temp directory listing
    StrVec dircontent = listdir (tn);

    // find all entries matching prefix and having numeric postfix, get list of numbers
    UintSet postfixes;
    unsigned prefix_len = prefix ? strlen (prefix) : 0;
    for (StrVec::iterator ii = dircontent.begin (); ii != dircontent.end (); ii ++)
    {
        // check if prefix matches
        if (prefix_len && (ii->substr (0, prefix_len) != prefix))
            continue;
        // check if postfix is numeric and get the number
        unsigned number = 0;
        std::string::iterator sitr;
        for (sitr = ii->begin () + prefix_len; sitr != ii->end (); sitr ++)
        {
            number *= 10;
            if (!isdigit (*sitr))
                break;
            else
                number += *sitr - '0';
        }
        if (sitr != ii->end ())
            continue;
        // store number to postfixes set
        postfixes.insert (number);
    }
    // now retrieve the numbers using first gap
    // make a set for quick presence check
    unsigned prev = 0;
    for (UintSet::iterator nitr = postfixes.begin (); nitr != postfixes.end (); nitr ++)
        if (prev + 1 < *nitr)
            break; // found the gap in sequence
        else
            prev = *nitr;
    if (prev == std::numeric_limits<unsigned>::max ()) // just for sanity :)
        ers << "No more temp file names available for prefix " << (prefix ? prefix : "") << " in directory " << tn << Throw;

    // prev + 1 is the right number
    std::ostringstream name (tn, std::ios::out | std::ios::app);
    name << PATH_SEPARATOR;
    if (prefix) name << prefix;
    name << prev + 1;
    return name.str ();
}
//! copy constructor
StrVec::StrVec(const StrVec &s)
{
	/**
	* @brief newData is a pair of pointers pointing to newly allocated and copied
	*                  range : [b, e)
	*/
	std::pair<std::string*, std::string*>
		newData = alloc_n_copy(s.begin(), s.end());

	element = newData.first;
	first_free = cap = newData.second;
}
Esempio n. 18
0
void
GncSqlBackend::ObjectBackendRegistry::load_remaining(GncSqlBackend* sql_be)
{

    for (auto entry : m_registry)
    {
        std::string type;
        GncSqlObjectBackendPtr obe = nullptr;
        std::tie(type, obe) = entry;

        /* Don't need to load anything if it has already been loaded with
         * the fixed order.
         */
        if (std::find(fixed_load_order.begin(), fixed_load_order.end(),
                      type) != fixed_load_order.end()) continue;
        if (std::find(business_fixed_load_order.begin(),
                      business_fixed_load_order.end(),
                      type) != business_fixed_load_order.end()) continue;

        obe->load_all (sql_be);
    }
}
Esempio n. 19
0
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;
}
Esempio n. 20
0
	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();
		}
	}
Esempio n. 21
0
// 全テーブルを取得し、string t と一致するテーブルのみを削除
static void
initTableFunc(std::string t, HbaseClient client)
{
    std::cout << "scanning tables..." << std::endl;
    StrVec tables;
    client.getTableNames(tables);
    for (StrVec::const_iterator it = tables.begin(); it != tables.end(); ++it) {
      std::cout << "  found: " << *it << std::endl;
      if (t == *it) {
        if (client.isTableEnabled(*it)) {
          std::cout << "    disabling table: " << *it << std::endl;
          client.disableTable(*it);
        }
        std::cout << "    deleting table: " << *it << std::endl;
        client.deleteTable(*it);
      }
    }
}
Esempio n. 22
0
File: SLData.cpp Progetto: clagv/sl
 bool Data::erase(const std::string& key, size_t keyIdx)
 {
     if(keyIdx < m_keyIdx.size())
     {
         KeyIdx ki(key, 0);
         size_t pos = (std::lower_bound(m_keyIdx.begin(), m_keyIdx.end(), ki, key_less) - m_keyIdx.begin()) + keyIdx;
         if(pos < m_keyIdx.size() && key_eql(ki, m_keyIdx[pos]))
         {
             // users shouldn't really erase keys while reading data but ...
             if(m_pos < m_keyIdx.size() && m_pos > pos)
                 --m_pos;
             m_keyIdx.erase(m_keyIdx.begin() + pos);
             m_keys.erase(m_keys.begin() + pos);
             m_varData.erase(m_varData.begin() + pos);
             return true;
         }
     }
     return false;
 }
Esempio n. 23
0
bool TestFileUtils :: process ()
{
    std::string fname = fixture_.dirname ();
    fname += path_separator ();
    fname += "*.txt";
    StrVec sv;
    expand_wildcards (fname.c_str (), sv);
    StrVec::iterator itr = sv.begin ();
    for (; itr != sv.end (); itr ++)
    {
        o_ << (*itr).c_str () << std::endl;
    }
    if (!sv.size ())
    {
        o_ << "No files to test reader" << std::endl;
        return false;
    }

    LineReader lr (sv.front ().c_str ());
    char* ln;
    int no = 0;
    int slen = 0;
    time_t st = time (NULL);
    while ((ln = lr.nextLine ()))
    {
        ++ no;
        slen += strlen (ln);
        //if (strlen (ln) > 100) o_ << ln;
        if (no % 100000 == 0)
        {
            int td = time (NULL) - st;
            double rd = double (slen) / (1024*1024);
            o_ << "\rline " << no << ", " << rd << " Mb, average speed " << rd / (td?td:1) << " Mb/s    " << std::flush;
        }
    }
    time_t et = time (NULL);
    lr.close ();
    return true;
}
Esempio n. 24
0
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);
}
Esempio n. 25
0
	int count(vector <string> answer) {
		int ans = 0;
		int N = (int)answer.size(), M = (int)answer[0].length();
		for (int b = 0; b < (1 << M); ++b) {
			StrVec v = answer;
			for (int i = 0; i < M; ++i) {
				if ((1 << i) & b) {
					for (int j = 0; j < N; ++j) {
						v[j][i] = ' ';
					}
				}
			}
			sort(v.begin(), v.end());
			int i;
			for (i = 1; i < N; ++i) {
				if (v[i - 1].compare(v[i]) == 0) {
					break;
				}
			}
			ans += i >= N;
		}
		return ans;
	}
Esempio n. 26
0
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);
}
Esempio n. 27
0
StrVec::StrVec(const StrVec& rhs)
{
    range_initialize(rhs.begin(), rhs.end());
}
Esempio n. 28
0
bool operator>(const StrVec &s1, const StrVec &s2) {
    return std::lexicographical_compare(s2.begin(), s2.end(), s1.begin(), s1.end());
}
Esempio n. 29
0
extern "C" int test_table()
{
    char buf[8][1024];
    int i;
    bool isFramed = false;
    bool tmptable = false;
    boost::shared_ptr<TTransport> socket(new TSocket("localhost", 9090));
    boost::shared_ptr<TTransport> transport;
    if (isFramed)
    {
        transport.reset(new TFramedTransport(socket));
    }
    else
    {
        transport.reset(new TBufferedTransport(socket));
    }
    boost::shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));

    const std::map<Text, Text>  dummyAttributes; // see HBASE-6806 HBASE-4658
    HbaseClient client(protocol);
    try
    {
        transport->open();
        std::string t[]= {"T1","T2","T3","T4","T5","T6","T7","T8"};
        StrVec tables;
        client.getTableNames(tables);

        for(i=0; i<8; i++)
        {
            tmptable = false;
            StrVec::const_iterator it = tables.begin();
            for (StrVec::const_iterator it = tables.begin(); it != tables.end(); ++it)
            {
                if (t[i] == *it)
                {
                    tmptable = true;
                }
            }
            if(!tmptable)//创建表
            {
                ColVec columns;
                columns.push_back(ColumnDescriptor());
                columns.back().name = "PROTOCOL";
                columns.push_back(ColumnDescriptor());
                columns.back().name = "INPUT_SNMP";
                columns.push_back(ColumnDescriptor());
                columns.back().name = "OUTPUT_SNMP";
                columns.push_back(ColumnDescriptor());
                columns.back().name = "IN_PKTS";
                columns.push_back(ColumnDescriptor());
                columns.back().name = "IN_BYTES";
                columns.push_back(ColumnDescriptor());
                columns.back().name = "SRC_TOS";
                columns.push_back(ColumnDescriptor());
                columns.back().name = "SRC_AS";
                columns.push_back(ColumnDescriptor());
                columns.back().name = "DST_AS";
                columns.push_back(ColumnDescriptor());
                columns.back().name = "TCP_FLAGS";
                std::cout << "creating table: " << t[i] << std::endl;
                try
                {
                    client.createTable(t[i], columns);
                }
                catch (const AlreadyExists &ae)
                {
                    std::cerr << "WARN: " << ae.message << std::endl;
                }
            }
        }
    }
    catch (const TException &tx)
    {
        std::cerr << "ERROR: " << tx.what() << std::endl;
    }
    return 0;
}
Esempio n. 30
0
 // copy controls
 StrVec(const StrVec &rhs)
 {
     auto vec = alloc_and_copy(rhs.begin(), rhs.end());
     element_ = vec.first;
     free_ = cap_ = vec.second;
 }