Commit 35c241de authored by Florent D'Halluin's avatar Florent D'Halluin
Browse files

[yavgui] Improve compilation.

Move structure modification handlers (templated code) in
a separate file so that they are only included where used.

* yavgui/src/g_vcsn_handler.cc: Minor adaptations.
* yavgui/src/g_vcsn_handler.hh,
* yavgui/src/g_vcsn_handler.hxx: Remove handler classes from here.
* yavgui/src/g_vcsn_handler_internal.hh,
* yavgui/src/yavgui/src/g_vcsn_handler_internal.hxx: New, Add classes.
parent db389ee6
2009-08-06 d-halluin <d-halluin@lrde.epita.fr>
[yavgui] Improve compilation.
Move structure modification handlers (templated code) in
a separate file so that they are only included where used.
* yavgui/src/g_vcsn_handler.cc: Minor adaptations.
* yavgui/src/g_vcsn_handler.hh,
* yavgui/src/g_vcsn_handler.hxx: Remove handler classes from here.
* yavgui/src/g_vcsn_handler_internal.hh,
* yavgui/src/yavgui/src/g_vcsn_handler_internal.hxx: New, Add classes.
2009-08-06 d-halluin <d-halluin@lrde.epita.fr>
 
[yavgui] Enable state properties dialog.
......
......@@ -23,19 +23,15 @@
*/
#include "g_vcsn_handler.hh"
#include "g_vcsn_handler_internal.hh"
using namespace gui::display;
using namespace gui::handlers;
namespace gui
{
namespace display
{
GVcsnHandler::AddState::AddState(SceneInfo& i, QPointF p)
: info(i),
pos(p)
{
}
void
GVcsnHandler::addState(QPointF pos)
{
......@@ -46,12 +42,6 @@ namespace gui
boost::apply_visitor(op, **(info_.automaton));
}
GVcsnHandler::DelState::DelState(SceneInfo& i, GState* s)
: info(i),
state(s)
{
}
void
GVcsnHandler::delState(GState* state)
{
......@@ -64,13 +54,6 @@ namespace gui
boost::apply_visitor(op, **(info_.automaton));
}
GVcsnHandler::SetInitial::SetInitial(SceneInfo& i, GState* s, QString e)
: info(i),
state(s),
entry(e)
{
}
void
GVcsnHandler::setInitial(GState* state, QString entry)
{
......@@ -83,13 +66,6 @@ namespace gui
boost::apply_visitor(op, **(info_.automaton));
}
GVcsnHandler::SetFinal::SetFinal(SceneInfo& i, GState* s, QString e)
: info(i),
state(s),
entry(e)
{
}
void
GVcsnHandler::setFinal(GState* state, QString entry)
{
......@@ -102,12 +78,6 @@ namespace gui
boost::apply_visitor(op, **(info_.automaton));
}
GVcsnHandler::DelTransition::DelTransition(SceneInfo& i, GTransition* t)
: info(i),
transition(t)
{
}
void
GVcsnHandler::delTransition(GTransition* transition)
{
......
......@@ -71,70 +71,6 @@ namespace gui
private:
struct AddState: public boost::static_visitor<>
{
AddState(SceneInfo& info,
QPointF pos);
template<typename Automaton>
void operator()(Automaton& automaton);
SceneInfo& info;
QPointF pos;
};
struct DelState: public boost::static_visitor<>
{
DelState(SceneInfo& info,
GState* state);
template<typename Automaton>
void operator()(Automaton& automaton);
SceneInfo& info;
GState* state;
};
struct DelTransition: public boost::static_visitor<>
{
DelTransition(SceneInfo& info,
GTransition* transition);
template<typename Automaton>
void operator()(Automaton& automaton);
SceneInfo& info;
GTransition* transition;
};
struct SetInitial: public boost::static_visitor<>
{
SetInitial(SceneInfo& info,
GState* state,
QString entry);
template<typename Automaton>
void operator()(Automaton& automaton);
SceneInfo& info;
GState* state;
QString entry;
};
struct SetFinal: public boost::static_visitor<>
{
SetFinal(SceneInfo& info,
GState* state,
QString entry);
template<typename Automaton>
void operator()(Automaton& automaton);
SceneInfo& info;
GState* state;
QString entry;
};
SceneInfo info_;
};
} // ! namespace display
......
......@@ -25,107 +25,14 @@
#ifndef G_VCSN_HANDLER_HXX_
# define G_VCSN_HANDLER_HXX_
# include "common.hh"
# include "exceptions.hh"
# include "g_vcsn_handler.hh"
# include "common.hh"
# include <cmath>
# include <sstream>
# include <vaucanson/misc/usual_macros.hh>
namespace gui
{
namespace display
{
template<typename Automaton>
void
GVcsnHandler::AddState::operator()(Automaton& automaton)
{
AUTOMATON_TYPES(Automaton)
int i = automaton.add_state();
GState *state = new GState(i, QColor("white"));
state->setPos(pos);
info.scene->addItem(state);
info.scene->connectState(state);
}
template<typename Automaton>
void
GVcsnHandler::DelState::operator()(Automaton& automaton)
{
AUTOMATON_TYPES(Automaton)
automaton.del_state(state->index());
delete (state); // removes it from the scene properly.
info.scene->itemDeselected();
state = 0;
}
template<typename Automaton>
void
GVcsnHandler::DelTransition::operator()(Automaton& automaton)
{
AUTOMATON_TYPES(Automaton)
// FIXME: this cast may be unsafe:
automaton.del_transition((htransition_t) transition->index());
delete (transition); // removes it from the scene properly.
info.scene->itemDeselected();
transition = 0;
}
template<typename Automaton>
void
GVcsnHandler::SetInitial::operator()(Automaton& automaton)
{
using namespace vcsn::boolean_automaton;
int i = state->index();
if (entry.isNull())
{
automaton.unset_initial(i);
state->set_initial_entry(0);
}
else
{
// FIXME: handle entries.
automaton.set_initial(i);
std::stringstream str;
str << automaton.get_initial(i);
state->set_initial_entry(str.str().c_str());
}
state->update();
}
template<typename Automaton>
void
GVcsnHandler::SetFinal::operator()(Automaton& automaton)
{
AUTOMATON_TYPES(Automaton)
int i = state->index();
if (entry.isNull())
{
automaton.unset_final(i);
state->set_final_entry(0);
}
else
{
// FIXME: Handle entries.
automaton.set_final(i);
std::stringstream s;
s << automaton.get_final(i);
state->set_final_entry(s.str().c_str());
}
state->update();
}
} // ! namespace display
} // ! namespace gui
......
// g_vcsn_handler_internal.hh: this file is part of Vaucanson.
//
// Vaucanson, a generic library for finite state machines.
//
// Copyright (C) 2006 The Vaucanson Group.
//
// 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.
//
// The complete GNU General Public Licence Notice can be found as the
// `COPYING' file in the root directory.
//
// The Vaucanson Group consists of people listed in the `AUTHORS' file.
//
/**
* @file g_vcsn_handler_internal.hh
* @author Florent D'Halluin <d-halluin@lrde.epita.fr>
*
* Implement the actual structure modification operations.
* Include only in g_vcsn_handler.cc since the code here is templated.
*/
#ifndef G_VCSN_HANDLER_INTERNAL_HH_
# define G_VCSN_HANDLER_INTERNAL_HH_
# include "common.hh"
# include "g_common.hh"
# include "vcsn_common.hh"
# include "g_vcsn_handler.hh"
# include "g_state.hh"
# include "g_transition.hh"
# include "g_view.hh"
# include "g_scene.hh"
# include <boost/variant.hpp>
using namespace gui::vcsn_internal;
using namespace gui::display;
namespace gui
{
namespace handlers
{
typedef display::GVcsnHandler::SceneInfo SceneInfo;
struct AddState: public boost::static_visitor<>
{
AddState(SceneInfo& info,
QPointF pos);
template<typename Automaton>
void operator()(Automaton& automaton);
SceneInfo& info;
QPointF pos;
};
struct DelState: public boost::static_visitor<>
{
DelState(SceneInfo& info,
GState* state);
template<typename Automaton>
void operator()(Automaton& automaton);
SceneInfo& info;
GState* state;
};
struct DelTransition: public boost::static_visitor<>
{
DelTransition(SceneInfo& info,
GTransition* transition);
template<typename Automaton>
void operator()(Automaton& automaton);
SceneInfo& info;
GTransition* transition;
};
struct SetInitial: public boost::static_visitor<>
{
SetInitial(SceneInfo& info,
GState* state,
QString entry);
template<typename Automaton>
void operator()(Automaton& automaton);
SceneInfo& info;
GState* state;
QString entry;
};
struct SetFinal: public boost::static_visitor<>
{
SetFinal(SceneInfo& info,
GState* state,
QString entry);
template<typename Automaton>
void operator()(Automaton& automaton);
SceneInfo& info;
GState* state;
QString entry;
};
} // ! namespace handlers
} // ! namespace gui
# include "g_vcsn_handler_internal.hxx"
#endif /* !G_VCSN_HANDLER_INTERNAL_HH_ */
// g_vcsn_handler_internal.hxx: this file is part of Vaucanson.
//
// Vaucanson, a generic library for finite state machines.
//
// Copyright (C) 2006 The Vaucanson Group.
//
// 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.
//
// The complete GNU General Public Licence Notice can be found as the
// `COPYING' file in the root directory.
//
// The Vaucanson Group consists of people listed in the `AUTHORS' file.
//
/**
* @file g_vcsn_handler_internal.hxx
* @author Florent D'Halluin <d-halluin@lrde.epita.fr>
*
* FIXME
*/
#ifndef G_VCSN_HANDLER_INTERNAL_HXX_
# define G_VCSN_HANDLER_INTERNAL_HXX_
# include "common.hh"
# include "exceptions.hh"
# include "g_vcsn_handler_internal.hh"
# include <cmath>
# include <sstream>
# include <vaucanson/misc/usual_macros.hh>
namespace gui
{
namespace handlers
{
AddState::AddState(SceneInfo& i, QPointF p)
: info(i),
pos(p)
{
}
template<typename Automaton>
void
AddState::operator()(Automaton& automaton)
{
AUTOMATON_TYPES(Automaton)
int i = automaton.add_state();
GState *state = new GState(i, QColor("white"));
state->setPos(pos);
info.scene->addItem(state);
info.scene->connectState(state);
}
DelState::DelState(SceneInfo& i, GState* s)
: info(i),
state(s)
{
}
template<typename Automaton>
void
DelState::operator()(Automaton& automaton)
{
AUTOMATON_TYPES(Automaton)
automaton.del_state(state->index());
delete (state); // removes it from the scene properly.
info.scene->itemDeselected();
state = 0;
}
DelTransition::DelTransition(SceneInfo& i, GTransition* t)
: info(i),
transition(t)
{
}
template<typename Automaton>
void
DelTransition::operator()(Automaton& automaton)
{
AUTOMATON_TYPES(Automaton)
// FIXME: this cast may be unsafe:
automaton.del_transition((htransition_t) transition->index());
delete (transition); // removes it from the scene properly.
info.scene->itemDeselected();
transition = 0;
}
SetInitial::SetInitial(SceneInfo& i, GState* s, QString e)
: info(i),
state(s),
entry(e)
{
}
template<typename Automaton>
void
SetInitial::operator()(Automaton& automaton)
{
using namespace vcsn::boolean_automaton;
int i = state->index();
if (entry.isNull())
{
automaton.unset_initial(i);
state->set_initial_entry(0);
}
else
{
// FIXME: handle entries.
automaton.set_initial(i);
std::stringstream str;
str << automaton.get_initial(i);
state->set_initial_entry(str.str().c_str());
}
state->update();
}
SetFinal::SetFinal(SceneInfo& i, GState* s, QString e)
: info(i),
state(s),
entry(e)
{
}
template<typename Automaton>
void
SetFinal::operator()(Automaton& automaton)
{
AUTOMATON_TYPES(Automaton)
int i = state->index();
if (entry.isNull())
{
automaton.unset_final(i);
state->set_final_entry(0);
}
else
{
// FIXME: Handle entries.
automaton.set_final(i);
std::stringstream s;
s << automaton.get_final(i);
state->set_final_entry(s.str().c_str());
}
state->update();
}
} // ! namespace handlers
} // ! namespace gui
#endif /* !G_VCSN_HANDLER_INTERNAL_HXX_ */
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment