resource.cpp
1 /*
2  * This file is part of CasADi.
3  *
4  * CasADi -- A symbolic framework for dynamic optimization.
5  * Copyright (C) 2010-2023 Joel Andersson, Joris Gillis, Moritz Diehl,
6  * KU Leuven. All rights reserved.
7  * Copyright (C) 2011-2014 Greg Horn
8  *
9  * CasADi is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 3 of the License, or (at your option) any later version.
13  *
14  * CasADi is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with CasADi; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  *
23  */
24 
25 
26 #include "resource.hpp"
27 #include "resource_internal.hpp"
28 #include "filesystem_impl.hpp"
29 
30 namespace casadi {
31 
33  }
34 
35  Resource::Resource(const std::string& path) {
36  // Pass through empty strings
38  own(new DirResource(path));
39  return;
40  }
41  own(new ZipResource(path));
42  }
43 
45  Resource ret;
46  ret.own(node);
47  return ret;
48  }
49 
51  return static_cast<const ResourceInternal*>(SharedObject::operator->());
52  }
53 
55  return static_cast<ResourceInternal*>(SharedObject::operator->());
56  }
57 
59  return *static_cast<const ResourceInternal*>(get());
60  }
61 
63  return dynamic_cast<const ResourceInternal*>(ptr)!=nullptr;
64  }
65 
67  return static_cast<ResourceInternal*>(SharedObject::get());
68  }
69 
70  const std::string& Resource::path() const {
71  return (*this)->path();
72  }
73 
74  void Resource::change_option(const std::string& option_name, const GenericType& option_value) {
75  return (*this)->change_option(option_name, option_value);
76  }
77 
79  return (*this)->serialize(s);
80  }
81 
84  }
85 
86 } // namespace casadi
Helper class for Serialization.
static bool is_directory(const std::string &path)
Definition: filesystem.cpp:38
static bool is_enabled()
Definition: filesystem.cpp:83
SharedObjectInternal * get() const
Get a const pointer to the node.
SharedObjectInternal * operator->() const
Access a member function or object.
Generic data type, can hold different types such as bool, casadi_int, std::string etc.
RAII class base for reading from resources.
static ResourceInternal * deserialize(DeserializingStream &s)
RAII class for reading from a zip file.
Definition: resource.hpp:44
const ResourceInternal & operator*() const
Reference to internal structure.
Definition: resource.cpp:58
void serialize(SerializingStream &s) const
Serialize an object.
Definition: resource.cpp:78
ResourceInternal * get() const
Definition: resource.cpp:66
static bool test_cast(const SharedObjectInternal *ptr)
Check if a particular cast is allowed.
Definition: resource.cpp:62
const ResourceInternal * operator->() const
Access a member function or object.
Definition: resource.cpp:50
Resource()
Default constructor.
Definition: resource.cpp:32
static Resource deserialize(DeserializingStream &s)
Deserialize with type disambiguation.
Definition: resource.cpp:82
const std::string & path() const
Get path for a consumer.
Definition: resource.cpp:70
void change_option(const std::string &option_name, const GenericType &option_value)
Change option after object creation for debugging.
Definition: resource.cpp:74
static Resource create(ResourceInternal *node)
Create from node.
Definition: resource.cpp:44
Helper class for Serialization.
RAII class for reading from a zip file.
The casadi namespace.
Definition: archiver.cpp:28
std::vector< casadi_int > path(const std::vector< casadi_int > &map, casadi_int i_start)