pingus-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Pingus-CVS] CVS: Games/Pingus/src/input pointer_factory.cxx,NONE,1.1 po


From: torangan
Subject: [Pingus-CVS] CVS: Games/Pingus/src/input pointer_factory.cxx,NONE,1.1 pointer_factory.hxx,NONE,1.1
Date: 9 Jul 2002 16:50:28 -0000

Update of /usr/local/cvsroot/Games/Pingus/src/input
In directory dark:/tmp/cvs-serv10790

Added Files:
        pointer_factory.cxx pointer_factory.hxx 
Log Message:
creates a Pointer Instance


--- NEW FILE: pointer_factory.cxx ---
//  $Id: pointer_factory.cxx,v 1.1 2002/07/09 16:50:26 torangan Exp $
// 
//  Pingus - A free Lemmings clone
//  Copyright (C) 2000 Ingo Ruhnke <address@hidden>
//
//  This program is free software; you can redistribute it and/or
//  modify it under the terms of the GNU General Public License
//  as published by the Free Software Foundation; either version 2
//  of the License, or (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
// 
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

#include <stdlib.h>
#include "../xml_helper.hxx"
#include "../pingus_error.hxx"
#include "axis_pointer.hxx"
#include "axis_factory.hxx"
#include "mouse_pointer.hxx"
#include "multiple_pointer.hxx"
#include "pointer.hxx"
#include "pointer_factory.hxx"

namespace Input {

  Pointer* PointerFactory::create(xmlNodePtr cur)
  {
    if (xmlIsBlankNode(cur)) 
      cur = cur->next;

    if ( ! strcmp(reinterpret_cast<const char*>(cur->name), "axis-pointer"))
      return axis_pointer(cur);
      
    else if ( ! strcmp(reinterpret_cast<const char*>(cur->name), 
"mouse-pointer"))
      return mouse_pointer();
      
    else if ( ! strcmp(reinterpret_cast<const char*>(cur->name), 
"multiple-pointer"))
      return multiple_pointer(cur);
      
    else
      throw PingusError("Unknown pointer type: " + 
std::string(reinterpret_cast<const char*>(cur->name)));
  }
  
  Pointer* PointerFactory::axis_pointer (xmlNodePtr cur)
  {
    char* speed_str = reinterpret_cast<char*>(xmlGetProp(cur, 
reinterpret_cast<const xmlChar*>("speed")));
    float speed = atof(speed_str);
    free(speed_str);

    std::vector<Axis*> axes;
    cur = cur->children;
    
    while (cur)
      {
        if (xmlIsBlankNode(cur))
          {
            cur = cur->next;
            continue;
          }
          
        axes.push_back(AxisFactory::create(cur));
        cur = cur->next;
      }
      
    return new AxisPointer(speed, axes);
  }

  Pointer* PointerFactory::mouse_pointer ()
  {
    return new MousePointer;
  }

  Pointer* PointerFactory::multiple_pointer (xmlNodePtr cur)
  {
    std::vector<Pointer*> pointers;
    cur = cur->children;

    while (cur)    
      {
        if (xmlIsBlankNode(cur))
          {
            cur = cur->next;
            continue;
          }

        pointers.push_back(create(cur));
        cur = cur->next;
      }
    
    return new MultiplePointer(pointers);
  }

}

/* EOF */

--- NEW FILE: pointer_factory.hxx ---
//  $Id: pointer_factory.hxx,v 1.1 2002/07/09 16:50:26 torangan Exp $
// 
//  Pingus - A free Lemmings clone
//  Copyright (C) 2000 Ingo Ruhnke <address@hidden>
//
//  This program is free software; you can redistribute it and/or
//  modify it under the terms of the GNU General Public License
//  as published by the Free Software Foundation; either version 2
//  of the License, or (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
// 
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

#ifndef HEADER_PINGUS_INPUT_POINTER_FACTORY_HXX
#define HEADER_PINGUS_INPUT_POINTER_FACTORY_HXX

#include "../libxmlfwd.hxx"

namespace Input {

  class Pointer;

  class PointerFactory 
  {
    private:
      static inline Pointer* axis_pointer     (xmlNodePtr cur);
      static inline Pointer* mouse_pointer    ();
      static inline Pointer* multiple_pointer (xmlNodePtr cur);
    
    public:
      static Pointer* create (xmlNodePtr cur);
  };
}

#endif

/* EOF */




reply via email to

[Prev in Thread] Current Thread [Next in Thread]