예제 #1
0
bool XorEncryptor::encryptData(std::fstream &original, std::fstream &result)
{
	if (!original.is_open() || !result.is_open())
	{
		return false;
	}

	original.seekg(0, std::ios::beg);
	result.seekp(0, std::ios::beg);

	char c = 0;
	unsigned i = 0;
	while (original.good())
	{
		original.read(&c, 1);
		c ^= password[i];
		if(original.gcount() > 0)
		{
			result.write(&c, 1);
		}

		if (++i == passSize)
		{
			i = 0;
		}
	}

	original.seekg(0, std::ios::beg);
	result.seekg(0, std::ios::beg);
	result.flush();

	return true;
}
예제 #2
0
bool Organism::Load (std::fstream &File) {
   File.read ((char *) &StateCount,   sizeof (int));
   File.read ((char *) &SensorCount,  sizeof (int));
   File.read ((char *) &CurrentState, sizeof (int));
   
   // Allocate memory for states:
   delete [] States;
   States = new State [StateCount];

   // Load states:
   int i;
   for (i = 0; i < StateCount; i++) {
      if (!States [i].Load (File))
         return false;
   }

   // Allocate memory for the sensors:
   delete [] Sensors;
   Sensors = new Sensor [SensorCount];

   // Load sensors:
   for (i = 0; i < SensorCount; i++) {
      if (!Sensors [i].Load (File))
         return false;
   }

   // Load the genome:
   if (!OrgGenome.Load (File))
      return false;

   if (!File.good ())
      return false;

   return true;
}
예제 #3
0
bool write(std::fstream& file, Json::Value const& root)
{
   Json::StyledWriter writer;
   std::string val = writer.write(root);
   LOG4CPLUS_INFO(CFileStorage::msLogger, val);
   file << val;
   file.flush();
   file.seekg(0, ios::beg);
   return file.good();
}
예제 #4
0
void manageFile(std::fstream &InputFile, std::vector<Operator> &operators)
{
	std::cout << "File is opened" << std::endl;
	if (InputFile.good())
	{
		std::string line = "";
		while (std::getline(InputFile, line))
		{
			fillOperators(line, operators);
		}
	}
}
예제 #5
0
static void readBoolean(std::fstream &str, bool &res)
{
  if(!str.good()){
    return;
  }
  std::string tmp;
  str>>tmp;
  std::transform(tmp.begin(), tmp.end(), tmp.begin(), ::tolower);
  if(tmp.find("true", 0) != std::string::npos){
    res = true;
  }else{
    res = false;
  }
}
예제 #6
0
bool CLayer:: read_layer_multi_contour_with_z(std::fstream& fin)
{

  int pos=-1;
  float levelID;
  int contourID;
  bool result=true;

  if (fin.good())
  {
    pos=fin.tellg();
    fin>>levelID;
    fin>>contourID;
    fin.seekg(pos);
  }
예제 #7
0
bool Organism::State::Save (std::fstream &File) {
   // File format:
   //              Count         sizeof (int)
   //              Name          sizeof (char) * Count

   int Count = Name.size() + 1;

   File.write ((const char *) &Count, sizeof (int));
   File.write ((const char *) Name.c_str(), sizeof (char) * Count);

   if (!File.good ())
      return false;

   return true;
}
예제 #8
0
bool Organism::State::Load (std::fstream &File) {
   int Count;

   File.read ((char *) &Count, sizeof (int));

   char *cname = new char [Count];
   File.read ((char *) cname, sizeof (char) * Count);

	Name = cname;

	delete [] cname;

   if (!File.good ())
      return false;

   return true;
}
예제 #9
0
void resultsfile::checkformodifications(std::fstream& file)
   {
   assert(file.good());
   trace << "DEBUG (resultsfile): checking file for modifications." << std::endl;
   // check for user modifications
   sha curdigest;
   file.seekg(0);
   curdigest.process(file);
   // reset file
   file.clear();
   if (curdigest == filedigest)
      file.seekp(fileptr);
   else
      {
      cerr << "NOTICE: file modifications found - appending." << std::endl;
      // set current write position to end-of-file
      file.seekp(0, std::ios_base::end);
      fileptr = file.tellp();
      }
   }
예제 #10
0
////////////////////////////////////////////////////////////////////////////////////
///
///   \brief Reads a line from a fstream adding it to a string, reading up
///          to a newline character.
///
///   \param[in] str File stream operator.
///   \param[out] line Line read from file (doesn't include carriage return).
///
///   \return Number of characters read.
///
////////////////////////////////////////////////////////////////////////////////////
unsigned int FileIO::ReadLine(std::fstream& str,
                              std::string& line)
{
    char ch;
    line.reserve(512);
    line.clear();
    while(str.eof() == false && str.good())
    {
        str.get(ch);
        if(ch == '\n')
        {
            break;
        }
        else
        {
            line.push_back(ch);
        }
    }

    return (unsigned int)line.size();
}
예제 #11
0
int main()
{
    
    f1.open("/Users/robinmalhotra2/Desktop/csl201check.txt",std::ios::in|std::ios::out);
    
    f1.getline(s, 80, ' ');
        while (f1.good())
    {

        
        
        
       
        std::cout<<"addasd";
        if ((strlen(s)==1) && (s[0])<'9' && (s[0])>'0')
            
        {
            switch ((s[0]))
            {
                    
                case '1':
                    createandprintlist();
                    
                
                    break;
                    
                case '2':
                    sortlist();
                    break;
                    
                case '3':
                    nextinsert();
                    break;
                    
                case '4':
                    searchlist();
                    break;
                    
                case '5':
                    deletenext();
                    break;
                    
                case '6':
                    deduplicate();
                    break;
                    
                case '7':
                    mergesortthing();
                    break;
                    
                case '8':
                    credits();
                    break;
                    
                    
                    
                default:
                    break;
            }
        }
        
        
    }
    f1.close();
    
    
    
}
예제 #12
0
파일: osfile.cpp 프로젝트: HalalUr/Reaping2
bool OsFileImpl::IsValid() const
{
    return mFile.good();
}
예제 #13
-9
bool OpenFile(const std::wstring& aFile, std::fstream& aStream,
			  std::ios_base::open_mode aMode)
{
	std::string s;
	aStream.open(Ucs2ToUtf8(aFile, s).c_str(), aMode);
	return aStream.good();
}
예제 #14
-28
static bool loadY4MHeader(std::fstream& fs, cv::Mat &img)
{
    fs.seekg(fs.beg);
    if (fs.good())
    {
        char inbuf [256];
        fs >> inbuf;
        if (strcmp(inbuf, "YUV4MPEG2") != 0)
        {
            return false;
        }
        fs.get(); // space
        int width, height;
        char c = fs.get();
        if (c != 'W')
        {
            return false;
        }
        fs >> width;
        c = fs.get();// space
        c = fs.get();
        if (c != 'H')
        {
            return false;
        }
        fs >> height;
        img.create(height * 3 / 2, width, CV_8UC1);
    }
예제 #15
-33
bool Organism::Save (std::fstream &File) const {
   // File format:
   //          StateCount         sizeof (int)
   //          SensorCount        sizeof (int)
   //          CurrentState       sizeof (int)
   //          States             sizeof (State) * StateCount
   //          Sensors            sizeof (Sensor) * SensorCount
   //          OrgGenome          varies
   File.write ((const char *) &StateCount,   sizeof (int));
   File.write ((const char *) &SensorCount,  sizeof (int));
   File.write ((const char *) &CurrentState, sizeof (int));
   
   // Save states:
   int i;
   for (i = 0; i < StateCount; i++) {
      if (!States [i].Save (File))
         return false;
   }

   // Save sensors:
   for (i = 0; i < SensorCount; i++) {
      if (!Sensors [i].Save (File))
         return false;
   }

   // Save the genome:
   if (!OrgGenome.Save (File))
      return false;

   if (!File.good ())
      return false;

   return true;
}
예제 #16
-47
void checkIfWriteSucceed(std::fstream& logFile)
{
    // The logFile.good returns 1 if everything was ok at the last op.
    // exitIfFail checks if the number she gets is not zero, so we use the not
    // to flip good to match exitIfFail
    exitIfFail(!logFile.good());
}