<commit_before>#include "Graph.h"
#include <algorithm>
#include <queue>
#include <stack>
vertex* Graph::at(const std::string& name)const
{
    auto it = m_V.find(name);
    if(it != m_V.end())
    {
        return it->second;
    }
    else throw;
}
std::vector<std::string> Graph::getkeys()const
{
    std::vector<std::string> ret;
    ret.resize(size());
    int ind = 0;
    for(auto& i : m_V)
    {
        ret[ind++] = i.first;
    }
    return ret;
}
Graph::Graph(const Graph& g)
{
    std::vector<std::string> names = g.getkeys();
    for(size_t i = 0; i < g.size(); i++)
        addvertex(names[i]);

    for(size_t i = 0; i < m_V.size(); i++)
    {
        auto it = m_V.find(names[i]);
        vertex* tmp = g.at(names[i]);
        vertex* pIt = it->second;
        for(auto& j : tmp->adj)
        {
            //1.cost
            //2.vertex* in this graph
            pIt->adj.push_back(std::make_pair(j.first,
                                              m_V.find(j.second->name)->second));
        }
    }
}
/*
    As long as there are vertexes
    change name,clean adjacency list.   x
    After that create new vertexes.     x
    Then fill adjacency lists.
    Clean remaining not needed vertexes x
*/
Graph& Graph::operator=(const Graph& g)
{
    int n = m_V.size() - g.size();
    ///if there are more vertexes than needed: n > 0
    ///if it is just the right size: n = 0
    ///if there are not enough vertexes: n < 0
    std::vector<std::string> names = getkeys();
    std::vector<std::string> namesTO = g.getkeys();
    if(!(n<0))
    {
        for(size_t i = 0; i < g.size(); i++)
        {
            auto it = m_V.find(names[i]);
            it->second->name = namesTO[i];
            it->second->adj.clear();
        }
        //Clean remaining not needed vertexes
        for(int i = g.size(); i < n; i++)
            removevertex(names[i]);
    }
    else
    {
        for(size_t i = 0; i < g.size(); i++)
            addvertex(namesTO[i]);
    }
    //Filling adjacency list
    for(size_t i = 0; i < g.size(); i++)
    {
        auto it = m_V.find(namesTO[i]);
        vertex* pIt = it->second;
        vertex* tmp = g.at(namesTO[i]);
        for(auto& j : tmp->adj)
        {
            pIt->adj.push_back(std::make_pair(j.first,
                                              m_V.find(j.second->name)->second));
        }
    }
    return *this;
}

Graph::~Graph()
{
    if(!m_V.empty())
    {
        for(auto& i : m_V)
            delete i.second;
    }
}

Graph::vmap::iterator Graph::addvertex(const std::string& name)
{
	auto it=m_V.find(name);
	if(it==m_V.end())
	{
		vertex *v;
		v = new vertex(name);
		m_V[name]=v;
		return it;
	}
	return m_V.end();
}

void Graph::addedge(const std::string& from, const std::string& to, int cost)
{
    auto fromIt = m_V.find(from);
    auto toIt   = m_V.find(to);
    if(fromIt != m_V.end() && toIt != m_V.end())
    {
        vertex *f = (fromIt->second);
        vertex *t = (toIt->second);
        std::pair<int,vertex*> edge = std::make_pair(cost,t);
        f->degp++;
        t->degm++;
        f->adj.push_back(edge);
    }
}

void Graph::removevertex(const std::string& name)
{
    auto it = m_V.find(name);
    if(it != m_V.end())
    {
        for(auto& i : m_V)
        {
            if(i.second != it->second)
            {
                vertex* v = i.second;
                for(auto& j : v->adj)
                {
                    if(j.second->name == name)
                    {
                        removeedge(j.second->name,name);
                    }
                }
            }
        }
        delete it->second;
        m_V.erase(it);
    }
}

void Graph::removeedge(const std::string& from, const std::string& to)
{
    auto fromIt = m_V.find(from);
    auto toIt   = m_V.find(to);
    if(fromIt != m_V.end() && toIt != m_V.end())
    {
        vertex* v = fromIt->second;
        size_t i = 0;
        while(i < v->adj.size() && !(v->adj[i].second->name == to))
            i++;
        if(i < v->adj.size())
        {
            v->adj.erase(v->adj.begin()+i);
        }
    }
}

bool Graph::adjacent(const std::string& from, const std::string& to)
{
    auto fromIt = m_V.find(from);
    auto toIt   = m_V.find(to);
    if(fromIt != m_V.end() && toIt != m_V.end())
    {
        for(auto& i : fromIt->second->adj)
        {
            if(i.second->name == to)
            {
                return true;
            }
        }
    }
    return false;
}

std::vector<std::string> Graph::neighbours(const std::string& name)
{
    auto it = m_V.find(name);
    std::vector<std::string> ret;
    if(it != m_V.end())
    {
        for(auto& i : it->second->adj)
            ret.push_back(i.second->name);
    }
    return ret;
}

std::string Graph::bfs(const std::string& name)
{
    std::string ret = "";
    auto it = m_V.find(name);
    if(it != m_V.end())
    {
        std::queue<vertex*> Queue;
        vertex* curr = it->second;
        Queue.push(curr);
        curr->visited = true;
        ret += curr->name + " ";

        while(!Queue.empty())
        {
            for(auto& i : curr->adj)
            {
                if(i.second->visited == false)
                {
                    Queue.push(i.second);
                    i.second->visited = true;
                    ret+= i.second->name + " ";
                }
            }
            Queue.pop();
            if(!Queue.empty())
            {
                curr = Queue.front();
            }
        }

        for(auto& i : m_V)
            i.second->visited = false;
    }
    return ret;
}

std::string Graph::dfs(const std::string& name, bool topo)
{
    std::string ret = "";
    auto it = m_V.find(name);
    if(it != m_V.end())
    {
        std::stack<vertex*> Stack;
        vertex* curr = it->second;
        Stack.push(curr);
        curr->visited = true;
        if(!topo)
            ret += curr->name + " ";

        while(!Stack.empty())
        {
            bool found = false;
            size_t i = 0;
            while(i < curr->adj.size() && !found)
            {
                if(curr->adj[i].second->visited == false)
                {
                    found = true;
                    curr = curr->adj[i].second;
                    curr->visited = true;
                    if(!topo)
                        ret += curr->name + " ";
                    Stack.push(curr);
                }
                i++;
            }
            if(!found)
            {
                Stack.pop();
                if(topo)
                {
                    ret += curr->name + " ";
                }
                if(!Stack.empty())
                {
                    curr = Stack.top();
                }
            }
        }
        if(topo)
        {
            std::reverse(ret.begin(),ret.end());
            ret.erase(ret.begin());//remove space at the beginning
        }
        else ret.erase(ret.end()-1);//remove space at the end
        for(auto& i : m_V)
            i.second->visited = false;
    }
    return ret;
}

std::string Graph::cycle(bool& found)
{
    std::string ret = "";

    return ret;
}
<commit_msg>Minor changes.<commit_after>#include "Graph.h"
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
vertex* Graph::at(const std::string& name)const
{
    auto it = m_V.find(name);
    if(it != m_V.end())
    {
        return it->second;
    }
    else throw;
}
std::vector<std::string> Graph::getkeys()const
{
    std::vector<std::string> ret;
    ret.resize(size());
    int ind = 0;
    for(auto& i : m_V)
    {
        ret[ind++] = i.first;
    }
    return ret;
}
Graph::Graph(const Graph& g)
{
    std::vector<std::string> names = g.getkeys();
    for(size_t i = 0; i < g.size(); i++)
        addvertex(names[i]);

    for(size_t i = 0; i < m_V.size(); i++)
    {
        auto it = m_V.find(names[i]);
        vertex* tmp = g.at(names[i]);
        vertex* pIt = it->second;
        for(auto& j : tmp->adj)
        {
            //1.cost
            //2.vertex* in this graph
            pIt->adj.push_back(std::make_pair(j.first,
                                              m_V.find(j.second->name)->second));
        }
    }
}
/*
    As long as there are vertexes
    change name,clean adjacency list.   x
    After that create new vertexes.     x
    Then fill adjacency lists.
    Clean remaining not needed vertexes x
*/
Graph& Graph::operator=(const Graph& g)
{
    int n = m_V.size() - g.size();
    ///if there are more vertexes than needed: n > 0
    ///if it is just the right size: n = 0
    ///if there are not enough vertexes: n < 0
    std::vector<std::string> names = getkeys();
    std::vector<std::string> namesTO = g.getkeys();
    if(!(n<0))
    {
        for(size_t i = 0; i < g.size(); i++)
        {
            auto it = m_V.find(names[i]);
            it->second->name = namesTO[i];
            it->second->adj.clear();
        }
        //Clean remaining not needed vertexes
        for(int i = g.size(); i < n; i++)
            removevertex(names[i]);
    }
    else
    {
        for(size_t i = 0; i < g.size(); i++)
            addvertex(namesTO[i]);
    }
    //Filling adjacency list
    for(size_t i = 0; i < g.size(); i++)
    {
        auto it = m_V.find(namesTO[i]);
        vertex* pIt = it->second;
        vertex* tmp = g.at(namesTO[i]);
        for(auto& j : tmp->adj)
        {
            pIt->adj.push_back(std::make_pair(j.first,
                                              m_V.find(j.second->name)->second));
        }
    }
    return *this;
}

Graph::~Graph()
{
    if(!m_V.empty())
    {
        for(auto& i : m_V)
            delete i.second;
    }
}

Graph::vmap::iterator Graph::addvertex(const std::string& name)
{
	auto it=m_V.find(name);
	if(it==m_V.end())
	{
		vertex *v;
		v = new vertex(name);
		m_V[name]=v;
		return it;
	}
	return m_V.end();
}

void Graph::addedge(const std::string& from, const std::string& to, int cost)
{
    auto fromIt = m_V.find(from);
    auto toIt   = m_V.find(to);
    if(fromIt != m_V.end() && toIt != m_V.end())
    {
        vertex *f = (fromIt->second);
        vertex *t = (toIt->second);
        std::pair<int,vertex*> edge = std::make_pair(cost,t);
        f->degp++;
        t->degm++;
        f->adj.push_back(edge);
    }
}

void Graph::removevertex(const std::string& name)
{
    auto it = m_V.find(name);
    if(it != m_V.end())
    {
        for(auto& i : m_V)
        {
            if(i.second != it->second)
            {
                vertex* v = i.second;
                for(auto& j : v->adj)
                {
                    if(j.second->name == name)
                    {
                        removeedge(j.second->name,name);
                    }
                }
            }
        }
        delete it->second;
        m_V.erase(it);
    }
}

void Graph::removeedge(const std::string& from, const std::string& to)
{
    auto fromIt = m_V.find(from);
    auto toIt   = m_V.find(to);
    if(fromIt != m_V.end() && toIt != m_V.end())
    {
        vertex* v = fromIt->second;
        size_t i = 0;
        while(i < v->adj.size() && !(v->adj[i].second->name == to))
            i++;
        if(i < v->adj.size())
        {
            v->adj.erase(v->adj.begin()+i);
        }
    }
}

bool Graph::adjacent(const std::string& from, const std::string& to)
{
    auto fromIt = m_V.find(from);
    auto toIt   = m_V.find(to);
    if(fromIt != m_V.end() && toIt != m_V.end())
    {
        for(auto& i : fromIt->second->adj)
        {
            if(i.second->name == to)
            {
                return true;
            }
        }
    }
    return false;
}

std::vector<std::string> Graph::neighbours(const std::string& name)
{
    auto it = m_V.find(name);
    std::vector<std::string> ret;
    if(it != m_V.end())
    {
        for(auto& i : it->second->adj)
            ret.push_back(i.second->name);
    }
    return ret;
}

std::string Graph::bfs(const std::string& name)
{
    std::string ret = "";
    auto it = m_V.find(name);
    if(it != m_V.end())
    {
        std::queue<vertex*> Queue;
        vertex* curr = it->second;
        Queue.push(curr);
        curr->visited = true;
        ret += curr->name + " ";

        while(!Queue.empty())
        {
            for(auto& i : curr->adj)
            {
                if(i.second->visited == false)
                {
                    Queue.push(i.second);
                    i.second->visited = true;
                    ret+= i.second->name + " ";
                }
            }
            Queue.pop();
            if(!Queue.empty())
            {
                curr = Queue.front();
            }
        }

        for(auto& i : m_V)
            i.second->visited = false;
    }
    return ret;
}

std::string Graph::dfs(const std::string& name, bool topo)
{
    std::string ret = "";
    auto it = m_V.find(name);
    if(it != m_V.end())
    {
        std::stack<vertex*> Stack;
        vertex* curr = it->second;
        Stack.push(curr);
        curr->visited = true;
        if(!topo)
            ret += curr->name + " ";

        while(!Stack.empty())
        {
            bool found = false;
            size_t i = 0;
            while(i < curr->adj.size() && !found)
            {
                if(curr->adj[i].second->visited == false)
                {
                    found = true;
                    curr = curr->adj[i].second;
                    curr->visited = true;
                    if(!topo)
                        ret += curr->name + " ";
                    Stack.push(curr);
                }
                i++;
            }
            if(!found)
            {
                Stack.pop();
                if(topo)
                {
                    ret += curr->name + " ";
                }
                if(!Stack.empty())
                {
                    curr = Stack.top();
                }
            }
        }
        if(topo)
        {
            std::reverse(ret.begin(),ret.end());
            ret.erase(ret.begin());//remove space at the beginning
        }
        else ret.erase(ret.end()-1);//remove space at the end
        for(auto& i : m_V)
            i.second->visited = false;
    }
    return ret;
}

std::string Graph::cycle(bool& found)
{
    std::string ret = "";
    return ret;
}
<|endoftext|>


<commit_before>#include "Common.h"
#include "Input.h"
#include "Window.h"
#include <memory>
using namespace std;
//#include <CEGUI/System.h>
//#include <CEGUI/GUIContext.h>
//#include <CEGUI/InjectedInputReceiver.h>

Input :: Input(Window* window):
    m_pWindow(window)
{
    m_DummySwitch.make_dummy();

    m_bRelMouse = !m_bRelMouse; // undo initial state
    relative_mouse(!m_bRelMouse); // redo initial state change

    //SDL_SetRelativeMouseMode(SDL_TRUE);
    //SDL_SetWindowGrab(SDL_GL_GetCurrentWindow(), SDL_TRUE);
    for(unsigned i=0; i<SDL_NumJoysticks(); ++i)
    {
        m_Joysticks.push_back(SDL_JoystickOpen(i));
    }
    SDL_JoystickEventState(SDL_ENABLE);
    SDL_StopTextInput();
}

Input :: ~Input()
{
    for(auto*& j: m_Joysticks)
    {
        SDL_JoystickClose(j);
        j = nullptr;
    }
    m_Joysticks.clear();
}

void Input :: Switch :: trigger()
{
    // TODO: add flag to method for overwriting history or modifying front?
    m_Records.push_back(Record());
    //m_Records.emplace_back();

    for(auto& c: m_Controllers)
        if(!c.expired())
        {
            auto s = c.lock();
            if(s)
                s->trigger();
            else
                c.reset();
        }
}

void Input :: logic(Freq::Time t)
{
    SDL_Event ev;
    //auto& gui = CEGUI::System::getSingleton().getDefaultGUIContext();
    //CEGUI::System::getSingleton().injectTimePulse(t.s());
    //gui.injectTimePulse(t.s());
    m_MouseRel = glm::ivec2();

    if(m_Listen == LISTEN_TEXT && m_ListenText.expired())
        listen(LISTEN_NONE);

    while(SDL_PollEvent(&ev))
    {
        switch(ev.type)
        {
            case SDL_QUIT:
                m_bQuit = true;
                break;

            case SDL_WINDOWEVENT:
                //if(ev.window.event == SDL_WINDOWEVENT_RESIZED)
                //    m_pWindow->resize(glm::ivec2(ev.window.data1, ev.window.data2));
                break;

            case SDL_KEYDOWN:
                m_Devices[KEYBOARD][0][ev.key.keysym.sym] = true;
                if(ev.key.keysym.sym == SDLK_ESCAPE)
                {
                    if(m_Listen == LISTEN_TEXT)
                        listen(LISTEN_NONE);
                    else
                        m_bEscape = true;
                }
                else if(ev.key.keysym.sym == SDLK_RETURN)
                {
                    if(m_Listen == LISTEN_TEXT)
                    {
                        listen(LISTEN_NONE);
                        m_Devices[KEYBOARD][0][ev.key.keysym.sym] = false;
                    }
                }
                else if(ev.key.keysym.sym == SDLK_BACKSPACE)
                {
                    if(m_Listen == LISTEN_TEXT)
                    {
                        auto lt = m_ListenText.lock();
                        if(not lt->empty())
                            *lt = lt->substr(0,lt->size()-1);
                        if(m_ListenCallback)
                            m_ListenCallback(false);
                    }
                }

                //gui.injectKeyDown((CEGUI::Key::Scan)ev.key.keysym.scancode);
                break;

            case SDL_KEYUP:
                m_Devices[KEYBOARD][0][ev.key.keysym.sym] = false;
                if(ev.key.keysym.sym == SDLK_ESCAPE)
                    m_bEscape = false;
                //gui.injectKeyUp((CEGUI::Key::Scan)ev.key.keysym.scancode);
                break;

            case SDL_DROPFILE:
                // string fn = ev.drop.file;
                // SDL_free(ev.drop.file);
                break;

            case SDL_JOYHATMOTION:
            {
                // 8 bits for hat id, 4 bits for each direction
                // yes, we could store dirs in just 2 bits, but they wouldn't
                //   have button-compatible mappings
                // direction bits are stored in this order:
                //   0 - left
                //   1 - right
                //   2 - up
                //   3 - down
                //unsigned id = (1<<12) + (unsigned(ev.jhat.hat) << 4);
                unsigned id = gamepad_hat_id(ev.jhat.hat << 4);
                //if(ev.jhat.value == SDL_HAT_CENTERED)
                //{
                    //// centering invalidates all other directions
                    //for(unsigned i=0; i<4; ++i) {
                    //    auto& dir = m_Devices[GAMEPAD][ev.jhat.which][id+i];
                    //    if(dir) dir = false;
                    //}
                //}
                //else
                //{
                    auto& left = m_Devices[GAMEPAD][ev.jhat.which][id];
                    auto& right = m_Devices[GAMEPAD][ev.jhat.which][id+1];
                    auto& up = m_Devices[GAMEPAD][ev.jhat.which][id+2];
                    auto& down = m_Devices[GAMEPAD][ev.jhat.which][id+3];
                    if(ev.jhat.value & SDL_HAT_LEFT)
                        left = true;
                    else if(left)
                        left = false;
                    if(ev.jhat.value & SDL_HAT_RIGHT)
                        right = true;
                    else if(right)
                        right = false;

                    if(ev.jhat.value & SDL_HAT_UP)
                        up = true;
                    else if(up)
                        up = false;
                    if(ev.jhat.value & SDL_HAT_DOWN)
                        down = true;
                    else if(down)
                        down = false;
                //}

                break;
            }

            case SDL_JOYAXISMOTION:
            {
                float val = (((int)ev.jaxis.value + 32768) + 0.5f) / 32767.0f - 1.0f;
                unsigned id = gamepad_analog_id(ev.jaxis.axis << 1);
                if(val >= 0.0f)
                {
                    //LOGf("pressure: %s", val);
                    m_Devices[GAMEPAD][ev.jaxis.which][id] = false;
                    m_Devices[GAMEPAD][ev.jaxis.which][id+1].pressure(val);
                }
                else
                {
                    //LOGf("pressure: %s", -val);
                    m_Devices[GAMEPAD][ev.jaxis.which][id].pressure(-val);
                    m_Devices[GAMEPAD][ev.jaxis.which][id+1] = false;
                }
                break;
            }
            case SDL_JOYBUTTONDOWN:
                //LOGf("gamepad%s %s", int(ev.jbutton.which) % int(ev.jbutton.button))
                m_Devices[GAMEPAD][ev.jbutton.which][ev.jbutton.button] = true;
                break;

            case SDL_JOYBUTTONUP:
                m_Devices[GAMEPAD][ev.jbutton.which][ev.jbutton.button] = false;
                break;

            case SDL_TEXTINPUT:
            {
                assert(SDL_IsTextInputActive());
                auto lt = m_ListenText.lock();
                *lt += ev.text.text;
                //LOG(ev.text.text);
                if(m_ListenCallback)
                    m_ListenCallback(false);
                break;
            }
            case SDL_TEXTEDITING:
            {
                assert(SDL_IsTextInputActive());
                //auto lt = m_ListenText.lock();
                //*lt = ev.edit.text;
                //LOGf("text: %s", ev.edit.text);
                //LOGf("length: %s", to_string(ev.edit.length));
                //LOGf("start: %s", to_string(ev.edit.start));
                //if(m_ListenCallback)
                //    m_ListenCallback(false);
                break;
            }
            case SDL_MOUSEMOTION:
                if(m_bRelMouse)
                    m_MouseRel += glm::vec2(ev.motion.xrel, ev.motion.yrel);
                else
                    m_MouseRel = m_MousePos;

                m_MousePos = glm::vec2(ev.motion.x, -ev.motion.y);

                if(!m_bRelMouse)
                    m_MouseRel = m_MousePos - m_MouseRel; // simulate mouse rel

                //gui.injectMousePosition(
                //    static_cast<float>(ev.motion.x),
                //    static_cast<float>(ev.motion.y)
                //);
                break;

            case SDL_MOUSEBUTTONDOWN:
            {
                if(ev.button.button == SDL_BUTTON_LEFT) {
                    m_Devices[MOUSE][0][0] = true;
                    //gui.injectMouseButtonDown(CEGUI::MouseButton::LeftButton);
                }
                else if(ev.button.button == SDL_BUTTON_RIGHT){
                    m_Devices[MOUSE][0][1] = true;
                    //gui.injectMouseButtonDown(CEGUI::MouseButton::RightButton);
                }
                else if(ev.button.button == SDL_BUTTON_MIDDLE){
                    m_Devices[MOUSE][0][2] = true;
                    //gui.injectMouseButtonDown(CEGUI::MouseButton::MiddleButton);
                }

                break;
            }

            case SDL_MOUSEBUTTONUP:
            {
                if(ev.button.button == SDL_BUTTON_LEFT){
                    m_Devices[MOUSE][0][0] = false;
                    //gui.injectMouseButtonUp(CEGUI::MouseButton::LeftButton);
                }
                else if(ev.button.button == SDL_BUTTON_RIGHT){
                    m_Devices[MOUSE][0][1] = false;
                    //gui.injectMouseButtonUp(CEGUI::MouseButton::RightButton);
                }
                else if(ev.button.button == SDL_BUTTON_MIDDLE){
                    m_Devices[MOUSE][0][2] = false;
                    //gui.injectMouseButtonUp(CEGUI::MouseButton::MiddleButton);
                }
                break;
            }
            //case SDL_WINDOWEVENT_RESIZED:
            //    break;
        }
    }

    for(auto& types: m_Devices)
        for(auto& devs: types.second)
            for(auto& c: devs.second)
                c.second.logic(t);

    //for(auto& c: m_Mouse)
    //    c.second.logic(t);
    //for(auto& c: m_Devices[KEYBOARD][0])
    //    c.second.logic(t);

    for(auto& c: m_Controllers)
    {
        if(c.second->triggered())
        {
            c.second->event();
            c.second->untrigger();
        }
        c.second->logic(t);
    }

    if(m_bRelMouse)
        SDL_WarpMouseInWindow(
            m_pWindow->sdl_window(),
            m_pWindow->center().x/2,
            m_pWindow->center().y/2
        );
}

unsigned int Input :: bind(
    std::string s,
    const std::shared_ptr<Controller>& controller
){
    // first token might be device name
    // if not, device is keyboard
    std::string device = s.substr(0,s.find(' '));
    if(device == "mouse")
    {
        std::string button = s.substr(device.length()+1);
        button = button.substr(0, button.find(' '));
        unsigned id = 0;
        if(button == "left")
            id = 0;
        else if(button == "right")
            id = 1;
        else if(button == "middle")
            id = 2;
        else
        {
            // use number
            id = boost::lexical_cast<unsigned>(button);
        }
        m_Binds.push_back(Bind(MOUSE, 0, id));
        m_Devices[MOUSE][0][id].plug(controller);
    }
    else if(device == "gamepad")
    {
        bool analog = false;
        bool hat = false;
        std::string button = s.substr(device.length()+1);
        if(boost::starts_with(button,"analog")){
            //LOG("analog");
            analog = true;
            button = button.substr(strlen("analog")+1);
        }else if(boost::starts_with(button,"hat")){
            //LOG("hat");
            hat = true;
            button = button.substr(strlen("hat")+1);
        }

        //LOGf("button %s", button);
        unsigned id = boost::lexical_cast<unsigned>(button);
        if(analog) id = Input::gamepad_analog_id(id);
        if(hat) id = Input::gamepad_hat_id(id);
        m_Binds.push_back(Bind(GAMEPAD, 0, id));
        m_Devices[GAMEPAD][0][id].plug(controller);
    }
    else
    {
        unsigned int id = SDL_GetKeyFromName(s.c_str());
        if(id == SDLK_UNKNOWN)
            ERRORf(ACTION, "bind key %s", s)
        m_Binds.push_back(id);
        m_Devices[KEYBOARD][0][id].plug(controller);
    }
    return m_Binds.size()-1;
}

unsigned Input :: gamepad_analog_id(unsigned id)
{
    return (1<<12) + id;
}

unsigned Input :: gamepad_hat_id(unsigned id)
{
    return (1<<16) + id;
}

void Input :: listen(
    Listen mode,
    std::shared_ptr<std::string> text,
    std::function<void(bool)> cb
){
    if(mode == m_Listen)
        return;

    if(mode == LISTEN_TEXT) {
        SDL_StartTextInput();
        m_ListenText = weak_ptr<string>(text);
        m_ListenCallback = std::move(cb);
    }
    if(mode == LISTEN_NONE) {
        if(m_Listen == LISTEN_TEXT){
            SDL_StopTextInput();
            if(m_ListenCallback)
                m_ListenCallback(true);
            m_ListenText = weak_ptr<string>();
        }
    }
    m_Listen = mode;
}

void Controller :: rumble(float magnitude, Freq::Time t)
{
    // TODO: add rumble support
    // http://wiki.libsdl.org/moin.cgi/CategoryForceFeedback

    //SDL_HapticRumblePlay(m_pHaptic, magnitude, t.ms());
}

<commit_msg>sanity check<commit_after>#include "Common.h"
#include "Input.h"
#include "Window.h"
#include <memory>
using namespace std;
//#include <CEGUI/System.h>
//#include <CEGUI/GUIContext.h>
//#include <CEGUI/InjectedInputReceiver.h>

Input :: Input(Window* window):
    m_pWindow(window)
{
    m_DummySwitch.make_dummy();

    m_bRelMouse = !m_bRelMouse; // undo initial state
    relative_mouse(!m_bRelMouse); // redo initial state change

    //SDL_SetRelativeMouseMode(SDL_TRUE);
    //SDL_SetWindowGrab(SDL_GL_GetCurrentWindow(), SDL_TRUE);
    for(unsigned i=0; i<SDL_NumJoysticks(); ++i)
    {
        m_Joysticks.push_back(SDL_JoystickOpen(i));
    }
    SDL_JoystickEventState(SDL_ENABLE);
    SDL_StopTextInput();
}

Input :: ~Input()
{
    for(auto*& j: m_Joysticks)
    {
        SDL_JoystickClose(j);
        j = nullptr;
    }
    m_Joysticks.clear();
}

void Input :: Switch :: trigger()
{
    // TODO: add flag to method for overwriting history or modifying front?
    m_Records.push_back(Record());
    //m_Records.emplace_back();

    for(auto& c: m_Controllers)
        if(!c.expired())
        {
            auto s = c.lock();
            if(s)
                s->trigger();
            else
                c.reset();
        }
}

void Input :: logic(Freq::Time t)
{
    SDL_Event ev;
    //auto& gui = CEGUI::System::getSingleton().getDefaultGUIContext();
    //CEGUI::System::getSingleton().injectTimePulse(t.s());
    //gui.injectTimePulse(t.s());
    m_MouseRel = glm::ivec2();

    if(m_Listen == LISTEN_TEXT && m_ListenText.expired())
    {
        kit::clear(m_ListenCallback); // probably no longer safe
        listen(LISTEN_NONE);
    }

    while(SDL_PollEvent(&ev))
    {
        switch(ev.type)
        {
            case SDL_QUIT:
                m_bQuit = true;
                break;

            case SDL_WINDOWEVENT:
                //if(ev.window.event == SDL_WINDOWEVENT_RESIZED)
                //    m_pWindow->resize(glm::ivec2(ev.window.data1, ev.window.data2));
                break;

            case SDL_KEYDOWN:
                m_Devices[KEYBOARD][0][ev.key.keysym.sym] = true;
                if(ev.key.keysym.sym == SDLK_ESCAPE)
                {
                    if(m_Listen == LISTEN_TEXT)
                        listen(LISTEN_NONE);
                    else
                        m_bEscape = true;
                }
                else if(ev.key.keysym.sym == SDLK_RETURN)
                {
                    if(m_Listen == LISTEN_TEXT)
                    {
                        listen(LISTEN_NONE);
                        m_Devices[KEYBOARD][0][ev.key.keysym.sym] = false;
                    }
                }
                else if(ev.key.keysym.sym == SDLK_BACKSPACE)
                {
                    if(m_Listen == LISTEN_TEXT)
                    {
                        auto lt = m_ListenText.lock();
                        if(not lt->empty())
                            *lt = lt->substr(0,lt->size()-1);
                        if(m_ListenCallback)
                            m_ListenCallback(false);
                    }
                }

                //gui.injectKeyDown((CEGUI::Key::Scan)ev.key.keysym.scancode);
                break;

            case SDL_KEYUP:
                m_Devices[KEYBOARD][0][ev.key.keysym.sym] = false;
                if(ev.key.keysym.sym == SDLK_ESCAPE)
                    m_bEscape = false;
                //gui.injectKeyUp((CEGUI::Key::Scan)ev.key.keysym.scancode);
                break;

            case SDL_DROPFILE:
                // string fn = ev.drop.file;
                // SDL_free(ev.drop.file);
                break;

            case SDL_JOYHATMOTION:
            {
                // 8 bits for hat id, 4 bits for each direction
                // yes, we could store dirs in just 2 bits, but they wouldn't
                //   have button-compatible mappings
                // direction bits are stored in this order:
                //   0 - left
                //   1 - right
                //   2 - up
                //   3 - down
                //unsigned id = (1<<12) + (unsigned(ev.jhat.hat) << 4);
                unsigned id = gamepad_hat_id(ev.jhat.hat << 4);
                //if(ev.jhat.value == SDL_HAT_CENTERED)
                //{
                    //// centering invalidates all other directions
                    //for(unsigned i=0; i<4; ++i) {
                    //    auto& dir = m_Devices[GAMEPAD][ev.jhat.which][id+i];
                    //    if(dir) dir = false;
                    //}
                //}
                //else
                //{
                    auto& left = m_Devices[GAMEPAD][ev.jhat.which][id];
                    auto& right = m_Devices[GAMEPAD][ev.jhat.which][id+1];
                    auto& up = m_Devices[GAMEPAD][ev.jhat.which][id+2];
                    auto& down = m_Devices[GAMEPAD][ev.jhat.which][id+3];
                    if(ev.jhat.value & SDL_HAT_LEFT)
                        left = true;
                    else if(left)
                        left = false;
                    if(ev.jhat.value & SDL_HAT_RIGHT)
                        right = true;
                    else if(right)
                        right = false;

                    if(ev.jhat.value & SDL_HAT_UP)
                        up = true;
                    else if(up)
                        up = false;
                    if(ev.jhat.value & SDL_HAT_DOWN)
                        down = true;
                    else if(down)
                        down = false;
                //}

                break;
            }

            case SDL_JOYAXISMOTION:
            {
                float val = (((int)ev.jaxis.value + 32768) + 0.5f) / 32767.0f - 1.0f;
                unsigned id = gamepad_analog_id(ev.jaxis.axis << 1);
                if(val >= 0.0f)
                {
                    //LOGf("pressure: %s", val);
                    m_Devices[GAMEPAD][ev.jaxis.which][id] = false;
                    m_Devices[GAMEPAD][ev.jaxis.which][id+1].pressure(val);
                }
                else
                {
                    //LOGf("pressure: %s", -val);
                    m_Devices[GAMEPAD][ev.jaxis.which][id].pressure(-val);
                    m_Devices[GAMEPAD][ev.jaxis.which][id+1] = false;
                }
                break;
            }
            case SDL_JOYBUTTONDOWN:
                //LOGf("gamepad%s %s", int(ev.jbutton.which) % int(ev.jbutton.button))
                m_Devices[GAMEPAD][ev.jbutton.which][ev.jbutton.button] = true;
                break;

            case SDL_JOYBUTTONUP:
                m_Devices[GAMEPAD][ev.jbutton.which][ev.jbutton.button] = false;
                break;

            case SDL_TEXTINPUT:
            {
                assert(SDL_IsTextInputActive());
                auto lt = m_ListenText.lock();
                *lt += ev.text.text;
                //LOG(ev.text.text);
                if(m_ListenCallback)
                    m_ListenCallback(false);
                break;
            }
            case SDL_TEXTEDITING:
            {
                assert(SDL_IsTextInputActive());
                //auto lt = m_ListenText.lock();
                //*lt = ev.edit.text;
                //LOGf("text: %s", ev.edit.text);
                //LOGf("length: %s", to_string(ev.edit.length));
                //LOGf("start: %s", to_string(ev.edit.start));
                //if(m_ListenCallback)
                //    m_ListenCallback(false);
                break;
            }
            case SDL_MOUSEMOTION:
                if(m_bRelMouse)
                    m_MouseRel += glm::vec2(ev.motion.xrel, ev.motion.yrel);
                else
                    m_MouseRel = m_MousePos;

                m_MousePos = glm::vec2(ev.motion.x, -ev.motion.y);

                if(!m_bRelMouse)
                    m_MouseRel = m_MousePos - m_MouseRel; // simulate mouse rel

                //gui.injectMousePosition(
                //    static_cast<float>(ev.motion.x),
                //    static_cast<float>(ev.motion.y)
                //);
                break;

            case SDL_MOUSEBUTTONDOWN:
            {
                if(ev.button.button == SDL_BUTTON_LEFT) {
                    m_Devices[MOUSE][0][0] = true;
                    //gui.injectMouseButtonDown(CEGUI::MouseButton::LeftButton);
                }
                else if(ev.button.button == SDL_BUTTON_RIGHT){
                    m_Devices[MOUSE][0][1] = true;
                    //gui.injectMouseButtonDown(CEGUI::MouseButton::RightButton);
                }
                else if(ev.button.button == SDL_BUTTON_MIDDLE){
                    m_Devices[MOUSE][0][2] = true;
                    //gui.injectMouseButtonDown(CEGUI::MouseButton::MiddleButton);
                }

                break;
            }

            case SDL_MOUSEBUTTONUP:
            {
                if(ev.button.button == SDL_BUTTON_LEFT){
                    m_Devices[MOUSE][0][0] = false;
                    //gui.injectMouseButtonUp(CEGUI::MouseButton::LeftButton);
                }
                else if(ev.button.button == SDL_BUTTON_RIGHT){
                    m_Devices[MOUSE][0][1] = false;
                    //gui.injectMouseButtonUp(CEGUI::MouseButton::RightButton);
                }
                else if(ev.button.button == SDL_BUTTON_MIDDLE){
                    m_Devices[MOUSE][0][2] = false;
                    //gui.injectMouseButtonUp(CEGUI::MouseButton::MiddleButton);
                }
                break;
            }
            //case SDL_WINDOWEVENT_RESIZED:
            //    break;
        }
    }

    for(auto& types: m_Devices)
        for(auto& devs: types.second)
            for(auto& c: devs.second)
                c.second.logic(t);

    //for(auto& c: m_Mouse)
    //    c.second.logic(t);
    //for(auto& c: m_Devices[KEYBOARD][0])
    //    c.second.logic(t);

    for(auto& c: m_Controllers)
    {
        if(c.second->triggered())
        {
            c.second->event();
            c.second->untrigger();
        }
        c.second->logic(t);
    }

    if(m_bRelMouse)
        SDL_WarpMouseInWindow(
            m_pWindow->sdl_window(),
            m_pWindow->center().x/2,
            m_pWindow->center().y/2
        );
}

unsigned int Input :: bind(
    std::string s,
    const std::shared_ptr<Controller>& controller
){
    // first token might be device name
    // if not, device is keyboard
    std::string device = s.substr(0,s.find(' '));
    if(device == "mouse")
    {
        std::string button = s.substr(device.length()+1);
        button = button.substr(0, button.find(' '));
        unsigned id = 0;
        if(button == "left")
            id = 0;
        else if(button == "right")
            id = 1;
        else if(button == "middle")
            id = 2;
        else
        {
            // use number
            id = boost::lexical_cast<unsigned>(button);
        }
        m_Binds.push_back(Bind(MOUSE, 0, id));
        m_Devices[MOUSE][0][id].plug(controller);
    }
    else if(device == "gamepad")
    {
        bool analog = false;
        bool hat = false;
        std::string button = s.substr(device.length()+1);
        if(boost::starts_with(button,"analog")){
            //LOG("analog");
            analog = true;
            button = button.substr(strlen("analog")+1);
        }else if(boost::starts_with(button,"hat")){
            //LOG("hat");
            hat = true;
            button = button.substr(strlen("hat")+1);
        }

        //LOGf("button %s", button);
        unsigned id = boost::lexical_cast<unsigned>(button);
        if(analog) id = Input::gamepad_analog_id(id);
        if(hat) id = Input::gamepad_hat_id(id);
        m_Binds.push_back(Bind(GAMEPAD, 0, id));
        m_Devices[GAMEPAD][0][id].plug(controller);
    }
    else
    {
        unsigned int id = SDL_GetKeyFromName(s.c_str());
        if(id == SDLK_UNKNOWN)
            ERRORf(ACTION, "bind key %s", s)
        m_Binds.push_back(id);
        m_Devices[KEYBOARD][0][id].plug(controller);
    }
    return m_Binds.size()-1;
}

unsigned Input :: gamepad_analog_id(unsigned id)
{
    return (1<<12) + id;
}

unsigned Input :: gamepad_hat_id(unsigned id)
{
    return (1<<16) + id;
}

void Input :: listen(
    Listen mode,
    std::shared_ptr<std::string> text,
    std::function<void(bool)> cb
){
    if(mode == m_Listen)
        return;

    if(mode == LISTEN_TEXT) {
        SDL_StartTextInput();
        m_ListenText = weak_ptr<string>(text);
        m_ListenCallback = std::move(cb);
    }
    if(mode == LISTEN_NONE) {
        if(m_Listen == LISTEN_TEXT){
            SDL_StopTextInput();
            if(m_ListenCallback)
                m_ListenCallback(true);
            m_ListenText = weak_ptr<string>();
        }
    }
    m_Listen = mode;
}

void Controller :: rumble(float magnitude, Freq::Time t)
{
    // TODO: add rumble support
    // http://wiki.libsdl.org/moin.cgi/CategoryForceFeedback

    //SDL_HapticRumblePlay(m_pHaptic, magnitude, t.ms());
}

<|endoftext|>


<commit_before>#include "FilterDockWidget.h"
#include "Settings.h"
#include <QCheckBox>
#include <QFileInfo>
#include <QFileDialog>
#include <QInputDialog>

FilterDockWidget::FilterDockWidget(QWidget *parent)
	: QDockWidget(parent)
	, ui_()
{
	ui_.setupUi(this);

	connect(ui_.maf, SIGNAL(valueChanged(double)), this, SIGNAL(filtersChanged()));
	connect(ui_.maf_enabled, SIGNAL(toggled(bool)), this, SIGNAL(filtersChanged()));

	connect(ui_.impact, SIGNAL(currentIndexChanged(int)), this, SIGNAL(filtersChanged()));
	connect(ui_.impact_enabled, SIGNAL(toggled(bool)), this, SIGNAL(filtersChanged()));

	connect(ui_.ihdb, SIGNAL(valueChanged(int)), this, SIGNAL(filtersChanged()));
	connect(ui_.ihdb_enabled, SIGNAL(toggled(bool)), this, SIGNAL(filtersChanged()));

	connect(ui_.vus, SIGNAL(currentIndexChanged(int)), this, SIGNAL(filtersChanged()));
	connect(ui_.vus_enabled, SIGNAL(toggled(bool)), this, SIGNAL(filtersChanged()));

	connect(ui_.geno, SIGNAL(currentIndexChanged(int)), this, SIGNAL(filtersChanged()));
	connect(ui_.geno_enabled, SIGNAL(toggled(bool)), this, SIGNAL(filtersChanged()));

	connect(ui_.quality_enabled, SIGNAL(toggled(bool)), this, SIGNAL(filtersChanged()));
	connect(ui_.trio_enabled, SIGNAL(toggled(bool)), this, SIGNAL(filtersChanged()));
	connect(ui_.important_enabled, SIGNAL(toggled(bool)), this, SIGNAL(filtersChanged()));

	connect(ui_.roi_add, SIGNAL(clicked()), this, SLOT(addRoi()));
	connect(ui_.roi_add_temp, SIGNAL(clicked()), this, SLOT(addRoiTemp()));
	connect(ui_.roi_remove, SIGNAL(clicked()), this, SLOT(removeRoi()));
	connect(ui_.rois, SIGNAL(currentIndexChanged(int)), this, SLOT(roiSelectionChanged(int)));

	connect(ui_.ref_add, SIGNAL(clicked()), this, SLOT(addRef()));
	connect(ui_.ref_remove, SIGNAL(clicked()), this, SLOT(removeRef()));
	connect(ui_.refs, SIGNAL(currentIndexChanged(int)), this, SLOT(referenceSampleChanged(int)));

	connect(ui_.gene, SIGNAL(editingFinished()), this, SLOT(geneChanged()));

	loadROIFilters();
	loadReferenceFiles();

	reset();
}

void FilterDockWidget::loadROIFilters()
{
	ui_.rois->blockSignals(true);

	//store old selection
	QString current = ui_.rois->currentText();

	//load from settings
	ui_.rois->clear();
	ui_.rois->addItem("none", "");
	QStringList rois = Settings::stringList("target_regions");
	rois.sort(); //note: path is included in order!
	foreach(const QString& roi_file, rois)
	{
		QFileInfo info(roi_file);
		ui_.rois->addItem(info.fileName(), roi_file);
	}

	//restore old selection
	int current_index = ui_.rois->findText(current);
	if (current_index==-1) current_index = 0;
	ui_.rois->setCurrentIndex(current_index);

	ui_.rois->blockSignals(false);
}

void FilterDockWidget::loadReferenceFiles()
{
	//store old selection
	QString current = ui_.rois->currentText();

	//load from settings
	ui_.refs->clear();
	ui_.refs->addItem("none", "");
	QStringList refs = Settings::stringList("reference_files");
	foreach(const QString& roi_file, refs)
	{
		QStringList parts = roi_file.split("\t");
		ui_.refs->addItem(parts[0], parts[1]);
	}

	//restore old selection
	int current_index = ui_.refs->findText(current);
	if (current_index==-1) current_index = 0;
	ui_.refs->setCurrentIndex(current_index);
}

void FilterDockWidget::reset()
{
	blockSignals(true);

	//annotations
	ui_.maf_enabled->setChecked(false);
	ui_.maf->setValue(1.0);
	ui_.impact_enabled->setChecked(false);
	ui_.impact->setCurrentText("HIGH,MODERATE,LOW");
	ui_.ihdb_enabled->setChecked(false);
	ui_.ihdb->setValue(5);
	ui_.vus_enabled->setChecked(false);
	ui_.vus->setCurrentText("3");
	ui_.geno_enabled->setChecked(false);
	ui_.geno->setCurrentText("hom");
	ui_.important_enabled->setChecked(false);
	ui_.quality_enabled->setChecked(false);
	ui_.trio_enabled->setChecked(false);

	//rois
	ui_.rois->setCurrentIndex(0);
	ui_.rois->setToolTip("");

	//refs
	ui_.refs->setCurrentIndex(0);
	ui_.refs->setToolTip("");

	//gene
	last_gene_ = "";
	ui_.gene->clear();

	blockSignals(false);
}

void FilterDockWidget::applyDefaultFilters()
{
	//block signals to avoid 10 updates of GUI
	blockSignals(true);

	//enable default filters
	ui_.maf_enabled->setChecked(true);
	ui_.maf->setValue(1.0);
	ui_.impact_enabled->setChecked(true);
	ui_.impact->setCurrentText("HIGH,MODERATE,LOW");
	ui_.ihdb_enabled->setChecked(true);
	ui_.ihdb->setValue(5);
	ui_.vus_enabled->setChecked(true);
	ui_.vus->setCurrentText("3");
	ui_.geno_enabled->setChecked(false);
	ui_.geno->setCurrentText("hom");
	ui_.important_enabled->setChecked(true);
	ui_.quality_enabled->setChecked(false);
	ui_.trio_enabled->setChecked(false);

	//re-enable signals
	blockSignals(false);

	//emit signal to update GUI
	emit filtersChanged();
}

bool FilterDockWidget::applyMaf() const
{
	return ui_.maf_enabled->isChecked();
}

double FilterDockWidget::mafPerc() const
{
	return ui_.maf->value();
}

bool FilterDockWidget::applyImpact() const
{
	return ui_.impact_enabled->isChecked();
}

QStringList FilterDockWidget::impact() const
{
	return ui_.impact->currentText().split(",");
}

bool FilterDockWidget::applyVus() const
{
	return ui_.vus_enabled->isChecked();
}

int FilterDockWidget::vus() const
{
	return ui_.vus->currentText().toInt();
}

bool FilterDockWidget::applyGenotype() const
{
	return ui_.geno_enabled->isChecked();
}

QString FilterDockWidget::genotype() const
{
	return ui_.geno->currentText();
}

bool FilterDockWidget::applyIhdb() const
{
	return ui_.ihdb_enabled->isChecked();
}

int FilterDockWidget::ihdb() const
{
	return ui_.ihdb->value();
}

bool FilterDockWidget::applyQuality() const
{
	return ui_.quality_enabled->isChecked();
}

bool FilterDockWidget::applyTrio() const
{
	return ui_.trio_enabled->isChecked();
}

bool FilterDockWidget::keepImportant() const
{
	return ui_.important_enabled->isChecked();
}

QString FilterDockWidget::targetRegion() const
{
	return ui_.rois->toolTip();
}

QString FilterDockWidget::gene() const
{
return ui_.gene->text();
}

QString FilterDockWidget::referenceSample() const
{
	return ui_.refs->toolTip();
}

QMap<QString, QString> FilterDockWidget::appliedFilters() const
{
	QMap<QString, QString> output;
	if (applyMaf()) output.insert("maf", QString::number(mafPerc(), 'f', 2) + "%");
	if (applyImpact()) output.insert("impact", impact().join(","));
	if (applyIhdb()) output.insert("ihdb", QString::number(ihdb()));
	if (applyVus()) output.insert("classification", QString::number(vus()));
	if (applyGenotype()) output.insert("genotype" , genotype());
	if (keepImportant()) output.insert("keep_important", "");
	if (applyQuality()) output.insert("quality", "");
	if (applyTrio()) output.insert("trio", "");

	return output;
}

void FilterDockWidget::addRoi()
{
	//get file to open
	QString path = Settings::path("path_regions");
	QString filename = QFileDialog::getOpenFileName(this, "Select target region file", path, "BED files (*.bed);;All files (*.*)");
	if (filename=="") return;

	//store open path
	Settings::setPath("path_regions", filename);

	//update settings
	QStringList rois = Settings::stringList("target_regions");
	rois.append(filename);
	rois.sort(Qt::CaseInsensitive);
	rois.removeDuplicates();
	Settings::setStringList("target_regions", rois);

	//update GUI
	loadROIFilters();
}

void FilterDockWidget::addRoiTemp()
{
	//get file to open
	QString path = Settings::path("path_regions");
	QString filename = QFileDialog::getOpenFileName(this, "Select target region file", path, "BED files (*.bed);;All files (*.*)");
	if (filename=="") return;

	//add to list
	ui_.rois->addItem(QFileInfo(filename).fileName(), filename);
}

void FilterDockWidget::removeRoi()
{
	QString filename = ui_.rois->itemData(ui_.rois->currentIndex()).toString();
	if (filename=="") return;

	//update settings
	QStringList rois = Settings::stringList("target_regions");
	rois.removeOne(filename);
	Settings::setStringList("target_regions", rois);

	//update GUI
	loadROIFilters();
	emit filtersChanged();
}

void FilterDockWidget::roiSelectionChanged(int index)
{
	ui_.rois->setToolTip(ui_.rois->itemData(index).toString());

	emit filtersChanged();
}

void FilterDockWidget::referenceSampleChanged(int index)
{
	ui_.refs->setToolTip(ui_.refs->itemData(index).toString());
}

void FilterDockWidget::geneChanged()
{
	if (gene()!=last_gene_)
	{
		last_gene_ = gene();
		emit filtersChanged();
	}
}

void FilterDockWidget::addRef()
{
	//get file to open
	QString path = Settings::path("path_variantlists");
	QString filename = QFileDialog::getOpenFileName(this, "Select reference file", path, "BAM files (*.bam);;All files (*.*)");
	if (filename=="") return;

	//get name
	QString name = QInputDialog::getText(this, "Reference file name", "Display name:");
	if (name=="") return;

	//update settings
	QStringList refs = Settings::stringList("reference_files");
	refs.append(name + "\t" + filename);
	refs.sort(Qt::CaseInsensitive);
	refs.removeDuplicates();
	Settings::setStringList("reference_files", refs);

	//update GUI
	loadReferenceFiles();
}

void FilterDockWidget::removeRef()
{
	QString name = ui_.refs->itemText(ui_.refs->currentIndex());
	QString filename = ui_.refs->itemData(ui_.refs->currentIndex()).toString();
	if (filename=="") return;

	//update settings
	QStringList refs = Settings::stringList("reference_files");
	refs.removeOne(name + "\t" + filename);
	Settings::setStringList("reference_files", refs);

	//update GUI
	loadReferenceFiles();
}
<commit_msg>GSvar: gene filter now trims input string.<commit_after>#include "FilterDockWidget.h"
#include "Settings.h"
#include <QCheckBox>
#include <QFileInfo>
#include <QFileDialog>
#include <QInputDialog>

FilterDockWidget::FilterDockWidget(QWidget *parent)
	: QDockWidget(parent)
	, ui_()
{
	ui_.setupUi(this);

	connect(ui_.maf, SIGNAL(valueChanged(double)), this, SIGNAL(filtersChanged()));
	connect(ui_.maf_enabled, SIGNAL(toggled(bool)), this, SIGNAL(filtersChanged()));

	connect(ui_.impact, SIGNAL(currentIndexChanged(int)), this, SIGNAL(filtersChanged()));
	connect(ui_.impact_enabled, SIGNAL(toggled(bool)), this, SIGNAL(filtersChanged()));

	connect(ui_.ihdb, SIGNAL(valueChanged(int)), this, SIGNAL(filtersChanged()));
	connect(ui_.ihdb_enabled, SIGNAL(toggled(bool)), this, SIGNAL(filtersChanged()));

	connect(ui_.vus, SIGNAL(currentIndexChanged(int)), this, SIGNAL(filtersChanged()));
	connect(ui_.vus_enabled, SIGNAL(toggled(bool)), this, SIGNAL(filtersChanged()));

	connect(ui_.geno, SIGNAL(currentIndexChanged(int)), this, SIGNAL(filtersChanged()));
	connect(ui_.geno_enabled, SIGNAL(toggled(bool)), this, SIGNAL(filtersChanged()));

	connect(ui_.quality_enabled, SIGNAL(toggled(bool)), this, SIGNAL(filtersChanged()));
	connect(ui_.trio_enabled, SIGNAL(toggled(bool)), this, SIGNAL(filtersChanged()));
	connect(ui_.important_enabled, SIGNAL(toggled(bool)), this, SIGNAL(filtersChanged()));

	connect(ui_.roi_add, SIGNAL(clicked()), this, SLOT(addRoi()));
	connect(ui_.roi_add_temp, SIGNAL(clicked()), this, SLOT(addRoiTemp()));
	connect(ui_.roi_remove, SIGNAL(clicked()), this, SLOT(removeRoi()));
	connect(ui_.rois, SIGNAL(currentIndexChanged(int)), this, SLOT(roiSelectionChanged(int)));

	connect(ui_.ref_add, SIGNAL(clicked()), this, SLOT(addRef()));
	connect(ui_.ref_remove, SIGNAL(clicked()), this, SLOT(removeRef()));
	connect(ui_.refs, SIGNAL(currentIndexChanged(int)), this, SLOT(referenceSampleChanged(int)));

	connect(ui_.gene, SIGNAL(editingFinished()), this, SLOT(geneChanged()));

	loadROIFilters();
	loadReferenceFiles();

	reset();
}

void FilterDockWidget::loadROIFilters()
{
	ui_.rois->blockSignals(true);

	//store old selection
	QString current = ui_.rois->currentText();

	//load from settings
	ui_.rois->clear();
	ui_.rois->addItem("none", "");
	QStringList rois = Settings::stringList("target_regions");
	rois.sort(); //note: path is included in order!
	foreach(const QString& roi_file, rois)
	{
		QFileInfo info(roi_file);
		ui_.rois->addItem(info.fileName(), roi_file);
	}

	//restore old selection
	int current_index = ui_.rois->findText(current);
	if (current_index==-1) current_index = 0;
	ui_.rois->setCurrentIndex(current_index);

	ui_.rois->blockSignals(false);
}

void FilterDockWidget::loadReferenceFiles()
{
	//store old selection
	QString current = ui_.rois->currentText();

	//load from settings
	ui_.refs->clear();
	ui_.refs->addItem("none", "");
	QStringList refs = Settings::stringList("reference_files");
	foreach(const QString& roi_file, refs)
	{
		QStringList parts = roi_file.split("\t");
		ui_.refs->addItem(parts[0], parts[1]);
	}

	//restore old selection
	int current_index = ui_.refs->findText(current);
	if (current_index==-1) current_index = 0;
	ui_.refs->setCurrentIndex(current_index);
}

void FilterDockWidget::reset()
{
	blockSignals(true);

	//annotations
	ui_.maf_enabled->setChecked(false);
	ui_.maf->setValue(1.0);
	ui_.impact_enabled->setChecked(false);
	ui_.impact->setCurrentText("HIGH,MODERATE,LOW");
	ui_.ihdb_enabled->setChecked(false);
	ui_.ihdb->setValue(5);
	ui_.vus_enabled->setChecked(false);
	ui_.vus->setCurrentText("3");
	ui_.geno_enabled->setChecked(false);
	ui_.geno->setCurrentText("hom");
	ui_.important_enabled->setChecked(false);
	ui_.quality_enabled->setChecked(false);
	ui_.trio_enabled->setChecked(false);

	//rois
	ui_.rois->setCurrentIndex(0);
	ui_.rois->setToolTip("");

	//refs
	ui_.refs->setCurrentIndex(0);
	ui_.refs->setToolTip("");

	//gene
	last_gene_ = "";
	ui_.gene->clear();

	blockSignals(false);
}

void FilterDockWidget::applyDefaultFilters()
{
	//block signals to avoid 10 updates of GUI
	blockSignals(true);

	//enable default filters
	ui_.maf_enabled->setChecked(true);
	ui_.maf->setValue(1.0);
	ui_.impact_enabled->setChecked(true);
	ui_.impact->setCurrentText("HIGH,MODERATE,LOW");
	ui_.ihdb_enabled->setChecked(true);
	ui_.ihdb->setValue(5);
	ui_.vus_enabled->setChecked(true);
	ui_.vus->setCurrentText("3");
	ui_.geno_enabled->setChecked(false);
	ui_.geno->setCurrentText("hom");
	ui_.important_enabled->setChecked(true);
	ui_.quality_enabled->setChecked(false);
	ui_.trio_enabled->setChecked(false);

	//re-enable signals
	blockSignals(false);

	//emit signal to update GUI
	emit filtersChanged();
}

bool FilterDockWidget::applyMaf() const
{
	return ui_.maf_enabled->isChecked();
}

double FilterDockWidget::mafPerc() const
{
	return ui_.maf->value();
}

bool FilterDockWidget::applyImpact() const
{
	return ui_.impact_enabled->isChecked();
}

QStringList FilterDockWidget::impact() const
{
	return ui_.impact->currentText().split(",");
}

bool FilterDockWidget::applyVus() const
{
	return ui_.vus_enabled->isChecked();
}

int FilterDockWidget::vus() const
{
	return ui_.vus->currentText().toInt();
}

bool FilterDockWidget::applyGenotype() const
{
	return ui_.geno_enabled->isChecked();
}

QString FilterDockWidget::genotype() const
{
	return ui_.geno->currentText();
}

bool FilterDockWidget::applyIhdb() const
{
	return ui_.ihdb_enabled->isChecked();
}

int FilterDockWidget::ihdb() const
{
	return ui_.ihdb->value();
}

bool FilterDockWidget::applyQuality() const
{
	return ui_.quality_enabled->isChecked();
}

bool FilterDockWidget::applyTrio() const
{
	return ui_.trio_enabled->isChecked();
}

bool FilterDockWidget::keepImportant() const
{
	return ui_.important_enabled->isChecked();
}

QString FilterDockWidget::targetRegion() const
{
	return ui_.rois->toolTip();
}

QString FilterDockWidget::gene() const
{
return ui_.gene->text().trimmed();
}

QString FilterDockWidget::referenceSample() const
{
	return ui_.refs->toolTip();
}

QMap<QString, QString> FilterDockWidget::appliedFilters() const
{
	QMap<QString, QString> output;
	if (applyMaf()) output.insert("maf", QString::number(mafPerc(), 'f', 2) + "%");
	if (applyImpact()) output.insert("impact", impact().join(","));
	if (applyIhdb()) output.insert("ihdb", QString::number(ihdb()));
	if (applyVus()) output.insert("classification", QString::number(vus()));
	if (applyGenotype()) output.insert("genotype" , genotype());
	if (keepImportant()) output.insert("keep_important", "");
	if (applyQuality()) output.insert("quality", "");
	if (applyTrio()) output.insert("trio", "");

	return output;
}

void FilterDockWidget::addRoi()
{
	//get file to open
	QString path = Settings::path("path_regions");
	QString filename = QFileDialog::getOpenFileName(this, "Select target region file", path, "BED files (*.bed);;All files (*.*)");
	if (filename=="") return;

	//store open path
	Settings::setPath("path_regions", filename);

	//update settings
	QStringList rois = Settings::stringList("target_regions");
	rois.append(filename);
	rois.sort(Qt::CaseInsensitive);
	rois.removeDuplicates();
	Settings::setStringList("target_regions", rois);

	//update GUI
	loadROIFilters();
}

void FilterDockWidget::addRoiTemp()
{
	//get file to open
	QString path = Settings::path("path_regions");
	QString filename = QFileDialog::getOpenFileName(this, "Select target region file", path, "BED files (*.bed);;All files (*.*)");
	if (filename=="") return;

	//add to list
	ui_.rois->addItem(QFileInfo(filename).fileName(), filename);
}

void FilterDockWidget::removeRoi()
{
	QString filename = ui_.rois->itemData(ui_.rois->currentIndex()).toString();
	if (filename=="") return;

	//update settings
	QStringList rois = Settings::stringList("target_regions");
	rois.removeOne(filename);
	Settings::setStringList("target_regions", rois);

	//update GUI
	loadROIFilters();
	emit filtersChanged();
}

void FilterDockWidget::roiSelectionChanged(int index)
{
	ui_.rois->setToolTip(ui_.rois->itemData(index).toString());

	emit filtersChanged();
}

void FilterDockWidget::referenceSampleChanged(int index)
{
	ui_.refs->setToolTip(ui_.refs->itemData(index).toString());
}

void FilterDockWidget::geneChanged()
{
	if (gene()!=last_gene_)
	{
		last_gene_ = gene();
		emit filtersChanged();
	}
}

void FilterDockWidget::addRef()
{
	//get file to open
	QString path = Settings::path("path_variantlists");
	QString filename = QFileDialog::getOpenFileName(this, "Select reference file", path, "BAM files (*.bam);;All files (*.*)");
	if (filename=="") return;

	//get name
	QString name = QInputDialog::getText(this, "Reference file name", "Display name:");
	if (name=="") return;

	//update settings
	QStringList refs = Settings::stringList("reference_files");
	refs.append(name + "\t" + filename);
	refs.sort(Qt::CaseInsensitive);
	refs.removeDuplicates();
	Settings::setStringList("reference_files", refs);

	//update GUI
	loadReferenceFiles();
}

void FilterDockWidget::removeRef()
{
	QString name = ui_.refs->itemText(ui_.refs->currentIndex());
	QString filename = ui_.refs->itemData(ui_.refs->currentIndex()).toString();
	if (filename=="") return;

	//update settings
	QStringList refs = Settings::stringList("reference_files");
	refs.removeOne(name + "\t" + filename);
	Settings::setStringList("reference_files", refs);

	//update GUI
	loadReferenceFiles();
}
<|endoftext|>


<commit_before><commit_msg>Remove memcpy_s for mac<commit_after><|endoftext|>


<commit_before>#include <algorithm>
#include <grammar.h>
#include <json_object.h>
#include <json_loader.h>
#include <shl_exception.h>
#include "grammar_compiler.h"

namespace shl {

Grammar GrammarCompiler::compile(const string& buffer) {
    JsonLoader loader;
    JsonObject object = loader.load(buffer);

    Grammar grammar;
    process(object, grammar);
    return grammar;
}

void GrammarCompiler::process(const JsonObject& object, Grammar& grammar) {
    grammar.desc = object.scope_name;
    grammar.file_types = object.file_types;

    compile_grammar(object, grammar);
    for ( auto& stocked : object.repository ) {
        const string& repo_name = stocked.first;
        const JsonObject& root = stocked.second;

        grammar.repository[repo_name] = Rule();
        compile_grammar(root, grammar.repository[repo_name]);
    }

    swap(grammar.desc, grammar.name);
}

void GrammarCompiler::compile_grammar(const JsonObject& object, Rule& rule) {
    rule.name = object.name;

    if (!object.include.empty()) {
        rule.include = WeakIncludePtr(object.include);
    } else if (!object.match.empty()) {
        rule.is_match_rule = true;
        rule.begin = Regex(object.match);
        rule.begin_captures = get_captures(object.captures);
    } else if (!object.begin.empty()) {
        rule.is_match_rule = false;
        rule.begin = Regex(object.begin);
        rule.begin_captures = get_captures(object.begin_captures);
        if (rule.begin_captures.empty()) rule.begin_captures = get_captures(object.captures);

        // TODO warning if end rule is empty
        rule.end = EndPatternRegex(object.end);
        rule.end_captures = get_captures(object.end_captures);
        if (rule.end_captures.empty()) rule.end_captures = get_captures(object.captures);
        rule.content_name = object.content_name;
        if (object.applyEndPatternLast == "true") rule.applyEndPatternLast = true;
    } else {
        if (object.patterns.empty()) {
            // TODO warning if empty rule is met
        }
    }

    rule.patterns = vector<Rule>(object.patterns.size());
    for (unsigned int idx = 0; idx < rule.patterns.size(); idx++) {
        compile_grammar(object.patterns[idx], rule.patterns[idx]);
    }
}

int to_int(const string& str) {
    for (unsigned int idx = 0; idx < str.size(); idx++) {
        if (!isdigit(str[idx])) throw InvalidGrammarException("only numeric capture keys are supported");
    }
    return atoi(str.c_str());
}

string to_capture_name(const map<string, string> m) {
    auto it = m.find("name");
    if (it == m.end()) throw InvalidGrammarException("capture should have the name property");
    return it->second;
}

map<int, string> GrammarCompiler::get_captures(const map<string, map<string, string> > raw_capture) {
    map<int, string> captures;
    for(auto raw_it = raw_capture.begin(); raw_it != raw_capture.end(); raw_it++) {
        int id = to_int(raw_it->first);
        string name = to_capture_name(raw_it->second);
        captures[id] = name;
    }

    return captures;
}

static void find_include(GrammarRegistry* registry, Grammar& grammar, WeakIncludePtr& include_rule) {
    string include_name = include_rule.name;

    // base reference
    if (include_name == "$base") {
        include_rule.is_base_ref = true;

    // self reference
    } else if (include_name == "$self") {
        include_rule.ptr = &grammar;

    // repository reference
    } else if (include_name[0] == '#'){
        string repo_name = include_name.substr(1);

        auto stock_res = grammar.repository.find(repo_name);
        if (stock_res != grammar.repository.end()) {
            include_rule.ptr = &stock_res->second;
        } else {
            throw InvalidGrammarException(string("can't find the name in repository: ") + repo_name);
        }

    // external grammar reference
    } else {
        if (registry == nullptr) {
            throw ShlException("can't refer to external grammar without grammar registry");
        } else {
            //TODO report if no external grammar found
            Grammar& embeded_grammar = registry->get_grammar(include_name);
            include_rule.ptr = &embeded_grammar;
        }
    }

}

static void _resolve_include(Grammar& grammar, Rule& rule, GrammarRegistry* registry) {
    if ( rule.include.name.empty() ) {
        for ( Rule& subrule : rule.patterns ) {
            _resolve_include(grammar, subrule, registry);
        }
    } else {
        find_include(registry, grammar, rule.include);
    }
}

void GrammarCompiler::resolve_include(Grammar& grammar, GrammarRegistry* registry) {
    _resolve_include(grammar, grammar, registry);

    for ( auto& stocked_rule : grammar.repository ) {
        _resolve_include(grammar, stocked_rule.second, registry);
    }
}
}
<commit_msg>add code to parse injections rule in GrammarCompiler<commit_after>#include <algorithm>
#include <grammar.h>
#include <json_object.h>
#include <json_loader.h>
#include <shl_exception.h>
#include "grammar_compiler.h"

namespace shl {

Grammar GrammarCompiler::compile(const string& buffer) {
    JsonLoader loader;
    JsonObject object = loader.load(buffer);

    Grammar grammar;
    process(object, grammar);
    return grammar;
}

void GrammarCompiler::process(const JsonObject& object, Grammar& grammar) {
    grammar.desc = object.scope_name;
    grammar.file_types = object.file_types;

    compile_grammar(object, grammar);
    for ( auto& stocked : object.repository ) {
        const string& repo_name = stocked.first;
        const JsonObject& root = stocked.second;

        grammar.repository[repo_name] = Rule();
        compile_grammar(root, grammar.repository[repo_name]);
    }
    for ( auto& stocked : object.injections ) {
        const string& repo_name = stocked.first;
        const JsonObject& root = stocked.second;

        grammar.injections[repo_name] = Rule();
        compile_grammar(root, grammar.repository[repo_name]);
    }

    swap(grammar.desc, grammar.name);
}

void GrammarCompiler::compile_grammar(const JsonObject& object, Rule& rule) {
    rule.name = object.name;

    if (!object.include.empty()) {
        rule.include = WeakIncludePtr(object.include);
    } else if (!object.match.empty()) {
        rule.is_match_rule = true;
        rule.begin = Regex(object.match);
        rule.begin_captures = get_captures(object.captures);
    } else if (!object.begin.empty()) {
        rule.is_match_rule = false;
        rule.begin = Regex(object.begin);
        rule.begin_captures = get_captures(object.begin_captures);
        if (rule.begin_captures.empty()) rule.begin_captures = get_captures(object.captures);

        // TODO warning if end rule is empty
        rule.end = EndPatternRegex(object.end);
        rule.end_captures = get_captures(object.end_captures);
        if (rule.end_captures.empty()) rule.end_captures = get_captures(object.captures);
        rule.content_name = object.content_name;
        if (object.applyEndPatternLast == "true") rule.applyEndPatternLast = true;
    } else {
        if (object.patterns.empty()) {
            // TODO warning if empty rule is met
        }
    }

    rule.patterns = vector<Rule>(object.patterns.size());
    for (unsigned int idx = 0; idx < rule.patterns.size(); idx++) {
        compile_grammar(object.patterns[idx], rule.patterns[idx]);
    }
}

int to_int(const string& str) {
    for (unsigned int idx = 0; idx < str.size(); idx++) {
        if (!isdigit(str[idx])) throw InvalidGrammarException("only numeric capture keys are supported");
    }
    return atoi(str.c_str());
}

string to_capture_name(const map<string, string> m) {
    auto it = m.find("name");
    if (it == m.end()) throw InvalidGrammarException("capture should have the name property");
    return it->second;
}

map<int, string> GrammarCompiler::get_captures(const map<string, map<string, string> > raw_capture) {
    map<int, string> captures;
    for(auto raw_it = raw_capture.begin(); raw_it != raw_capture.end(); raw_it++) {
        int id = to_int(raw_it->first);
        string name = to_capture_name(raw_it->second);
        captures[id] = name;
    }

    return captures;
}

static void find_include(GrammarRegistry* registry, Grammar& grammar, WeakIncludePtr& include_rule) {
    string include_name = include_rule.name;

    // base reference
    if (include_name == "$base") {
        include_rule.is_base_ref = true;

    // self reference
    } else if (include_name == "$self") {
        include_rule.ptr = &grammar;

    // repository reference
    } else if (include_name[0] == '#'){
        string repo_name = include_name.substr(1);

        auto stock_res = grammar.repository.find(repo_name);
        if (stock_res != grammar.repository.end()) {
            include_rule.ptr = &stock_res->second;
        } else {
            throw InvalidGrammarException(string("can't find the name in repository: ") + repo_name);
        }

    // external grammar reference
    } else {
        if (registry == nullptr) {
            throw ShlException("can't refer to external grammar without grammar registry");
        } else {
            //TODO report if no external grammar found
            Grammar& embeded_grammar = registry->get_grammar(include_name);
            include_rule.ptr = &embeded_grammar;
        }
    }

}

static void _resolve_include(Grammar& grammar, Rule& rule, GrammarRegistry* registry) {
    if ( rule.include.name.empty() ) {
        for ( Rule& subrule : rule.patterns ) {
            _resolve_include(grammar, subrule, registry);
        }
    } else {
        find_include(registry, grammar, rule.include);
    }
}

void GrammarCompiler::resolve_include(Grammar& grammar, GrammarRegistry* registry) {
    _resolve_include(grammar, grammar, registry);

    for ( auto& stocked_rule : grammar.repository ) {
        _resolve_include(grammar, stocked_rule.second, registry);
    }
}
}
<|endoftext|>


<commit_before>/*
 * The Apache Software License, Version 1.1
 *
 *
 * Copyright (c) 1999 The Apache Software Foundation.  All rights
 * reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. The end-user documentation included with the redistribution,
 *    if any, must include the following acknowledgment:
 *       "This product includes software developed by the
 *        Apache Software Foundation (http://www.apache.org/)."
 *    Alternately, this acknowledgment may appear in the software itself,
 *    if and wherever such third-party acknowledgments normally appear.
 *
 * 4. The names "Xalan" and "Apache Software Foundation" must
 *    not be used to endorse or promote products derived from this
 *    software without prior written permission. For written
 *    permission, please contact apache@apache.org.
 *
 * 5. Products derived from this software may not be called "Apache",
 *    nor may "Apache" appear in their name, without prior written
 *    permission of the Apache Software Foundation.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 * ====================================================================
 *
 * This software consists of voluntary contributions made by many
 * individuals on behalf of the Apache Software Foundation and was
 * originally based on software copyright (c) 1999, International
 * Business Machines, Inc., http://www.ibm.com.  For more
 * information on the Apache Software Foundation, please see
 * <http://www.apache.org/>.
 */
#if !defined(GCCDEFINITIONS_HEADER_GUARD_1357924680)
#define GCCDEFINITIONS_HEADER_GUARD_1357924680

// ---------------------------------------------------------------------------
//  A define in the build for each project is also used to control whether
//  the export keyword is from the project's viewpoint or the client's.
//  These defines provide the platform specific keywords that they need
//  to do this.
// ---------------------------------------------------------------------------
#define XALAN_PLATFORM_EXPORT
#define XALAN_PLATFORM_IMPORT
#define XALAN_PLATFORM_EXPORT_FUNCTION(T) T XALAN_PLATFORM_EXPORT
#define XALAN_PLATFORM_IMPORT_FUNCTION(T) T XALAN_PLATFORM_IMPORT

#if __GNUC__ < 3 && __GNUC_MINOR__ < 1
#define XALAN_OLD_STREAM_HEADERS
#define XALAN_NO_MEMBER_TEMPLATES
#define XALAN_NO_STD_ALLOCATORS
#endif

#define XALAN_NO_STD_NUMERIC_LIMITS
#define XALAN_RTTI_AVAILABLE
#define XALAN_SGI_BASED_STL
#define XALAN_XALANDOMCHAR_USHORT_MISMATCH
#define XALAN_POSIX2_AVAILABLE
#define XALAN_INLINE_INITIALIZATION

#define XALAN_UNALIGNED

#endif	// GCCDEFINITIONS_HEADER_GUARD_1357924680
<commit_msg>Fixed conditional compilation and added comment.<commit_after>/*
 * The Apache Software License, Version 1.1
 *
 *
 * Copyright (c) 1999 The Apache Software Foundation.  All rights
 * reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. The end-user documentation included with the redistribution,
 *    if any, must include the following acknowledgment:
 *       "This product includes software developed by the
 *        Apache Software Foundation (http://www.apache.org/)."
 *    Alternately, this acknowledgment may appear in the software itself,
 *    if and wherever such third-party acknowledgments normally appear.
 *
 * 4. The names "Xalan" and "Apache Software Foundation" must
 *    not be used to endorse or promote products derived from this
 *    software without prior written permission. For written
 *    permission, please contact apache@apache.org.
 *
 * 5. Products derived from this software may not be called "Apache",
 *    nor may "Apache" appear in their name, without prior written
 *    permission of the Apache Software Foundation.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 * ====================================================================
 *
 * This software consists of voluntary contributions made by many
 * individuals on behalf of the Apache Software Foundation and was
 * originally based on software copyright (c) 1999, International
 * Business Machines, Inc., http://www.ibm.com.  For more
 * information on the Apache Software Foundation, please see
 * <http://www.apache.org/>.
 */
#if !defined(GCCDEFINITIONS_HEADER_GUARD_1357924680)
#define GCCDEFINITIONS_HEADER_GUARD_1357924680

// ---------------------------------------------------------------------------
//  A define in the build for each project is also used to control whether
//  the export keyword is from the project's viewpoint or the client's.
//  These defines provide the platform specific keywords that they need
//  to do this.
// ---------------------------------------------------------------------------
#define XALAN_PLATFORM_EXPORT
#define XALAN_PLATFORM_IMPORT
#define XALAN_PLATFORM_EXPORT_FUNCTION(T) T XALAN_PLATFORM_EXPORT
#define XALAN_PLATFORM_IMPORT_FUNCTION(T) T XALAN_PLATFORM_IMPORT

#if __GNUC__ < 3
#define XALAN_OLD_STREAM_HEADERS
#define XALAN_NO_MEMBER_TEMPLATES
#define XALAN_NO_STD_ALLOCATORS
#endif

// As of 3.1, std::numeric_limits<double> is broken, so
// we don't use it.
#define XALAN_NO_STD_NUMERIC_LIMITS
#define XALAN_RTTI_AVAILABLE
#define XALAN_SGI_BASED_STL
#define XALAN_XALANDOMCHAR_USHORT_MISMATCH
#define XALAN_POSIX2_AVAILABLE
#define XALAN_INLINE_INITIALIZATION

#define XALAN_UNALIGNED

#endif	// GCCDEFINITIONS_HEADER_GUARD_1357924680
<|endoftext|>


<commit_before>/*
 * The Apache Software License, Version 1.1
 *
 *
 * Copyright (c) 1999 The Apache Software Foundation.  All rights
 * reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. The end-user documentation included with the redistribution,
 *    if any, must include the following acknowledgment:
 *       "This product includes software developed by the
 *        Apache Software Foundation (http://www.apache.org/)."
 *    Alternately, this acknowledgment may appear in the software itself,
 *    if and wherever such third-party acknowledgments normally appear.
 *
 * 4. The names "Xalan" and "Apache Software Foundation" must
 *    not be used to endorse or promote products derived from this
 *    software without prior written permission. For written
 *    permission, please contact apache@apache.org.
 *
 * 5. Products derived from this software may not be called "Apache",
 *    nor may "Apache" appear in their name, without prior written
 *    permission of the Apache Software Foundation.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 * ====================================================================
 *
 * This software consists of voluntary contributions made by many
 * individuals on behalf of the Apache Software Foundation and was
 * originally based on software copyright (c) 1999, International
 * Business Machines, Inc., http://www.ibm.com.  For more
 * information on the Apache Software Foundation, please see
 * <http://www.apache.org/>.
 */
#if !defined(GCCDEFINITIONS_HEADER_GUARD_1357924680)
#define GCCDEFINITIONS_HEADER_GUARD_1357924680

// ---------------------------------------------------------------------------
//  A define in the build for each project is also used to control whether
//  the export keyword is from the project's viewpoint or the client's.
//  These defines provide the platform specific keywords that they need
//  to do this.
// ---------------------------------------------------------------------------
#define XALAN_PLATFORM_EXPORT
#define XALAN_PLATFORM_IMPORT
#define XALAN_PLATFORM_EXPORT_FUNCTION(T) T XALAN_PLATFORM_EXPORT
#define XALAN_PLATFORM_IMPORT_FUNCTION(T) T XALAN_PLATFORM_IMPORT

#define XALAN_NO_MEMBER_TEMPLATES
#define XALAN_RTTI_AVAILABLE
#define XALAN_OLD_STREAM_HEADERS
#define XALAN_SGI_BASED_STL
#define XALAN_XALANDOMCHAR_USHORT_MISMATCH
#define XALAN_NO_STD_ALLOCATORS
#define XALAN_POSIX2_AVAILABLE
#define XALAN_INLINE_INITIALIZATION
#define XALAN_NO_STD_NUMERIC_LIMITS

#define XALAN_UNALIGNED

#endif	// GCCDEFINITIONS_HEADER_GUARD_1357924680
<commit_msg>Update for newer gcc versions.<commit_after>/*
 * The Apache Software License, Version 1.1
 *
 *
 * Copyright (c) 1999 The Apache Software Foundation.  All rights
 * reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. The end-user documentation included with the redistribution,
 *    if any, must include the following acknowledgment:
 *       "This product includes software developed by the
 *        Apache Software Foundation (http://www.apache.org/)."
 *    Alternately, this acknowledgment may appear in the software itself,
 *    if and wherever such third-party acknowledgments normally appear.
 *
 * 4. The names "Xalan" and "Apache Software Foundation" must
 *    not be used to endorse or promote products derived from this
 *    software without prior written permission. For written
 *    permission, please contact apache@apache.org.
 *
 * 5. Products derived from this software may not be called "Apache",
 *    nor may "Apache" appear in their name, without prior written
 *    permission of the Apache Software Foundation.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 * ====================================================================
 *
 * This software consists of voluntary contributions made by many
 * individuals on behalf of the Apache Software Foundation and was
 * originally based on software copyright (c) 1999, International
 * Business Machines, Inc., http://www.ibm.com.  For more
 * information on the Apache Software Foundation, please see
 * <http://www.apache.org/>.
 */
#if !defined(GCCDEFINITIONS_HEADER_GUARD_1357924680)
#define GCCDEFINITIONS_HEADER_GUARD_1357924680

// ---------------------------------------------------------------------------
//  A define in the build for each project is also used to control whether
//  the export keyword is from the project's viewpoint or the client's.
//  These defines provide the platform specific keywords that they need
//  to do this.
// ---------------------------------------------------------------------------
#define XALAN_PLATFORM_EXPORT
#define XALAN_PLATFORM_IMPORT
#define XALAN_PLATFORM_EXPORT_FUNCTION(T) T XALAN_PLATFORM_EXPORT
#define XALAN_PLATFORM_IMPORT_FUNCTION(T) T XALAN_PLATFORM_IMPORT

#if __GNUC__ < 3 && __GNUC_MINOR__ < 1
#define XALAN_OLD_STREAM_HEADERS
#define XALAN_NO_MEMBER_TEMPLATES
#define XALAN_NO_STD_NUMERIC_LIMITS
#define XALAN_NO_STD_ALLOCATORS
#endif

#define XALAN_RTTI_AVAILABLE
#define XALAN_SGI_BASED_STL
#define XALAN_XALANDOMCHAR_USHORT_MISMATCH
#define XALAN_POSIX2_AVAILABLE
#define XALAN_INLINE_INITIALIZATION

#define XALAN_UNALIGNED

#endif	// GCCDEFINITIONS_HEADER_GUARD_1357924680
<|endoftext|>