⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 archive.hh

📁 hadoop:Nutch集群平台
💻 HH
字号:
/** * Copyright 2005 The Apache Software Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * *     http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */#ifndef ARCHIVE_HH_#define ARCHIVE_HH_#include "recordio.hh"namespace hadoop {class Index {public:  virtual bool done() = 0;  virtual void incr() = 0;  virtual ~Index() {}};class IArchive {public:  virtual void deserialize(int8_t& t, const char* tag) = 0;  virtual void deserialize(bool& t, const char* tag) = 0;  virtual void deserialize(int32_t& t, const char* tag) = 0;  virtual void deserialize(int64_t& t, const char* tag) = 0;  virtual void deserialize(float& t, const char* tag) = 0;  virtual void deserialize(double& t, const char* tag) = 0;  virtual void deserialize(std::string& t, const char* tag) = 0;  virtual void deserialize(std::string& t, size_t& len, const char* tag) = 0;  virtual void startRecord(hadoop::Record& s, const char* tag) = 0;  virtual void endRecord(hadoop::Record& s, const char* tag) = 0;  virtual Index* startVector(const char* tag) = 0;  virtual void endVector(Index* idx, const char* tag) = 0;  virtual Index* startMap(const char* tag) = 0;  virtual void endMap(Index* idx, const char* tag) = 0;  virtual void deserialize(hadoop::Record& s, const char* tag) {    s.deserialize(*this, tag);  }  template <typename T>  void deserialize(std::vector<T>& v, const char* tag) {    Index* idx = startVector(tag);    while (!idx->done()) {      T t;      deserialize(t, tag);      v.push_back(t);      idx->incr();    }    endVector(idx, tag);  }  template <typename K, typename V>  void deserialize(std::map<K,V>& v, const char* tag) {    Index* idx = startMap(tag);    while (!idx->done()) {      K key;      deserialize(key, tag);      V value;      deserialize(value, tag);      v[key] = value;      idx->incr();    }    endMap(idx, tag);  }};class OArchive {public:  virtual void serialize(int8_t t, const char* tag) = 0;  virtual void serialize(bool t, const char* tag) = 0;  virtual void serialize(int32_t t, const char* tag) = 0;  virtual void serialize(int64_t t, const char* tag) = 0;  virtual void serialize(float t, const char* tag) = 0;  virtual void serialize(double t, const char* tag) = 0;  virtual void serialize(const std::string& t, const char* tag) = 0;  virtual void serialize(const std::string& t, size_t len, const char* tag) = 0;  virtual void startRecord(const hadoop::Record& s, const char* tag) = 0;  virtual void endRecord(const hadoop::Record& s, const char* tag) = 0;  virtual void startVector(size_t len, const char* tag) = 0;  virtual void endVector(size_t len, const char* tag) = 0;  virtual void startMap(size_t len, const char* tag) = 0;  virtual void endMap(size_t len, const char* tag) = 0;  virtual void serialize(const hadoop::Record& s, const char* tag) {    s.serialize(*this, tag);  }  template <typename T>  void serialize(const std::vector<T>& v, const char* tag) {    startVector(v.size(), tag);    if (v.size()>0) {      for (size_t cur = 0; cur<v.size(); cur++) {        serialize(v[cur], tag);      }    }    endVector(v.size(), tag);  }  template <typename K, typename V>  void serialize(const std::map<K,V>& v, const char* tag) {    startMap(v.size(), tag);    if (v.size()>0) {      typedef typename std::map<K,V>::const_iterator CI;      for (CI cur = v.begin(); cur!=v.end(); cur++) {        serialize(cur->first, tag);        serialize(cur->second, tag);      }    }    endMap(v.size(), tag); }};}; // end namespace hadoop#endif /*ARCHIVE_HH_*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -