Make the code compile also in g++ 4.7 where read/write are not
[SXSI/XMLTree.git] / xml-tree.cpp
index 158ec1b..d31c1ce 100644 (file)
@@ -97,8 +97,12 @@ xml_tree::xml_tree(std::vector<int32_t> *tags_,
   this->tag_ids = tag_ids;
   tag_names = new std::vector<std::string>();
   tag_names->resize(tag_ids->size());
-  for(auto val : *(this->tag_ids))
-    (*this->tag_names)[val.second] = val.first;
+  std::unordered_map<std::string, tag_t>::iterator val;
+  //for(auto val : *(this->tag_ids))
+  //(*this->tag_names)[val.second] = val.first;
+  for(val = this->tag_ids->begin(); val != this->tag_ids->end(); ++val)
+    (*this->tag_names)[val->second] = val->first;
+
 
   uint32_t max_tag = tag_names->size() - 1;
   bit_vector *tmp_bitmap = new bit_vector(npar, 1, 0);
@@ -371,8 +375,7 @@ std::pair<int32_t, int32_t> xml_tree::text_id_range(xml_tree::node_t x) const
     i = 0;
   else
     i = text_positions->rank1(x-1);
- j = text_positions->rank1(y);
+  j = text_positions->rank1(y);
 //  fprintf(stderr, "Rank of node %i is %i, rank of closing %i is %i\n", x, i, y, j);
   if (i == j)
     return std::make_pair(xml_tree::NIL, xml_tree::NIL);
@@ -446,7 +449,8 @@ const char * xml_tree::get_tag_name_by_ref(xml_tree::tag_t tagid) const
 
 xml_tree::tag_t xml_tree::register_tag(char *s)
 {
-  auto found = tag_ids->find(std::string(s));
+  std::unordered_map<std::string, tag_t>::iterator found;
+  found = tag_ids->find(std::string(s));
   if (found == tag_ids->end())
     return xml_tree::NIL_TAG_ID;
   else
@@ -499,7 +503,7 @@ void xml_tree::print(xml_tree::node_t x, int fd, bool no_text)
   unsigned char * orig_text;
   unsigned char * current_text;
 
-  auto r = text_id_range(x);
+  std::pair<int32_t, int32_t> r = text_id_range(x);
   if (r.first == xml_tree::NIL)
     current_text = 0;
   else {
@@ -555,6 +559,7 @@ void xml_tree::print(xml_tree::node_t x, int fd, bool no_text)
                 uputs((const char*) &(get_tag_name_by_ref(tag(n))[3]), fd);
                 n++;
                 uputs("=\"", fd);
+                current_text += (current_text[0] == 1);
                 read = uprintf((const char*) current_text, fd);
                 current_text += read + 1;
                 uputc('"', fd);
@@ -592,97 +597,6 @@ void xml_tree::print(xml_tree::node_t x, int fd, bool no_text)
 
 }
 
-// void xml_tree::print(xml_tree::node_t x, int fd, bool no_text)
-// {
-//   if (print_buffer == 0) {
-//     print_buffer = new std::string(BUFFER_SIZE, 0);
-//     print_buffer->clear();
-//     print_stack = new std::vector<std::string>();
-//     print_stack->reserve(256);
-//   };
-
-//   xml_tree::node_t fin = bp_find_close(par, x);
-//   xml_tree::node_t n = x;
-//   xml_tree::tag_t label = tag(n);
-//   unsigned char * current_text;
-
-
-//   while (n <= fin) {
-
-//     if (bp_inspect(par, n)) {
-//       if (label == xml_tree::PCDATA_OPEN_TAG_ID){
-//         if (no_text) {
-//           uputs("<$/>", fd);
-//         } else {
-//       current_text = get_text(text_id(n));
-//       uprintf( (const char*) (current_text + (current_text[0] == 1)), fd);
-
-//       if (current_text && text_index_type != TextCollectionBuilder::index_type_default)
-//         text_collection->DeleteText(current_text);
-
-//       n += 2; // skip closin $
-//       label = tag(n);
-//     };
-//       } else {
-//       uputc('<', fd);
-//       uput_str((*tag_names)[label], fd);
-//       n++;
-//       if (bp_inspect(par, n)) {
-//         print_stack->push_back((*tag_names)[label]);
-//         label = tag(n);
-//         if (label == xml_tree::ATTRIBUTE_OPEN_TAG_ID) {
-//           n++;
-//           if (no_text) uputs("><@@>", fd);
-
-//           while (bp_inspect(par, n))
-//             if (no_text) {
-//               uputc('<', fd);
-//               uputs((const char*) &(get_tag_name_by_ref(tag(n))[3]), fd);
-//               uputc('>', fd);
-//               uputs("<$@/></", fd);
-//               uputs((const char*) &(get_tag_name_by_ref(tag(n))[3]), fd);
-//               uputc('>', fd);
-//               n += 4;
-//             } else {
-//               uputc(' ', fd);
-//               uputs((const char*) &(get_tag_name_by_ref(tag(n))[3]), fd);
-//               n+= 2;
-//               uputs("=\"", fd);
-//               current_text = get_text(text_id(n));
-//               uprintf((const char*) (current_text + (current_text[0] == 1)), fd);
-//               if (current_text && text_index_type != TextCollectionBuilder::index_type_default)
-//                   text_collection->DeleteText(current_text);
-//               uputc('"', fd);
-//               n += 2;
-//             };
-
-//           if (no_text)
-//             uputs("</@@>", fd);
-//           else uputc('>', fd);
-//           n++;
-//           label = tag(n);
-//         } else
-//           uputc('>', fd);
-//       } else {
-//         uputs("/>", fd);
-//         n++;
-//         label = tag(n);
-//       };
-//     };
-//       } else do {
-//       uputs("</", fd);
-//       uput_str(print_stack->back(), fd);
-//       uputc('>', fd);
-//       print_stack->pop_back();
-//       n++;
-//     } while (!bp_inspect(par, n) && !print_stack->empty());
-//       label = tag(n);
-//     };
-//   uputc('\n', fd);
-
-// }
-
-
 
 static inline uchar * next_char(uchar *s, size_t &numtexts)
 {