source: dev/trunk/abdev/BasicCompiler_Common/include/Source.h@ 266

Last change on this file since 266 was 266, checked in by dai_9181, 17 years ago

BasicSourceのシリアライズがうまくいっていない

File size: 3.0 KB
Line 
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
14using namespace std;
15
16struct INCLUDEFILEINFO{
17 char **ppFileNames;
18 int FilesNum;
19 int LineOfFile[MAX_LEN];
20};
21
22class Text{
23protected:
24 char *buffer;
25 int length;
26
27 // XMLシリアライズ用
28private:
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 }
51public:
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
82class BasicSource : public Text
83{
84 // XMLシリアライズ用
85private:
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
116public:
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};
Note: See TracBrowser for help on using the repository browser.