[ create a new paste ] login | about

Link: http://codepad.org/cn75w9Vc    [ raw code | output | fork ]

C++, pasted on Jan 4:
#include <map>
#include <vector>
#include <string>
#include <iostream>

using namespace std;

struct S_browser {

     std::string name;
     double version;

};

bool operator< (const S_browser& lhs, const S_browser& rhs) {

         if (lhs.name != rhs.name) {
            return lhs.name < rhs.name;
         }
    
         if (lhs.version != rhs.version) {
            return lhs.version < rhs.version;
         }
         return false;
         
}

struct S_html_attr_value {
	
      string content; //this is the actual attr value
      string desc; //of the actual attr value :D
      vector<S_browser> supported_browsers;
      bool required; //by a browser
      bool deprecated; //according to the specification
      std::vector<std::string> notes;
      std::vector<std::string> tips;
      bool is_absolute; //this boolean variable indicates whether or not this attribute value is absolute (i.e.
                        //clearly defined, and never changed).
      bool is_relative; //this boolean variable indicates whether or not this attribute value is relative (i.e.
                        //has a value which might vary depending on the use case; an example of
                        //this is class="<i>classname</i>" where <i>classname</i> is a user-defined string
                        //given as the classname for the attribute 'class'. <i>classname</i> in this example
                        //is a relative attribute value.).
      bool has_unusual_format; //this boolean variable indicates whether or not this attribute value's content has an
                               //unusual format (i.e. contains content in the 'content' string which will not be displayed
                               //in the GUI where this attr value option is displayed, or perhaps will be displayed separate
                               //then the rest of the content in the string
      bool is_case_insensitive; //this boolean variable indicates whether or not this attribute value's content is 
                                //case-insensitive (i.e. meaning it does not matter whether the content has 
                                //lowercase or capital letters)
      bool dtd_strict_supports_this;
      bool dtd_transitional_supports_this;
      bool dtd_frameset_supports_this;
    
      S_html_attr_value() {
      	
          required = false;
          deprecated = false;
          is_absolute = false;
          is_relative = false;
          has_unusual_format = false;
          is_case_insensitive = false;
          dtd_strict_supports_this = false;
          dtd_transitional_supports_this = false;
          dtd_frameset_supports_this = false;
    
      }

      S_html_attr_value operator= (const S_html_attr_value& otherAttrValue) {

          content = otherAttrValue.content;
          desc = otherAttrValue.desc;
          supported_browsers = otherAttrValue.supported_browsers;
          required = otherAttrValue.required;
          deprecated = otherAttrValue.deprecated;
          notes = otherAttrValue.notes;
          tips = otherAttrValue.tips;
          is_absolute = otherAttrValue.is_absolute;
          is_relative = otherAttrValue.is_relative;
          has_unusual_format = otherAttrValue.has_unusual_format;
          is_case_insensitive = otherAttrValue.is_case_insensitive;
          dtd_strict_supports_this = otherAttrValue.dtd_strict_supports_this;
          dtd_transitional_supports_this = otherAttrValue.dtd_transitional_supports_this;
          dtd_frameset_supports_this = otherAttrValue.dtd_frameset_supports_this;
          return otherAttrValue;

      }

      bool operator== (const S_html_attr_value& attrValue) const {
 
          if (attrValue.content == this->content)
             return true;
                                         
          return false;
    
      }

      bool operator< (const S_html_attr_value& attrValue) const {
          if (content < attrValue.content)
             return true;

          return false;
      }

      void clear() {
      	
          //clear everything except content
          if (!desc.empty())
             desc.clear();
          if (!supported_browsers.empty())
             supported_browsers.clear();
          required = false;
          deprecated = false;
          if (!notes.empty())
             notes.clear();
          if (!tips.empty())
             tips.clear();
          is_absolute = false;
          is_relative = false;
          has_unusual_format = false;
          is_case_insensitive = false;
          dtd_strict_supports_this = false;
          dtd_transitional_supports_this = false;
          dtd_frameset_supports_this = false;
    
      }

};

int main() {

  typedef vector<S_html_attr_value> TYPE_attr_values;
  TYPE_attr_values supported_attr_values_for_Dummy_Browser;
  S_html_attr_value test_attr_value;
  test_attr_value.content = "This";
  supported_attr_values_for_Dummy_Browser.push_back(test_attr_value);
  TYPE_attr_values* supported_attr_values_for_Dummy_Browser_P;
  TYPE_attr_values supported_attr_values_for_IE;
  TYPE_attr_values* supported_attr_values_for_IE_P;
  S_browser dummy_browser;
  dummy_browser.name = "Dummy";
  S_browser ie_browser;
  ie_browser.name = "Internet Explorer";
  map<S_browser, TYPE_attr_values> a_map;
  
  a_map.insert(make_pair(dummy_browser, supported_attr_values_for_Dummy_Browser));
  a_map.insert(make_pair(ie_browser, supported_attr_values_for_IE));
  
  supported_attr_values_for_Dummy_Browser_P = &a_map[dummy_browser];
  supported_attr_values_for_IE_P = &a_map[ie_browser];
  typedef TYPE_attr_values::iterator supported_attr_values_IT;
  for (supported_attr_values_IT it = supported_attr_values_for_Dummy_Browser_P->begin(); 
       it != supported_attr_values_for_Dummy_Browser_P->end(); it++) {
      if (it->content == "This") {
         cout<< "Found a match in it->content for \"This\"" <<endl;
         supported_attr_values_for_IE_P->push_back(*it);
      }
  }
  return 0;

}


Output:
1
Found a match in it->content for "This"


Create a new paste based on this one


Comments: