Changeset 31390 for main/trunk


Ignore:
Timestamp:
2017-02-08T20:07:14+13:00 (7 years ago)
Author:
ak19
Message:

Improved newly added oaiaction::getMeta(). Now return type is a bool and it now uses map.find() to locate requested meta.

Location:
main/trunk/greenstone2/runtime-src/src/oaiservr
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/runtime-src/src/oaiservr/oaiaction.cpp

    r31387 r31390  
    449449// Method that looks for the requested metaname in the doc_info, and if found, sets the value
    450450// in the argument 'metavalue'.
    451 void oaiaction::getMeta(ResultDocInfo_t &doc_info, const text_t &metaname, text_t &metavalue)
    452 {
    453   text_t current_metaname;
    454 
     451bool oaiaction::getMeta(ResultDocInfo_t &doc_info, const text_t &metaname, text_t &metavalue)
     452{
    455453  //ofstream         logout("oai.log", ios::app);
    456 
    457   MetadataInfo_tmap::iterator current = doc_info.metadata.begin();
    458   MetadataInfo_tmap::iterator end = doc_info.metadata.end();
    459 
    460   while(current != end){
    461     current_metaname = current->first;
    462     lc(current_metaname); // lowercased for string comparison below
    463 
    464     if (current_metaname == metaname && current->second.values.size() >= 1) { // found match with a value
    465       metavalue = current->second.values[0];
    466 
    467       //logout << "Looking for metaname = " << current_metaname << endl;
    468       //logout << "\t\t\t Found value = " << metavalue << endl;
    469       return; // done
    470     }
    471 
    472     ++current;
    473   }
    474 
    475   //logout.close();
     454  //logout << "oaiaction::getMeta(): Looking for metaname = " << metaname << endl;
     455
     456  // use map::find, rather than testing map["array-index"], as the latter will create that index and
     457  // insert an empty value into it, when we just want to test for it.
     458  // See http://www.cplusplus.com/reference/map/map/operator[]/
     459  // See also http://stackoverflow.com/questions/1939953/how-to-find-if-a-given-key-exists-in-a-c-stdmap
     460
     461  if(doc_info.metadata.find(metaname) == doc_info.metadata.end()) {
     462    //logout << "\t\t\t Could not find meta " << metaname << endl;
     463    //logout.close();
     464    return false;
     465  } else { // found meta
     466    metavalue = doc_info.metadata[metaname].values[0];
     467    //logout << "\t\t\t Found value = " << metavalue << endl;
     468    //logout.close();
     469    return true;
     470  }
     471 
    476472}
    477473
  • main/trunk/greenstone2/runtime-src/src/oaiservr/oaiaction.h

    r31387 r31390  
    6666  text_t getErrorType(){return this->errorType;};
    6767  void   getLastModifiedDate(ResultDocInfo_t &doc_info, text_t &lastModified);
    68   void   getMeta(ResultDocInfo_t &doc_info, const text_t &metaname, text_t &metavalue);
     68  bool   getMeta(ResultDocInfo_t &doc_info, const text_t &metaname, text_t &metavalue);
    6969  bool   inDateRange(const text_t &from, const text_t &until, const text_t &collection,
    7070             const text_t &OID, recptproto *protocol, ostream &logout);
Note: See TracChangeset for help on using the changeset viewer.