unsigned int WorldState::comp(const WorldState &ws1, const WorldState &ws2) { int score = 0; return ws1.mState == ws2.mState ? 0 : 1; // Iterators run from lowest to highest key values. worldrep::const_iterator p1 = ws1.mState.begin(); worldrep::const_iterator p2 = ws2.mState.begin(); while(p1 != ws1.mState.end() || p2 != ws2.mState.end()) { // One state may have run out of keys. if(p1 == ws1.mState.end()) { score++; p2++; continue; } if(p2 == ws2.mState.end()) { score++; p1++; continue; } // Compare names of predicates (keys). int cmp = getPName(p1) != getPName(p2); if(cmp == 0) { // Names are equal. Check for different values. if(getPVal(p1) != getPVal(p2)) score++; p1++; p2++; } else if(cmp > 0) { // Key 1 is greater. score++; p2++; } else // if(cmp < 0) { // Key 2 is greater. score++; p1++; } } return score; }
JsonObject* SamiPet::asJsonObject() { JsonObject *pJsonObject = new JsonObject(); pJsonObject->Construct(); JsonString *pIdKey = new JsonString(L"id"); pJsonObject->Add(pIdKey, toJson(getPId(), "Long", "")); JsonString *pCategoryKey = new JsonString(L"category"); pJsonObject->Add(pCategoryKey, toJson(getPCategory(), "SamiCategory", "")); JsonString *pNameKey = new JsonString(L"name"); pJsonObject->Add(pNameKey, toJson(getPName(), "String", "")); JsonString *pPhotoUrlsKey = new JsonString(L"photoUrls"); pJsonObject->Add(pPhotoUrlsKey, toJson(getPPhotoUrls(), "String", "array")); JsonString *pTagsKey = new JsonString(L"tags"); pJsonObject->Add(pTagsKey, toJson(getPTags(), "SamiTag", "array")); JsonString *pStatusKey = new JsonString(L"status"); pJsonObject->Add(pStatusKey, toJson(getPStatus(), "String", "")); return pJsonObject; }
JsonObject* SamiShipment::asJsonObject() { JsonObject *pJsonObject = new JsonObject(); pJsonObject->Construct(); JsonString *pIdKey = new JsonString(L"id"); pJsonObject->Add(pIdKey, toJson(getPId(), "String", "")); JsonString *pNameKey = new JsonString(L"name"); pJsonObject->Add(pNameKey, toJson(getPName(), "String", "")); JsonString *pPriorityKey = new JsonString(L"priority"); pJsonObject->Add(pPriorityKey, toJson(getPPriority(), "Integer", "")); JsonString *pPickupKey = new JsonString(L"pickup"); pJsonObject->Add(pPickupKey, toJson(getPPickup(), "SamiStop", "")); JsonString *pDeliveryKey = new JsonString(L"delivery"); pJsonObject->Add(pDeliveryKey, toJson(getPDelivery(), "SamiStop", "")); JsonString *pSizeKey = new JsonString(L"size"); pJsonObject->Add(pSizeKey, toJson(getPSize(), "Integer", "array")); JsonString *pRequired_skillsKey = new JsonString(L"required_skills"); pJsonObject->Add(pRequired_skillsKey, toJson(getPRequiredSkills(), "String", "array")); JsonString *pAllowed_vehiclesKey = new JsonString(L"allowed_vehicles"); pJsonObject->Add(pAllowed_vehiclesKey, toJson(getPAllowedVehicles(), "String", "array")); return pJsonObject; }
/// This hash method sums the string hashes of all the predicate names in /// this state, XORing certain bits based on the values of each predicate. /// @todo Is there a better hash func to use? Should do some unit testing. void WorldState::updateHash() { mHash = 0; worldrep::const_iterator it; for(it = mState.begin(); it != mState.end(); it++) { //unsigned int l = getPName(it).length(); //while(l) // mHash = 31 * mHash + getPName(it)[--l]; //mHash ^= getPVal(it) << getPName(it).length() % (sizeof(unsigned int) - sizeof(PVal)); mHash = 31 * mHash + (getPVal(it) << getPName(it)); } }
JsonObject* SamiCategory::asJsonObject() { JsonObject *pJsonObject = new JsonObject(); pJsonObject->Construct(); JsonString *pIdKey = new JsonString(L"id"); pJsonObject->Add(pIdKey, toJson(getPId(), "Long", "")); JsonString *pNameKey = new JsonString(L"name"); pJsonObject->Add(pNameKey, toJson(getPName(), "String", "")); return pJsonObject; }
JsonObject* SamiGroup::asJsonObject() { JsonObject *pJsonObject = new JsonObject(); pJsonObject->Construct(); JsonString *p_idKey = new JsonString(L"_id"); pJsonObject->Add(p_idKey, toJson(getPId(), "String", "")); JsonString *pNameKey = new JsonString(L"name"); pJsonObject->Add(pNameKey, toJson(getPName(), "String", "")); JsonString *pIs_defaultKey = new JsonString(L"is_default"); pJsonObject->Add(pIs_defaultKey, toJson(getPIsDefault(), "Boolean", "")); JsonString *pIs_hiddenKey = new JsonString(L"is_hidden"); pJsonObject->Add(pIs_hiddenKey, toJson(getPIsHidden(), "Boolean", "")); JsonString *pNew_weekly_mailer_contentKey = new JsonString(L"new_weekly_mailer_content"); pJsonObject->Add(pNew_weekly_mailer_contentKey, toJson(getPNewWeeklyMailerContent(), "String", "")); JsonString *pNewsletter_subjectKey = new JsonString(L"newsletter_subject"); pJsonObject->Add(pNewsletter_subjectKey, toJson(getPNewsletterSubject(), "String", "")); JsonString *pAutopublishKey = new JsonString(L"autopublish"); pJsonObject->Add(pAutopublishKey, toJson(getPAutopublish(), "Boolean", "")); JsonString *pNumber_articles_per_groupKey = new JsonString(L"number_articles_per_group"); pJsonObject->Add(pNumber_articles_per_groupKey, toJson(getPNumberArticlesPerGroup(), "Integer", "")); JsonString *pNumber_articles_per_newsletterKey = new JsonString(L"number_articles_per_newsletter"); pJsonObject->Add(pNumber_articles_per_newsletterKey, toJson(getPNumberArticlesPerNewsletter(), "Integer", "")); return pJsonObject; }