degate  0.1.2
DeepCopyable.cc
Go to the documentation of this file.
00001 /* -*-c++-*-
00002 
00003  This file is part of the IC reverse engineering tool degate.
00004 
00005  Copyright 2012 Robert Nitsch
00006 
00007  Degate is free software: you can redistribute it and/or modify
00008  it under the terms of the GNU General Public License as published by
00009  the Free Software Foundation, either version 3 of the License, or
00010  any later version.
00011 
00012  Degate is distributed in the hope that it will be useful,
00013  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  GNU General Public License for more details.
00016 
00017  You should have received a copy of the GNU General Public License
00018  along with degate. If not, see <http://www.gnu.org/licenses/>.
00019 */
00020 
00021 #include "DeepCopyable.h"
00022 
00023 #include <assert.h>
00024 
00025 namespace degate {
00026 
00027 DeepCopyable_shptr DeepCopyable::cloneDeep(oldnew_t *oldnew) const {
00028   auto _this = shared_from_this();
00029   if (cloneOnce(_this, oldnew)) {
00030     cloneDeepInto((*oldnew)[_this], oldnew);
00031   }
00032   return (*oldnew)[_this];
00033 }
00034 
00035 bool DeepCopyable::cloneOnce(const c_DeepCopyable_shptr &o, std::map<c_DeepCopyable_shptr, DeepCopyable_shptr> *__oldnew) {
00036   assert(o.get() != 0);
00037   
00038   std::map<c_DeepCopyable_shptr, DeepCopyable_shptr> &oldnew = *__oldnew;
00039   if (oldnew.count(o) > 0) {
00040     return false;
00041   }
00042   
00043   DeepCopyable_shptr clone = o->cloneShallow();
00044   oldnew[o] = clone;
00045   return true;
00046 }
00047 
00048 }