doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DeclEntityDef.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 =================
35 idDeclEntityDef::Size
36 =================
37 */
38 size_t idDeclEntityDef::Size( void ) const {
39  return sizeof( idDeclEntityDef ) + dict.Allocated();
40 }
41 
42 /*
43 ================
44 idDeclEntityDef::FreeData
45 ================
46 */
48  dict.Clear();
49 }
50 
51 /*
52 ================
53 idDeclEntityDef::Parse
54 ================
55 */
56 bool idDeclEntityDef::Parse( const char *text, const int textLength ) {
57  idLexer src;
58  idToken token, token2;
59 
60  src.LoadMemory( text, textLength, GetFileName(), GetLineNum() );
62  src.SkipUntilString( "{" );
63 
64  while (1) {
65  if ( !src.ReadToken( &token ) ) {
66  break;
67  }
68 
69  if ( !token.Icmp( "}" ) ) {
70  break;
71  }
72  if ( token.type != TT_STRING ) {
73  src.Warning( "Expected quoted string, but found '%s'", token.c_str() );
74  MakeDefault();
75  return false;
76  }
77 
78  if ( !src.ReadToken( &token2 ) ) {
79  src.Warning( "Unexpected end of file" );
80  MakeDefault();
81  return false;
82  }
83 
84  if ( dict.FindKey( token ) ) {
85  src.Warning( "'%s' already defined", token.c_str() );
86  }
87  dict.Set( token, token2 );
88  }
89 
90  // we always automatically set a "classname" key to our name
91  dict.Set( "classname", GetName() );
92 
93  // "inherit" keys will cause all values from another entityDef to be copied into this one
94  // if they don't conflict. We can't have circular recursions, because each entityDef will
95  // never be parsed mroe than once
96 
97  // find all of the dicts first, because copying inherited values will modify the dict
99 
100  while ( 1 ) {
101  const idKeyValue *kv;
102  kv = dict.MatchPrefix( "inherit", NULL );
103  if ( !kv ) {
104  break;
105  }
106 
107  const idDeclEntityDef *copy = static_cast<const idDeclEntityDef *>( declManager->FindType( DECL_ENTITYDEF, kv->GetValue(), false ) );
108  if ( !copy ) {
109  src.Warning( "Unknown entityDef '%s' inherited by '%s'", kv->GetValue().c_str(), GetName() );
110  } else {
111  defList.Append( copy );
112  }
113 
114  // delete this key/value pair
115  dict.Delete( kv->GetKey() );
116  }
117 
118  // now copy over the inherited key / value pairs
119  for ( int i = 0 ; i < defList.Num() ; i++ ) {
120  dict.SetDefaults( &defList[ i ]->dict );
121  }
122 
123  // precache all referenced media
124  // do this as long as we arent in modview
125  if ( !( com_editors & (EDITOR_RADIANT|EDITOR_AAS) ) ) {
127  }
128 
129  return true;
130 }
131 
132 /*
133 ================
134 idDeclEntityDef::DefaultDefinition
135 ================
136 */
137 const char *idDeclEntityDef::DefaultDefinition( void ) const {
138  return
139  "{\n"
140  "\t" "\"DEFAULTED\"\t\"1\"\n"
141  "}";
142 }
143 
144 /*
145 ================
146 idDeclEntityDef::Print
147 
148 Dumps all key/value pairs, including inherited ones
149 ================
150 */
152  dict.Print();
153 }
int GetLineNum(void) const
Definition: DeclManager.h:168
int type
Definition: Token.h:77
void Delete(const char *key)
Definition: Dict.cpp:496
const char * GetFileName(void) const
Definition: DeclManager.h:171
const int DECL_LEXER_FLAGS
Definition: DeclManager.h:93
const idStr & GetKey(void) const
Definition: Dict.h:52
virtual void CacheDictionaryMedia(const idDict *dict)=0
virtual const char * DefaultDefinition() const
const idKeyValue * MatchPrefix(const char *prefix, const idKeyValue *lastMatch=NULL) const
Definition: Dict.cpp:523
virtual void FreeData(void)
const char * GetName(void) const
Definition: DeclManager.h:140
Definition: Token.h:71
void SetFlags(int flags)
Definition: Lexer.h:298
#define TT_STRING
Definition: Token.h:41
GLuint src
Definition: glext.h:5390
void Set(const char *key, const char *value)
Definition: Dict.cpp:275
int i
Definition: process.py:33
int Icmp(const char *text) const
Definition: Str.h:667
virtual size_t Size(void) const
virtual bool Parse(const char *text, const int textLength)
int com_editors
Definition: Common.cpp:97
Definition: Lexer.h:137
void SetDefaults(const idDict *dict)
Definition: Dict.cpp:179
#define NULL
Definition: Lib.h:88
void Clear(void)
Definition: Dict.cpp:201
virtual const idDecl * FindType(declType_t type, const char *name, bool makeDefault=true)=0
const idStr & GetValue(void) const
Definition: Dict.h:53
virtual void Print(void)
const idKeyValue * FindKey(const char *key) const
Definition: Dict.cpp:451
int LoadMemory(const char *ptr, int length, const char *name, int startLine=1)
Definition: Lexer.cpp:1646
idDeclManager * declManager
int Append(const type &obj)
Definition: List.h:646
void void Warning(const char *str,...) id_attribute((format(printf
Definition: Lexer.cpp:241
int Num(void) const
Definition: List.h:265
const char * c_str(void) const
Definition: Str.h:487
int SkipUntilString(const char *string)
Definition: Lexer.cpp:1097
idGame * game
Definition: Game_local.cpp:65
void MakeDefault(void)
Definition: DeclManager.h:190
Definition: List.h:84
size_t Allocated(void) const
Definition: Dict.cpp:258
void Print() const
Definition: Dict.cpp:218
int ReadToken(idToken *token)
Definition: Lexer.cpp:820