temp. commented to build on linux (diary disabled)
[scilab.git] / scilab / modules / output_stream / src / cpp / diary_manager.cpp
1 /*
2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2009 - DIGITEO - Allan CORNET
4
5 * This file must be used under the terms of the CeCILL.
6 * This source file is licensed as described in the file COPYING, which
7 * you should have received as part of this distribution.  The terms
8 * are also available at    
9 * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
10 *
11 */
12 /*--------------------------------------------------------------------------*/
13 #include "diary_manager.hxx"
14 #include "DiaryList.hxx"
15 #include "diary.h"
16 /*--------------------------------------------------------------------------*/
17 static DiaryList *SCIDIARY = NULL;
18 /*--------------------------------------------------------------------------*/
19 static int createDiaryManager(void)
20 {
21         if (SCIDIARY == NULL)
22         {
23                 SCIDIARY = new DiaryList();
24                 return 0;
25         }
26         return 1;
27 }
28 /*--------------------------------------------------------------------------*/
29 static int destroyDiaryManager(void)
30 {
31         if (SCIDIARY)
32         {
33                 delete SCIDIARY;
34                 SCIDIARY = NULL;
35                 return 0;
36         }
37         return 1;
38 }
39 /*--------------------------------------------------------------------------*/
40 wchar_t *getDiaryFilename(int _Id)
41 {
42         wchar_t *wcFilename = NULL;
43         if (SCIDIARY)
44         {
45                 if (SCIDIARY->getFilename(_Id).compare(L""))
46                 {
47                         wcFilename = new wchar_t[SCIDIARY->getFilename(_Id).length()];
48                         wcscpy(wcFilename, SCIDIARY->getFilename(_Id).c_str());
49                 }
50         }
51         return wcFilename;
52 }
53 /*--------------------------------------------------------------------------*/
54 wchar_t **getDiaryFilenames(int *array_size)
55 {
56         *array_size = 0;
57         if (SCIDIARY)
58         {
59                 std::wstring * wstringFilenames = SCIDIARY->getFilenames(array_size);
60                 if (array_size > 0)
61                 {
62                         wchar_t **wcFilenames = new wchar_t*[*array_size]; 
63                         for(int i = 0; i < *array_size; i++)
64                         {
65                                 wcFilenames[i] = new wchar_t[wstringFilenames[i].length()];
66                                 wcscpy(wcFilenames[i], wstringFilenames[i].c_str());
67                         }
68                         return wcFilenames;
69                 }
70         }
71         return NULL;
72 }
73 /*--------------------------------------------------------------------------*/
74 int *getDiaryIDs(int *array_size)
75 {
76         *array_size = 0;
77         if (SCIDIARY)
78         {
79                 int *iIDs = SCIDIARY->getIDs(array_size);
80                 return iIDs;
81         }
82         return NULL;
83 }
84 /*--------------------------------------------------------------------------*/
85 double *getDiaryIDsAsDouble(int *array_size)
86 {
87         int *iIDs = getDiaryIDs(array_size);
88         if (*array_size > 0)
89         {
90                 if (iIDs)
91                 {
92                         double *dIDs = new double[*array_size];
93                         for(int i = 0;i < *array_size; i++)
94                         {
95                                 dIDs[i] = (double)iIDs[i];
96                         }
97                         delete [] iIDs;
98                         return dIDs;
99                 }
100                 else
101                 {
102                         *array_size = 0;
103                 }
104         }
105         return NULL;
106 }
107 /*--------------------------------------------------------------------------*/
108 int diaryCloseAll(void)
109 {
110         destroyDiaryManager();
111         return 0;
112 }
113 /*--------------------------------------------------------------------------*/
114 int diaryClose(int _iId)
115 {
116         if (SCIDIARY)
117         {
118                 if (_iId > 0)
119                 {
120                         if (SCIDIARY->closeDiary(_iId)) return 0;
121                 }
122         }
123         return 1;
124 }
125 /*--------------------------------------------------------------------------*/
126 int diaryClose(wchar_t *filename)
127 {
128         if (SCIDIARY)
129         {
130                 int iID = SCIDIARY->getID(filename);
131                 if (iID > 0)
132                 {
133                         if (SCIDIARY->closeDiary(iID)) return 0;
134                 }
135         }
136         return 1;
137 }
138 /*--------------------------------------------------------------------------*/
139 int diaryPauseAll(void)
140 {
141         if (SCIDIARY)
142         {
143                 SCIDIARY->setSuspendWrite(true);
144                 return 0;
145         }
146         return 1;
147 }
148 /*--------------------------------------------------------------------------*/
149 int diaryPause(int _iId)
150 {
151         if (SCIDIARY)
152         {
153                 SCIDIARY->setSuspendWrite(_iId, true);
154                 return 0;
155         }
156         return 1;
157 }
158 /*--------------------------------------------------------------------------*/
159 int diaryPause(wchar_t *filename)
160 {
161         if (SCIDIARY)
162         {
163                 int iID = SCIDIARY->getID(std::wstring(filename));
164                 if (iID != -1)
165                 {
166                         SCIDIARY->setSuspendWrite(iID, true);
167                         return 0;
168                 }
169         }
170         return 1;
171 }
172 /*--------------------------------------------------------------------------*/
173 int diaryResumeAll(void)
174 {
175         if (SCIDIARY)
176         {
177                 SCIDIARY->setSuspendWrite(false);
178                 return 0;
179         }
180         return 1;
181 }
182 /*--------------------------------------------------------------------------*/
183 int diaryResume(int _iId)
184 {
185         if (SCIDIARY)
186         {
187                 SCIDIARY->setSuspendWrite(_iId, false);
188                 return 0;
189         }
190         return 1;
191 }
192 /*--------------------------------------------------------------------------*/
193 int diaryResume(wchar_t *filename)
194 {
195         if (SCIDIARY)
196         {
197                 int iID = SCIDIARY->getID(std::wstring(filename));
198                 if (iID != -1)
199                 {
200                         SCIDIARY->setSuspendWrite(iID, false);
201                         return 0;
202                 }
203         }
204         return 1;
205 }
206 /*--------------------------------------------------------------------------*/
207 int diaryExists(int _iId)
208 {
209         if (SCIDIARY)
210         {
211                 if (SCIDIARY->exists(_iId)) return 0;
212         }
213         return 1;
214 }
215 /*--------------------------------------------------------------------------*/
216 int diaryExists(wchar_t *filename)
217 {
218         if (SCIDIARY)
219         {
220                 if (SCIDIARY->exists(std::wstring(filename))) return 0;
221         }
222         return 1;
223 }
224 /*--------------------------------------------------------------------------*/
225 int diaryNew(wchar_t *filename)
226 {
227         createDiaryManager();
228
229         if (SCIDIARY)
230         {
231                 return SCIDIARY->openDiary(std::wstring(filename));
232         }
233
234         return -1;
235 }
236 /*--------------------------------------------------------------------------*/
237 int diaryAppend(wchar_t *filename)
238 {
239         createDiaryManager();
240         if (SCIDIARY)
241         {
242                 return SCIDIARY->openDiary(std::wstring(filename),1);
243         }
244         return -1;
245 }
246 /*--------------------------------------------------------------------------*/
247 int diaryWrite(wchar_t *wstr, BOOL bInput)
248 {
249         if (SCIDIARY)
250         {
251                 if (bInput) SCIDIARY->write(std::wstring(wstr), true);
252                 else SCIDIARY->write(std::wstring(wstr), false);
253                 return 0;
254         }
255         return 1;
256 }
257 /*--------------------------------------------------------------------------*/
258 int diaryWriteln(wchar_t *wstr, BOOL bInput)
259 {
260         if (SCIDIARY)
261         {
262                 if (bInput) SCIDIARY->writeln(std::wstring(wstr), true);
263                 else SCIDIARY->writeln(std::wstring(wstr), false);
264                 return 0;
265         }
266         return 1;
267 }
268 /*--------------------------------------------------------------------------*/
269 int diarySetFilterMode(int _iId, int mode)
270 {
271         if (SCIDIARY)
272         {
273                 SCIDIARY->setFilterMode(_iId, mode);
274                 return 0;
275         }
276         return 1;
277 }
278 /*--------------------------------------------------------------------------*/
279 int diarySetPrefixMode(int ID_diary,int iPrefixMode)
280 {
281         if (SCIDIARY)
282         {
283                 SCIDIARY->setPrefixMode(ID_diary, iPrefixMode);
284                 return 0;
285         }
286         return 1;
287 }
288 /*--------------------------------------------------------------------------*/
289 int diaryGetPrefixMode(int ID_diary)
290 {
291         if (SCIDIARY)
292         {
293                 return SCIDIARY->getPrefixMode(ID_diary);
294         }
295         return -1;
296 }
297 /*--------------------------------------------------------------------------*/
298 int diarySetPrefixIoModeFilter(int ID_diary,int mode)
299 {
300         if (SCIDIARY)
301         {
302                 SCIDIARY->setPrefixIoModeFilter(ID_diary, mode);
303                 return 0;
304         }
305         return 1;
306 }
307 /*--------------------------------------------------------------------------*/
308 int diaryGetPrefixIoModeFilter(int ID_diary)
309 {
310         if (SCIDIARY)
311         {
312                 return SCIDIARY->getPrefixIoModeFilter(ID_diary);
313         }
314         return -1;
315 }
316 /*--------------------------------------------------------------------------*/