Parcourir la source

move operator<< definition to library

Eric Ramat il y a 2 ans
Parent
commit
8f136ef8bb

+ 22 - 0
CMakeLists.txt

@@ -110,6 +110,28 @@ ELSE (UNIX)
     INSTALL(FILES "COPYING" DESTINATION "${ARTIS_SHARE_DIRS}" RENAME "CopyRight.txt")
 ENDIF (UNIX)
 
+#
+# Add sources for a target
+# add_sources(<target> <source1> [<source2> ...])
+#
+function(ADD_SOURCES target)
+    get_property(prop_defined GLOBAL PROPERTY ${target}_SRCS DEFINED)
+    if(NOT prop_defined)
+        define_property(GLOBAL PROPERTY ${target}_SRCS
+                BRIEF_DOCS "Sources for the ${target} target"
+                FULL_DOCS "List of source files for the ${target} target")
+    endif()
+
+    set(SRCS)
+    foreach(src ${ARGN})
+        if(NOT IS_ABSOLUTE "${src}")
+            get_filename_component(src "${src}" ABSOLUTE)
+        endif()
+        list(APPEND SRCS "${src}")
+    endforeach()
+    set_property(GLOBAL APPEND PROPERTY "${target}_SRCS" "${SRCS}")
+endfunction()
+
 #
 # Browse the src subdirectory
 #

+ 18 - 0
src/CMakeLists.txt

@@ -1 +1,19 @@
 ADD_SUBDIRECTORY(artis-star)
+
+#
+# Build the shared library.
+#
+
+GET_PROPERTY(artislib_SRCS GLOBAL PROPERTY artislib_SRCS)
+
+ADD_LIBRARY(artislib SHARED ${artislib_SRCS})
+
+TARGET_LINK_LIBRARIES(artislib ${Boost_LIBRARIES})
+
+SET_TARGET_PROPERTIES(artislib PROPERTIES
+        VERSION 0
+        OUTPUT_NAME "artis-star-${ARTIS_VERSION_SHORT}"
+        CLEAN_DIRECT_OUTPUT 1)
+
+INSTALL(TARGETS artislib RUNTIME DESTINATION bin LIBRARY DESTINATION
+        lib ARCHIVE DESTINATION lib)

+ 1 - 1
src/artis-star.pc.in

@@ -7,5 +7,5 @@ Name: artis-star
 Description: ARTIS* Multimodeling and Simulation tools
 Requires:
 Version: @ARTIS_VERSION@
-Libs:	-L${libdir}
+Libs:	-L${libdir} -lartis-star-@ARTIS_VERSION_SHORT@
 Cflags: -I${includedir}/artis-star-@ARTIS_VERSION_SHORT@ -I@ARTIS_PKGCONFIG_BOOSTINCLUDE_DIRS@

+ 1 - 1
src/artis-star/CMakeLists.txt

@@ -1,2 +1,2 @@
 ADD_SUBDIRECTORY(common)
-ADD_SUBDIRECTORY(kernel)
+ADD_SUBDIRECTORY(kernel)

+ 1 - 1
src/artis-star/common/event/Bag.hpp

@@ -1,5 +1,5 @@
 /**
- * @file common/Bag.hpp
+ * @file common/event/Bag.hpp
  * @author The ARTIS Development Team
  * See the AUTHORS or Authors.txt file
  */

+ 3 - 0
src/artis-star/common/event/CMakeLists.txt

@@ -7,6 +7,9 @@ LINK_DIRECTORIES(
         ${Boost_LIBRARY_DIRS})
 
 SET(COMMON_EVENT_HPP Bag.hpp ExternalEvent.hpp InternalEvent.hpp Value.hpp)
+SET(COMMON_EVENT_CPP Value.cpp)
+
+ADD_SOURCES(artislib ${COMMON_EVENT_HPP} ${COMMON_EVENT_CPP})
 
 INSTALL(FILES ${COMMON_EVENT_HPP} DESTINATION
         ${ARTIS_INCLUDE_DIRS}/common/event)

+ 1 - 1
src/artis-star/common/event/ExternalEvent.hpp

@@ -1,5 +1,5 @@
 /**
- * @file common/ExternalEvent.hpp
+ * @file common/event/ExternalEvent.hpp
  * @author The ARTIS Development Team
  * See the AUTHORS or Authors.txt file
  */

+ 1 - 1
src/artis-star/common/event/InternalEvent.hpp

@@ -1,5 +1,5 @@
 /**
- * @file common/InternalEvent.hpp
+ * @file common/event/InternalEvent.hpp
  * @author The ARTIS Development Team
  * See the AUTHORS or Authors.txt file
  */

+ 130 - 0
src/artis-star/common/event/Value.cpp

@@ -0,0 +1,130 @@
+/**
+ * @file common/event/Value.cpp
+ * @author The ARTIS Development Team
+ * See the AUTHORS or Authors.txt file
+ */
+
+/*
+ * ARTIS - the multimodeling and simulation environment
+ * This file is a part of the ARTIS environment
+ *
+ * Copyright (C) 2013-2022 ULCO http://www.univ-littoral.fr
+ *
+ * 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.
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "Value.hpp"
+
+namespace artis::common::event {
+
+const Value::ConvertFunctions Value::convert = {
+  {
+    typeid(double).hash_code(),         [](const Value &value) {
+    double v;
+
+    value.operator()(v);
+    return std::to_string(v);
+  }},
+  {
+    typeid(int).hash_code(),            [](const Value &value) {
+    int v;
+
+    value.operator()(v);
+    return std::to_string(v);
+  }},
+  {
+    typeid(unsigned int).hash_code(),   [](const Value &value) {
+    unsigned int v;
+
+    value.operator()(v);
+    return std::to_string(v);
+  }},
+  {
+    typeid(bool).hash_code(),           [](const Value &value) {
+    bool v;
+
+    value.operator()(v);
+    return v ? "true" : "false";
+  }},
+  {
+    typeid(char).hash_code(),           [](const Value &value) {
+    char v;
+
+    value.operator()(v);
+    return std::string(&v, 1);
+  }},
+  {
+    typeid(double *).hash_code(),       [](const Value &value) {
+
+    double *v;
+    std::string str;
+    size_t size = value._size / sizeof(double);
+
+    value.operator()(v);
+    for (size_t i = 0; i < size; ++i) {
+      str += std::to_string(v[i]) + std::string(" ");
+    }
+    return str;
+  }},
+  {
+    typeid(int *).hash_code(),          [](const Value &value) {
+    int *v;
+    std::string str;
+    size_t size = value._size / sizeof(int);
+
+    value.operator()(v);
+    for (size_t i = 0; i < size; ++i) {
+      str += std::to_string(v[i]) + std::string(" ");
+    }
+    return str;
+  }},
+  {
+    typeid(unsigned int *).hash_code(), [](const Value &value) {
+    unsigned int *v;
+    std::string str;
+    size_t size = value._size / sizeof(unsigned int);
+
+    value.operator()(v);
+    for (size_t i = 0; i < size; ++i) {
+      str += std::to_string(v[i]) + std::string(" ");
+    }
+    return str;
+  }},
+  {
+    typeid(bool *).hash_code(),         [](const Value &value) {
+    bool *v;
+    std::string str;
+    size_t size = value._size / sizeof(bool);
+
+    value.operator()(v);
+    for (size_t i = 0; i < size; ++i) {
+      str += (v[i] ? "true" : "false") + std::string(" ");
+    }
+    return str;
+  }},
+  {
+    typeid(char *).hash_code(),         [](const Value &value) {
+    char *v;
+
+    value.operator()(v);
+    return std::string(v, value._size / sizeof(char));
+  }
+  }};
+
+std::ostream &operator<<(std::ostream &o, const artis::common::event::Value &value) {
+  o << value.to_string();
+  return o;
+}
+
+} // namespace artis common event

+ 3 - 100
src/artis-star/common/event/Value.hpp

@@ -1,5 +1,5 @@
 /**
- * @file common/Value.hpp
+ * @file common/event/Value.hpp
  * @author The ARTIS Development Team
  * See the AUTHORS or Authors.txt file
  */
@@ -207,105 +207,8 @@ private:
   size_t _type_id = 0;
 };
 
-std::ostream& operator<<(std::ostream& o, const Value& value) {
-  o << value.to_string();
-  return o;
-}
-
-const Value::ConvertFunctions Value::convert = {
-  {
-    typeid(double).hash_code(),         [](const Value &value) {
-    double v;
-
-    value.operator()(v);
-    return std::to_string(v);
-  }},
-  {
-    typeid(int).hash_code(),            [](const Value &value) {
-    int v;
-
-    value.operator()(v);
-    return std::to_string(v);
-  }},
-  {
-    typeid(unsigned int).hash_code(),   [](const Value &value) {
-    unsigned int v;
-
-    value.operator()(v);
-    return std::to_string(v);
-  }},
-  {
-    typeid(bool).hash_code(),           [](const Value &value) {
-    bool v;
-
-    value.operator()(v);
-    return v ? "true" : "false";
-  }},
-  {
-    typeid(char).hash_code(),           [](const Value &value) {
-    char v;
-
-    value.operator()(v);
-    return std::string(&v, 1);
-  }},
-  {
-    typeid(double *).hash_code(),       [](const Value &value) {
-
-    double *v;
-    std::string str;
-    size_t size = value._size / sizeof(double);
-
-    value.operator()(v);
-    for (size_t i = 0; i < size; ++i) {
-      str += std::to_string(v[i]) + std::string(" ");
-    }
-    return str;
-  }},
-  {
-    typeid(int *).hash_code(),          [](const Value &value) {
-    int *v;
-    std::string str;
-    size_t size = value._size / sizeof(int);
-
-    value.operator()(v);
-    for (size_t i = 0; i < size; ++i) {
-      str += std::to_string(v[i]) + std::string(" ");
-    }
-    return str;
-  }},
-  {
-    typeid(unsigned int *).hash_code(), [](const Value &value) {
-    unsigned int *v;
-    std::string str;
-    size_t size = value._size / sizeof(unsigned int);
-
-    value.operator()(v);
-    for (size_t i = 0; i < size; ++i) {
-      str += std::to_string(v[i]) + std::string(" ");
-    }
-    return str;
-  }},
-  {
-    typeid(bool *).hash_code(),         [](const Value &value) {
-    bool *v;
-    std::string str;
-    size_t size = value._size / sizeof(bool);
-
-    value.operator()(v);
-    for (size_t i = 0; i < size; ++i) {
-      str += (v[i] ? "true" : "false") + std::string(" ");
-    }
-    return str;
-  }},
-  {
-    typeid(char *).hash_code(),         [](const Value &value) {
-    char *v;
-
-    value.operator()(v);
-    return std::string(v, value._size / sizeof(char));
-  }
-  }};
+std::ostream& operator<<(std::ostream& o, const artis::common::event::Value& value);
 
-} // namespace artis common
+} // namespace artis common event
 
 #endif

+ 6 - 6
tests/CMakeLists.txt

@@ -12,9 +12,9 @@ ADD_EXECUTABLE(common_state_tests common_state.cpp)
 ADD_EXECUTABLE(common_value_tests common_value.cpp)
 ADD_EXECUTABLE(kernel_pdevs_simulator_tests kernel_pdevs_simulator.cpp)
 
-TARGET_LINK_LIBRARIES(common_bag_tests ${Boost_LIBRARIES})
-TARGET_LINK_LIBRARIES(common_context_tests ${Boost_LIBRARIES})
-TARGET_LINK_LIBRARIES(common_observe_tests ${Boost_LIBRARIES})
-TARGET_LINK_LIBRARIES(common_state_tests ${Boost_LIBRARIES})
-TARGET_LINK_LIBRARIES(common_value_tests ${Boost_LIBRARIES})
-TARGET_LINK_LIBRARIES(kernel_pdevs_simulator_tests ${Boost_LIBRARIES})
+TARGET_LINK_LIBRARIES(common_bag_tests ${Boost_LIBRARIES} artislib)
+TARGET_LINK_LIBRARIES(common_context_tests ${Boost_LIBRARIES} artislib)
+TARGET_LINK_LIBRARIES(common_observe_tests ${Boost_LIBRARIES} artislib)
+TARGET_LINK_LIBRARIES(common_state_tests ${Boost_LIBRARIES} artislib)
+TARGET_LINK_LIBRARIES(common_value_tests ${Boost_LIBRARIES} artislib)
+TARGET_LINK_LIBRARIES(kernel_pdevs_simulator_tests ${Boost_LIBRARIES} artislib)