]> git.stg.codes - stg.git/blobdiff - projects/stargazer/tariff_impl.cpp
Minor changes for Darwin.
[stg.git] / projects / stargazer / tariff_impl.cpp
index c6785cead85c26f71ea5e273014f0d71428a8d5f..1fa2e82f624e2c06a155d068666ac09b537e6dea 100644 (file)
  $Author: faust $
  */
 
-#include <ctime>
-#include <algorithm> // std::max
-
-#include "stg/common.h"
 #include "tariff_impl.h"
+
 #include "stg_timer.h"
+#include "stg/common.h"
+
+#include <ctime>
+#include <algorithm> // std::max
 
 //-----------------------------------------------------------------------------
 TARIFF_IMPL & TARIFF_IMPL::operator=(const TARIFF_DATA & td)
@@ -42,12 +43,6 @@ tariffData = td;
 return *this;
 }
 //-----------------------------------------------------------------------------
-TARIFF_IMPL & TARIFF_IMPL::operator=(const TARIFF_IMPL & t)
-{
-tariffData = t.tariffData;
-return *this;
-}
-//-----------------------------------------------------------------------------
 double TARIFF_IMPL::GetPriceWithTraffType(uint64_t up,
                                      uint64_t down,
                                      int dir,
@@ -145,3 +140,28 @@ else
     return tariffData.dirPrice[dir].priceDayA;
 }
 //-----------------------------------------------------------------------------
+std::string TARIFF_IMPL::TariffChangeIsAllowed(const TARIFF & to, time_t currentTime) const
+{
+time_t timeout = GetChangePolicyTimeout();
+if (currentTime > timeout && timeout != 0)
+    return "";
+switch (GetChangePolicy())
+    {
+    case TARIFF::ALLOW:
+        return "";
+    case TARIFF::TO_CHEAP:
+        if (to.GetFee() < GetFee())
+            return "";
+        else
+            return "New tariff '" + to.GetName() + "' is more expensive than current tariff '" + GetName() + "'. The policy is '" + TARIFF::ChangePolicyToString(GetChangePolicy()) + "'.";
+    case TARIFF::TO_EXPENSIVE:
+        if (to.GetFee() >= GetFee())
+            return "";
+        else
+            return "New tariff '" + to.GetName() + "' is more cheap than current tariff '" + GetName() + "'. The policy is '" + TARIFF::ChangePolicyToString(GetChangePolicy()) + "'.";
+    case TARIFF::DENY:
+        return "Current tariff '" + GetName() + "', new tariff '" + to.GetName() + "'. The policy is '" + TARIFF::ChangePolicyToString(GetChangePolicy()) + "'.";
+    }
+return "";
+}
+//-----------------------------------------------------------------------------