doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DeclPDA.cpp
Go to the documentation of this file.
1 /*
2 ===========================================================================
3 
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
6 
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
8 
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13 
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
21 
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
23 
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
25 
26 ===========================================================================
27 */
28 
29 #include "../idlib/precompiled.h"
30 #pragma hdrstop
31 
32 /*
33 =================
34 idDeclPDA::Size
35 =================
36 */
37 size_t idDeclPDA::Size( void ) const {
38  return sizeof( idDeclPDA );
39 }
40 
41 /*
42 ===============
43 idDeclPDA::Print
44 ===============
45 */
46 void idDeclPDA::Print( void ) const {
47  common->Printf( "Implement me\n" );
48 }
49 
50 /*
51 ===============
52 idDeclPDA::List
53 ===============
54 */
55 void idDeclPDA::List( void ) const {
56  common->Printf( "Implement me\n" );
57 }
58 
59 /*
60 ================
61 idDeclPDA::Parse
62 ================
63 */
64 bool idDeclPDA::Parse( const char *text, const int textLength ) {
65  idLexer src;
66  idToken token;
67 
68  src.LoadMemory( text, textLength, GetFileName(), GetLineNum() );
70  src.SkipUntilString( "{" );
71 
72  // scan through, identifying each individual parameter
73  while( 1 ) {
74 
75  if ( !src.ReadToken( &token ) ) {
76  break;
77  }
78 
79  if ( token == "}" ) {
80  break;
81  }
82 
83  if ( !token.Icmp( "name") ) {
84  src.ReadToken( &token );
85  pdaName = token;
86  continue;
87  }
88 
89  if ( !token.Icmp( "fullname") ) {
90  src.ReadToken( &token );
91  fullName = token;
92  continue;
93  }
94 
95  if ( !token.Icmp( "icon") ) {
96  src.ReadToken( &token );
97  icon = token;
98  continue;
99  }
100 
101  if ( !token.Icmp( "id") ) {
102  src.ReadToken( &token );
103  id = token;
104  continue;
105  }
106 
107  if ( !token.Icmp( "post") ) {
108  src.ReadToken( &token );
109  post = token;
110  continue;
111  }
112 
113  if ( !token.Icmp( "title") ) {
114  src.ReadToken( &token );
115  title = token;
116  continue;
117  }
118 
119  if ( !token.Icmp( "security") ) {
120  src.ReadToken( &token );
121  security = token;
122  continue;
123  }
124 
125  if ( !token.Icmp( "pda_email") ) {
126  src.ReadToken( &token );
127  emails.Append( token );
129  continue;
130  }
131 
132  if ( !token.Icmp( "pda_audio") ) {
133  src.ReadToken( &token );
134  audios.Append( token );
136  continue;
137  }
138 
139  if ( !token.Icmp( "pda_video") ) {
140  src.ReadToken( &token );
141  videos.Append( token );
143  continue;
144  }
145 
146  }
147 
148  if ( src.HadError() ) {
149  src.Warning( "PDA decl '%s' had a parse error", GetName() );
150  return false;
151  }
152 
155  return true;
156 }
157 
158 /*
159 ===================
160 idDeclPDA::DefaultDefinition
161 ===================
162 */
163 const char *idDeclPDA::DefaultDefinition( void ) const {
164  return
165  "{\n"
166  "\t" "name \"default pda\"\n"
167  "}";
168 }
169 
170 /*
171 ===================
172 idDeclPDA::FreeData
173 ===================
174 */
175 void idDeclPDA::FreeData( void ) {
176  videos.Clear();
177  audios.Clear();
178  emails.Clear();
179  originalEmails = 0;
180  originalVideos = 0;
181 }
182 
183 /*
184 =================
185 idDeclPDA::AddVideo
186 =================
187 */
188 void idDeclPDA::AddVideo( const char *name, bool unique ) const {
189  if ( unique && ( videos.Find( name ) != NULL ) ) {
190  return;
191  }
192  if ( declManager->FindType( DECL_VIDEO, name, false ) == NULL ) {
193  common->Printf( "Video %s not found\n", name );
194  return;
195  }
196  videos.Append( name );
197 }
198 
199 /*
200 =================
201 idDeclPDA::AddAudio
202 =================
203 */
204 void idDeclPDA::AddAudio( const char *name, bool unique ) const {
205  if ( unique && ( audios.Find( name ) != NULL ) ) {
206  return;
207  }
208  if ( declManager->FindType( DECL_AUDIO, name, false ) == NULL ) {
209  common->Printf( "Audio log %s not found\n", name );
210  return;
211  }
212  audios.Append( name );
213 }
214 
215 /*
216 =================
217 idDeclPDA::AddEmail
218 =================
219 */
220 void idDeclPDA::AddEmail( const char *name, bool unique ) const {
221  if ( unique && ( emails.Find( name ) != NULL ) ) {
222  return;
223  }
224  if ( declManager->FindType( DECL_EMAIL, name, false ) == NULL ) {
225  common->Printf( "Email %s not found\n", name );
226  return;
227  }
228  emails.Append( name );
229 }
230 
231 /*
232 =================
233 idDeclPDA::RemoveAddedEmailsAndVideos
234 =================
235 */
237  int num = emails.Num();
238  if ( originalEmails < num ) {
239  while ( num && num > originalEmails ) {
240  emails.RemoveIndex( --num );
241  }
242  }
243  num = videos.Num();
244  if ( originalVideos < num ) {
245  while ( num && num > originalVideos ) {
246  videos.RemoveIndex( --num );
247  }
248  }
249 }
250 
251 /*
252 =================
253 idDeclPDA::SetSecurity
254 =================
255 */
256 void idDeclPDA::SetSecurity( const char *sec ) const {
257  security = sec;
258 }
259 
260 /*
261 =================
262 idDeclPDA::GetNumVideos
263 =================
264 */
265 const int idDeclPDA::GetNumVideos() const {
266  return videos.Num();
267 }
268 
269 /*
270 =================
271 idDeclPDA::GetNumAudios
272 =================
273 */
274 const int idDeclPDA::GetNumAudios() const {
275  return audios.Num();
276 }
277 
278 /*
279 =================
280 idDeclPDA::GetNumEmails
281 =================
282 */
283 const int idDeclPDA::GetNumEmails() const {
284  return emails.Num();
285 }
286 
287 /*
288 =================
289 idDeclPDA::GetVideoByIndex
290 =================
291 */
293  if ( index >= 0 && index < videos.Num() ) {
294  return static_cast< const idDeclVideo* >( declManager->FindType( DECL_VIDEO, videos[index], false ) );
295  }
296  return NULL;
297 }
298 
299 /*
300 =================
301 idDeclPDA::GetAudioByIndex
302 =================
303 */
305  if ( index >= 0 && index < audios.Num() ) {
306  return static_cast< const idDeclAudio* >( declManager->FindType( DECL_AUDIO, audios[index], false ) );
307  }
308  return NULL;
309 }
310 
311 /*
312 =================
313 idDeclPDA::GetEmailByIndex
314 =================
315 */
317  if ( index >= 0 && index < emails.Num() ) {
318  return static_cast< const idDeclEmail* >( declManager->FindType( DECL_EMAIL, emails[index], false ) );
319  }
320  return NULL;
321 }
322 
323 /*
324 =================
325 idDeclEmail::Size
326 =================
327 */
328 size_t idDeclEmail::Size( void ) const {
329  return sizeof( idDeclEmail );
330 }
331 
332 /*
333 ===============
334 idDeclEmail::Print
335 ===============
336 */
337 void idDeclEmail::Print( void ) const {
338  common->Printf( "Implement me\n" );
339 }
340 
341 /*
342 ===============
343 idDeclEmail::List
344 ===============
345 */
346 void idDeclEmail::List( void ) const {
347  common->Printf( "Implement me\n" );
348 }
349 
350 /*
351 ================
352 idDeclEmail::Parse
353 ================
354 */
355 bool idDeclEmail::Parse( const char *_text, const int textLength ) {
356  idLexer src;
357  idToken token;
358 
359  src.LoadMemory( _text, textLength, GetFileName(), GetLineNum() );
361  src.SkipUntilString( "{" );
362 
363  text = "";
364  // scan through, identifying each individual parameter
365  while( 1 ) {
366 
367  if ( !src.ReadToken( &token ) ) {
368  break;
369  }
370 
371  if ( token == "}" ) {
372  break;
373  }
374 
375  if ( !token.Icmp( "subject") ) {
376  src.ReadToken( &token );
377  subject = token;
378  continue;
379  }
380 
381  if ( !token.Icmp( "to") ) {
382  src.ReadToken( &token );
383  to = token;
384  continue;
385  }
386 
387  if ( !token.Icmp( "from") ) {
388  src.ReadToken( &token );
389  from = token;
390  continue;
391  }
392 
393  if ( !token.Icmp( "date") ) {
394  src.ReadToken( &token );
395  date = token;
396  continue;
397  }
398 
399  if ( !token.Icmp( "text") ) {
400  src.ReadToken( &token );
401  if ( token != "{" ) {
402  src.Warning( "Email decl '%s' had a parse error", GetName() );
403  return false;
404  }
405  while ( src.ReadToken( &token ) && token != "}" ) {
406  text += token;
407  }
408  continue;
409  }
410 
411  if ( !token.Icmp( "image") ) {
412  src.ReadToken( &token );
413  image = token;
414  continue;
415  }
416  }
417 
418  if ( src.HadError() ) {
419  src.Warning( "Email decl '%s' had a parse error", GetName() );
420  return false;
421  }
422  return true;
423 }
424 
425 /*
426 ===================
427 idDeclEmail::DefaultDefinition
428 ===================
429 */
430 const char *idDeclEmail::DefaultDefinition( void ) const {
431  return
432  "{\n"
433  "\t" "{\n"
434  "\t\t" "to\t5Mail recipient\n"
435  "\t\t" "subject\t5Nothing\n"
436  "\t\t" "from\t5No one\n"
437  "\t" "}\n"
438  "}";
439 }
440 
441 /*
442 ===================
443 idDeclEmail::FreeData
444 ===================
445 */
446 void idDeclEmail::FreeData( void ) {
447 }
448 
449 /*
450 =================
451 idDeclVideo::Size
452 =================
453 */
454 size_t idDeclVideo::Size( void ) const {
455  return sizeof( idDeclVideo );
456 }
457 
458 /*
459 ===============
460 idDeclVideo::Print
461 ===============
462 */
463 void idDeclVideo::Print( void ) const {
464  common->Printf( "Implement me\n" );
465 }
466 
467 /*
468 ===============
469 idDeclVideo::List
470 ===============
471 */
472 void idDeclVideo::List( void ) const {
473  common->Printf( "Implement me\n" );
474 }
475 
476 /*
477 ================
478 idDeclVideo::Parse
479 ================
480 */
481 bool idDeclVideo::Parse( const char *text, const int textLength ) {
482  idLexer src;
483  idToken token;
484 
485  src.LoadMemory( text, textLength, GetFileName(), GetLineNum() );
487  src.SkipUntilString( "{" );
488 
489  // scan through, identifying each individual parameter
490  while( 1 ) {
491 
492  if ( !src.ReadToken( &token ) ) {
493  break;
494  }
495 
496  if ( token == "}" ) {
497  break;
498  }
499 
500  if ( !token.Icmp( "name") ) {
501  src.ReadToken( &token );
502  videoName = token;
503  continue;
504  }
505 
506  if ( !token.Icmp( "preview") ) {
507  src.ReadToken( &token );
508  preview = token;
509  continue;
510  }
511 
512  if ( !token.Icmp( "video") ) {
513  src.ReadToken( &token );
514  video = token;
516  continue;
517  }
518 
519  if ( !token.Icmp( "info") ) {
520  src.ReadToken( &token );
521  info = token;
522  continue;
523  }
524 
525  if ( !token.Icmp( "audio") ) {
526  src.ReadToken( &token );
527  audio = token;
529  continue;
530  }
531 
532  }
533 
534  if ( src.HadError() ) {
535  src.Warning( "Video decl '%s' had a parse error", GetName() );
536  return false;
537  }
538  return true;
539 }
540 
541 /*
542 ===================
543 idDeclVideo::DefaultDefinition
544 ===================
545 */
546 const char *idDeclVideo::DefaultDefinition( void ) const {
547  return
548  "{\n"
549  "\t" "{\n"
550  "\t\t" "name\t5Default Video\n"
551  "\t" "}\n"
552  "}";
553 }
554 
555 /*
556 ===================
557 idDeclVideo::FreeData
558 ===================
559 */
560 void idDeclVideo::FreeData( void ) {
561 }
562 
563 /*
564 =================
565 idDeclAudio::Size
566 =================
567 */
568 size_t idDeclAudio::Size( void ) const {
569  return sizeof( idDeclAudio );
570 }
571 
572 /*
573 ===============
574 idDeclAudio::Print
575 ===============
576 */
577 void idDeclAudio::Print( void ) const {
578  common->Printf( "Implement me\n" );
579 }
580 
581 /*
582 ===============
583 idDeclAudio::List
584 ===============
585 */
586 void idDeclAudio::List( void ) const {
587  common->Printf( "Implement me\n" );
588 }
589 
590 /*
591 ================
592 idDeclAudio::Parse
593 ================
594 */
595 bool idDeclAudio::Parse( const char *text, const int textLength ) {
596  idLexer src;
597  idToken token;
598 
599  src.LoadMemory( text, textLength, GetFileName(), GetLineNum() );
601  src.SkipUntilString( "{" );
602 
603  // scan through, identifying each individual parameter
604  while( 1 ) {
605 
606  if ( !src.ReadToken( &token ) ) {
607  break;
608  }
609 
610  if ( token == "}" ) {
611  break;
612  }
613 
614  if ( !token.Icmp( "name") ) {
615  src.ReadToken( &token );
616  audioName = token;
617  continue;
618  }
619 
620  if ( !token.Icmp( "audio") ) {
621  src.ReadToken( &token );
622  audio = token;
624  continue;
625  }
626 
627  if ( !token.Icmp( "info") ) {
628  src.ReadToken( &token );
629  info = token;
630  continue;
631  }
632 
633  if ( !token.Icmp( "preview") ) {
634  src.ReadToken( &token );
635  preview = token;
636  continue;
637  }
638 
639  }
640 
641  if ( src.HadError() ) {
642  src.Warning( "Audio decl '%s' had a parse error", GetName() );
643  return false;
644  }
645  return true;
646 }
647 
648 /*
649 ===================
650 idDeclAudio::DefaultDefinition
651 ===================
652 */
653 const char *idDeclAudio::DefaultDefinition( void ) const {
654  return
655  "{\n"
656  "\t" "{\n"
657  "\t\t" "name\t5Default Audio\n"
658  "\t" "}\n"
659  "}";
660 }
661 
662 /*
663 ===================
664 idDeclAudio::FreeData
665 ===================
666 */
667 void idDeclAudio::FreeData( void ) {
668 }
int GetLineNum(void) const
Definition: DeclManager.h:168
virtual void SetSecurity(const char *sec) const
Definition: DeclPDA.cpp:256
idStr info
Definition: DeclPDA.h:114
idStrList videos
Definition: DeclPDA.h:153
virtual const idSoundShader * FindSound(const char *name, bool makeDefault=true)=0
virtual void AddAudio(const char *name, bool unique=true) const
Definition: DeclPDA.cpp:204
virtual size_t Size(void) const
Definition: DeclPDA.cpp:328
virtual const int GetNumVideos() const
Definition: DeclPDA.cpp:265
void void bool HadError(void) const
Definition: Lexer.cpp:1794
const char * GetFileName(void) const
Definition: DeclManager.h:171
const int DECL_LEXER_FLAGS
Definition: DeclManager.h:93
idDeclVideo()
Definition: DeclPDA.h:71
idStr preview
Definition: DeclPDA.h:115
idStr audioName
Definition: DeclPDA.h:113
idStr post
Definition: DeclPDA.h:160
idStr icon
Definition: DeclPDA.h:158
virtual void FreeData(void)
Definition: DeclPDA.cpp:446
virtual const char * DefaultDefinition(void) const
Definition: DeclPDA.cpp:546
virtual void Print(void) const
Definition: DeclPDA.cpp:46
const char * GetName(void) const
Definition: DeclManager.h:140
GLenum GLsizei GLenum GLenum const GLvoid * image
Definition: glext.h:2855
Definition: Token.h:71
void SetFlags(int flags)
Definition: Lexer.h:298
virtual const idMaterial * FindMaterial(const char *name, bool makeDefault=true)=0
GLuint src
Definition: glext.h:5390
idStr title
Definition: DeclPDA.h:161
virtual bool Parse(const char *text, const int textLength)
Definition: DeclPDA.cpp:355
idDeclEmail()
Definition: DeclPDA.h:43
GLuint GLuint num
Definition: glext.h:5390
int Icmp(const char *text) const
Definition: Str.h:667
idStrList audios
Definition: DeclPDA.h:154
virtual size_t Size(void) const
Definition: DeclPDA.cpp:568
virtual const idDeclAudio * GetAudioByIndex(int index) const
Definition: DeclPDA.cpp:304
virtual void Print(void) const
Definition: DeclPDA.cpp:463
Definition: Lexer.h:137
virtual bool Parse(const char *text, const int textLength)
Definition: DeclPDA.cpp:595
idStr to
Definition: DeclPDA.h:63
GLuint index
Definition: glext.h:3476
virtual const idDeclVideo * GetVideoByIndex(int index) const
Definition: DeclPDA.cpp:292
idStr date
Definition: DeclPDA.h:62
virtual void AddEmail(const char *name, bool unique=true) const
Definition: DeclPDA.cpp:220
idStr preview
Definition: DeclPDA.h:87
idStr from
Definition: DeclPDA.h:64
idStr videoName
Definition: DeclPDA.h:89
idCommon * common
Definition: Common.cpp:206
virtual const int GetNumAudios() const
Definition: DeclPDA.cpp:274
#define NULL
Definition: Lib.h:88
idStr audio
Definition: DeclPDA.h:112
virtual const idDecl * FindType(declType_t type, const char *name, bool makeDefault=true)=0
int originalEmails
Definition: DeclPDA.h:163
virtual void List(void) const
Definition: DeclPDA.cpp:472
idStr subject
Definition: DeclPDA.h:61
type * Find(type const &obj) const
Definition: List.h:782
virtual void Print(void) const
Definition: DeclPDA.cpp:337
int originalVideos
Definition: DeclPDA.h:164
idStr audio
Definition: DeclPDA.h:91
virtual const char * DefaultDefinition(void) const
Definition: DeclPDA.cpp:653
virtual void Printf(const char *fmt,...) id_attribute((format(printf
int LoadMemory(const char *ptr, int length, const char *name, int startLine=1)
Definition: Lexer.cpp:1646
virtual const int GetNumEmails() const
Definition: DeclPDA.cpp:283
idDeclPDA()
Definition: DeclPDA.h:121
idDeclManager * declManager
virtual bool Parse(const char *text, const int textLength)
Definition: DeclPDA.cpp:64
virtual const idDeclEmail * GetEmailByIndex(int index) const
Definition: DeclPDA.cpp:316
virtual size_t Size(void) const
Definition: DeclPDA.cpp:37
int Append(const type &obj)
Definition: List.h:646
void void Warning(const char *str,...) id_attribute((format(printf
Definition: Lexer.cpp:241
virtual bool Parse(const char *text, const int textLength)
Definition: DeclPDA.cpp:481
virtual void RemoveAddedEmailsAndVideos() const
Definition: DeclPDA.cpp:236
virtual void AddVideo(const char *name, bool unique=true) const
Definition: DeclPDA.cpp:188
virtual void List(void) const
Definition: DeclPDA.cpp:346
idStr video
Definition: DeclPDA.h:88
int Num(void) const
Definition: List.h:265
bool RemoveIndex(int index)
Definition: List.h:849
const GLcharARB * name
Definition: glext.h:3629
idStrList emails
Definition: DeclPDA.h:155
idStr text
Definition: DeclPDA.h:60
idStr fullName
Definition: DeclPDA.h:157
int SkipUntilString(const char *string)
Definition: Lexer.cpp:1097
virtual void FreeData(void)
Definition: DeclPDA.cpp:560
idStr security
Definition: DeclPDA.h:162
virtual void FreeData(void)
Definition: DeclPDA.cpp:175
idStr pdaName
Definition: DeclPDA.h:156
virtual void List(void) const
Definition: DeclPDA.cpp:586
virtual void Print(void) const
Definition: DeclPDA.cpp:577
virtual void List(void) const
Definition: DeclPDA.cpp:55
virtual const char * DefaultDefinition(void) const
Definition: DeclPDA.cpp:163
virtual const char * DefaultDefinition(void) const
Definition: DeclPDA.cpp:430
idStr info
Definition: DeclPDA.h:90
virtual void FreeData(void)
Definition: DeclPDA.cpp:667
int ReadToken(idToken *token)
Definition: Lexer.cpp:820
virtual size_t Size(void) const
Definition: DeclPDA.cpp:454
idDeclAudio()
Definition: DeclPDA.h:97
void Clear(void)
Definition: List.h:184