예제 #1
0
void Lexical :: tokenCheck(char *t)
{
	fstream f;

	f.open("keywords.txt", ios::in);
	char *k;
	int check=0;

	while(!f.eof())
	{
		if(f.eof())
			break;

		f.getline(k, '\n');
		if(strcmpi(k,t) == 0)
		{
			check=1;
			break;
		}
	}

	if(check==1)
	{
		kwd.write(t, strlen(t));
		kwd<<"\n";
	}
	else
	{
		idf.write(t, strlen(t));
		idf<<"\n";
	}
	f.close();
}
예제 #2
0
//----------------------------------------------------------------------------------------------
int ObjectSerializer::SerializeBasicType(char* pMem, TypeNode* pType, fstream& pen)
{
	int size = m_basicTypeSize[pType->Type];
	bool isNull = false;
	_ASSERTE(pType->Children.size() == 0);

	// Continuous pointers to scattered basic-type data
	if (pType->Indirection)
	{
		unsigned* addr32 = reinterpret_cast<unsigned*>(pMem);
		isNull = (*addr32 == NULL);
		pen.write(reinterpret_cast<char*>(&isNull), sizeof(bool));
		if (!isNull)
		{
			pMem = reinterpret_cast<char*>(*addr32);
			pen.write(pMem, size);
		}
		size = sizeof(unsigned);
	}
	// Continuous basic-type data values
	else
	{
		pen.write(pMem, size);
	}

	return size;
}
예제 #3
0
// Writes a line in a binary file
// Format: word_id, doc_id, freq_in_doc, position
void InvertedIndex::write_line(int word_id, int doc_id, int freq, int pos, fstream& file){
	// file << word_id << doc_id << freq << pos;
	file.write((const char*) &word_id, sizeof(word_id));
	file.write((const char*) &doc_id, sizeof(doc_id));
	file.write((const char*) &freq, sizeof(freq));
	file.write((const char*) &pos, sizeof(pos));
}
/**************************************************
 *       Write a Structure to a File              *
 **************************************************
 * Purpose:  Write an array structure to a file
 * Input:
 *    file-> Where to write
 * Output:
 *    a-> The structure that contains the data
 */
void wrtStrc(fstream & file,Array *a){
    //Write the size of the array
    file.write(reinterpret_cast<char *>(&a->size),sizeof(a->size));
    //Write the array elements
    file.write(reinterpret_cast<char *>(a->data),
                          a->size*sizeof(a->size));
}
예제 #5
0
파일: main.cpp 프로젝트: kenalv/Datos2
int main()
{
//insertar Arcos
    struct arcoArch reg1;

    strcpy(reg1.destino, "Ana");
    strcpy(reg1.dirigido, "TRUE");
    reg1.distancia = 100;
    reg1.velocidad = 80;
    reg1.sig=-1;
    archivoArcos.write(reinterpret_cast<char *>(&reg1),sizeof(reg1));
//Insertar Archivo Ciudades


    struct conductoresArch reg2;

    strcpy(reg2.nombreConductor, "Kenneth");
    strcpy(reg2.tipoVehiculo, "New");
    reg2.der=3;
    reg2.izq = -1;
    reg2.id = 30;
    archivoConductores.write(reinterpret_cast<char *>(&reg2),sizeof(reg2));

        archivoArcos.seekg(sizeof(0,ios::beg));
        archivoArcos.read(reinterpret_cast<char*>(&reg1),sizeof(reg1));
    cout<<sizeof(reg1);
    return 0;
}
예제 #6
0
    void BoundingVolume::WriteBV(fstream &fout, BoundingVolume* bvPtr)
    {
        unsigned int bvType = bvPtr->GetCOType();
        fout.write( (char*)&bvType, sizeof(unsigned int) );

        switch(bvType)
        {
        case EDCO_SPHERE:
            {
                Sphere* spherePtr = (Sphere*)bvPtr;

                fout.write( (char*)spherePtr->center.v, sizeof(Float3) );
                fout.write( (char*)&spherePtr->radius, sizeof(float) );
            }
            break;
        case EDCO_AABB:
            {
                Aabb* aabbPtr = (Aabb*)bvPtr;

                fout.write( (char*)aabbPtr->min.v, sizeof(Float3) );
                fout.write( (char*)aabbPtr->max.v, sizeof(Float3) );
            }
            break;
        default:
            break;
        }	
    }
예제 #7
0
//----------------------------------------------------------------------------------------------
int ObjectSerializer::SerializeUserDefinedType(ISerializable *pObj, TypeNode* pType, bool isPtr, fstream& pen)
{
	int     size = 0;
	bool    isNull = false;

	if (isPtr)
	{
		// Access the pointer pointed by the pointer to pointer
		pObj = (*(ISerializable**)pObj);
		int         length = 0;
		string      typeName;
		char        buffer[MaxTypeNameLength + 1];

		isNull = (NULL == pObj);
		pen.write(reinterpret_cast<char*>(&isNull), sizeof(bool));

		if (!isNull)
		{
			auto        objLayout = pObj->GetObjectLayout();

			typeName = g_ObjectFactory.FromCName(objLayout.CName());

			PerformLateBinding(pObj, pType);

			length = typeName.size();
			_ASSERTE(length <= MaxTypeNameLength);
			strcpy_s(buffer, typeName.c_str());
			buffer[length] = 0;
			pen.write(buffer, MaxTypeNameLength + 1);

			Iterator* addresses = objLayout.GetIterator();
			unsigned* addr32;
			for (int memberIdx = 0; addresses->MoveNext(); ++memberIdx)
			{
				_ASSERTE(memberIdx < pType->Children.size());
				addr32 = reinterpret_cast<unsigned*>(addresses->Current());
				SerializeType(reinterpret_cast<char*>(*addr32), pType->Children[memberIdx].Ptr32, pen);
			}
		}
		size = sizeof(unsigned);
	}
	else
	{
		auto objLayout = pObj->GetObjectLayout();
		Iterator* addresses = objLayout.GetIterator();
		unsigned* addr32;
		for (int memberIdx = 0; addresses->MoveNext(); ++memberIdx)
		{
			_ASSERTE(memberIdx < pType->Children.size());
			addr32 = reinterpret_cast<unsigned*>(addresses->Current());
			SerializeType(reinterpret_cast<char*>(*addr32), pType->Children[memberIdx].Ptr32, pen);
		}

		size = objLayout.TypeSize();
	}

	return size;
}
예제 #8
0
void Hme_tree_gateway::save_model(fstream &save_stream) {
	bool is_leaf = false;
	save_stream.write((char*) &is_leaf, sizeof(is_leaf));
	for (size_t i = 0; i != parameters_count_; i++) {
		save_stream.write((char*) A_ + i, sizeof(A_[i]));
	}
	left_child_->save_model(save_stream);
	right_child_->save_model(save_stream);
}
예제 #9
0
void function1(const char *path){
	ifstream in(path);
    //ofstream out1("D:\\131250072_1.txt");
    ofstream out1("131250072_1.txt");
    char a[1024] = {0};

	if (in.is_open() && out1.is_open() && back.is_open()){
        int index = 0;
        int len = 0;
		while(in.getline(a, 1024)){
            index = 0;
            len = 0;
            while (split(&a[index], &len)){
                switch(legal_str(&a[index], len)) {
                    case '+':
                        code_plus(&a[index], len);
                        my_lower(&a[index], len-1);
                        out1.write(&a[index], len-1);//omit the sign of '+'
                        back.write(&a[index], len-1);
                        break;
                    case '-':
                    {
                        char res[MAX_WORD] = {0};
                        code_minus(&a[index], len, res);
                        my_lower(&a[index], len);
                        out1.write(res, strlen(res));
                        back.write(res, strlen(res));
                        break;
                    }
                    case '*':
                        asp(&a[index], len);
                        my_lower(&a[index], len);
                        out1.write(&a[index], len);
                        back.write(&a[index], len);
                        break;
                    case STR:
                        my_lower(&a[index], len);
                        out1.write(&a[index], len);
                        back.write(&a[index], len);
                        break;
                    default:
                        cout << "illegal char" << endl;
                        break;
                }
                index += len;
            }
            out1 << endl;
            back << " ";
		}
        out1.close();
        back << endl;// without it getline fail to read from it????

	} else {
		cout << "no file" << endl;
	}
}
void BackpropagationPerceptron::save(fstream &save_stream) {
	save_stream.write((char*) &add_const_x_, sizeof(add_const_x_));
	save_stream.write((char*) &layers_count_, sizeof(layers_count_));
	save_stream.write((char*) layer_neuron_count_, sizeof(layer_neuron_count_[0]) * layers_count_);
	for (size_t i = 0; i != layers_count_ - 1; i++) {
		for (size_t j = 0; j != W_[i]->rows_count(); j++) {
			save_stream.write((char*) (*W_[i])[j], sizeof(*(*W_[i])[j]) * W_[i]->columns_count());
		}
	}
}
bool Entity_ParticleSystemType::serialize(fstream& file)
{
    if(!file.is_open()) return false;
    file.write((char*) &type, sizeof(type)); //so that when we read in the file, we can tell which type of entity it is.
    int entity_signtype_version = 2;
    file.write((char*) &entity_signtype_version, sizeof(entity_signtype_version));
    file.write((char*) &x, sizeof(x));
    file.write((char*) &y, sizeof(y));
    file.write((char*) &w, sizeof(w));
    file.write((char*) &h, sizeof(h));
    file.write((char*) &texture_index, sizeof(texture_index));
    return true;
}
예제 #12
0
파일: main.cpp 프로젝트: qingping95/ACM
void write_bmp_paltte()        //灰度图像需要调色板
{
    unsigned char j=0;
    unsigned char z=0;
    for (int i=0;i<1024;i+=4)
    {
        output_file.write((char*)&j,sizeof(unsigned char));
        output_file.write((char*)&j,sizeof(unsigned char));
        output_file.write((char*)&j,sizeof(unsigned char));

        output_file.write((char*)&z,sizeof(unsigned char));
        j++;
    }
}
예제 #13
0
bool Entity_DeathLaserType::serialize(fstream& file)
{
    if(!file.is_open()) return false;
    string::size_type type_length = type.size();
    file.write((char*) &type_length, sizeof type_length);
    file.write(type.data(), type_length); //this is so when we open the file, we can know who this entity is. (Basically my shitty programming, not knowing of Templates)
    int Entity_DeathLaserType_version = 1;
    file.write((char*) &Entity_DeathLaserType_version, sizeof(Entity_DeathLaserType_version));
    file.write((char*) &x, sizeof(x));
    file.write((char*) &y, sizeof(y));
    file.write((char*) &w, sizeof(w));
    file.write((char*) &h, sizeof(h));
    return true;
}
예제 #14
0
void Configuration::writeBin_ (fstream& f) const
{
	size_t tmp1, tmp2;
	
	// writing all the Configuration type variables
	tmp1 = cvars.size ();
	f.write ( (const char*) &tmp1, sizeof ( tmp1 ) );
	for ( size_t i = 0; i < tmp1; i++ )
	{
		// writing the size and the name itself
		tmp2 = cvars[i].name ().size ();
		f.write ( (const char*) &tmp2, sizeof ( tmp2 ) );
		f.write ( cvars[i].name ().c_str (), tmp2 );
		
		cvars[i].value ().writeBin_ ( f );
	}
	
	// writing all the data variables
	tmp1 = vars.size ();
	f.write ( (const char*) &tmp1, sizeof ( tmp1 ) );
	for ( size_t i = 0; i < tmp1; i++ )
	{
		// writing the size and the name itself
		tmp2 = vars[i].name ().size ();
		f.write ( (const char*) &tmp2, sizeof ( tmp2 ) );
		f.write ( vars[i].name ().c_str (), tmp2 );
		
		// writing the size and the value itself
		tmp2 = vars[i].value ().size ();
		f.write ( (const char*) &tmp2, sizeof ( tmp2 ) );
		f.write ( vars[i].value ().c_str (), tmp2 );
	}
}
예제 #15
0
//option 3
void TransferTextToBinary
    (
    fstream& ioFile,
    bool& successful
    )
{
    string fileName;
    ReadString("Enter name of input textfile containing club "
        "members: ",fileName);
    ifstream inputTextFile(fileName);
    ioFile.open("working.bin",ios::binary| ios::out| ios::in| ios::trunc);
    if(!inputTextFile)
    {
        cout << "\nError opening input textfile.\nReturning to menu." << endl;
        Pause();
        successful = false;
    }
    else if(!ioFile)
    {
        cout << "\nError opening working binary file."
            "\nReturning to menu." << endl;
        Pause();
        successful = false;
    }
    else
    {
        string temp;
        int count = 1;
        //get the name
        while(getline(inputTextFile,temp,'\n'))
        {   
            if(count == 1)
            {
                //clear the char array
                memset(member.name,'\0',31);
                for(unsigned int i = 0 ; i < temp.length(); i++)
                    member.name[i] = temp[i];
                count++;
            }
            //get the age and balance
            getline(inputTextFile,temp,'\n');
            if(count == 2)
            {
                string::size_type space = temp.find(' ');
                string tempAge = temp.substr(0,space);
                //find the age and store it in struc
                member.age = atoi(tempAge.c_str());
                string::size_type dollar = temp.find('$');
                string tempBalance = temp.substr(dollar+1);
                //find the balance and store it in struc
                member.balance = atof(tempBalance.c_str());
                count--;
            }
            //write the struc into the binary file
            ioFile.write((char *)&member, sizeof(ClubMember));
        }
        successful = true;
        inputTextFile.close();
    }
}
예제 #16
0
파일: flac.cpp 프로젝트: chrschmidt/lplex
int flacHeader::write(fstream &out, FLAC__StreamMetadata *meta)
{
	static uint8_t fHeader[42] = { 'f','L','a','C', 0x80, 0x20, 0x00, 0x00 };
	writeStreamInfo( fHeader + 8, meta );
	out.write( (const char*)fHeader, 42 );
	return 1;
}
예제 #17
0
 /**
  * Moves a single record
  */
 void move(size_t to, size_t from) {
     char buf[SIZE];
     file.seekg(from * SIZE);
     file.read(reinterpret_cast<char*>(buf), SIZE);
     file.seekp(to * SIZE);
     file.write(reinterpret_cast<const char*>(buf), SIZE);
 }
예제 #18
0
void inputData(fstream &fRef)
{
	Tool temp;

	int number;
	string name;
	double price;
	int stock;


	cout << "Enter the part number (0 - 99, -1 to end input): ";
	cin >> number;

	while(number != -1)
	{
		cout << "Enter the tool name: ";
		cin.ignore();
		getline(cin, name);
		temp.setToolName(name);
		temp.setPartNumber(number);

		cout << "Enter quantity and price: ";
		cin >> stock >> price;
		temp.setInStock(stock);
		temp.setUnitPrice(price);

		fRef.seekp(temp.getPartNumber() * sizeof(Tool));


		fRef.write( reinterpret_cast< char * >( &temp ), sizeof( Tool ));

		cout << "Enter the part number (0-99, -1 to end input): ";
		cin >> number;
	}
}
예제 #19
0
void initializeFile( fstream &hw )
{
   Hardware newHw;

   for ( int i = 0; i < 100; i++ )
      hw.write( reinterpret_cast< char * >( &newHw ), sizeof( Hardware ) );
}
예제 #20
0
int CRcvBuffer::readBufferToFile(fstream& ofs, const int& len)
{
   int p = m_iStartPos;
   int lastack = m_iLastAckPos;
   int rs = len;

   while ((p != lastack) && (rs > 0))
   {
      int unitsize = m_pUnit[p]->m_Packet.getLength() - m_iNotch;
      if (unitsize > rs)
         unitsize = rs;

      ofs.write(m_pUnit[p]->m_Packet.m_pcData + m_iNotch, unitsize);

      if ((rs > unitsize) || (rs == m_pUnit[p]->m_Packet.getLength() - m_iNotch))
      {
         CUnit* tmp = m_pUnit[p];
         m_pUnit[p] = NULL;
         tmp->m_iFlag = 0;
         -- m_pUnitQueue->m_iCount;

         if (++ p == m_iSize)
            p = 0;

         m_iNotch = 0;
      }
      else
         m_iNotch += rs;

      rs -= unitsize;
   }

   m_iStartPos = p;
   return len - rs;
}
예제 #21
0
// update balance in record
void updateRecord( fstream &updateFile )
{
   // obtain number of account to update
   int accountNumber = getAccount( "Enter account to update" );

   // move file-position pointer to correct record in file
   updateFile.seekg( ( accountNumber - 1 ) * sizeof( ClientData ) );

   // read first record from file
   ClientData client;
   updateFile.read( reinterpret_cast< char * >( &client ), 
      sizeof( ClientData ) );

   // update record
   if ( client.getAccountNumber() != 0 ) 
   {
      outputLine( cout, client ); // display the record

      // request user to specify transaction
      cout << "\nEnter charge (+) or payment (-): ";
      double transaction; // charge or payment
      cin >> transaction;

      // update record balance
      double oldBalance = client.getBalance();
      client.setBalance( oldBalance + transaction );
      outputLine( cout, client ); // display the record

      // move file-position pointer to correct record in file
      updateFile.seekp( ( accountNumber - 1 ) * sizeof( ClientData ) );

      // write updated record over old record in file
      updateFile.write( reinterpret_cast< const char * >( &client ), 
         sizeof( ClientData ) );
   } // end if
예제 #22
0
int32_t CIniLoader::GenerateFile(fstream& file)
{
	using namespace std;
	string ret;

#ifdef __linux__
	#define KZLIB_NEW_LINE "\n"
#elif defined(_WIN32) || defined(_WIN64)
	#define KZLIB_NEW_LINE "\r\n"
#endif

	for (map< string,ConfItem >::iterator pos = m_confItem.begin(),endPos = m_confItem.end();
		pos != endPos;++pos)
	{// save item
		ret += "[";
		ret += pos->first;
		ret += "]"KZLIB_NEW_LINE;

		for (ConfItem::iterator subPos = pos->second.begin(),subEndPos = pos->second.end();
			subPos != subEndPos;++subPos)
		{// save the key and value to item
			ret += "\t";
			ret += subPos->first;
			ret += " = ";
			ret += subPos->second;
			ret += KZLIB_NEW_LINE;
		}
	}

	file.write(ret.c_str(),static_cast< streamsize >(ret.size()));
	return 0;
}
예제 #23
0
/*
    SaveMap
    overwrites the data file with a current version of the map
*/
void DATABASE::SaveMap(void)
{
    string temp;
    char* cstr;
    ofstream file;

    file.open(IOFILE,ios::trunc);

    if (file.eof())
        cout<<"eofbit set"<<endl;
    if (file.fail())
        cout<<"failbit set"<<endl;
    if (file.bad())
        cout<<"badbit set"<<endl;
    
     if (file.fail())
     {
         cout<<"\nFile read\\write failed: SaveMap()\n";
         exit(777);
     }
    for (iter = mymap.begin(); iter != mymap.end(); ++iter)
     {
         temp = iter->second;

         // converting string to array
         cstr = new char [temp.size()+1];
         strcpy(cstr,temp.c_str());
         cstr[temp.size()]='\n';

        file.write(cstr,temp.size()+1);
        delete cstr;
     }
    file.close();
    cout<<"File saved."<<endl;
}
예제 #24
0
void write_comb_c(fstream &f)
{
cout<<"Combinations are being processed.........\nPlease Wait........";
char cb[6][3][3],cb_n[6][3][3],cb_o[6][3][3];
int max_mv=0;
long int s=0,cur_rec;
cb_comb c,c_n,c_o;
f.open("combinat.dat",ios::in|ios::binary|ios::nocreate);
f.seekg(-sizeof(c),ios::end);
f.read((char*)(&c),sizeof(c));
f.close();
max_mv=c.r_moves()-1;
f.open("combinat.dat",ios::in|ios::binary|ios::nocreate);
f.seekg(0);
while(f.read((char*)(&c),sizeof(c)))
if(max_mv==c.r_moves())
	{
	cur_rec=(f.tellg()/sizeof(c))-1;
	break;
	}
f.close();
cout<<cur_rec;
getch();
c.cpy_cube(cb);
while(max_mv==c.r_moves())
	{
	for(int i=0;i<6;i++)
	for(int j=0;j<2;j++)
		{
		c_n.new_comb(cb,v[i],dr[j],max_mv);
		c_n.cpy_cube(cb_n);
		s=0;
		f.open("combinat.dat",ios::in|ios::binary|ios::nocreate);
		f.seekg(0);
		while(f.read((char*)(&c_o),sizeof(c)))
			{
			c_o.cpy_cube(cb_o);
			if(c_o.r_moves()<=c_n.r_moves())
			s+=cmp_cb(cb_n,cb_o);
			if(s>0)
			break;
			}
		f.close();
		if(s==0)
			{
			f.open("combinat.dat",ios::app|ios::binary|ios::nocreate);
			f.write((char*)(&c_n),sizeof(c));
			f.close();
			}
		}
	cur_rec++;
	f.open("combinat.dat",ios::in|ios::binary|ios::nocreate);
	f.seekg(sizeof(c)*cur_rec);
	f.read((char*)(&c),sizeof(c));
	c.cpy_cube(cb);
	f.close();
	}
return;
}
예제 #25
0
void check(student &studx, char namex[])
{
		 if(strcmp(namex, studx.name)==0)
		 {
			 studx.accept();
			 usefile.write((char*)&studx, sizeof(studx));
		 }
}
예제 #26
0
static void do_write(fstream &f, long pos, int n, const char *path,
		     const uint64_t *buf) throw(error)
{
	f.seekg(pos * 8);
	if (!f.write(reinterpret_cast<const char *>(buf), n * 8))
		throw_rw_error(path, true, pos * 8, n * 8);

}
void makeEmptyBirary(fstream f)
{
	sale sold = { 0,0,0.0 };
	for (int i = 0; i <= 100; i++)
	{
		f.write(reinterpret_cast < const char* >(&sold), sizeof(sale));
	}
}
예제 #28
0
  void disk_list<T>::disk(fstream& f, long int k, long int m)
  { 
	  long int i,j,kk;
	  T w, u, t;
      i=k; j=m; kk=(long)(i+j)/2;
      f.seekg(kk*sizeof(T));
      f.read((char *)&w, sizeof(T));
      t = w;
      do
	  { 
		  f.seekg(i*sizeof(T));
		  f.read((char *)&w, sizeof(T));		
          while ((strcmp(w.SORT_KEY,t.SORT_KEY)<0)&&(i<=j))
		  { 
			  i=i+1; 
			  f.seekg(i*sizeof(T));
		      f.read((char *)&w, sizeof(T));
		  }
		  f.seekg(j*sizeof(T));
		  f.read((char *)&w, sizeof(T));
          while ((strcmp(w.SORT_KEY,t.SORT_KEY)>0)&&(i<=j))
		  { 
			  j=j-1; 
		      f.seekg(j*sizeof(T));
		      f.read((char *)&w, sizeof(T));
		  }
          if (i<=j)
		  {
		      f.seekg(i*sizeof(T));
		      f.read((char *)&w, sizeof(T));
		      f.seekg(j*sizeof(T));
		      f.read((char *)&u, sizeof(T));

		      f.seekg(i*sizeof(T));
		      f.write((char *)&u, sizeof(T));
		      f.seekg(j*sizeof(T));
		      f.write((char *)&w, sizeof(T));
			 
			  i=i+1; j=j-1;
		  }
	  }while (i<=j);
      if (k<j) disk(f,k,j);
      if (i<m) disk(f,i,m);
      return;
  }
// function to clear file
void initializeFile( fstream &fRef )
{
   Tool blankItem; // empty Tool object

   // fill file with blank records
   for ( int i = 0; i < 100; i++ )
      fRef.write( 
         reinterpret_cast< char * >( &blankItem ), sizeof( Tool ) );
} // end function initializeFile
예제 #30
0
	void writeString(const char* _str,unsigned _count) {
		if(_str==0 || _count==0)
			return ;
		unsigned i=0;
		for(i=0;i<_count;++i) {
			char ch[1] = {getOX(_str[i<<1],_str[1+(i<<1)])-128};
			file.write(ch,sizeof(ch));
		}
	}