1 #include "../include/animorph/Hotspot.h" 2 3 #include <cstring> 4 5 using namespace std; 6 using namespace Animorph; 7 load(const std::string & filename)8bool Hotspot::load (const std::string& filename) 9 { 10 FileReader file_reader; 11 12 file_reader.open (filename); 13 14 if (!file_reader) 15 return false; 16 17 fromStream (file_reader); 18 19 return true; 20 } 21 fromStream(std::ifstream & in_stream)22void Hotspot::fromStream (std::ifstream &in_stream) 23 { 24 int vertex_number; 25 26 clear (); 27 28 char buffer[MAX_LINE_BUFFER]; 29 string hs_name; 30 while (in_stream.getline (buffer, MAX_LINE_BUFFER)) 31 { 32 if (isalpha (buffer[0])) // line is a hotspot identifier 33 { 34 // delete tailing ':' 35 if (buffer[strlen (buffer)-1] == ':') 36 buffer[strlen (buffer)-1] = '\0'; 37 38 hs_name = buffer; 39 40 // force creation of empty Hotspots 41 HotspotData iv = (*this)[hs_name]; 42 } 43 else // line is a hotspot number 44 { 45 if (hs_name == "") 46 { 47 cerr << "There's something wrong in the hotspot file!" << endl; 48 continue; 49 } 50 51 if (sscanf (buffer, "%d\n", &vertex_number) == 1) 52 { 53 HotspotData &iv = (*this)[hs_name]; 54 55 iv.push_back (vertex_number); 56 } 57 } 58 } 59 } 60