1 /**
2 * @file bindings/cli/get_allocated_memory.hpp
3 * @author Ryan Curtin
4 *
5 * If the parameter has a type that may need to be deleted, return the address
6 * of that object. Otherwise return NULL.
7 *
8 * mlpack is free software; you may redistribute it and/or modify it under the
9 * terms of the 3-clause BSD license. You should have received a copy of the
10 * 3-clause BSD license along with mlpack. If not, see
11 * http://www.opensource.org/licenses/BSD-3-Clause for more information.
12 */
13 #ifndef MLPACK_BINDINGS_CLI_GET_ALLOCATED_MEMORY_HPP
14 #define MLPACK_BINDINGS_CLI_GET_ALLOCATED_MEMORY_HPP
15
16 #include <mlpack/core/util/param_data.hpp>
17
18 namespace mlpack {
19 namespace bindings {
20 namespace cli {
21
22 template<typename T>
GetAllocatedMemory(util::ParamData &,const typename boost::disable_if<data::HasSerialize<T>>::type * =0,const typename boost::disable_if<arma::is_arma_type<T>>::type * =0)23 void* GetAllocatedMemory(
24 util::ParamData& /* d */,
25 const typename boost::disable_if<data::HasSerialize<T>>::type* = 0,
26 const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0)
27 {
28 return NULL;
29 }
30
31 template<typename T>
GetAllocatedMemory(util::ParamData &,const typename boost::enable_if<arma::is_arma_type<T>>::type * =0)32 void* GetAllocatedMemory(
33 util::ParamData& /* d */,
34 const typename boost::enable_if<arma::is_arma_type<T>>::type* = 0)
35 {
36 return NULL;
37 }
38
39 template<typename T>
GetAllocatedMemory(util::ParamData & d,const typename boost::disable_if<arma::is_arma_type<T>>::type * =0,const typename boost::enable_if<data::HasSerialize<T>>::type * =0)40 void* GetAllocatedMemory(
41 util::ParamData& d,
42 const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0,
43 const typename boost::enable_if<data::HasSerialize<T>>::type* = 0)
44 {
45 // Here we have a model, which is a tuple, and we need the address of the
46 // memory.
47 typedef std::tuple<T*, std::string> TupleType;
48 return std::get<0>(*boost::any_cast<TupleType>(&d.value));
49 }
50
51 template<typename T>
GetAllocatedMemory(util::ParamData & d,const void *,void * output)52 void GetAllocatedMemory(util::ParamData& d,
53 const void* /* input */,
54 void* output)
55 {
56 *((void**) output) =
57 GetAllocatedMemory<typename std::remove_pointer<T>::type>(d);
58 }
59
60 } // namespace cli
61 } // namespace bindings
62 } // namespace mlpack
63
64 #endif
65