acl/lib_acl_cpp/include/acl_cpp/stdlib/diff_manager.hpp

152 lines
4.3 KiB
C++
Raw Normal View History

#pragma once
#include "../acl_cpp_define.hpp"
#include <list>
#include <vector>
#include "noncopyable.hpp"
namespace acl
{
class diff_object;
/**
*
*/
class diff_manager : public noncopyable
{
public:
diff_manager(long long range_from = -1, long long range_to = -1);
~diff_manager(void);
/**
*
* @return {dbuf_guard&} 使
* diff_manager diff_manager
*
*/
dbuf_guard& get_dbuf(void);
/**
*
*
* @param curr_objs {const std::vector<diff_object*>&}
* @param old_olds {const std::list<diff_object*>&}
* 使
*/
void diff_changes(const std::vector<diff_object*>& curr_objs,
const std::vector<diff_object*>& old_olds);
/**
*
* @return {std::vector<diff_object*>&}
*/
const std::vector<diff_object*>& get_new(void) const
{
return objs_new_;
}
/**
* diff_changes
*
* @return {std::vector<diff_object*>&}
*/
const std::vector<diff_object*>& get_deleted(void) const
{
return objs_del_;
}
/**
* diff_changes
*
* @return {std::vector<std::pair<diff_object*, diff_object*> >&}
* pair first second
*
* @sample
* const std::vector<std::pair<diff_object*, diff_object*> >&
* results = manager.get_updated();
* std::vector<std::pair<diff_object*, diff_object*> >::const_iterator
* cit = results.begin();
* for (; cit != results.end(); ++cit)
* printf(">> key: %s, curr value:%s, old value: %s\r\n",
* (*cit).first->get_key(),
* (*cit).first->get_val(),
* (*cit).second->get_val());
*/
const std::vector<std::pair<diff_object*, diff_object*> >&
get_updated(void) const
{
return objs_upd_;
}
/**
* diff_manger
* @return {std::vector<diff_object*>&}
*/
const std::vector<diff_object*>& get_same(void) const
{
return objs_equ_;
}
/**
*
* @return {const std::vector<diff_object*>&}
*/
const std::vector<diff_object*>& get_extra_added(void) const
{
return objs_new_extra_;
}
/**
*
* @return {const std::vector<diff_object*>&}
*/
const std::vector<diff_object*>& get_extra_deleted(void) const
{
return objs_del_extra_;
}
/**
*
* @return {const std::vector<diff_object*>&}
*/
const std::vector<std::pair<diff_object*, diff_object*> >&
get_extra_updated(void) const
{
return objs_upd_extra_;
}
/**
* 使 diff_manager
*
*/
void reset(void);
private:
dbuf_guard dbuf_;
long long range_from_;
long long range_to_;
// 相同的对象集合
std::vector<diff_object*> objs_equ_;
// 变化的对象集合
// 新增的对象集合
std::vector<diff_object*> objs_new_;
// 删除的对象集合
std::vector<diff_object*> objs_del_;
// 修改的对象集合
std::vector<std::pair<diff_object*, diff_object*> > objs_upd_;
// 多余的对象集合
// 新增的多余对象集合
std::vector<diff_object*> objs_new_extra_;
// 删除的多余对象集合
std::vector<diff_object*> objs_del_extra_;
// 修改的多余对象集合
std::vector<std::pair<diff_object*, diff_object*> > objs_upd_extra_;
};
} // namespace acl