From 4f4b80f7d94f7cbf8503460855d21dd9d8931eb1 Mon Sep 17 00:00:00 2001
From: Victor Kotlyar <Victor.Kotlyar@cern.ch>
Date: Wed, 7 Sep 2016 09:27:14 +0200
Subject: [PATCH] Moved castor::utils::SmartArrayPtr to cta::SmartArrayPtr

---
 common/CMakeLists.txt                         |  1 +
 .../castor/utils => common}/SmartArrayPtr.hpp | 31 ++++-------
 .../utils => common}/SmartArrayPtrTest.cpp    | 55 +++++++++----------
 .../castor/tape/reactor/PollReactorImpl.cpp   |  6 +-
 .../tape/tapeserver/daemon/ProcessForker.cpp  |  2 +-
 .../tapeserver/daemon/ProcessForkerUtils.cpp  |  4 +-
 tapeserver/castor/utils/CMakeLists.txt        |  1 -
 7 files changed, 44 insertions(+), 56 deletions(-)
 rename {tapeserver/castor/utils => common}/SmartArrayPtr.hpp (81%)
 rename {tapeserver/castor/utils => common}/SmartArrayPtrTest.cpp (56%)

diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt
index f2aa5b97ca..6929c02195 100644
--- a/common/CMakeLists.txt
+++ b/common/CMakeLists.txt
@@ -145,6 +145,7 @@ set (COMMON_UNIT_TESTS_LIB_SRC_FILES
   log/StringLoggerTest.cpp
   remoteFS/RemotePathTest.cpp
   SmartFdTest.cpp
+  SmartArrayPtrTest.cpp
   CRCTest.cpp
   threading/DaemonTest.cpp
   threading/SocketPairTest.cpp
diff --git a/tapeserver/castor/utils/SmartArrayPtr.hpp b/common/SmartArrayPtr.hpp
similarity index 81%
rename from tapeserver/castor/utils/SmartArrayPtr.hpp
rename to common/SmartArrayPtr.hpp
index 5a718d4026..2f1ddc2c61 100644
--- a/tapeserver/castor/utils/SmartArrayPtr.hpp
+++ b/common/SmartArrayPtr.hpp
@@ -1,25 +1,20 @@
-/******************************************************************************
+/*
+ * The CERN Tape Archive (CTA) project
+ * Copyright (C) 2015  CERN
  *
- * This file is part of the Castor project.
- * See http://castor.web.cern.ch/castor
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
  *
- * Copyright (C) 2003  CERN
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
  *
- * 
- * @author Castor Dev team, castor-dev@cern.ch
- *****************************************************************************/
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
 
 #pragma once
 
@@ -29,8 +24,7 @@
 #include <stdio.h>
 
 
-namespace castor {
-namespace utils {
+namespace cta {
 
 /**
  * A smart pointer that owns a pointer to an array and unlike std::unique_ptr
@@ -156,6 +150,5 @@ private:
 
 }; // class SmartArrayPtr
 
-} // namespace utils
-} // namespace castor
+} // namespace cta
 
diff --git a/tapeserver/castor/utils/SmartArrayPtrTest.cpp b/common/SmartArrayPtrTest.cpp
similarity index 56%
rename from tapeserver/castor/utils/SmartArrayPtrTest.cpp
rename to common/SmartArrayPtrTest.cpp
index 5cdcc20ed8..c8c6fdd792 100644
--- a/tapeserver/castor/utils/SmartArrayPtrTest.cpp
+++ b/common/SmartArrayPtrTest.cpp
@@ -1,27 +1,22 @@
-/******************************************************************************
+/*
+ * The CERN Tape Archive (CTA) project
+ * Copyright (C) 2015  CERN
  *
- * This file is part of the Castor project.
- * See http://castor.web.cern.ch/castor
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
  *
- * Copyright (C) 2003  CERN
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
  *
- *
- * @author Castor Dev team, castor-dev@cern.ch
- *****************************************************************************/
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
 
-#include "castor/utils/SmartArrayPtr.hpp"
+#include "common/SmartArrayPtr.hpp"
 
 #include <gtest/gtest.h>
 #include <list>
@@ -33,7 +28,7 @@
 
 namespace unitTests {
 
-class castor_utils_SmartArrayPtrTest : public ::testing::Test {
+class cta_SmartArrayPtrTest : public ::testing::Test {
 protected:
 
   virtual void SetUp() {
@@ -43,25 +38,25 @@ protected:
   }
 };
 
-TEST_F(castor_utils_SmartArrayPtrTest, constructor) {
+TEST_F(cta_SmartArrayPtrTest, constructor) {
   char *ptr = new char[10];
-  castor::utils::SmartArrayPtr<char> smartPtr(ptr);
+  cta::SmartArrayPtr<char> smartPtr(ptr);
 
   ASSERT_EQ(ptr, smartPtr.get());
 }
 
-TEST_F(castor_utils_SmartArrayPtrTest, reset) {
+TEST_F(cta_SmartArrayPtrTest, reset) {
   char *ptr = new char[10];
-  castor::utils::SmartArrayPtr<char> smartPtr;
+  cta::SmartArrayPtr<char> smartPtr;
 
   ASSERT_EQ((char *)0, smartPtr.get());
   smartPtr.reset(ptr);
   ASSERT_EQ(ptr, smartPtr.get());
 }
 
-TEST_F(castor_utils_SmartArrayPtrTest, assignment) {
-  castor::utils::SmartArrayPtr<char> smartPtr1;
-  castor::utils::SmartArrayPtr<char> smartPtr2;
+TEST_F(cta_SmartArrayPtrTest, assignment) {
+  cta::SmartArrayPtr<char> smartPtr1;
+  cta::SmartArrayPtr<char> smartPtr2;
 
   ASSERT_EQ((char *)0, smartPtr1.get());
   ASSERT_EQ((char *)0, smartPtr2.get());
@@ -75,19 +70,19 @@ TEST_F(castor_utils_SmartArrayPtrTest, assignment) {
   ASSERT_EQ(ptr, smartPtr2.get());
 }
 
-TEST_F(castor_utils_SmartArrayPtrTest, releaseNull) {
-  castor::utils::SmartArrayPtr<char> smartPtr;
+TEST_F(cta_SmartArrayPtrTest, releaseNull) {
+  cta::SmartArrayPtr<char> smartPtr;
   ASSERT_THROW(smartPtr.release(), cta::exception::NotAnOwner);
 }
 
-TEST_F(castor_utils_SmartArrayPtrTest, subscriptRead) {
+TEST_F(cta_SmartArrayPtrTest, subscriptRead) {
   char *ptr = new char[4];
   ptr[0] = 'T';
   ptr[1] = 'e';
   ptr[2] = 's';
   ptr[3] = 't';
 
-  castor::utils::SmartArrayPtr<char> smartPtr(ptr);
+  cta::SmartArrayPtr<char> smartPtr(ptr);
   ASSERT_EQ(ptr, smartPtr.get());
 
   ASSERT_EQ('T', smartPtr[0]);
@@ -96,14 +91,14 @@ TEST_F(castor_utils_SmartArrayPtrTest, subscriptRead) {
   ASSERT_EQ('t', smartPtr[3]);
 }
 
-TEST_F(castor_utils_SmartArrayPtrTest, subscriptAssigment) {
+TEST_F(cta_SmartArrayPtrTest, subscriptAssigment) {
   char *ptr = new char[4];
   ptr[0] = 'T';
   ptr[1] = 'e';
   ptr[2] = 's';
   ptr[3] = 't';
 
-  castor::utils::SmartArrayPtr<char> smartPtr(ptr);
+  cta::SmartArrayPtr<char> smartPtr(ptr);
   ASSERT_EQ(ptr, smartPtr.get());
 
   ASSERT_EQ('T', smartPtr[0]);
diff --git a/tapeserver/castor/tape/reactor/PollReactorImpl.cpp b/tapeserver/castor/tape/reactor/PollReactorImpl.cpp
index c12841df80..705d17c7bf 100644
--- a/tapeserver/castor/tape/reactor/PollReactorImpl.cpp
+++ b/tapeserver/castor/tape/reactor/PollReactorImpl.cpp
@@ -21,7 +21,7 @@
 
 #include "common/exception/BadAlloc.hpp"
 #include "castor/tape/reactor/PollReactorImpl.hpp"
-#include "castor/utils/SmartArrayPtr.hpp"
+#include "common/SmartArrayPtr.hpp"
 #include "castor/utils/utils.hpp"
 
 #include <unistd.h>
@@ -90,7 +90,7 @@ void castor::tape::reactor::PollReactorImpl::removeHandler(
 //------------------------------------------------------------------------------
 void castor::tape::reactor::PollReactorImpl::handleEvents(const int timeout) {
   nfds_t nfds = 0;
-  castor::utils::SmartArrayPtr<struct pollfd> fds(buildPollFds(nfds));
+  cta::SmartArrayPtr<struct pollfd> fds(buildPollFds(nfds));
 
   const int pollrc = poll(fds.get(), nfds, timeout);
 
@@ -121,7 +121,7 @@ struct pollfd *castor::tape::reactor::PollReactorImpl::buildPollFds(
   nfds_t &nfds) {
   nfds = m_handlers.size();
 
-  castor::utils::SmartArrayPtr<struct pollfd> fds;
+  cta::SmartArrayPtr<struct pollfd> fds;
   try {
     fds.reset(new struct pollfd[nfds]);
   } catch(std::bad_alloc &ba) {
diff --git a/tapeserver/castor/tape/tapeserver/daemon/ProcessForker.cpp b/tapeserver/castor/tape/tapeserver/daemon/ProcessForker.cpp
index 9f9e2d511c..456f816474 100644
--- a/tapeserver/castor/tape/tapeserver/daemon/ProcessForker.cpp
+++ b/tapeserver/castor/tape/tapeserver/daemon/ProcessForker.cpp
@@ -44,7 +44,7 @@
 #include "castor/tape/tapeserver/daemon/LabelSession.hpp"
 #include "castor/tape/tapeserver/daemon/ProcessForker.hpp"
 #include "castor/tape/tapeserver/daemon/ProcessForkerUtils.hpp"
-#include "castor/utils/SmartArrayPtr.hpp"
+#include "common/SmartArrayPtr.hpp"
 #include "castor/utils/utils.hpp"
 #include "catalogue/CatalogueFactory.hpp"
 #include "common/exception/Exception.hpp"
diff --git a/tapeserver/castor/tape/tapeserver/daemon/ProcessForkerUtils.cpp b/tapeserver/castor/tape/tapeserver/daemon/ProcessForkerUtils.cpp
index 452622c71a..d96a7a1251 100644
--- a/tapeserver/castor/tape/tapeserver/daemon/ProcessForkerUtils.cpp
+++ b/tapeserver/castor/tape/tapeserver/daemon/ProcessForkerUtils.cpp
@@ -23,7 +23,7 @@
 
 #include "castor/io/io.hpp"
 #include "castor/tape/tapeserver/daemon/ProcessForkerUtils.hpp"
-#include "castor/utils/SmartArrayPtr.hpp"
+#include "common/SmartArrayPtr.hpp"
 #include "castor/utils/utils.hpp"
 #include "common/exception/Exception.hpp"
 
@@ -469,7 +469,7 @@ std::string castor::tape::tapeserver::daemon::ProcessForkerUtils::
       throw ex;
     }
 
-    utils::SmartArrayPtr<char> payloadBuf(new char[payloadLen]);
+    cta::SmartArrayPtr<char> payloadBuf(new char[payloadLen]);
     io::readBytes(fd, timeout, payloadLen, payloadBuf.get());
 
     return std::string(payloadBuf.get(), payloadLen);
diff --git a/tapeserver/castor/utils/CMakeLists.txt b/tapeserver/castor/utils/CMakeLists.txt
index 1de6a22bc3..c7bfc5c712 100644
--- a/tapeserver/castor/utils/CMakeLists.txt
+++ b/tapeserver/castor/utils/CMakeLists.txt
@@ -35,7 +35,6 @@ target_link_libraries(ctautils castorlog)
 install(TARGETS ctautils DESTINATION usr/${CMAKE_INSTALL_LIBDIR})
 
 add_library (ctautilsunittests SHARED
-  SmartArrayPtrTest.cpp
   UtilsTest.cpp)
 
 install(TARGETS ctautilsunittests DESTINATION usr/${CMAKE_INSTALL_LIBDIR})
-- 
GitLab