Ignore:
Timestamp:
2003-07-12T08:58:10+12:00 (21 years ago)
Author:
sjboddie
Message:

Replaced overloaded get_formatted_string() functions in formattools with
a single function by using a text_tmap in place of the old link, text,
icon, and highlight variables.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/src/recpt/formattools.cpp

    r4868 r4906  
    3232
    3333// a few function prototypes
     34
    3435static text_t format_string (const text_t& collection, recptproto* collectproto,
    3536                 ResultDocInfo_t &docinfo, displayclass &disp,
    36                  format_t *formatlistptr,
    37                  const text_t &link, const text_t &icon,
    38                  const text_t &text, bool highlight, ostream& logout);
     37                 format_t *formatlistptr, text_tmap &options,
     38                 ostream& logout);
    3939
    4040static bool parse_action (text_t::const_iterator &here, const text_t::const_iterator &end,
    4141              format_t *formatlistptr, text_tset &metadata, bool &getParents);
    4242
    43 text_t format_summary (const text_t& collection, recptproto* collectproto,
    44               ResultDocInfo_t &docinfo, displayclass &disp,
    45               const text_t &text, bool highlight,
    46                ostream& logout);
     43static text_t format_summary (const text_t& collection, recptproto* collectproto,
     44                  ResultDocInfo_t &docinfo, displayclass &disp,
     45                  text_tmap &options, ostream& logout);
    4746
    4847
     
    866865static text_t get_or (const text_t& collection, recptproto* collectproto,
    867866              ResultDocInfo_t &docinfo, displayclass &disp,
    868               format_t *orptr,
    869               const text_t &link, const text_t &icon,
    870               const text_t &text, bool highlight,
     867              format_t *orptr, text_tmap &options,
    871868              ostream& logout) {
    872869
     
    875872
    876873    tmp = format_string (collection,collectproto, docinfo, disp, orptr,
    877              link, icon, text, highlight, logout);
     874             options, logout);
    878875    if (!tmp.empty()) return tmp;
    879876
     
    886883              ResultDocInfo_t &docinfo, displayclass &disp,
    887884              const decision_t &decision,
    888               format_t *ifptr, format_t *elseptr, const text_t &link,
    889               const text_t &icon, const text_t &text, bool highlight,
    890               ostream& logout)
     885              format_t *ifptr, format_t *elseptr,
     886              text_tmap &options, ostream& logout)
    891887{
    892888
     
    897893      if (ifptr != NULL)
    898894    return get_formatted_string (collection,collectproto, docinfo, disp, ifptr,
    899                      link, icon, text, highlight, logout);
     895                     options, logout);
    900896    }
    901897    else {
    902898      if (elseptr != NULL)
    903899    return get_formatted_string (collection,collectproto, docinfo, disp, elseptr,
    904                      link, icon, text, highlight, logout);
     900                     options, logout);
    905901    }
    906902  }
     
    920916      if (ifptr != NULL)
    921917    return get_formatted_string (collection, collectproto, docinfo, disp, ifptr,
    922                      link, icon, text, highlight, logout);
     918                     options, logout);
    923919    } else {
    924920      if (elseptr != NULL)
    925921    return get_formatted_string (collection, collectproto, docinfo, disp, elseptr,
    926                      link, icon, text, highlight, logout);
     922                     options, logout);
    927923    }
    928924  }
     
    947943text_t format_string (const text_t& collection, recptproto* collectproto,
    948944              ResultDocInfo_t &docinfo, displayclass &disp,
    949               format_t *formatlistptr,
    950               const text_t &link, const text_t &icon,
    951               const text_t &text, bool highlight,
     945              format_t *formatlistptr, text_tmap &options,
    952946              ostream& logout) {
    953947
     
    958952    return formatlistptr->text;
    959953  case comLink:
    960     return link;
     954    return options["link"];
    961955  case comEndLink:
    962     if (link.empty()) return "";
     956    if (options["link"].empty()) return "";
    963957    else return "</a>";
    964958  case comHref:
    965     return get_href(link);
     959    return get_href(options["link"]);
    966960  case comIcon:
    967     return icon;
     961    return options["icon"];
    968962  case comNum:
    969963    return docinfo.result_num;
     
    971965    return get_related_docs(collection, collectproto, docinfo, logout);
    972966  case comSummary:
    973     return format_summary(collection,collectproto,docinfo,disp,text,highlight,logout);
     967    return format_summary(collection, collectproto, docinfo, disp, options, logout);
    974968  case comMeta:
    975969
     
    998992        = get_formatted_string(collection, collectproto,
    999993                       response.docInfo[0], disp, expanded_formatlistptr,
    1000                        link, icon, highlight, logout);
     994                       options, logout);
    1001995         
    1002996          return expanded_metavalue;
     
    10131007    }
    10141008  case comDoc:
    1015     return text;
     1009    return options["text"];
    10161010  case comHighlight:
    1017     if (highlight) return "<b>";
     1011    if (options["highlight"] == "1") return "<b>";
    10181012    break;
    10191013  case comEndHighlight:
    1020     if (highlight) return "</b>";
     1014    if (options["highlight"] == "1") return "</b>";
    10211015    break;
    10221016  case comIf:
    10231017    return get_if (collection, collectproto, docinfo, disp,
    10241018           formatlistptr->decision, formatlistptr->ifptr,
    1025            formatlistptr->elseptr, link, icon, text, highlight,
    1026            logout);
     1019           formatlistptr->elseptr, options, logout);
    10271020  case comOr:
    10281021    return get_or (collection,collectproto, docinfo, disp, formatlistptr->orptr,
    1029            link, icon, text, highlight, logout);
     1022           options, logout);
    10301023  }
    10311024  return "";
    1032 }
    1033 
    1034 
    1035 
    1036 
    1037 text_t get_formatted_string (const text_t& collection, recptproto* collectproto,
    1038                  ResultDocInfo_t& docinfo, displayclass &disp,
    1039                  format_t* formatlistptr,
    1040                  const text_t& link, const text_t& icon,
    1041                  const text_t& text, const bool highlight,
    1042                  ostream& logout) {
    1043 
    1044   text_t ft;
    1045   while (formatlistptr != NULL)
    1046     {
    1047       ft += format_string (collection, collectproto, docinfo, disp, formatlistptr,
    1048                link, icon, text, highlight, logout);
    1049       formatlistptr = formatlistptr->nextptr;
    1050     }
    1051 
    1052   return ft;
    10531025}
    10541026
    10551027text_t get_formatted_string (const text_t& collection, recptproto* collectproto,
    10561028                 ResultDocInfo_t &docinfo, displayclass &disp,
    1057                  format_t *formatlistptr,
    1058                  const text_t &link, const text_t &icon,
    1059                  const bool highlight,
     1029                 format_t *formatlistptr, text_tmap &options,
    10601030                 ostream& logout) {
    10611031
    1062   text_t text = "";
    1063 
    1064   return get_formatted_string(collection, collectproto, docinfo, disp, formatlistptr,
    1065                               link, icon, text, highlight, logout);
    1066 }
    1067 
    1068 text_t get_formatted_string (const text_t& collection, recptproto* collectproto,
    1069                  ResultDocInfo_t &docinfo, displayclass &disp,
    1070                  format_t *formatlistptr,
    1071                  const text_t& text,
    1072                  ostream& logout) {
    1073 
    1074   text_t link = "<a href=\"_httpdocument_&cl=search&d=" + docinfo.OID + "\">";
    1075   text_t icon = "_icontext_";
    1076   bool highlight = false;
    1077 
    1078   return get_formatted_string(collection, collectproto, docinfo, disp, formatlistptr,
    1079                   link, icon, text, highlight, logout);
    1080 }
    1081 
    1082 text_t get_formatted_string (const text_t& collection, recptproto* collectproto,
    1083                  ResultDocInfo_t &docinfo, displayclass &disp,
    1084                  format_t *formatlistptr,
    1085                  ostream& logout) {
    1086 
    1087   text_t text = "";
    1088 
    1089   return get_formatted_string(collection, collectproto, docinfo, disp, formatlistptr,
    1090                   text, logout);
     1032   text_t ft;
     1033   while (formatlistptr != NULL)
     1034      {
     1035     ft += format_string (collection, collectproto, docinfo, disp, formatlistptr,
     1036                  options, logout);
     1037     formatlistptr = formatlistptr->nextptr;
     1038      }
     1039   
     1040   return ft;
    10911041}
    10921042
     
    10971047
    10981048text_t format_summary (const text_t& collection, recptproto* collectproto,
    1099               ResultDocInfo_t &docinfo, displayclass &disp,
    1100               const text_t &text, bool highlight,
    1101               ostream& logout) {
     1049               ResultDocInfo_t &docinfo, displayclass &disp,
     1050               text_tmap &options, ostream& logout) {
    11021051
    11031052  // GRB: added code here to ensure that the cstr (and other collections)
     
    11111060
    11121061  text_t textToSummarise, query;
    1113   if(text.empty()) { // get document text
    1114       DocumentRequest_t docrequest;
    1115       DocumentResponse_t docresponse;
    1116       comerror_t err;
    1117       docrequest.OID = docinfo.OID;
    1118       collectproto->get_document (collection, docrequest, docresponse, err, logout);
    1119       textToSummarise = docresponse.doc;
     1062  if(options["text"].empty()) { // get document text
     1063     DocumentRequest_t docrequest;
     1064     DocumentResponse_t docresponse;
     1065     comerror_t err;
     1066     docrequest.OID = docinfo.OID;
     1067     collectproto->get_document (collection, docrequest, docresponse, err, logout);
     1068     textToSummarise = docresponse.doc;
    11201069  } else // in practice, this would not happen, because text is only
    11211070         // loaded with the [Text] command
    1122       textToSummarise = text;
     1071     textToSummarise = options["text"];
    11231072  disp.expandstring("_cgiargq_",query);
    11241073  return summarise(textToSummarise,query,80);
Note: See TracChangeset for help on using the changeset viewer.