/[projet1]/public/pc/tools/osdk/main/common/includes/common.h
Defence Force logotype

Contents of /public/pc/tools/osdk/main/common/includes/common.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1215 - (show annotations)
Sun Sep 28 18:56:36 2014 UTC (5 years, 1 month ago) by mmu_man
File MIME type: text/plain
File size: 5236 byte(s)
Fake nullptr for GCC < 4.6

1
2 #ifndef _COMMON_H_
3 #define _COMMON_H_
4
5 #ifdef _MSC_VER
6 // Disable the warning C4706 -> assignment within conditional expression
7 // Allow us to use Warning level 4 instead of level 3
8 #pragma warning( disable : 4706)
9 #pragma warning( disable : 4786) // Debug symbols thing
10 #pragma warning( disable : 4996) // #define _CRT_SECURE_NO_WARNINGS
11 //#define _CRT_SECURE_NO_WARNINGS
12 #endif
13
14
15 #include <string>
16 #include <vector>
17
18 #include <fcntl.h>
19
20 #ifndef O_BINARY
21 #define O_BINARY 0
22 #endif
23
24 #ifdef _WIN32
25 #define strncasecmp _strnicmp
26 #include <io.h>
27 #else
28 #include <unistd.h>
29 #endif
30
31 #if defined(__GNUC__) && __GNUC__ == 4 && __GNUC_MINOR__ < 6
32 #define nullptr (NULL)
33 #endif
34
35 //
36 // Debugging macros
37 //
38 #ifdef _DEBUG
39 #define _BREAK_ __asm { int 3 }
40 #define _BREAK_IF_(cond) if (cond) __asm { int 3 } else ((void)0)
41 #else
42 #define _BREAK_ ((void)0)
43 #define _BREAK_IF_(cond) ((void)0)
44 #endif
45
46
47 //
48 // Argument parsing, error handling
49 //
50 void SetApplicationParameters(const char* pcApplicationName,int nVersionMajor,int nVersionMinor,const char* pcUsageMessage);
51
52 void ShowError(const char *pcMessage,...);
53
54
55 class ArgumentParser
56 {
57 public:
58 ArgumentParser(int argc,char *argv[]);
59 ~ArgumentParser() {}
60
61 const char* GetParameter(int nParameterIndex);
62 int GetParameterCount();
63
64 bool ProcessNextArgument();
65
66 bool IsSwitch(const char *ptr_switch);
67 bool IsParameter();
68
69 std::string GetStringValue();
70 int GetIntegerValue(int default_value);
71 bool GetBooleanValue(bool default_value);
72 bool GetSeparator(const char* ptr_separator_list);
73 const char* GetRemainingStuff();
74
75 private:
76 ArgumentParser();
77
78 private:
79 int m_argc;
80 char** m_argv;
81 long m_first_param;
82
83 int m_remaining_argc;
84 long m_nb_arg;
85 const char* m_ptr_arg;
86 };
87
88 bool get_switch(const char *&ptr_arg,const char *ptr_switch);
89 int get_value(const char *&ptr_arg,long default_value);
90 std::string get_string(const char *&ptr_arg);
91
92
93 //
94 // File loading and saving
95 //
96 bool LoadFile(const char* pcFileName,void* &pcBuffer,size_t &cBufferSize);
97 bool SaveFile(const char* pcFileName,const void* pcBuffer,size_t cBufferSize);
98 bool DeleteFile(const char* pcFileName);
99
100 bool LoadText(const char* pcFileName,std::vector<std::string>& cTextData);
101
102 bool IsUpToDate(const char* sourceFile,const char* targetFile);
103 bool IsUpToDate(const std::string& sourceFile,const std::string& targetFile);
104
105
106 //
107 // Compression (moved out FilePack)
108 //
109 long LZ77_Compress(void *buf_src,void *buf_dest,long size_buf_src);
110 void LZ77_UnCompress(void *buf_src,void *buf_dest,long size);
111 long LZ77_ComputeDelta(unsigned char *buf_comp,long size_uncomp,long size_comp);
112 extern unsigned char gLZ77_XorMask;
113
114 //
115 // Preprocessing and filtering
116 //
117 int StringReplace(std::string& cMainString,const std::string& cSearchedString,const std::string& cReplaceString);
118 std::string StringTrim(const std::string& cInputString,const std::string& cFilteredOutCharacterList=" \t\f\v\n\r");
119 std::string StringFormat(const char* pFormatString,...);
120 std::string StringMakeLabel(const std::string& sourceString);
121
122 int ConvertAdress(const char *ptr_value);
123
124 class TextFileGenerator
125 {
126 public:
127 enum Language_e
128 {
129 _eLanguage_Undefined_,
130 eLanguage_C,
131 eLanguage_Assembler,
132 eLanguage_BASIC
133 };
134
135 enum Endianness_e
136 {
137 _eEndianness_Undefined_,
138 _eEndianness_Little,
139 _eEndianness_Big
140 };
141
142 enum NumericBase_e
143 {
144 _eNumericBase_Undefined_,
145 _eNumericBase_Hexadecimal,
146 _eNumericBase_Decimal
147 };
148
149 public:
150 TextFileGenerator();
151 ~TextFileGenerator();
152
153 void SetDataSize(int nDataSize) { m_nDataSize=nDataSize; }
154 void SetFileType(Language_e nFileType) { m_nFileType=nFileType; }
155 void SetEndianness(Endianness_e nEndianness) { m_nEndianness=nEndianness; }
156 void SetNumericBase(NumericBase_e nNumericBase) { m_nNumericBase=nNumericBase; }
157 void SetValuesPerLine(unsigned int nValuesPerLine) { m_nValuesPerLine=nValuesPerLine; }
158 void SetLabel(const std::string& cLabel) { m_cLabelName=cLabel; }
159 void SetLineNumber(int nLineNumber) { m_nFirstLineNumber=nLineNumber; }
160 void SetIncrementLineNumber(int nIncrementLineNumber) { m_nIncrementLineNumber=nIncrementLineNumber; }
161
162 int GetDataSize() { return m_nDataSize; }
163 Language_e GetFileType() { return m_nFileType; }
164 Endianness_e GetEndianness() { return m_nEndianness; }
165 NumericBase_e GetNumericBase() { return m_nNumericBase; }
166 unsigned int GetValuesPerLine() { return m_nValuesPerLine; }
167 const std::string& GetLabel() { return m_cLabelName; }
168 int GetLineNumber() { return m_nFirstLineNumber; }
169 int GetIncrementLineNumber() { return m_nIncrementLineNumber; }
170
171 std::string ConvertData(const void* pSourceData,size_t nFileSize);
172
173 private:
174 int m_nDataSize;
175 Language_e m_nFileType;
176 Endianness_e m_nEndianness;
177 NumericBase_e m_nNumericBase;
178 unsigned int m_nValuesPerLine;
179
180 bool m_bEnableLineNumber;
181 int m_nFirstLineNumber;
182 int m_nIncrementLineNumber;
183
184 std::string m_cLabelName;
185 };
186
187
188 #endif // _COMMON_H_

  ViewVC Help
Powered by ViewVC 1.1.26