CppADCodeGen
2.4.3
A C++ Algorithmic Differentiation Package with Source Code Generation
Loading...
Searching...
No Matches
save_files_model_library_processor.hpp
1
#ifndef CPPAD_CG_SAVE_FILES_MODEL_LIBRARY_PROCESSOR_INCLUDED
2
#define CPPAD_CG_SAVE_FILES_MODEL_LIBRARY_PROCESSOR_INCLUDED
3
/* --------------------------------------------------------------------------
4
* CppADCodeGen: C++ Algorithmic Differentiation with Source Code Generation:
5
* Copyright (C) 2019 Joao Leal
6
* Copyright (C) 2013 Ciengis
7
*
8
* CppADCodeGen is distributed under multiple licenses:
9
*
10
* - Eclipse Public License Version 1.0 (EPL1), and
11
* - GNU General Public License Version 3 (GPL3).
12
*
13
* EPL1 terms and conditions can be found in the file "epl-v10.txt", while
14
* terms and conditions for the GPL3 can be found in the file "gpl3.txt".
15
* ----------------------------------------------------------------------------
16
* Author: Joao Leal
17
*/
18
19
namespace
CppAD
{
20
namespace
cg {
21
28
template
<
class
Base>
29
class
SaveFilesModelLibraryProcessor
:
public
ModelLibraryProcessor
<Base> {
30
public
:
31
32
inline
explicit
SaveFilesModelLibraryProcessor
(
ModelLibraryCSourceGen<Base>
&
modelLibraryHelper
) :
33
ModelLibraryProcessor<Base>
(
modelLibraryHelper
) {
34
}
35
36
inline
virtual
~SaveFilesModelLibraryProcessor
() =
default
;
37
38
inline
void
saveSources() {
39
saveSourcesTo(
"cppadcg_sources"
);
40
}
41
42
inline
void
saveSourcesTo(
const
std::string&
sourcesFolder
) {
43
44
auto
saveFile
= [&](
const
std::string&
filename
,
const
std::string&
source
){
45
std::ofstream
sourceFile
;
46
std::string
file
=
system::createPath
(
sourcesFolder
,
filename
);
47
sourceFile
.open(
file
.c_str());
48
sourceFile
<<
source
;
49
sourceFile
.close();
50
};
51
52
system::createFolder
(
sourcesFolder
);
53
54
const
std::map<std::string, ModelCSourceGen<Base>*>&
models
= this->modelLibraryHelper_->getModels();
55
56
for
(
const
auto
&
itm
:
models
) {
57
const
std::map<std::string, std::string>&
sources
= this->getSources(*
itm
.second);
58
59
for
(
const
auto
&
it
:
sources
) {
60
saveFile
(
it
.first,
it
.second);
61
}
62
}
63
64
for
(
const
auto
&
it
: this->modelLibraryHelper_->getLibrarySources()) {
65
saveFile
(
it
.first,
it
.second);
66
}
67
68
for
(
const
auto
&
it
: this->modelLibraryHelper_->getCustomSources()) {
69
saveFile
(
it
.first,
it
.second);
70
}
71
}
72
73
inline
static
void
saveLibrarySourcesTo(
ModelLibraryCSourceGen<Base>
&
modelLibraryHelper
,
74
const
std::string&
sourcesFolder
) {
75
SaveFilesModelLibraryProcessor
s(
modelLibraryHelper
);
76
s.saveSourcesTo(
sourcesFolder
);
77
}
78
79
};
80
81
}
// END cg namespace
82
}
// END CppAD namespace
83
84
#endif
CppAD::cg::ModelLibraryCSourceGen
Definition
model_library_c_source_gen.hpp:28
CppAD::cg::ModelLibraryProcessor
Definition
model_library_processor.hpp:28
CppAD::cg::SaveFilesModelLibraryProcessor
Definition
save_files_model_library_processor.hpp:29
CppAD::cg::system::createPath
std::string createPath(const std::string &baseFolder, const std::string &file)
CppAD::cg::system::createFolder
void createFolder(const std::string &folder)
CppAD
Definition
abstract_atomic_fun.hpp:19
CppAD::GreaterThanZero
bool GreaterThanZero(const cg::CG< Base > &x)
Definition
ordered.hpp:21
include
cppad
cg
model
save_files_model_library_processor.hpp
Generated on Tue Sep 10 2024 03:29:11 for CppADCodeGen by
1.10.0