Example #1
0
bool CSpringGame::FileExists(std::string filename) {
    filename = ConfigFolderPath() + std::string("/ai/")+filename;
    std::ifstream InFile( filename.c_str());
    bool r = InFile.is_open();
    if(r) {
        InFile.close();
    }
    return r;
}
Example #2
0
bool gmfCompiler::encode(const char* filename, const char* cfg)
{
	std::string m_filename(filename);

	if ( m_filename.empty() )
	{
		return false;
	}

	// open file
	FILE* tmpFile = fopen( m_filename.c_str(), "rb" );

	TCHAR* strMeshData = NULL;

	if (tmpFile)
	{
		fseek(tmpFile, 0, SEEK_END);
		uint32 size = ftell(tmpFile);
		fseek(tmpFile, 0, SEEK_SET);

		strMeshData = new TCHAR[size];
		fread( strMeshData, 1, size, tmpFile );

		fclose(tmpFile);
	}

	// File input
	TCHAR strCommand[256] = {0};
	gkStdStringstream InFile( strMeshData );

	if( !InFile )
	{
		delete[] strMeshData;
		return false;
	}
	for(; ; )
	{
		InFile >> strCommand;
		if( !InFile )
			break;

		if( 0 == _tcscmp( strCommand, _T("#") ) )
		{
			// Comment
		}
		else if( 0 == _tcscmp( strCommand, _T("v") ) )
		{
			// Vertex Position
			float x, y, z;
			InFile >> x >> y >> z;
			m_positions.push_back( Vec3( x, y, z ) );
		}
		else if( 0 == _tcscmp( strCommand, _T("vt") ) )
Example #3
0
cObject* ObjLoader::LoadOBJFromFile(const char* FileName)
{
	if(FileName == 0)
		return NULL;

	std::vector<glm::vec3>  VertexList;
	std::vector<glm::vec2>  TexCoordList;
	std::vector<glm::vec3>  NormalList;
	std::vector<bgMaterial>  MatrialList;

    char Command[256] = {0};
    ifstream InFile(FileName);
	if(!InFile){ 
		return NULL;
	}

	char MaterialFilename[MAX_PATH] = {0};
	StringCchCopy(MediaPath, MAX_PATH -1, FileName);	
	if(char* pch = _tcsrchr(MediaPath, _T('\\'))){
		 StringCchCopy(MediaPath, pch+2 - MediaPath, MediaPath);
	}
	
	cGeometryObject *pOBJModel = new cGeometryObject();
	cModel* pModel = new cModel;
	pOBJModel->ModelList.push_back(pModel);

	cStringHelper StringHelper;
	size_t NumFace  = 0;
	char TitleName[MAX_PATH] = {0};
	cFileHelper FileHelper;
	FileHelper.GetFileNameTitle(FileName,TitleName, MAX_PATH -1);
	pOBJModel->Name = TitleName ; //StringHelper.charToString(TitleName);
	
	for(;;)
    {
        InFile >> Command;
        if( !InFile )
            break;
        
        if( 0 == strcmp(Command, "#"))
        {
            // Comment
        }
        else if(0 == strcmp(Command, "v"))
        {
            // Vertex Position
            float x, y, z;
            InFile >> x >> y >> z;
			VertexList.push_back(glm::vec3(x, y, z)); 			
        }
        else if(0 == strcmp(Command, "vt"))
Example #4
0
flusspferd::string JS_fread( flusspferd::string fileName )
{
	std::string inputBuffer;
	char cBuf[1025];
	std::ifstream InFile( (std::string("./js_files/") + fileName.to_string()).c_str() );
	if( InFile.is_open() )
	{
		InFile.get(cBuf, 1024);
		cBuf[ InFile.gcount() ] = '\0';
		InFile.close();
		return flusspferd::string( cBuf );
	}
	return flusspferd::string( "" );
}
Example #5
0
std::string CSpringGame::ReadFile(std::string filename) {

    std::ifstream InFile( filename.c_str());
    if( !InFile ) {
        //cerr << "Couldn't open input file" << endl;
        return "";
    }

    std::string s ="";

    // create reader objects
    std::istream_iterator<std::string> DataBegin( InFile );
    std::istream_iterator<std::string> DataEnd;

    while( DataBegin != DataEnd ) {
        s += *DataBegin;
        DataBegin++;
    }
    return s;
}
Example #6
0
void CQSV2FLVDlg::OnBnClickedBtnAdd()
{
	// TODO: 添加文件列表
	CString		szFileName;
	CString		szCount;
	POSITION	pos;
	int			i;
	int			nCount=0;		//文件数量
	//输入文件
	CFileDialog InFile( TRUE,NULL,NULL,OFN_FILEMUSTEXIST|OFN_ALLOWMULTISELECT,_T("奇艺视频|*.QSV|所有文件(*.*)|*.*||") );
	InFile.m_ofn.nMaxFile  = 10000;		//文件上限
	InFile.m_ofn.lpstrFile = (LPWSTR)malloc(InFile.m_ofn.nMaxFile*sizeof(TCHAR));
	memset(InFile.m_ofn.lpstrFile,0,InFile.m_ofn.nMaxFile);

	nCount = m_ctrlList.GetItemCount();
	if(InFile.DoModal() == IDOK)
	{
		pos=InFile.GetStartPosition(); 
		while(pos)
		{	
			szFileName=InFile.GetNextPathName(pos);
			m_ctrlList.InsertItem(nCount,  NULL);	//添加行
			m_ctrlList.SetItemText(nCount, 1, szFileName);
			m_ctrlList.SetItemText(nCount, 2, TEXT("就绪") );
			nCount++;
		}
		for(i=0; i<nCount; i++)
		{
			szCount.Format(_T("%d"),i+1);
			m_ctrlList.SetItemText(i,0,szCount);
		}
		GetDlgItem(IDC_BTN_DEL)->EnableWindow(TRUE);	//启用START
		GetDlgItem(IDC_BTN_START)->EnableWindow(TRUE);
	}
	free(InFile.m_ofn.lpstrFile);
}
Example #7
0
void CWorldsDlg::OnWorldDecompress()
{

	//first off, we need to get the filename of the selected item
	CString sInFileName = GetSelectedItemFileName();

	int nDotPos = sInFileName.ReverseFind('.');
	if(nDotPos == -1)
		return;

	CString sExt = sInFileName.Mid(nDotPos + 1);
	if(sExt.CompareNoCase("ltc") != 0)
		return;

	//make sure it is compressed
	if(CLTAUtil::IsFileCompressed(sInFileName) == false)
	{
		//this shouldn't ever happen. The wrong menu item managed to come up
		ASSERT(false);
		return;
	}

	//make sure that the region we are compressing is not open for editing
	for(uint32 nCurrRegion = 0; nCurrRegion < GetProjectBar()->m_RegionDocs.GetSize(); nCurrRegion++)
	{
		if(sInFileName.CompareNoCase(GetProjectBar()->m_RegionDocs[nCurrRegion]->m_FileName) == 0)
		{
			//they are trying to compress a file that is open, we can't allow this, otherwise
			//when they save, it will save to the wrong filename. Another approach
			//would be to update the region's filename, but I don't think I'll have enough
			//time to thoroughly test this to my satisfaction, so I'll go with the error
			MessageBox(	sInFileName + " is currently open for editing.\nYou must close this file before you decompress it",
						"Cannot Decompress Open File", MB_ICONEXCLAMATION | MB_OK);
			return;
		}
	}



	CString sOutFileName = ConvertExtension(sInFileName, ".ltc", ".lta");

	//see if the file already exists
	if(DoesFileExist(sOutFileName) == TRUE)
	{
		//prompt the user with an overwrite prompt
		if(MessageBox("The file " + sOutFileName + " already exists.\nWould you like to overwrite this file?",
					"File already exists", MB_ICONQUESTION | MB_YESNO) == IDNO)
		{
			//the user didn't want to overwrite the file
			return;
		}
	}

	//now we open up the input file, and compress it
	BeginWaitCursor();

	CLTAFile InFile(sInFileName, true, true);
	//make sure the files opened okay
	if(InFile.IsValid() == false)
	{
		MessageBox(	"Unable to open " + sInFileName + " for reading\nDecompression not performed", 
					"Error", MB_ICONEXCLAMATION | MB_OK);
		return;
	}

	CLTAFile OutFile(sOutFileName, false, false);
	//make sure the files opened okay
	if(OutFile.IsValid() == false)
	{
		MessageBox(	"Unable to open " + sOutFileName + " for writing\nDecompression not performed", 
					"Error", MB_ICONEXCLAMATION | MB_OK);
		return;
	}

	//now we just decompress
	uint8 nByte;
	while(InFile.ReadByte(nByte))
	{
		if(OutFile.WriteByte(nByte) == false)
		{
			MessageBox(	"Error while saving to " + sOutFileName + "\nDecompression not performed",
						"Error", MB_ICONEXCLAMATION | MB_OK);
			return;
		}
	}

	//close out the files
	InFile.Close();
	OutFile.Close();

	//now we need to delete the input file
	// Delete the world
	if (!DeleteFile(sInFileName))
	{
		MessageBox("Error deleting world" + sInFileName, "Error", MB_OK | MB_ICONEXCLAMATION);
		return;
	}

	// Refresh the display list
	PopulateList();

	EndWaitCursor();
}
void TForm1::AnalyseOneFunction(int &FunctionCount, int NumberOfCalls, AnsiString FunctionString, std::ofstream &OutFile)
{
AnsiString Prelim = "./";
for(int x=0;x<5000;x++)
    {
    DupNumArray[x] = -1;
    MissingNumArray[x] = -1;
    }
Label1->Caption = "Analysing function:   " + FunctionString + " (" + AnsiString(FunctionCount + 1) + "/" + AnsiString(NumberOfCalls) + ")";
Form1->Repaint();
int DupNumArrayIndex = 0;
for(int x=0;x<NumFiles;x++)
    {
    AnsiString FullFileName = Prelim + FileString[x];
    std::ifstream InFile(FullFileName.c_str());
    if(InFile == 0)
        {
        ShowMessage("Input file failed to open - " + FileString[x]);
        return;
        }
    char Buffer[5000];
    bool EndOfFile = false;
    while(!EndOfFile)
        {
        InFile.getline(Buffer, 5000);
        AnsiString OneLine(Buffer);
        for(int x = 1; x< OneLine.Length() - FunctionString.Length() + 1;x++)
            {
            if(OneLine.SubString(x,FunctionString.Length() + 1) == FunctionString + '(')
            //rule out other functions that contain the sought function name (allow to be preceded by space, !, ., > or (
                {if((x == 1) || (OneLine[x-1] < '"') || (OneLine[x-1] == '.') || (OneLine[x-1] == '>') || (OneLine[x-1] == '('))
                    {
                    AnsiString NumberLineStr = OneLine.SubString(x + FunctionString.Length() + 1,OneLine.Length() - (x + FunctionString.Length() + 1));
                    AnsiString NumberString = "";
                    while((NumberLineStr.Length() > 0) && ((NumberLineStr[1] <= '9') && (NumberLineStr[1] >= '0')))
                        {
                        NumberString+= NumberLineStr[1];
                        NumberLineStr.Delete(1,1);
                        }
                    if(NumberString != "")
                        {
                        int Number = NumberString.ToInt();
                        DupNumArray[DupNumArrayIndex] = Number;
                        DupNumArrayIndex++;
                        }
                    }
                }
            }
        if(InFile.eof())
            {
            EndOfFile = true;
            }
        }
    InFile.close();
    }
//Label1->Caption = "Array analysis started for function " + FunctionString;
//Form1->Repaint();
int MaxIndex = -1;//so first brings it to 0
int MaxNumber = -1;
for(int x=0;x<5000;x++)
    {
    if(DupNumArray[x] > -1)
        {
        MaxIndex++;
        if(DupNumArray[x] > MaxNumber) MaxNumber = DupNumArray[x];
        }
    else break;
    }
for(int x=0;x<MaxIndex+1;x++)
    {
    MissingNumArray[x] = DupNumArray[x];
    }
//check for duplicates
for(int x=0;x<MaxIndex + 1;x++)
    {
    int CheckNumber = DupNumArray[x];
    if(CheckNumber == -1) continue;
    int RepeatCount = 0;
    for(int y=x+1;y<MaxIndex + 1;y++)
        {
        if(DupNumArray[y] == CheckNumber)
            {
            RepeatCount++;
            DupNumArray[y] = -1;//so it isn't counted again if appears more than twice in all
            }
        }
    if(RepeatCount > 0)
        {
        AnsiString MessageString = "Number " + AnsiString(CheckNumber) + " repeated " + AnsiString(RepeatCount) + " times in function " + FunctionString;
        if(Screen)
            {
            int button = Application->MessageBox(MessageString.c_str(), "", MB_OKCANCEL);
            if (button == IDCANCEL)
                {
                BreakFlag = true;
                return;
                }
            }
        if(Print) OutFile << MessageString.c_str() << CHAR(13) << CHAR(10);
        }
    }

//now check for missing numbers
if(CheckBox1->Checked)
    {
    int IncNumber = 0;
    bool FoundFlag=false;
    while(IncNumber <= MaxNumber)
        {
        FoundFlag = false;
        for(int x=0;x<MaxIndex + 1;x++)
            {
            if(MissingNumArray[x] == IncNumber)
                {
                FoundFlag = true;
                break;
                }
            }
        if(!FoundFlag)
            {
            AnsiString MessageString = "Number " + AnsiString(IncNumber) + " missing for function " + FunctionString;
            if(Screen)
                {
                int button = Application->MessageBox(MessageString.c_str(), "", MB_OKCANCEL);
                if (button == IDCANCEL)
                    {
                    BreakFlag = true;
                    return;
                    }
                }
            if(Print) OutFile << MessageString.c_str() << CHAR(13) << CHAR(10);
            }
        IncNumber++;
        }
    }
FunctionCount++;
}
Example #9
0
int main(int argc, char* argv[]) {
  Env = TEnv(argc, argv, TNotify::StdNotify);
  Env.PrepArgs(TStr::Fmt("Flow. build: %s, %s. Time: %s", __TIME__, __DATE__, TExeTm::GetCurTm()));
  double NetPRTimeSum = 0;
  double NetEKTimeSum = 0;
  int NumWins = 0;
  Try
  const TStr InFNm = Env.GetIfArgPrefixStr("-i:", "", "Input file");
  const int Iters = Env.GetIfArgPrefixInt("-n:", 10, "Number of runs per thread");
  const int Threads = Env.GetIfArgPrefixInt("-t:", 4, "Number of threads");
  printf("Integer Flow Test\n");
  printf("Filename: %s\n", InFNm.CStr());
  printf("Building Network...\n");
  TFIn InFile(InFNm);
  // If the input file is a binary, use the following line to load the network
  PNEANet Net = TNEANet::Load(InFile);
  // If the input file is a text file, use the following to load the network and save as binary
  // PNEANet Net;
  // int MaxEdgeCap = BuildCapacityNetwork(InFNm, Net);
  // const TStr OutFNm = Env.GetIfArgPrefixStr("-o:", "", "Output file");
  // TFOut OutFile(OutFNm);
  // Net->Save(OutFile);
  printf("PNEANet Nodes: %d, Edges: %d\n\n", Net->GetNodes(), Net->GetEdges());
  #pragma omp parallel for reduction(+:NetEKTimeSum,NetPRTimeSum,NumWins) schedule(static, 1)
  for (int t = 0; t < Threads; t++) {
    TRnd Random(t);
    for (int i = 0; i < Iters; i++) {
      int SrcNId = Net->GetRndNId(Random);
      int SnkNId = Net->GetRndNId(Random);

      double PRBeginTime = getcputime();
      int NetMaxFlowPR = TSnap::GetMaxFlowIntPR(Net, SrcNId, SnkNId);
      double PREndTime = getcputime();
      double NetPRFlowRunTime = PREndTime - PRBeginTime;

      double EKBeginTime = getcputime();
      int NetMaxFlowEK = TSnap::GetMaxFlowIntEK(Net, SrcNId, SnkNId);
      double EKEndTime = getcputime();
      double NetEKFlowRunTime = EKEndTime - EKBeginTime;
      
      IAssert(NetMaxFlowPR == NetMaxFlowEK);

      if (NetPRFlowRunTime < NetEKFlowRunTime) { NumWins++; }

      NetPRTimeSum += NetPRFlowRunTime;
      NetEKTimeSum += NetEKFlowRunTime;
      
      #pragma omp critical
      {
#ifndef NOMP
        printf("Thread: %d\n", omp_get_thread_num());
#endif
        printf("Source: %d, Sink %d\n", SrcNId, SnkNId);
        printf("Max Flow: %d\n", NetMaxFlowEK);
        printf("PR CPU Time: %f\n", NetPRFlowRunTime);
        printf("EK CPU Time: %f\n", NetEKFlowRunTime);
        printf("\n");
      }
    }
  }
  int TotalRuns = Iters*Threads;
  printf ("Avg PR PNEANet Time: %f\n", NetPRTimeSum/TotalRuns);
  printf ("Avg EK PNEANet Time: %f\n", NetEKTimeSum/TotalRuns);
  printf ("%d out of %d PR was faster\n", NumWins, TotalRuns);
  Catch
  return 0;
}
Example #10
0
BOOL CFilterDialog::OnInitDialog() 
{
	CDialog::OnInitDialog();

	//Read user selections from the Usersel.
	CString QCATFilterSel = "";
	CString MatchCaseState = "";
	CString StringFiterSel = "";
	m_check_case = true;

	char InString[StringLength];
	CString UserSelectionFilePathName = ExecutablePath + "UserSelection.cfg";
	ifstream InUserSel(UserSelectionFilePathName,ios::nocreate);
	if (InUserSel.is_open())
	{
		InUserSel.getline(InString,StringLength);
		QCATFilterSel = InString;
		InUserSel.getline(InString,StringLength);
		MatchCaseState = InString;
		if (MatchCaseState == "ON")
			m_check_case = true;
		else 
			m_check_case = false;
		InUserSel.getline(InString,StringLength);
		m_FiltersPath = InString;
		InUserSel.getline(InString,StringLength);
		StringFiterSel = InString;
	}
	InUserSel.close();

	//Read the "QCATCodes.txt" file in order to extract the QCAT filtre codes
	CString QCATCodesFilePathName = ExecutablePath + "QCATCodes.txt";
	ifstream InFile(QCATCodesFilePathName);
	while(!InFile.eof())
	{
		InFile.getline(InString,StringLength);
		CString str1 = InString;
		if (!str1.IsEmpty())
		{
			CString str2 = str1.Left(str1.Find(" CODE:"));
			str1.Replace(str2 + " CODE:","");
			m_QCATCodeaMap.SetAt(str2,str1); //load the QCAT filter name and code in a MAP structure
		}
	}
		//Fill the QCAT list control wiht the CODES names
	m_QCAT_Filters.InsertColumn(0, "String", LVCFMT_LEFT, 400); //Set 1 column for the list control
	m_QCAT_Filters.ModifyStyle(NULL, LVS_REPORT | LVS_NOCOLUMNHEADER); //Set the list control to report style without column header
	m_QCAT_Filters.SetExtendedStyle(LVS_EX_CHECKBOXES); //Use the check boxes with list control

	m_QCATFilters = "";
	POSITION pos = m_QCATCodeaMap.GetStartPosition();
	int nItem;
	CString key, value;
	int count = 0;
	CString str = QCATFilterSel.Left(QCATFilterSel.Find(';')); //QCATFilterSel conatins the least of the filter the user selected last time
	QCATFilterSel.Replace(str + "; ",""); //Extract the left-most filter name from QCATFilterSel
	while (pos != NULL)
	{
		m_QCATCodeaMap.GetNextAssoc(pos, key, value);
		nItem = m_QCAT_Filters.InsertItem(count, key); //Add the filter name to the list control
		if (str == key) //If the filter name is one the user had selected last time...
		{
			m_QCAT_Filters.SetCheck(count,true); //Set it checked
			str = QCATFilterSel.Left(QCATFilterSel.Find(';')); //Extract the next filter name the user had selected last time from QCATFilterSel
			QCATFilterSel.Replace(str + "; ","");
		}
		count++;
	}

	//This bit of code reads the files names from a folder and put it in a list structure
	WIN32_FIND_DATA ff;
//	HANDLE findhandle = FindFirstFile( FilterFolder + "\\*.flt", &ff ); //FilterFolder conatins the user selected folder with the strings
	HANDLE findhandle = FindFirstFile( m_FiltersPath + "\\*.flt", &ff ); //FilterFolder conatins the user selected folder with the strings
	if( findhandle != INVALID_HANDLE_VALUE )
	{
		BOOL res = TRUE;
		while( res )
		{
			// We only want files
			if( !( ff.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) )
			{
				BOOL    added = FALSE;
				CString file;
				file = ff.cFileName;

				// Return the array alphabetically ordered
				for( int i = 0; i < m_FilterList.GetSize(); i++ )
				{
					if ( m_FilterList.GetAt( i ) > file )
					{
						m_FilterList.InsertAt( i, file );
						added = TRUE;
						break;
					}
				}
				if ( !added )
				{
					m_FilterList.Add( file );
				}
			}

			res = FindNextFile( findhandle, &ff );
		}

		FindClose( findhandle );
	}

	//Fill the string list control wiht the filter names
	m_String_Filters.InsertColumn(0, "String", LVCFMT_LEFT, 400);
	m_String_Filters.ModifyStyle(NULL, LVS_REPORT | LVS_NOCOLUMNHEADER);
	m_String_Filters.SetExtendedStyle(LVS_EX_CHECKBOXES);

	m_StringFilters = "";
	CString StrTemp = StringFiterSel.Left(StringFiterSel.Find(';')); //Extarct from StringFiterSel the first filter the user selected last time
	StringFiterSel.Replace(StrTemp + "; ","");
	for ( count = 0; count < m_FilterList.GetSize(); count++)
	{
		int nItem = m_String_Filters.InsertItem(count, m_FilterList.GetAt( count ));
		if (StrTemp == m_FilterList.GetAt( count )) //If the filter was used last time as well...
		{
			m_String_Filters.SetCheck(count,true); //set it cheked
			StrTemp = StringFiterSel.Left(StringFiterSel.Find(';')); //Extract the next filter used last time
			StringFiterSel.Replace(StrTemp + "; ","");
		}
	}

	UpdateData(false);

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
Example #11
0
bool HdfsLoader::load(double sample_rate){
#ifdef HDFS_LOAD
	if(Config::local_disk_mode) {
		connector_ = new LocalDiskConnector(writepath);
	}
	else {
		connector_ = new HdfsConnector(writepath);
	}
	connector_->openFiles(open_flag_);
#endif

	if (open_flag_ == CREATE)
	{
		//TODO: for reloading after select, unbinding the original data
		if (table_descriptor_->getProjectoin(0)->getPartitioner()->allPartitionBound())
		{
			for(int i = 0; i < table_descriptor_->getNumberOfProjection(); i++)
			{
				for(int j = 0; j < table_descriptor_->getProjectoin(i)->getPartitioner()->getNumberOfPartitions(); j++)
				{
					Catalog::getInstance()->getBindingModele()->UnbindingEntireProjection(table_descriptor_->getProjectoin(i)->getPartitioner());
				}
			}
		}
		cout << "\n\n\n--------------------------Load Begin!--------------------------\n";
	}
	else
		cout << "\n\n\n--------------------------Append Begin!--------------------------\n";

	vector<string>::iterator iter;
/*for testing*/	int t_count = 1;
	for (iter = file_list.begin(); iter != file_list.end(); iter++)
	{
		ifstream InFile((*iter).c_str());
		if(!InFile.good()){
			printf("Cannot open source file:%s , reason: %s\n",(*iter).c_str(),strerror(errno));
			return false;
		}
		while(!InFile.eof()/* for testing && t_count++ < 500 */)
		{
			s_record.clear();
			getline(InFile,s_record,row_separator);
			if((double)rand()/RAND_MAX>sample_rate)
				continue;
///*for testing*/ if(row_id/t_count > 100000)
///*for testing*/		break;

			//TODO(yukai): get the return value and handle it
			insertRecords();
		}
		InFile.close();
/*for testing*/	t_count++;
	}

	cout << "----------------------------"<<endl;

	//flush the last block which is not full of 64*1024Byte
	for(int i = 0; i < table_descriptor_->getNumberOfProjection(); i++)
	{
		for(int j = 0; j < table_descriptor_->getProjectoin(i)->getPartitioner()->getNumberOfPartitions(); j++)
		{
			if(!pj_buffer[i][j]->Empty())
			{
				pj_buffer[i][j]->serialize(*sblock);

#ifdef HDFS_LOAD
				tSize num_written_every64k_bytes = connector_->flush(i, j, sblock->getBlock(), sblock->getsize());
				//hdfsWrite(connector_->get_fs(), connector_->get_writefile()[i][j], (void*)sblock->getBlock(), sblock->getsize());
#endif
				cout << row_id << "\tThe last block has written to HDFS!\n";

				blocks_per_partition[i][j]++;
				pj_buffer[i][j]->setEmpty();
			}
		}

	}

///*for testing begin*/
//	for(int i = 0; i < table_descriptor_->getNumberOfProjection(); i++)
//	{
//		for(int j = 0; j < table_descriptor_->getProjectoin(i)->getPartitioner()->getNumberOfPartitions(); j++)
//		{
//			cout << blocks_per_partition[i][j] << " ";
//		}
//		cout << endl;
//	}
///*for testing end*/

#ifdef HDFS_LOAD
	if(connector_->closeFiles() == false)
	{
		cout << "Failed to close HDFS." << endl;
		exit(-1);
	}else
 		cout << "HDFS close successfully." << endl;
#endif

	//register the number of rows in table to catalog
	table_descriptor_->setRowNumber(row_id);
	//register the partition information to catalog
	for(int i = 0; i < table_descriptor_->getNumberOfProjection(); i++)
	{
		for(int j = 0; j < table_descriptor_->getProjectoin(i)->getPartitioner()->getNumberOfPartitions(); j++)
		{
//			table_descriptor_->getProjectoin(i)->getPartitioner()->RegisterPartitionWithNumberOfBlocks(j, blocks_per_partition[i][j],tuples_per_partition[i][j]);
			table_descriptor_->getProjectoin(i)->getPartitioner()->RegisterPartitionWithNumberOfBlocks(j, blocks_per_partition[i][j]);
			if (open_flag_ == APPEND)
			{
				table_descriptor_->getProjectoin(i)->getPartitioner()->UpdatePartitionWithNumberOfChunksToBlockManager(j, blocks_per_partition[i][j]);
			}
			cout << "Number of blocks " << i << "\t" << j << "\t: " << blocks_per_partition[i][j] << endl;
		}
	}
	if (open_flag_ == CREATE)
		cout << "\n\n\n--------------------------Load End!--------------------------\n";
	else
		cout << "\n\n\n--------------------------Append End!--------------------------\n";
 	return true;
}
Example #12
0
//called to load in a sprite file and build up information about it
bool CSpriteFile::Load(const char* pszFilename)
{
	//open up the file
#if _MSC_VER >= 1300
	std::ifstream InFile( pszFilename, std::ios::in | std::ios::binary );
#else
	ifstream InFile(pszFilename, ios::in | ios::nocreate | ios::binary);
#endif
	//check the open
	if(!InFile)
		return false;

	//now read in the header data
	uint32 nTempVal;

	//read in the number of frames
	InFile.read((char*)&nTempVal, sizeof(nTempVal));

	//resize accordingly
	if(!SetNumFrames(nTempVal))
		return false;

	//read in the rest of the header
	InFile.read((char*)&m_nFrameRate, sizeof(m_nFrameRate));

	InFile.read((char*)&nTempVal, sizeof(nTempVal));
	m_bTransparent = !!nTempVal;
	InFile.read((char*)&nTempVal, sizeof(nTempVal));
	m_bTranslucent = !!nTempVal;

	InFile.read((char*)&m_nKey, sizeof(m_nKey));


	//now read in all the names
	for(uint32 nCurrFrame = 0; nCurrFrame < m_nNumFrames; nCurrFrame++)
	{
		//the name of the frame
		char pszFrame[MAX_PATH + 1];

		//the length of the name
		uint16 nStrLen = 0; 

		//read in the name
		InFile.read((char*)&nStrLen, sizeof(nStrLen));

		//now read in each character
		for(uint32 nCurrChar = 0; nCurrChar < nStrLen; nCurrChar++)
		{
			char ch;
			InFile.read(&ch, sizeof(ch));

			if(nCurrChar < MAX_PATH)
			{
				pszFrame[nCurrChar] = ch;
				pszFrame[nCurrChar + 1] = '\0';
			}
		}

		//now set this name
		SetFrame(nCurrFrame, pszFrame);
	}

	//success
	return true;
}