Skip to content

Commit 30f9030

Browse files
committed
project imported
1 parent 699c0f6 commit 30f9030

20 files changed

+1281
-0
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,7 @@
3030
*.exe
3131
*.out
3232
*.app
33+
34+
*~
35+
36+
build/*

CMakeLists.txt

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
cmake_minimum_required(VERSION 3.10)
2+
3+
# set the project name
4+
project(cpp2octave_demo)
5+
6+
# specify the C++ standard
7+
set(CMAKE_CXX_STANDARD 17)
8+
9+
add_subdirectory("cpp2oct")
10+
11+
# add the executable
12+
add_executable(${PROJECT_NAME} cpp2octave.cpp)
13+
14+
target_include_directories(${PROJECT_NAME} PUBLIC
15+
"${PROJECT_SOURCE_DIR}/cpp2oct")
16+
17+
target_link_libraries(${PROJECT_NAME} "cpp2oct")

cpp2oct/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
file(GLOB Sources "*.cpp")
2+
add_library(cpp2oct STATIC ${Sources})

cpp2oct/c2o_behavior_gen.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//#include "StdAfx.h"
2+
#include "c2o_behavior_gen.hpp"
3+
4+
5+
namespace cpp2octave{
6+
const string c2o_behavior_gen::P__SCRIPT_DEF_EXTENSION = ".m";
7+
8+
9+
};

cpp2oct/c2o_behavior_gen.hpp

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#pragma once
2+
3+
#include <iostream>
4+
5+
using namespace std;
6+
7+
namespace cpp2octave{
8+
9+
class c2o_behavior_gen
10+
{
11+
public:
12+
static const string P__SCRIPT_DEF_EXTENSION;
13+
14+
};
15+
16+
17+
};

cpp2oct/c2o_datafile_gen.cpp

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//#include "StdAfx.h"
2+
#include "c2o_datafile_gen.h"
3+
4+
5+
namespace cpp2octave {
6+
7+
namespace c2o_datafile_gen_policies {
8+
9+
const string c2o_datafile_WM_ASCII::WM_FILE_PREFIX = "ASCII";
10+
const string c2o_datafile_WM_ASCII::OCT_READ_MODE = "r";
11+
12+
const string
13+
c2o_datafile_WM_ASCII::
14+
reading_tags< double >::READING_TAG = "%f ";
15+
16+
const string
17+
c2o_datafile_WM_ASCII::
18+
reading_tags< int >::READING_TAG = "%d ";
19+
20+
const ios_base::openmode
21+
c2o_datafile_WM_ASCII::
22+
WM_IOS_MODE = ios::out;
23+
24+
25+
///////////////////////////////////////////////////////
26+
27+
const string c2o_datafile_WM_BIN::WM_FILE_PREFIX = "BIN";
28+
const string c2o_datafile_WM_BIN::OCT_READ_MODE = "rb";
29+
30+
const string
31+
c2o_datafile_WM_BIN::
32+
reading_tags< double >::READING_TAG = "double";
33+
34+
const string
35+
c2o_datafile_WM_BIN::
36+
reading_tags< int >::READING_TAG = "int";
37+
38+
const ios_base::openmode
39+
c2o_datafile_WM_BIN::
40+
WM_IOS_MODE = ios::out | ios::binary;
41+
42+
};
43+
};
44+

cpp2oct/c2o_datafile_gen.h

+159
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
#pragma once
2+
#include "cpp2oct_core.h"
3+
4+
using namespace std;
5+
6+
namespace cpp2octave {
7+
8+
namespace c2o_datafile_gen_policies{
9+
class c2o_datafile_WM_ASCII {
10+
public:
11+
static const string WM_FILE_PREFIX; // = "ASCII"
12+
static const string OCT_READ_MODE; //="r"
13+
14+
static const ios_base::openmode WM_IOS_MODE;// = ios::out;
15+
16+
template< class T > class reading_tags { };
17+
18+
19+
20+
template< class T >
21+
static c2o_obj& serial_write(
22+
bool octFileIsOpen,
23+
c2o_obj& dest ,
24+
const T* vect ,
25+
size_t N ,
26+
ofstream& out_file ,
27+
c2o_obj & out_file_link ,
28+
cpp2oct_core * owner
29+
){
30+
if( octFileIsOpen ){
31+
stringstream o;
32+
for( int i = 0 ; i < N ; i++ ){
33+
o << vect[i] << " " ;
34+
}
35+
o << "\n";
36+
out_file << o.str();
37+
38+
owner->oct_f_call(
39+
dest ,
40+
"fscanf" ,
41+
out_file_link ,
42+
reading_tags< T >::READING_TAG ,
43+
static_cast<int> ( N )
44+
);
45+
}
46+
47+
return dest;
48+
}
49+
};
50+
51+
template< >
52+
class c2o_datafile_WM_ASCII::reading_tags< double > { public: static const string READING_TAG; };
53+
54+
template< >
55+
class c2o_datafile_WM_ASCII::reading_tags< int > { public: static const string READING_TAG; };
56+
57+
class c2o_datafile_WM_BIN {
58+
public:
59+
static const string WM_FILE_PREFIX; //= "BIN"
60+
static const string OCT_READ_MODE; //="rb"
61+
62+
static const ios_base::openmode WM_IOS_MODE;// = ios::out || ios::binary;
63+
64+
template< class T > class reading_tags { };
65+
66+
67+
68+
template< class T >
69+
static c2o_obj& serial_write(
70+
bool octFileIsOpen,
71+
c2o_obj& dest ,
72+
const T* vect ,
73+
size_t N ,
74+
ofstream& out_file ,
75+
c2o_obj & out_file_link ,
76+
cpp2oct_core * owner
77+
){
78+
79+
if( octFileIsOpen ){
80+
out_file.write ((char*)vect, N * sizeof (T));
81+
82+
owner->oct_f_call(
83+
dest ,
84+
"fread" ,
85+
out_file_link ,
86+
static_cast<int> ( N ),
87+
reading_tags< T >::READING_TAG
88+
);
89+
}
90+
91+
return dest;
92+
93+
}
94+
};
95+
template< >
96+
class c2o_datafile_WM_BIN::reading_tags< double > { public: static const string READING_TAG; };
97+
98+
template< >
99+
class c2o_datafile_WM_BIN::reading_tags< int > { public: static const string READING_TAG; };
100+
};
101+
102+
103+
using namespace c2o_datafile_gen_policies;
104+
105+
106+
typedef c2o_datafile_gen_policies::c2o_datafile_WM_ASCII c2o_datafile_P_ASCII;
107+
typedef c2o_datafile_gen_policies::c2o_datafile_WM_BIN c2o_datafile_P_BIN;
108+
109+
110+
template< class P__ >
111+
class c2o_datafile_gen :
112+
public c2o_datafile_handler
113+
{
114+
private:
115+
ofstream out_file;
116+
c2o_obj out_file_link;
117+
bool octFileIsOpen;
118+
119+
void out_file_init( ){
120+
stringstream s;
121+
s << path << DIR_SEP_CH << f_name;
122+
string fname_str = s.str();
123+
out_file.open( fname_str.c_str() , /*ios::out | ios::binary*/ P__::WM_IOS_MODE );
124+
125+
owner->f_fopen( out_file_link , fname_str , P__::OCT_READ_MODE );
126+
octFileIsOpen = true;
127+
};
128+
129+
public:
130+
c2o_datafile_gen( cpp2oct_core * _owner , string _f_name ) :
131+
c2o_datafile_handler( _owner , _f_name ),
132+
out_file_link(_owner->oct_new_obj_base( string(P__::WM_FILE_PREFIX).append("_f_").append(_f_name)) )
133+
134+
{
135+
out_file_init( );
136+
};
137+
138+
c2o_obj& serial_write( c2o_obj& dest , const int* vect , size_t N ){
139+
return P__::serial_write( octFileIsOpen , dest , vect , N , out_file , out_file_link , owner );
140+
}
141+
142+
c2o_obj& serial_write( c2o_obj& dest , const double* vect , size_t N ){
143+
return P__::serial_write( octFileIsOpen , dest , vect , N , out_file , out_file_link , owner);
144+
}
145+
146+
void datafile_close( void ){
147+
if( octFileIsOpen ){
148+
out_file.close() ;
149+
owner->f_fclose( out_file_link );
150+
octFileIsOpen = false;
151+
}
152+
};
153+
154+
~c2o_datafile_gen(void){
155+
datafile_close( );
156+
};
157+
};
158+
159+
}

cpp2oct/c2o_datafile_handler.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//#include "StdAfx.h"
2+
#include "c2o_datafile_handler.h"
3+
4+
5+
/*c2o_datafile_handler::c2o_datafile_handler(void)
6+
{
7+
}
8+
9+
10+
c2o_datafile_handler::~c2o_datafile_handler(void)
11+
{
12+
}
13+
*/

cpp2oct/c2o_datafile_handler.h

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#pragma once
2+
3+
4+
5+
/*
6+
* Interface for storing vectors
7+
*/
8+
/*class c2o_datafile_handler
9+
{
10+
public:
11+
c2o_datafile_handler(void);
12+
13+
14+
15+
16+
~c2o_datafile_handler(void);
17+
};
18+
19+
*/

cpp2oct/c2o_fname_handler.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//#include "StdAfx.h"
2+
#include "c2o_fname_handler.h"
3+
4+
5+
namespace cpp2octave{
6+
7+
const string c2o_fname_handler::P__SCRIPT_DEF_EXTENSION = ".m";
8+
9+
10+
};

cpp2oct/c2o_fname_handler.h

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#pragma once
2+
3+
#include <iostream>
4+
5+
using namespace std;
6+
7+
namespace cpp2octave{
8+
9+
class c2o_fname_handler
10+
{
11+
12+
private:
13+
string main_script_name;
14+
string support_folder_name;
15+
public:
16+
17+
static const string P__SCRIPT_DEF_EXTENSION;
18+
19+
20+
c2o_fname_handler( string env_name , string path , string support_folder ){
21+
main_script_name
22+
.append( path )
23+
.append( env_name )
24+
.append( P__SCRIPT_DEF_EXTENSION );
25+
26+
support_folder_name
27+
.append( path )
28+
//.append( "/" ) //TODO: discuss better path form
29+
.append( support_folder )
30+
.append( "_" )
31+
.append( env_name );
32+
33+
}
34+
35+
string get_main_script_name(){ return main_script_name; }
36+
string get_support_folder_name(){ return support_folder_name; }
37+
38+
39+
};
40+
41+
};

cpp2oct/cpp2oct.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//#include "StdAfx.h"
2+
#include "cpp2oct.h"
3+
4+
namespace cpp2octave {
5+
6+
cpp2oct::cpp2oct( string _env_name ) : cpp2oct_core( _env_name )
7+
{
8+
}
9+
10+
11+
cpp2oct::~cpp2oct(void)
12+
{
13+
datafile_set.remove_if( delete_datafile_set_ptrs );
14+
}
15+
16+
};

0 commit comments

Comments
 (0)