Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » How to load only header of the file with LoadFromFile?
How to load only header of the file with LoadFromFile? [message #19740] Thu, 08 January 2009 20:22 Go to next message
White_Owl is currently offline  White_Owl
Messages: 27
Registered: January 2009
Location: New York
Promising Member
I have a pretty big data file with a lot of data.
I need to show list of my data files. So I'd like to read only headers of my data file and ignore actual data.

Right now I see two ways:
1) Modify all LoadFrom*() functions, to add the third parameter bool header=false. And add to Stream function IsHeader();
That would be pretty universal, but a lot of work.

2) Solution "for right now":
class MyData {
public:
   bool header_only;
   String data_description;

   void Serialize(Stream &s) {
      s % data_description;
      if(s.IsLoading() && header_only) return;
      s % data1 % data2 % data3 ;
   }
};
.....
MyData d;
d.header_only = true;
LoadFromFile(d, file_name);


Is there a third more elegant way?
Re: How to load only header of the file with LoadFromFile? [message #19741 is a reply to message #19740] Thu, 08 January 2009 23:05 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Many.

LoadFromFile is too problem specific for your needs IMO.

If you want to use Serialize, you can still dividide it to Header and Data sections - you only cannot use LoadFromFile because it adds some magic values around the data. But you can call Serialize directly.

Mirek
Re: How to load only header of the file with LoadFromFile? [message #19745 is a reply to message #19741] Fri, 09 January 2009 19:22 Go to previous messageGo to next message
White_Owl is currently offline  White_Owl
Messages: 27
Registered: January 2009
Location: New York
Promising Member
luzr wrote on Thu, 08 January 2009 23:05

If you want to use Serialize, you can still dividide it to Header and Data sections
Are you suggesting to divide my data class to header and actual_data classes?
That can work, but I do not like this idea, because for all other purposes one big class would be better than two separate.

luzr wrote on Thu, 08 January 2009 23:05

- you only cannot use LoadFromFile because it adds some magic values around the data.
Well, I generate these files myself so it should not be a problem...
luzr wrote on Thu, 08 January 2009 23:05

But you can call Serialize directly
Something like this?
class MyData {
   void Serialize_Header(Stream &s) {
      s % data_description;
   }
   void Serialize_Data(Stream &s) {
      s % data1 % data2 % data3;
   }
   void Serialize(Stream &s) {
      Serialize_Header(s);
      Serialize_Data(s);
   }
};
.....
FileIn fi(file_name);
MyData d;
d.Serialize_Header(fi);
fi.Close()
But in that case LoadFromFile() wont work at all, since both header and data would have this 'magic values' around them?
Re: How to load only header of the file with LoadFromFile? [message #19746 is a reply to message #19745] Sat, 10 January 2009 10:10 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
White_Owl wrote on Fri, 09 January 2009 13:22

But in that case LoadFromFile() wont work at all, since both header and data would have this 'magic values' around them?


Yes, but you have effectively created your own implementation.

Search the forum, there is explanation of what LoadFromFile really does. It is likely that you do not need all of that Smile

Mirek
Previous Topic: GetUserName fails on WinXP/MinGW
Next Topic: Quick bi-array
Goto Forum:
  


Current Time: Mon Apr 29 19:23:09 CEST 2024

Total time taken to generate the page: 0.01968 seconds