OSDN Git Service

utakataの標準となる例外クラス及びマクロを定義した。
[simplecms/utakata.git] / src / type.cpp
index 714700e..51e5aea 100755 (executable)
@@ -1,56 +1,41 @@
-#include "type.h"
-#include "data_structure.h"
-#include "class.h"
-#include "object.h"
+#include <algorithm>
+#include <string>
+#include "src/type.h"
 
+namespace type = utakata::type;
 
-using namespace utakata::type;
-using namespace utakata;
-
-type::Type::Type(const std::string& str) : hash_(0), hash_string_(str)
-{
-    makeHash();
-}
-
-type::Type::Type(const type::Type& t)
-{
-    hash_ = t.hash_;
-    hash_string_ = t.hash_string_;
+// 宣言のコメントを参照してください。
+type::Type::Type(const std::string& str) : hash_(0), hash_string_(str) {
+  MakeHash();
 }
 
-type::Type& type::Type::operator=(const type::Type& p)
-{
-    hash_ = p.hash_;
-    hash_string_ = p.hash_string_;
-    return *this;
-}
-
-void type::Type::makeHash()
-{
-    // 簡単にハッシュを作成する。
-    std::string::const_iterator beg = hash_string_.begin(), end = hash_string_.end();
+// 宣言のコメントを参照してください。
+type::Type::Type(const type::Type& t) : hash_(t.hash_),
+                                        hash_string_(t.hash_string_) {}
 
-    unsigned char ch = *beg;
-    for (; beg != end; ++beg)
-    {
-        // 各文字毎に簡単なハッシュ値を算出する。
-        hash_ += (ch + (!(ch << 4)));
-        ch = *beg;
-    }
+// 宣言のコメントを参照してください。
+type::Type& type::Type::operator=(const type::Type& p) {
+  type::Type tmp(p);
+  Swap(tmp);
+  return *this;
 }
 
-TypeDescripter::TypeDescripter(const Type& type,
-                               const smart_ptr<data::DataEntity>& entity) :
-    type_(type), entity_(entity)
-{}
-
-const Type& TypeDescripter::getType() const
-{
-    // 実体を返すが、単純に参照を返すのみとする。
-    return type_;
+// ここでのハッシュ値は、次のようなアルゴリズムで生成されます。
+// 渡された文字列 s のn文字目の文字をSnと表したとき、
+// hash = (S1 + !(S1 << 4)) + (S2 + !(S2 << 4))...(Sn + !(Sn << 4))
+// とした結果のハッシュ値となります。
+void type::Type::MakeHash() {
+  std::string::const_iterator beg = hash_string_.begin(),
+      end = hash_string_.end();
+
+  for (; beg != end; ++beg) {
+    // 各文字毎に簡単なハッシュ値を算出する。
+    hash_ += (*beg + (!(*beg << 4)));
+  }
 }
 
-smart_ptr<data::DataEntity> TypeDescripter::getEntity()
-{
-    return entity_;
+// 宣言のコメントを参照してください。
+void type::Type::Swap(type::Type& type) {
+  std::swap(hash_, type.hash_);
+  std::swap(hash_string_, type.hash_string_);
 }