1 | #pragma once
|
---|
2 |
|
---|
3 | #include <vector>
|
---|
4 | #include <string>
|
---|
5 |
|
---|
6 | #include <windows.h>
|
---|
7 | #include <stdlib.h>
|
---|
8 |
|
---|
9 | #include <jenga/include/common/Exception.h>
|
---|
10 | #include <jenga/include/smoothie/BasicFixed.h>
|
---|
11 |
|
---|
12 | #include <BoostSerializationSupport.h>
|
---|
13 |
|
---|
14 | using namespace std;
|
---|
15 |
|
---|
16 | struct INCLUDEFILEINFO{
|
---|
17 | char **ppFileNames;
|
---|
18 | int FilesNum;
|
---|
19 | int LineOfFile[MAX_LEN];
|
---|
20 | };
|
---|
21 |
|
---|
22 | class Text{
|
---|
23 | protected:
|
---|
24 | char *buffer;
|
---|
25 | int length;
|
---|
26 |
|
---|
27 | // XMLシリアライズ用
|
---|
28 | private:
|
---|
29 | friend class boost::serialization::access;
|
---|
30 | BOOST_SERIALIZATION_SPLIT_MEMBER();
|
---|
31 | template<class Archive> void load(Archive& ar, const unsigned int version)
|
---|
32 | {
|
---|
33 | trace_for_serialize( "serializing(load) - Text" );
|
---|
34 |
|
---|
35 | std::string str;
|
---|
36 | ar & BOOST_SERIALIZATION_NVP( str );
|
---|
37 |
|
---|
38 | // 読み込み後の処理
|
---|
39 | Clear();
|
---|
40 | Add( str );
|
---|
41 | }
|
---|
42 | template<class Archive> void save(Archive& ar, const unsigned int version) const
|
---|
43 | {
|
---|
44 | trace_for_serialize( "serializing(save) - Text" );
|
---|
45 |
|
---|
46 | // 保存準備
|
---|
47 | std::string str( buffer, length );
|
---|
48 |
|
---|
49 | ar & BOOST_SERIALIZATION_NVP( str );
|
---|
50 | }
|
---|
51 | public:
|
---|
52 |
|
---|
53 | Text(){
|
---|
54 | buffer = (char *)calloc( 1, 1 );
|
---|
55 | length = 0;
|
---|
56 | }
|
---|
57 | ~Text(){
|
---|
58 | free( buffer );
|
---|
59 | }
|
---|
60 | void Clear()
|
---|
61 | {
|
---|
62 | length = 0;
|
---|
63 | }
|
---|
64 | void Add( const std::string &str )
|
---|
65 | {
|
---|
66 | buffer = (char *)realloc( buffer, length + str.size() + 1 );
|
---|
67 | lstrcpy( buffer + length, str.c_str() );
|
---|
68 | length += (int)str.size();
|
---|
69 | }
|
---|
70 |
|
---|
71 | bool ReadFile( const string &filePath );
|
---|
72 |
|
---|
73 | static void Text::SlideString(char *buffer, int slide){
|
---|
74 | char *temp;
|
---|
75 | temp=(char *)malloc(lstrlen(buffer)+1);
|
---|
76 | lstrcpy(temp,buffer);
|
---|
77 | lstrcpy(buffer+slide,temp);
|
---|
78 | free(temp);
|
---|
79 | }
|
---|
80 | };
|
---|
81 |
|
---|
82 | class BasicSource : public Text
|
---|
83 | {
|
---|
84 | // XMLシリアライズ用
|
---|
85 | private:
|
---|
86 | friend class boost::serialization::access;
|
---|
87 | template<class Archive> void serialize(Archive& ar, const unsigned int version)
|
---|
88 | {
|
---|
89 | trace_for_serialize( "serializing - BasicSource" );
|
---|
90 |
|
---|
91 | ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( Text );
|
---|
92 | }
|
---|
93 |
|
---|
94 | static const string generateDirectiveName;
|
---|
95 |
|
---|
96 | void Realloc( int newLength ){
|
---|
97 | buffer = (char *)realloc( buffer, newLength + 255 );
|
---|
98 |
|
---|
99 | length = newLength;
|
---|
100 |
|
---|
101 | extern char *basbuf;
|
---|
102 | basbuf = buffer + 2;
|
---|
103 | }
|
---|
104 |
|
---|
105 | void IncludeFiles();
|
---|
106 |
|
---|
107 | void ChangeReturnLineChar();
|
---|
108 |
|
---|
109 | void RemoveComments();
|
---|
110 |
|
---|
111 | bool ReadFile_InIncludeDirective( const string &filePath );
|
---|
112 | void DirectiveIncludeOrRequire();
|
---|
113 |
|
---|
114 | void RemoveReturnLineUnderbar();
|
---|
115 |
|
---|
116 | public:
|
---|
117 | BasicSource(){}
|
---|
118 | ~BasicSource(){}
|
---|
119 |
|
---|
120 | char *GetBuffer(){
|
---|
121 | return buffer+2;
|
---|
122 | }
|
---|
123 | const char *GetBuffer() const
|
---|
124 | {
|
---|
125 | return buffer+2;
|
---|
126 | }
|
---|
127 | int GetLength() const
|
---|
128 | {
|
---|
129 | return length-2;
|
---|
130 | }
|
---|
131 |
|
---|
132 | void SetBuffer( const char *buffer );
|
---|
133 |
|
---|
134 | bool ReadFile( const string &filePath );
|
---|
135 |
|
---|
136 | bool Generate( const string &genName, const char *buffer );
|
---|
137 |
|
---|
138 | void Addition( const char *buffer );
|
---|
139 |
|
---|
140 | void operator = ( const BasicSource &source ){
|
---|
141 | Realloc( source.length );
|
---|
142 | lstrcpy( buffer, source.buffer );
|
---|
143 | }
|
---|
144 |
|
---|
145 | char operator[]( int index ) const
|
---|
146 | {
|
---|
147 | if( index>GetLength() )
|
---|
148 | {
|
---|
149 | Jenga::Throw( "BasicSource bad access" );
|
---|
150 | }
|
---|
151 | return buffer[2+index];
|
---|
152 | }
|
---|
153 | };
|
---|