[266] | 1 | #pragma once
|
---|
| 2 |
|
---|
[279] | 3 | class IncludedFilesRelation
|
---|
| 4 | {
|
---|
| 5 | std::vector<std::string> filePaths;
|
---|
| 6 | std::vector<int> lineFileNumbers;
|
---|
| 7 |
|
---|
| 8 | // XMLシリアライズ用
|
---|
| 9 | private:
|
---|
| 10 | friend class boost::serialization::access;
|
---|
| 11 | template<class Archive> void serialize(Archive& ar, const unsigned int version)
|
---|
| 12 | {
|
---|
| 13 | trace_for_serialize( "serializing - IncludedFilesRelation" );
|
---|
| 14 |
|
---|
| 15 | ar & BOOST_SERIALIZATION_NVP( filePaths );
|
---|
| 16 | ar & BOOST_SERIALIZATION_NVP( lineFileNumbers );
|
---|
| 17 | }
|
---|
| 18 |
|
---|
| 19 | public:
|
---|
| 20 | IncludedFilesRelation()
|
---|
| 21 | {
|
---|
| 22 | }
|
---|
| 23 | ~IncludedFilesRelation()
|
---|
| 24 | {
|
---|
| 25 | }
|
---|
| 26 |
|
---|
| 27 | const int GetFileNumber( int lineNumber ) const
|
---|
| 28 | {
|
---|
| 29 | return lineFileNumbers[lineNumber];
|
---|
| 30 | }
|
---|
| 31 | const std::string &GetFilePath( int lineNumber ) const
|
---|
| 32 | {
|
---|
| 33 | return filePaths[GetFileNumber( lineNumber )];
|
---|
| 34 | }
|
---|
| 35 | const std::string &GetFilePathFromFileNumber( int fileNumber ) const
|
---|
| 36 | {
|
---|
| 37 | return filePaths[fileNumber];
|
---|
| 38 | }
|
---|
| 39 | int GetFileCounts() const
|
---|
| 40 | {
|
---|
[308] | 41 | return (int)filePaths.size();
|
---|
[279] | 42 | }
|
---|
| 43 |
|
---|
| 44 | int AddFile( const std::string &filePath )
|
---|
| 45 | {
|
---|
| 46 | filePaths.push_back( filePath );
|
---|
[308] | 47 | return (int)filePaths.size()-1;
|
---|
[279] | 48 | }
|
---|
| 49 | void AddLine( int fileNumber )
|
---|
| 50 | {
|
---|
| 51 | lineFileNumbers.push_back( fileNumber );
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | int GetLineCounts() const
|
---|
| 55 | {
|
---|
[308] | 56 | return (int)lineFileNumbers.size();
|
---|
[279] | 57 | }
|
---|
| 58 | };
|
---|
| 59 |
|
---|
[266] | 60 | class Text{
|
---|
| 61 | protected:
|
---|
| 62 | char *buffer;
|
---|
| 63 | int length;
|
---|
| 64 |
|
---|
| 65 | public:
|
---|
| 66 |
|
---|
| 67 | Text(){
|
---|
| 68 | buffer = (char *)calloc( 1, 1 );
|
---|
| 69 | length = 0;
|
---|
| 70 | }
|
---|
[280] | 71 | Text( const Text &text )
|
---|
| 72 | : length( text.length )
|
---|
| 73 | {
|
---|
| 74 | buffer = (char *)malloc( length + 1 );
|
---|
| 75 | memcpy( buffer, text.buffer, length );
|
---|
| 76 | buffer[length] = 0;
|
---|
| 77 | }
|
---|
[266] | 78 | ~Text(){
|
---|
| 79 | free( buffer );
|
---|
| 80 | }
|
---|
| 81 | void Clear()
|
---|
| 82 | {
|
---|
| 83 | length = 0;
|
---|
| 84 | }
|
---|
| 85 | void Add( const std::string &str )
|
---|
| 86 | {
|
---|
| 87 | buffer = (char *)realloc( buffer, length + str.size() + 1 );
|
---|
| 88 | lstrcpy( buffer + length, str.c_str() );
|
---|
| 89 | length += (int)str.size();
|
---|
| 90 | }
|
---|
[268] | 91 | void Add( const std::vector<char> &str )
|
---|
| 92 | {
|
---|
| 93 | buffer = (char *)realloc( buffer, length + str.size() + 1 );
|
---|
| 94 | lstrcpy( buffer + length, &str[0] );
|
---|
| 95 | length += (int)str.size();
|
---|
| 96 | }
|
---|
[266] | 97 |
|
---|
[523] | 98 | bool ReadFile( const std::string &filePath );
|
---|
[266] | 99 |
|
---|
| 100 | static void Text::SlideString(char *buffer, int slide){
|
---|
| 101 | char *temp;
|
---|
| 102 | temp=(char *)malloc(lstrlen(buffer)+1);
|
---|
| 103 | lstrcpy(temp,buffer);
|
---|
| 104 | lstrcpy(buffer+slide,temp);
|
---|
| 105 | free(temp);
|
---|
| 106 | }
|
---|
| 107 | };
|
---|
| 108 |
|
---|
| 109 | class BasicSource : public Text
|
---|
| 110 | {
|
---|
[523] | 111 | static const std::string generateDirectiveName;
|
---|
[266] | 112 |
|
---|
[279] | 113 | IncludedFilesRelation includedFilesRelation;
|
---|
| 114 |
|
---|
| 115 | // XMLシリアライズ用
|
---|
| 116 | private:
|
---|
| 117 | friend class boost::serialization::access;
|
---|
| 118 | BOOST_SERIALIZATION_SPLIT_MEMBER();
|
---|
| 119 | template<class Archive> void load(Archive& ar, const unsigned int version)
|
---|
| 120 | {
|
---|
| 121 | trace_for_serialize( "serializing(load) - BasicSource" );
|
---|
| 122 |
|
---|
| 123 | std::string _buffer;
|
---|
| 124 | ar & BOOST_SERIALIZATION_NVP( _buffer );
|
---|
| 125 | ar & BOOST_SERIALIZATION_NVP( length );
|
---|
| 126 | ar & BOOST_SERIALIZATION_NVP( includedFilesRelation );
|
---|
| 127 |
|
---|
| 128 | // 読み込み後の処理
|
---|
| 129 | Realloc( length );
|
---|
| 130 | for( int i=0; i<length; i++ )
|
---|
| 131 | {
|
---|
| 132 | ULONG_PTR l1 = ( ( _buffer[i*3] >= 'a' ) ? ( _buffer[i*3] - 'a' + 0x0a ) : ( _buffer[i*3] - '0' ) ) * 0x10;
|
---|
| 133 | ULONG_PTR l2 = ( _buffer[i*3+1] >= 'a' ) ? ( _buffer[i*3+1] - 'a' + 0x0a ) : ( _buffer[i*3+1] - '0' );
|
---|
| 134 | ULONG_PTR l = l1 + l2;
|
---|
| 135 | buffer[i] = static_cast<char>(l);
|
---|
| 136 | }
|
---|
| 137 | buffer[length] = 0;
|
---|
| 138 | }
|
---|
| 139 | template<class Archive> void save(Archive& ar, const unsigned int version) const
|
---|
| 140 | {
|
---|
| 141 | trace_for_serialize( "serializing(save) - BasicSource" );
|
---|
| 142 |
|
---|
| 143 | // 保存準備
|
---|
| 144 | char *tempCode = (char *)calloc( (length+1) * 3, 1 );
|
---|
| 145 | for( int i=0; i<length; i++ )
|
---|
| 146 | {
|
---|
| 147 | char temp[32];
|
---|
| 148 | sprintf( temp, "%02x,", (unsigned char)buffer[i] );
|
---|
| 149 | tempCode[i*3] = temp[0];
|
---|
| 150 | tempCode[i*3+1] = temp[1];
|
---|
| 151 | tempCode[i*3+2] = temp[2];
|
---|
| 152 | }
|
---|
| 153 |
|
---|
| 154 | std::string _buffer = tempCode;
|
---|
| 155 | free( tempCode );
|
---|
| 156 |
|
---|
| 157 | ar & BOOST_SERIALIZATION_NVP( _buffer );
|
---|
| 158 | ar & BOOST_SERIALIZATION_NVP( length );
|
---|
| 159 | ar & BOOST_SERIALIZATION_NVP( includedFilesRelation );
|
---|
| 160 | }
|
---|
| 161 |
|
---|
| 162 | private:
|
---|
[281] | 163 | void Realloc( int newLength )
|
---|
| 164 | {
|
---|
| 165 | bool isEqualBasbuf = false;
|
---|
| 166 | extern char *basbuf;
|
---|
[282] | 167 | if( basbuf == buffer + 2 )
|
---|
[281] | 168 | {
|
---|
| 169 | isEqualBasbuf = true;
|
---|
| 170 | }
|
---|
| 171 |
|
---|
[266] | 172 | buffer = (char *)realloc( buffer, newLength + 255 );
|
---|
| 173 |
|
---|
| 174 | length = newLength;
|
---|
| 175 |
|
---|
[281] | 176 | if( isEqualBasbuf )
|
---|
| 177 | {
|
---|
| 178 | basbuf = buffer + 2;
|
---|
| 179 | }
|
---|
[266] | 180 | }
|
---|
| 181 |
|
---|
| 182 | void IncludeFiles();
|
---|
| 183 |
|
---|
| 184 | void ChangeReturnLineChar();
|
---|
| 185 |
|
---|
| 186 | void RemoveComments();
|
---|
| 187 |
|
---|
[523] | 188 | bool ReadFile_InIncludeDirective( const std::string &filePath );
|
---|
[266] | 189 | void DirectiveIncludeOrRequire();
|
---|
| 190 |
|
---|
| 191 | void RemoveReturnLineUnderbar();
|
---|
| 192 |
|
---|
[322] | 193 | void Initialize( const std::string &source );
|
---|
| 194 |
|
---|
[266] | 195 | public:
|
---|
| 196 | BasicSource(){}
|
---|
[280] | 197 | BasicSource( const BasicSource &basicSource )
|
---|
| 198 | : Text( basicSource )
|
---|
| 199 | , includedFilesRelation( basicSource.includedFilesRelation )
|
---|
| 200 | {
|
---|
| 201 | }
|
---|
[322] | 202 | BasicSource( const std::string &source )
|
---|
| 203 | {
|
---|
| 204 | Initialize( source );
|
---|
| 205 | }
|
---|
[266] | 206 | ~BasicSource(){}
|
---|
| 207 |
|
---|
| 208 | char *GetBuffer(){
|
---|
| 209 | return buffer+2;
|
---|
| 210 | }
|
---|
| 211 | const char *GetBuffer() const
|
---|
| 212 | {
|
---|
| 213 | return buffer+2;
|
---|
| 214 | }
|
---|
| 215 | int GetLength() const
|
---|
| 216 | {
|
---|
| 217 | return length-2;
|
---|
| 218 | }
|
---|
[304] | 219 | void _ResetLength()
|
---|
| 220 | {
|
---|
| 221 | length = lstrlen( buffer );
|
---|
| 222 | }
|
---|
[266] | 223 |
|
---|
[279] | 224 | const IncludedFilesRelation &GetIncludedFilesRelation() const
|
---|
| 225 | {
|
---|
| 226 | return includedFilesRelation;
|
---|
| 227 | }
|
---|
| 228 |
|
---|
[266] | 229 | void SetBuffer( const char *buffer );
|
---|
| 230 |
|
---|
[523] | 231 | bool ReadFile( const std::string &filePath );
|
---|
[266] | 232 |
|
---|
[523] | 233 | bool Generate( const std::string &genName, const char *buffer );
|
---|
[266] | 234 |
|
---|
| 235 | void Addition( const char *buffer );
|
---|
| 236 |
|
---|
[280] | 237 | bool GetLineInfo( int sourceCodePos, int &line, std::string &fileName ) const;
|
---|
[279] | 238 |
|
---|
[266] | 239 | void operator = ( const BasicSource &source ){
|
---|
| 240 | Realloc( source.length );
|
---|
| 241 | lstrcpy( buffer, source.buffer );
|
---|
| 242 | }
|
---|
| 243 |
|
---|
| 244 | char operator[]( int index ) const
|
---|
| 245 | {
|
---|
| 246 | if( index>GetLength() )
|
---|
| 247 | {
|
---|
| 248 | Jenga::Throw( "BasicSource bad access" );
|
---|
| 249 | }
|
---|
| 250 | return buffer[2+index];
|
---|
| 251 | }
|
---|
| 252 | };
|
---|
[322] | 253 | typedef std::vector<BasicSource> BasicSources;
|
---|
| 254 |
|
---|
| 255 | class SourceTemplate
|
---|
| 256 | {
|
---|
| 257 | std::string source;
|
---|
| 258 | public:
|
---|
| 259 | SourceTemplate( const std::string &filePath );
|
---|
| 260 | ~SourceTemplate()
|
---|
| 261 | {
|
---|
| 262 | }
|
---|
| 263 |
|
---|
| 264 | std::string GetResult( const std::map<std::string,std::string> &values );
|
---|
| 265 | };
|
---|