/[usata]/usata2/src/xml/scene_parser_elements.cpp
ViewVC logotype

Diff of /usata2/src/xml/scene_parser_elements.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by skunix, Fri Feb 18 02:24:33 2005 UTC revision 1.2 by skunix, Tue Feb 22 18:17:57 2005 UTC
# Line 17  Line 17 
17    
18  #include <boost/lexical_cast.hpp>  #include <boost/lexical_cast.hpp>
19    
20    
21  namespace usata  namespace usata
22  {  {
23    
# Line 83  namespace scene_parser_elements Line 84  namespace scene_parser_elements
84  SceneElementType ObjectElements[] =  SceneElementType ObjectElements[] =
85  {  {
86          {"int", IntE::create },          {"int", IntE::create },
87            {"str", StringE::create},
88          {0,0}          {0,0}
89  };  };
90    
# Line 111  ObjectE::create(SceneElement* parent,Sce Line 113  ObjectE::create(SceneElement* parent,Sce
113  bool  bool
114  ObjectE::take_data_any(const std::string& name, const boost::any&data)  ObjectE::take_data_any(const std::string& name, const boost::any&data)
115  {  {
116          mOd->props.add(name,data);                if (mOk)
117          return true;          {
118                    mOd->props.add(name,data);
119                    return true;
120            }      
121            return false;
122  }  }
123    
124    const char *missing_required = "'object' element missing required attribute";
125    
126  void  void
127  ObjectE::start_element(const char*, const char **attrib)  ObjectE::start_element(const char*, const char **attrib)
128  {  {
129            const char * Type;
130    
131            Type = attr_check("type", attrib);
132            if (!Type)
133                    Type=attr_check("cls", attrib);
134    
135            if (!Type)
136            {
137                    int line = mParser->get_line();
138                    const std::string& stream_name = mParser->get_stream_name();
139                    log::BufferedStream ls(log::Level::WARNING);
140                    if (!Type)
141                    {
142                            ls      << stream_name << ':' << line << ": "
143                                    << missing_required <<" 'type'" << log::commit;
144                    }
145                    return;
146            }
147            mOk=true;
148            mOd.reset(new ObjectDescription);
149            mOd->type=Type;
150    
151    
152            return;
153  }  }
154    
155  void  void
156  ObjectE::end_element()  ObjectE::end_element()
157  {  {
158            if (mOk)
159            {
160                    mParser->add_object(mOd.release());
161            }
162  }  }
163    
164  SceneElement*  SceneElement*
165  ObjectE::make_child(const char* eName)  ObjectE::make_child(const char* eName)
166  {  {
167            SceneElementType* set = check_element_type(eName, ObjectElements);
168            if (set)
169            {
170                    return set->create(this, mParser);
171            }
172    
173          return 0;          return 0;
174  }  }
175  ObjectE::ObjectE(SceneElement* parent, SceneParser*parser)  ObjectE::ObjectE(SceneElement* parent, SceneParser*parser)
176  :       SceneElement(parent,parser),  :       SceneElement(parent,parser),
177          mOd(new ObjectDescription)          mOd(new ObjectDescription),
178            mOk(false)
179  {  {
180  }  }
181    
# Line 156  SimpleElementBase::start_element(const c Line 198  SimpleElementBase::start_element(const c
198                  mHaveName=true;                  mHaveName=true;
199          }          }
200    
201          process(aValue);          SceneElementHub * seh_p = dynamic_cast<SceneElementHub*>(mParent);
202    
203            if (!seh_p)
204            {
205                    // FIXME: warn
206                    return;
207            }      
208            
209    
210            process(aValue, *seh_p);
211            return;
212  }  }
213    
214    
215  IntE::IntE(SceneElement* parent, SceneParser* parser)  IntE::IntE(SceneElement* parent, SceneParser* parser)
216  : SimpleElementBase(parent,parser)  : SimpleElementBase(parent,parser)
217  {  { }
   
 }  
218    
219  SceneElement *  SceneElement *
220  IntE::create(SceneElement*p, SceneParser*pp)  IntE::create(SceneElement*p, SceneParser*pp)
# Line 173  IntE::create(SceneElement*p, SceneParser Line 223  IntE::create(SceneElement*p, SceneParser
223  }  }
224    
225  void  void
226  IntE::process(const char* v)  IntE::process(const char* v, SceneElementHub& pSEH)
227  {  {
228          try          try
229          {          {
# Line 185  IntE::process(const char* v) Line 235  IntE::process(const char* v)
235                  mValue=0;                  mValue=0;
236          }          }
237    
238            pSEH.take_data_any(mName, boost::any(mValue) );
239    
240          return;          return;
241  }  }
242    
243    StringE::StringE(SceneElement* parent, SceneParser* parser)
244    :       SimpleElementBase(parent, parser)
245    { }
246    
247  void  void
248  IntE::end_element()  StringE::process(const char * v, SceneElementHub & pSEH)
249  {  {
250          SceneElementHub * seh = dynamic_cast<SceneElementHub*>(mParent);          std::string value(v);
251          if (!seh)          pSEH.take_data_any(mName, boost::any(value));
         {  
                 //FIXME: warn!  
                 return;  
         }  
         boost::any ccc(mValue);  
         seh->take_data_any(mName, ccc);  
   
252          return;          return;
253  }  }
254    SceneElement *
255  void  StringE::create(SceneElement*p, SceneParser*pp)
 IntE::content(const char*b, int l)  
256  {  {
257            return new StringE(p,pp);
258  }  }
259    
   
   
260  }  }
261  }  }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26