コード例 #1
0
ファイル: VEditCommon.cpp プロジェクト: amongll/AVFX
void parse_macros(const char* str, hash_multimap<string, int>& idxes,
		vector<string>& segments)
{

	if ( !str || !strlen(str) ) {
		idxes.clear();
		segments.clear();
		return;
	}

	string v (str);
	//string cur_token;

	size_t	pend_pos = 0, chk_pos =  0;
	size_t	ps1,ps2;

	do {
		ps1 = v.find("#(", chk_pos);
		if( ps1 != string::npos ) {
			ps2  = v.find(")", ps1 + 2);
			if (ps2 != string::npos) {
				if ( ps1 + 2 == ps2 ) {
					chk_pos = ps2 + 1;
				}
				else {
					string nm = v.substr(ps1 + 2, ps2 - ps1 - 2 );
					if ( is_valid_identifier(nm.c_str()) ) {
						if (pend_pos < ps1) {
							segments.push_back(v.substr(pend_pos, ps1 - pend_pos));
						}
						chk_pos = pend_pos =  ps2 + 1;
						segments.push_back(nm);
						idxes.insert(make_pair(nm, segments.size() -1 ));
						//idxes[nm] = segments.size() - 1;
					}
					else {
						chk_pos = ps2 + 1;
					}
				}
			}
			else {
				//chk_pos = cur_token.size();
				chk_pos = v.size();
			}
		}
		else {
			//chk_pos = cur_token.size();
			chk_pos = v.size();
		}

		if (chk_pos == v.size()) {
			if ( pend_pos < chk_pos ) {
				segments.push_back(v.substr(pend_pos, chk_pos - 1));
			}
			break;
		}
	} while(1);
}
コード例 #2
0
ファイル: data.cpp プロジェクト: mokayy/KDDCup2011
void read_trackData()
{
	FILE *fp = fopen("trackData1.txt","r");
	int value;
	char *cur;
	char buf[200];
	int trackid, albumid, artistid;
	while(! feof(fp) ) {
		fgets(buf, 200, fp);
		if (feof(fp)) break;

		trackid = atoi(strtok(buf, "|"));

		if(imap.count(trackid) == 0 )
			continue;
		int iid = imap[trackid];
		items[iid].type = TRACK;
		cur = strtok(NULL, "|");
		if (cur[0] != 'N') {
			albumid = atoi(cur);
			items[iid].albumid = albumMap[albumid];
		}
		cur = strtok(NULL, "|");
		if (cur[0] != 'N') {
			artistid = atoi(cur);
			items[iid].artistid = artistMap[artistid];
		}
		while( (cur = strtok(NULL, "|")) != NULL) {
			int value = atoi(cur);
			int gid = genreMap[value];
			genreItemMap.insert(hash_multimap<int,int>::value_type(iid, gid));
		}
	}
}
コード例 #3
0
ファイル: data.cpp プロジェクト: mokayy/KDDCup2011
void read_albumData()
{
	FILE *fp = fopen("albumData1.txt","r");
	int value;
	char *cur;
	char buf[200];
	int trackid, albumid, artistid;
	int aid = 0;
	while(! feof(fp) ) {
		fgets(buf, 200, fp);
		if (feof(fp)) break;

		albumid = atoi(strtok(buf, "|"));
		albumMap[albumid] = aid;

		if (imap.count(albumid) != 0) {
			int iid = imap[albumid];
			cur = strtok(NULL, "|");

			items[iid].albumid = aid;
			if (cur[0] != 'N') {
				items[iid].artistid = artistMap[atoi(cur)];
			}
			while( (cur = strtok(NULL, "|")) != NULL) {
				int value = atoi(cur);
				int gid = genreMap[value];
				genreItemMap.insert(hash_multimap<int,int>::value_type(iid, gid));
			}
		}
		aid++;
	}
}
コード例 #4
0
ファイル: data.cpp プロジェクト: mokayy/KDDCup2011
void read_genres()
{
	FILE *fp = fopen("genreData1.txt","r");
	int lines = 0, value;
	int gid = 0;
	while(! feof(fp) ) {
		fscanf(fp, "%d\n", &value);
		if(feof(fp)) break;
		genreMap[value] = gid;
		if(imap.count(value) > 0) {
			int iid = imap[value];
			items[iid].type = GENRE;
			genreItemMap.insert(hash_multimap<int,int>::value_type(iid, gid));
		}
		gid++;
	}
}