<commit_before>// (C) 2014 Arek Olek

#include <functional>
#include <unordered_map>

#include <boost/functional/hash.hpp>
#include <boost/graph/adjacency_matrix.hpp>

#include "debug.hpp"
#include "range.hpp"

namespace detail {
  boost::adjacency_matrix<boost::undirectedS> typedef graph;
}

namespace std {
  template<typename S, typename T>
  struct hash<pair<S, T>> {
    inline size_t operator()(const pair<S, T> & v) const {
      size_t seed = 0;
      boost::hash_combine(seed, v.first);
      boost::hash_combine(seed, v.second);
      return seed;
    }
  };
}

template <class Graph>
class leaf_info {
public:
  leaf_info(Graph const & T_) : T(T_) {
    update();
  }
  bool is_path() const {
    return L.size() == 2;
  }
  std::vector<unsigned> const & leaves() const {
    return L;
  }
  unsigned branching(unsigned l) const {
    // b(l)
    return B.at(l);
  }
  unsigned parent(unsigned x, unsigned l) const {
    // x->l
    return P.at(uintpair(l, x));
  }
  unsigned branching_neighbor(unsigned l) const {
    // b(l)->l
    return parent(branching(l), l);
  }
  unsigned branching_neighbor(unsigned l, unsigned x) const {
    // b(l)->x
    return BN.at(uintpair(l, x));
  }
  bool on_branch(unsigned l, unsigned x) const {
    return l == x || branching(l) == x || BN.count(uintpair(l, x)) == 0;
  }
  bool is_short(unsigned l) {
    return parent(branching(l), l) == l;
  }
  void update() {
    L.clear();
    B.clear();
    P.clear();
    BN.clear();
    for(auto v : range(vertices(T)))
      if(degree(v, T) == 1) {
        L.push_back(v);
        traverse(v, T);
      }
  }
  void traverse(unsigned l, Graph const & T) {
    traverse(l, l, l, T);
  }
  void traverse(unsigned l, unsigned a, unsigned b, Graph const & T) {
    do {
      std::tie(a, b) = next(a, b, T);
      P[uintpair(l, b)] = a;
    } while(degree(b, T) == 2);
    if(degree(b, T) > 2) {
      B[l] = b;
      for(auto v : range(adjacent_vertices(b, T)))
        if(v != a)
          traverse(l, v, b, v, T);
    }
  }
  void traverse(unsigned l, unsigned blx, unsigned a, unsigned b, Graph const & T) {
    P[uintpair(l, b)] = a;
    BN[uintpair(l, b)] = blx;
    while(degree(b, T) == 2) {
      std::tie(a, b) = next(a, b, T);
      P[uintpair(l, b)] = a;
      BN[uintpair(l, b)] = blx;
    }
    if(degree(b, T) > 2) {
      for(auto v : range(adjacent_vertices(b, T)))
        if(v != a)
          traverse(l, blx, b, v, T);
    }
  }
  std::pair<unsigned, unsigned> next(unsigned a, unsigned b, Graph const & T) {
    auto it = adjacent_vertices(b, T).first;
    return std::make_pair(b, a == *it ? *(++it) : *it);
  }
private:
  Graph const& T;
  std::vector<unsigned> L;
  std::pair<unsigned, unsigned> typedef uintpair;
  std::unordered_map<unsigned, unsigned> B;
  std::unordered_map<uintpair, unsigned> P, BN;
};

class prieto {
public:
  template<class Graph, class Tree>
  int operator()(Graph& G, Tree& T) {
    //detail::graph M(num_vertices(G));
    //detail::copy_edges(G, M);
    leaf_info<Tree> info(T);
    int i = -1;
    do {
      ++i;
      //show("tree" + std::to_string(i++) + ".dot", M, T);
    } while(!info.is_path() && rule2(G, T, info));
    return i;
  }
};

template <class Graph, class Tree, class LeafInfo>
bool rule1(Graph& G, Tree& T, LeafInfo& info) {
  for(auto l1 : info.leaves())
    for(auto l2 : info.leaves())
      if(edge(l1, l2, G).second) {
        auto x = l1;
        auto y = *adjacent_vertices(l1, T).first;
        while(y != l2) {
          x = y;
          y = info.parent(y, l2);
          if(degree(x, T) > 2 && degree(y, T) > 2) {
            add_edge(l1, l2, T);
            remove_edge(x, y, T);
            info.update();
            return true;
          }
        }
      }
  return false;
}

template <class Graph, class Tree, class LeafInfo>
bool rule2(Graph& G, Tree& T, LeafInfo& info) {
  for(auto l1 : info.leaves())
    for(auto l2 : info.leaves())
      if(edge(l1, l2, G).second) {
        add_edge(l1, l2, T);
        auto b = info.branching(l1);
        remove_edge(b, info.parent(b, l1), T);
        info.update();
        return true;
      }
  return false;
}

template <class Graph, class Tree, class LeafInfo>
bool rule3(Graph& G, Tree& T, LeafInfo& info) {
  for(auto l : info.leaves())
    for(auto x : range(adjacent_vertices(l, G)))
      if(!info.on_branch(l, x)) {
        auto xl = info.parent(x, l);
        if(degree(xl, T) > 2) {
          add_edge(l, x, T);
          remove_edge(x, xl, T);
          info.update();
          return true;
        }
      }
  return false;
}

template <class Graph, class Tree, class LeafInfo>
bool rule4(Graph& G, Tree& T, LeafInfo& info) {
  int n = num_vertices(G);
  std::vector<std::vector<std::pair<int,int>>> extra(n);
  for(auto l : info.leaves())
    for(auto x : range(adjacent_vertices(l, G)))
      if(!info.on_branch(l, x)) {
        auto xl = info.parent(x, l);
        if(degree(xl, T) == 2)
          extra[xl].emplace_back(l, x);
      }

  for(int l2 : info.leaves())
    for(int xl = 0; xl < n; ++xl)
      if(!extra[xl].empty() && edge(l2, xl, G).second) {
        int l, x;
        if(extra[xl].size() == 1 && extra[xl].begin()->first == l2) continue;
        std::tie(l, x) = extra[xl].begin()->first == l2 ? *(extra[xl].begin()+1) : *extra[xl].begin();
        add_edge(l, x, T);
        remove_edge(x, xl, T);
        info.update();

        add_edge(l2, xl, T);
        auto b = info.branching(l2);
        remove_edge(b, info.parent(b, l2), T);
        info.update();
        return true;
      }
  return false;
}

template <class Graph, class Tree, class LeafInfo>
bool rule5(Graph& G, Tree& T, LeafInfo& info) {
  for(auto l : info.leaves())
    for(auto x : range(adjacent_vertices(l, G)))
      if(!info.on_branch(l, x)) {
        auto bl = info.branching(l);
        auto blx = info.branching_neighbor(l, x);
        if(degree(blx, T) > 2) {
          add_edge(l, x, T);
          remove_edge(bl, blx, T);
          info.update();
          return true;
        }
      }
  return false;
}

template <class Graph, class Tree, class LeafInfo>
bool rule6(Graph& G, Tree& T, LeafInfo& info) {
  int n = num_vertices(G);
  std::vector<std::vector<std::pair<int,int>>> extra(n);
  for(auto l : info.leaves())
    for(auto x : range(adjacent_vertices(l, G)))
      if(!info.on_branch(l, x)) {
        auto blx = info.branching_neighbor(l, x);
        if(degree(blx, T) == 2) {
          extra[blx].emplace_back(l, x);
        }
      }

  for(int l2 : info.leaves())
    for(int blx = 0; blx < n; ++blx)
      if(!extra[blx].empty() && edge(l2, blx, G).second) {
        int l, x;
        if(extra[blx].size() == 1 && extra[blx].begin()->first == l2) continue;
        std::tie(l, x) = extra[blx].begin()->first == l2 ? *(extra[blx].begin()+1) : *extra[blx].begin();
        add_edge(l, x, T);
        remove_edge(info.branching(l), blx, T);
        info.update();

        add_edge(l2, blx, T);
        auto b = info.branching(l2);
        remove_edge(b, info.parent(b, l2), T);
        info.update();
        return true;
      }
  return false;
}

template <class Graph, class Tree, class LeafInfo>
bool rule7(Graph& G, Tree& T, LeafInfo& info) {
  for(auto e : range(edges(T))) {
    auto x = source(e, T);
    auto y = target(e, T);
    for(auto l : info.leaves()) {
      if(info.is_short(l)
        && !edge(l, x, T).second && !edge(l, y, T).second
        && edge(l, x, G).second && edge(l, y, G).second) {
        add_edge(l, x, T);
        add_edge(l, y, T);
        remove_edge(x, y, T);
        remove_edge(l, info.branching(l), T);
        info.update();
        return true;
      }
    }
  }
  return false;
}

template <class Graph, class Tree, class LeafInfo>
bool rule8(Graph& G, Tree& T, LeafInfo& info) {
  for(auto l1 : info.leaves()) if(!info.is_short(l1)) {
    for(auto l2 : info.leaves()) if(/*!info.is_short(l2) && */l1 != l2) {
      auto bl = info.branching(l1);
      auto blp = info.parent(bl, l1);
      if(edge(blp, l2, G).second) {
        add_edge(blp, l2, T);
        remove_edge(blp, bl, T);
        info.update();
        return true;
      }
    }
  }
  return false;
}

class lost_light {
public:
  template <class Graph, class Tree>
  int operator() (Graph& G, Tree& T) {
    leaf_info<Tree> info(T);
    std::function<bool(Graph&,Tree&,leaf_info<Tree>&)> typedef rule;
    std::vector<rule> rules {
      rule2<Graph,Tree,leaf_info<Tree>>,
      rule3<Graph,Tree,leaf_info<Tree>>,
      rule4<Graph,Tree,leaf_info<Tree>>,
      rule5<Graph,Tree,leaf_info<Tree>>,
      rule6<Graph,Tree,leaf_info<Tree>>,
    };
    int i = 0;
    bool applied = true;
    while(applied && !info.is_path()) {
      applied = false;
      for(auto rule : rules) {
        if(rule(G, T, info)) {
          ++i;
          applied = true;
          break;
        }
      }
    }
    return i;
  }
};

class lost {
public:
  template <class Graph, class Tree>
  int operator() (Graph& G, Tree& T) {
    leaf_info<Tree> info(T);
    std::function<bool(Graph&,Tree&,leaf_info<Tree>&)> typedef rule;
    std::vector<rule> rules {
      rule1<Graph,Tree,leaf_info<Tree>>,
      rule2<Graph,Tree,leaf_info<Tree>>,
      rule3<Graph,Tree,leaf_info<Tree>>,
      rule4<Graph,Tree,leaf_info<Tree>>,
      rule5<Graph,Tree,leaf_info<Tree>>,
      rule6<Graph,Tree,leaf_info<Tree>>,
      rule7<Graph,Tree,leaf_info<Tree>>,
      rule8<Graph,Tree,leaf_info<Tree>>,
    };
    int i = 0;
    bool applied = true;
    while(applied && !info.is_path()) {
      applied = false;
      for(auto rule : rules) {
        if(rule(G, T, info)) {
          ++i;
          applied = true;
          break;
        }
      }
    }
    return i;
  }
};
<commit_msg>rule 9<commit_after>// (C) 2014 Arek Olek

#include <functional>
#include <unordered_map>

#include <boost/functional/hash.hpp>
#include <boost/graph/adjacency_matrix.hpp>

#include "debug.hpp"
#include "range.hpp"

namespace detail {
  boost::adjacency_matrix<boost::undirectedS> typedef graph;
}

namespace std {
  template<typename S, typename T>
  struct hash<pair<S, T>> {
    inline size_t operator()(const pair<S, T> & v) const {
      size_t seed = 0;
      boost::hash_combine(seed, v.first);
      boost::hash_combine(seed, v.second);
      return seed;
    }
  };
}

template <class Graph>
class leaf_info {
public:
  leaf_info(Graph const & T_) : T(T_) {
    update();
  }
  bool is_path() const {
    return L.size() == 2;
  }
  std::vector<unsigned> const & leaves() const {
    return L;
  }
  unsigned branching(unsigned l) const {
    // b(l)
    return B.at(l);
  }
  unsigned parent(unsigned x, unsigned l) const {
    // x->l
    return P.at(uintpair(l, x));
  }
  unsigned branching_neighbor(unsigned l) const {
    // b(l)->l
    return parent(branching(l), l);
  }
  unsigned branching_neighbor(unsigned l, unsigned x) const {
    // b(l)->x
    return BN.at(uintpair(l, x));
  }
  unsigned branch(unsigned x) const {
    // l: x ∈ br(l)
    return BR.find(x)->second;
  }
  bool on_branch(unsigned l, unsigned x) const {
    return l == x || branching(l) == x || (on_trunk(x) ? false : branch(x) == l);
  }
  bool on_trunk(unsigned x) const {
    return BR.count(x) == 0;
  }
  bool is_short(unsigned l) const {
    return parent(branching(l), l) == l;
  }
  void update() {
    L.clear();
    B.clear();
    P.clear();
    BN.clear();
    BR.clear();
    for(auto v : range(vertices(T)))
      if(degree(v, T) == 1) {
        L.push_back(v);
        traverse(v, T);
      }
  }
  void traverse(unsigned l, Graph const & T) {
    traverse(l, l, l, T);
  }
  void traverse(unsigned l, unsigned a, unsigned b, Graph const & T) {
    do {
      std::tie(a, b) = next(a, b, T);
      P[uintpair(l, b)] = a;
      BR.emplace(a, l);
    } while(degree(b, T) == 2);
    BR.emplace(b, l);
    if(degree(b, T) > 2) {
      B[l] = b;
      for(auto v : range(adjacent_vertices(b, T)))
        if(v != a)
          traverse(l, v, b, v, T);
    }
  }
  void traverse(unsigned l, unsigned blx, unsigned a, unsigned b, Graph const & T) {
    P[uintpair(l, b)] = a;
    BN[uintpair(l, b)] = blx;
    while(degree(b, T) == 2) {
      std::tie(a, b) = next(a, b, T);
      P[uintpair(l, b)] = a;
      BN[uintpair(l, b)] = blx;
    }
    if(degree(b, T) > 2) {
      for(auto v : range(adjacent_vertices(b, T)))
        if(v != a)
          traverse(l, blx, b, v, T);
    }
  }
  std::pair<unsigned, unsigned> next(unsigned a, unsigned b, Graph const & T) {
    auto it = adjacent_vertices(b, T).first;
    return std::make_pair(b, a == *it ? *(++it) : *it);
  }
private:
  Graph const& T;
  std::vector<unsigned> L;
  std::pair<unsigned, unsigned> typedef uintpair;
  std::unordered_multimap<unsigned, unsigned> BR;
  std::unordered_map<unsigned, unsigned> B;
  std::unordered_map<uintpair, unsigned> P, BN;
};

class prieto {
public:
  template<class Graph, class Tree>
  int operator()(Graph& G, Tree& T) {
    //detail::graph M(num_vertices(G));
    //detail::copy_edges(G, M);
    leaf_info<Tree> info(T);
    int i = -1;
    do {
      ++i;
      //show("tree" + std::to_string(i++) + ".dot", M, T);
    } while(!info.is_path() && rule2(G, T, info));
    return i;
  }
};

template <class Graph, class Tree, class LeafInfo>
bool rule1(Graph& G, Tree& T, LeafInfo& info) {
  for(auto l1 : info.leaves())
    for(auto l2 : info.leaves())
      if(edge(l1, l2, G).second) {
        auto x = l1;
        auto y = *adjacent_vertices(l1, T).first;
        while(y != l2) {
          x = y;
          y = info.parent(y, l2);
          if(degree(x, T) > 2 && degree(y, T) > 2) {
            add_edge(l1, l2, T);
            remove_edge(x, y, T);
            info.update();
            return true;
          }
        }
      }
  return false;
}

template <class Graph, class Tree, class LeafInfo>
bool rule2(Graph& G, Tree& T, LeafInfo& info) {
  for(auto l1 : info.leaves())
    for(auto l2 : info.leaves())
      if(edge(l1, l2, G).second) {
        add_edge(l1, l2, T);
        auto b = info.branching(l1);
        remove_edge(b, info.parent(b, l1), T);
        info.update();
        return true;
      }
  return false;
}

template <class Graph, class Tree, class LeafInfo>
bool rule3(Graph& G, Tree& T, LeafInfo& info) {
  for(auto l : info.leaves())
    for(auto x : range(adjacent_vertices(l, G)))
      if(!info.on_branch(l, x)) {
        auto xl = info.parent(x, l);
        if(degree(xl, T) > 2) {
          add_edge(l, x, T);
          remove_edge(x, xl, T);
          info.update();
          return true;
        }
      }
  return false;
}

template <class Graph, class Tree, class LeafInfo>
bool rule4(Graph& G, Tree& T, LeafInfo& info) {
  int n = num_vertices(G);
  std::vector<std::vector<std::pair<int,int>>> extra(n);
  for(auto l : info.leaves())
    for(auto x : range(adjacent_vertices(l, G)))
      if(!info.on_branch(l, x)) {
        auto xl = info.parent(x, l);
        if(degree(xl, T) == 2)
          extra[xl].emplace_back(l, x);
      }

  for(int l2 : info.leaves())
    for(int xl = 0; xl < n; ++xl)
      if(!extra[xl].empty() && edge(l2, xl, G).second) {
        int l, x;
        if(extra[xl].size() == 1 && extra[xl].begin()->first == l2) continue;
        std::tie(l, x) = extra[xl].begin()->first == l2 ? *(extra[xl].begin()+1) : *extra[xl].begin();
        add_edge(l, x, T);
        remove_edge(x, xl, T);
        info.update();

        add_edge(l2, xl, T);
        auto b = info.branching(l2);
        remove_edge(b, info.parent(b, l2), T);
        info.update();
        return true;
      }
  return false;
}

template <class Graph, class Tree, class LeafInfo>
bool rule5(Graph& G, Tree& T, LeafInfo& info) {
  for(auto l : info.leaves())
    for(auto x : range(adjacent_vertices(l, G)))
      if(!info.on_branch(l, x)) {
        auto bl = info.branching(l);
        auto blx = info.branching_neighbor(l, x);
        if(degree(blx, T) > 2) {
          add_edge(l, x, T);
          remove_edge(bl, blx, T);
          info.update();
          return true;
        }
      }
  return false;
}

template <class Graph, class Tree, class LeafInfo>
bool rule6(Graph& G, Tree& T, LeafInfo& info) {
  int n = num_vertices(G);
  std::vector<std::vector<std::pair<int,int>>> extra(n);
  for(auto l : info.leaves())
    for(auto x : range(adjacent_vertices(l, G)))
      if(!info.on_branch(l, x)) {
        auto blx = info.branching_neighbor(l, x);
        if(degree(blx, T) == 2) {
          extra[blx].emplace_back(l, x);
        }
      }

  for(int l2 : info.leaves())
    for(int blx = 0; blx < n; ++blx)
      if(!extra[blx].empty() && edge(l2, blx, G).second) {
        int l, x;
        if(extra[blx].size() == 1 && extra[blx].begin()->first == l2) continue;
        std::tie(l, x) = extra[blx].begin()->first == l2 ? *(extra[blx].begin()+1) : *extra[blx].begin();
        add_edge(l, x, T);
        remove_edge(info.branching(l), blx, T);
        info.update();

        add_edge(l2, blx, T);
        auto b = info.branching(l2);
        remove_edge(b, info.parent(b, l2), T);
        info.update();
        return true;
      }
  return false;
}

template <class Graph, class Tree, class LeafInfo>
bool rule7(Graph& G, Tree& T, LeafInfo& info) {
  for(auto e : range(edges(T))) {
    auto x = source(e, T);
    auto y = target(e, T);
    for(auto l : info.leaves()) {
      if(info.is_short(l)
        && !edge(l, x, T).second && !edge(l, y, T).second
        && edge(l, x, G).second && edge(l, y, G).second) {
        add_edge(l, x, T);
        add_edge(l, y, T);
        remove_edge(x, y, T);
        remove_edge(l, info.branching(l), T);
        info.update();
        return true;
      }
    }
  }
  return false;
}

template <class Graph, class Tree, class LeafInfo>
bool rule8(Graph& G, Tree& T, LeafInfo& info) {
  for(auto l1 : info.leaves()) if(!info.is_short(l1)) {
    for(auto l2 : info.leaves()) if(/*!info.is_short(l2) && */l1 != l2) {
      auto bl = info.branching(l1);
      auto blp = info.parent(bl, l1);
      if(edge(blp, l2, G).second) {
        add_edge(blp, l2, T);
        remove_edge(blp, bl, T);
        info.update();
        return true;
      }
    }
  }
  return false;
}

template <class Graph, class Tree, class LeafInfo>
bool rule9(Graph& G, Tree& T, LeafInfo& info) {
  std::vector<unsigned> lg;
  for(auto l : info.leaves())
    if(!info.is_short(l))
      lg.push_back(l);
  unsigned n = lg.size();
  std::vector<bool> m(n * n);
  enumerate(lg, [&](unsigned i, unsigned l1) {
    enumerate(lg, [&](unsigned j, unsigned l2) {
      m[i*n + j] =
        info.branching(l1) != info.branching(l2) &&
        edge(
          info.branching_neighbor(l1),
          info.branching_neighbor(l2),
          G).second;
    });
  });
  enumerate(lg, [&](unsigned i, unsigned l1) {
    unsigned count = 0, l2 = 0;
    bool ok = false;
    for(auto x : range(adjacent_vertices(l1, G)))
      if(!info.on_branch(l1, x)) {
        ++count;
        if(info.on_trunk(x) || degree(x, T) > 2)
          ok = true;
        else if(count == 1)
          l2 = info.branch(x);
        else if(l2 != info.branch(x))
          ok = true;
        if(ok) break;
      }
    if(count == 0)
      for(unsigned j = 0; j < lg.size(); ++j)
        m[i*n + j] = false;
    else if(!ok)
      for(unsigned j = 0; j < lg.size(); ++j)
        if(lg[j] == l2)
          m[i*n + j] = false;
  });
  for(unsigned i = 0; i < lg.size(); ++i) {
    unsigned l1 = lg[i];
    for(unsigned j = 0; j < lg.size(); ++j) {
      unsigned l2 = lg[j];
      if(m[i*n + j]) {
        for(auto x : range(adjacent_vertices(l1, G)))
          if(!info.on_branch(l1, x) && (!info.on_branch(l2, x) || degree(x, T) > 2)) {
            show("nine1.dot", G, T);
            unsigned bn1 = info.branching_neighbor(l1);
            unsigned bn2 = info.branching_neighbor(l2);
            add_edge(l1, x, T);
            add_edge(bn1, bn2, T);
            remove_edge(info.branching(l1), bn1, T);
            remove_edge(info.branching(l2), bn2, T);
            info.update();
            show("nine2.dot", G, T);
            return true;
          }
        assert(false);
      }
    }
  }
  return false;
}

class lost_light {
public:
  template <class Graph, class Tree>
  int operator() (Graph& G, Tree& T) {
    leaf_info<Tree> info(T);
    std::function<bool(Graph&,Tree&,leaf_info<Tree>&)> typedef rule;
    std::vector<rule> rules {
      rule2<Graph,Tree,leaf_info<Tree>>,
      rule3<Graph,Tree,leaf_info<Tree>>,
      rule4<Graph,Tree,leaf_info<Tree>>,
      rule5<Graph,Tree,leaf_info<Tree>>,
      rule6<Graph,Tree,leaf_info<Tree>>,
    };
    int i = 0;
    bool applied = true;
    while(applied && !info.is_path()) {
      applied = false;
      for(auto rule : rules) {
        if(rule(G, T, info)) {
          ++i;
          applied = true;
          break;
        }
      }
    }
    return i;
  }
};

class lost {
public:
  template <class Graph, class Tree>
  int operator() (Graph& G, Tree& T) {
    leaf_info<Tree> info(T);
    std::function<bool(Graph&,Tree&,leaf_info<Tree>&)> typedef rule;
    std::vector<rule> rules {
      rule1<Graph,Tree,leaf_info<Tree>>,
      rule2<Graph,Tree,leaf_info<Tree>>,
      rule3<Graph,Tree,leaf_info<Tree>>,
      rule4<Graph,Tree,leaf_info<Tree>>,
      rule5<Graph,Tree,leaf_info<Tree>>,
      rule6<Graph,Tree,leaf_info<Tree>>,
      rule7<Graph,Tree,leaf_info<Tree>>,
      rule8<Graph,Tree,leaf_info<Tree>>,
      rule9<Graph,Tree,leaf_info<Tree>>,
    };
    int i = 0;
    bool applied = true;
    while(applied && !info.is_path()) {
      applied = false;
      for(auto rule : rules) {
        if(rule(G, T, info)) {
          ++i;
          applied = true;
          break;
        }
      }
    }
    return i;
  }
};
<|endoftext|>


<commit_before>#include <iostream>
#include <queue>
#include <stdio.h>
using namespace std;

#include "Binary-tree.hpp"
#include "pretty-print.hpp"

// Функция создает сбалансированное дерево и возращает корневой узел дерева
Node* createBalancedTree(Node** node, int *&val, int cnt, int depth)
{
	if (cnt <= 0)
		return NULL;

	if ((*node) == NULL) {
		(*node) = new Node(*val);
		++val;
		--cnt;
	}

	int cntl = cnt / 2;
	int cntr = cnt - cntl;

	if (cntl > 0) {
		createBalancedTree(&(*node)->left, val, cntl);
	}

	if (cntr > 0) {
		createBalancedTree(&(*node)->right, val, cntr);
	}
	return (*node);
}

int main()
{
	#define ARRSIZE 11
	int data[ARRSIZE] = {25, 50, 10, 5, 30, 55, 0, 40, 35, 15, 45};
	for (int i = 0; i < ARRSIZE; i++)
		cout << data[i] << " ";
	cout << endl << endl;

	// Создаем переменную узла и сохраняем в неё корневой узел хаотично заполненного дерева
	//printPretty(createSampleTree());

	// Exer.1 - Balanced B-Tree
	Node* node = NULL;
	int *it = (int *)&data;
	printf("before it: %p\n", it);
	printPretty(createBalancedTree(&node, it, ARRSIZE, 0));
	printf("after it: %p\n", it);
	return 0;
}
<commit_msg>#fix build<commit_after>#include <iostream>
#include <queue>
#include <stdio.h>
using namespace std;

#include "Binary-tree.hpp"
#include "pretty-print.hpp"

// Функция создает сбалансированное дерево и возращает корневой узел дерева
Node* createBalancedTree(Node** node, int *&val, int cnt)
{
	if (cnt <= 0)
		return NULL;

	if ((*node) == NULL) {
		(*node) = new Node(*val);
		++val;
		--cnt;
	}

	int cntl = cnt / 2;
	int cntr = cnt - cntl;

	if (cntl > 0) {
		createBalancedTree(&(*node)->left, val, cntl);
	}

	if (cntr > 0) {
		createBalancedTree(&(*node)->right, val, cntr);
	}
	return (*node);
}

int main()
{
	#define ARRSIZE 11
	int data[ARRSIZE] = {25, 50, 10, 5, 30, 55, 0, 40, 35, 15, 45};
	for (int i = 0; i < ARRSIZE; i++)
		cout << data[i] << " ";
	cout << endl << endl;

	// Exer.1 - Balanced B-Tree
	Node* node = NULL;
	int *it = (int *)&data;
	printPretty(createBalancedTree(&node, it, ARRSIZE));
	return 0;
}
<|endoftext|>


<commit_before>#include <iostream>
#include <queue>
#include <stdio.h>
using namespace std;

#include "Binary-tree.hpp"
#include "pretty-print.hpp"

// Функция создает сбалансированное дерево и возращает корневой узел дерева
Node* createBalancedBTree(Node** node, int *&value, int cnt)
{
	if (cnt <= 0)
		return NULL;

	if (node == NULL) {
		Node* tmp = NULL;
		node = &tmp;
	}

	if ((*node) == NULL) {
		(*node) = new Node(*value);
		++value;
		--cnt;
	}

	int cntr = cnt / 2;
	int cntl = cnt - cntr;

	if (cntl > 0)
		createBalancedBTree(&(*node)->left, value, cntl);

	if (cntr > 0)
		createBalancedBTree(&(*node)->right, value, cntr);
	return (*node);
}

// Функция создает бинарное дерево поиска и возращает корневой узел дерева
Node* insertSearchBTree(Node** node, int value)
{
	if ((*node) == NULL) {
		(*node) = new Node(value);
		return *node;
	}

	if ((*node)->data > value) {
		return insertSearchBTree(&(*node)->left, value);
	} else if ((*node)->data < value) {
		return insertSearchBTree(&(*node)->right, value);
	} else {
		std::cout << "something going wrong! " << value << endl;
	}
}

// Функция создает бинарное дерево поиска и возращает корневой узел дерева
Node* createSearchBTree(int *array, int size)
{
	Node* node = NULL;
	for (int i = 0; i < size; ++i)
		insertSearchBTree(&node, array[i]);
	return node;
}

void findRowsSumm(Node *node, int *rows, int currentDepth)
{
	if (node == NULL)
		return;

	rows[currentDepth] += node->data;
	findRowsSumm(node->left, rows, currentDepth+1);
	findRowsSumm(node->right, rows, currentDepth+1);
}

int findRowWithMaxSumm(Node *node, int rowsCount)
{
	if (node == NULL)
		return -1;

	int *rowsSumm = new int[rowsCount];
	for (int i = 0; i < rowsCount; ++i)
		rowsSumm[i] = 0;

	findRowsSumm(node, rowsSumm, 0);

	int maxRow = -1;
	int maxValue = 0;
	for (int i = 0; i < rowsCount; i++)
	{
		if ((rowsSumm[i] >= 0) && (rowsSumm[i] > maxValue)) {
			maxRow = i;
			maxValue = rowsSumm[i];
		}
	}
	return maxRow;
}

int main()
{
	int data[] = {35, 55, 15, 50, 40, 0, 10, 45, 5, 30, 25};
	int size = sizeof(data) / (sizeof(data[0]));

	cout << "Exer.1 - Balanced B-Tree" << endl;
	int *it = (int *)&data;
	Node* balancedBTreeRoot = createBalancedBTree(NULL, it, size);
	printPretty(balancedBTreeRoot);
	cout << endl;

	cout << "Exer.2 - Search B-Tree" << endl;
	Node* searchBTreeRoot = createSearchBTree(data, size);
	printPretty(searchBTreeRoot);
	cout << endl;

	cout << "Exer.6 - Find row with max summ of values from search B-Tree" << endl;
	printPretty(searchBTreeRoot);
	cout << "Count starts from 0, -1 = no values found" << endl;
	cout << "Answer is " << findRowWithMaxSumm(searchBTreeRoot, size) << endl;
	cout << endl;

	return 0;
}
<commit_msg>lab5 free nodes memory<commit_after>#include <iostream>
#include <queue>
#include <stdio.h>
using namespace std;

#include "Binary-tree.hpp"
#include "pretty-print.hpp"

// Функция создает сбалансированное дерево и возращает корневой узел дерева
Node* createBalancedBTree(Node** node, int *&value, int cnt)
{
	if (cnt <= 0)
		return NULL;

	if (node == NULL) {
		Node* tmp = NULL;
		node = &tmp;
	}

	if ((*node) == NULL) {
		(*node) = new Node(*value);
		++value;
		--cnt;
	}

	int cntr = cnt / 2;
	int cntl = cnt - cntr;

	if (cntl > 0)
		createBalancedBTree(&(*node)->left, value, cntl);

	if (cntr > 0)
		createBalancedBTree(&(*node)->right, value, cntr);
	return (*node);
}

// Функция создает бинарное дерево поиска и возращает корневой узел дерева
Node* insertSearchBTree(Node** node, int value)
{
	if ((*node) == NULL) {
		(*node) = new Node(value);
		return *node;
	}

	if ((*node)->data > value) {
		return insertSearchBTree(&(*node)->left, value);
	} else if ((*node)->data < value) {
		return insertSearchBTree(&(*node)->right, value);
	} else {
		std::cout << "something going wrong! " << value << endl;
	}
}

// Функция создает бинарное дерево поиска и возращает корневой узел дерева
Node* createSearchBTree(int *array, int size)
{
	Node* node = NULL;
	for (int i = 0; i < size; ++i)
		insertSearchBTree(&node, array[i]);
	return node;
}

void findRowsSumm(Node *node, int *rows, int currentDepth)
{
	if (node == NULL)
		return;

	rows[currentDepth] += node->data;
	findRowsSumm(node->left, rows, currentDepth+1);
	findRowsSumm(node->right, rows, currentDepth+1);
}

int findRowWithMaxSumm(Node *node, int rowsCount)
{
	if (node == NULL)
		return -1;

	int *rowsSumm = new int[rowsCount];
	for (int i = 0; i < rowsCount; ++i)
		rowsSumm[i] = 0;

	findRowsSumm(node, rowsSumm, 0);

	int maxRow = -1;
	int maxValue = 0;
	for (int i = 0; i < rowsCount; i++)
	{
		if ((rowsSumm[i] >= 0) && (rowsSumm[i] > maxValue)) {
			maxRow = i;
			maxValue = rowsSumm[i];
		}
	}
	delete [] rowsSumm;
	return maxRow;
}

void destroyTree(Node *node) {
	if (node != NULL) {
		destroyTree(node->left);
		destroyTree(node->right);
	}

	delete node;
}

int main()
{
	int data[] = {35, 55, 15, 50, 40, 0, 10, 45, 5, 30, 25};
	int size = sizeof(data) / (sizeof(data[0]));

	cout << "Exer.1 - Balanced B-Tree" << endl;
	int *it = (int *)&data;
	Node* balancedBTreeRoot = createBalancedBTree(NULL, it, size);
	printPretty(balancedBTreeRoot);
	destroyTree(balancedBTreeRoot);
	cout << endl;

	cout << "Exer.2 - Search B-Tree" << endl;
	Node* searchBTreeRoot = createSearchBTree(data, size);
	printPretty(searchBTreeRoot);
	// destroyTree(searchBTreeRoot);
	cout << endl;

	cout << "Exer.6 - Find row with max summ of values from search B-Tree" << endl;
	printPretty(searchBTreeRoot);
	int row = findRowWithMaxSumm(searchBTreeRoot, size);
	destroyTree(searchBTreeRoot);
	cout << "Count starts from 0, -1 = no values found" << endl;
	cout << "Answer is " << row << endl;
	cout << endl;

	return 0;
}
<|endoftext|>


<commit_before>/*
 * Copyright (c) 2015 Juniper Networks, Inc. All rights reserved.
 */

#include <sys/socket.h>
#if defined(__linux__)
#include <linux/netlink.h>
#elif defined(__FreeBSD__)
#include "vr_os.h"
#endif
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <asm/types.h>
#include <boost/asio.hpp>

#include <base/timer.h>
#include <base/task_trigger.h>
#include <net/address_util.h>
#include <cmn/agent_cmn.h>
#include <services/services_init.h>
#include <uve/stats_collector.h>
#include <services/icmp_error_proto.h>
#include <pkt/flow_proto.h>
#include <ksync/ksync_index.h>
#include <ksync/ksync_entry.h>
#include <ksync/ksync_object.h>
#include <ksync/ksync_netlink.h>
#include <ksync/ksync_sock.h>
#include <ksync/ksync_sock_user.h>

#include <vr_types.h>
#include <nl_util.h>
#include <vr_flow.h>
#include <vr_genetlink.h>

#include "ksync_init.h"
#include "ksync_flow_memory.h"
#include "sandesh_ksync.h"

#ifdef _WIN32
#include <windows_shmem_ioctl.h>
#endif

using namespace boost::asio::ip;
static const int kTestFlowTableSize = 131072 * sizeof(vr_flow_entry);

KSyncMemory::KSyncMemory(KSync *ksync, uint32_t minor_id) :
    ksync_(ksync),
    table_path_(),
    major_devid_(0),
    minor_devid_(minor_id),
    table_size_(0),
    table_entries_count_(0),
    audit_timer_(TimerManager::CreateTimer
                 (*(ksync->agent()->event_manager())->io_service(),
                  " Audit Timer",
                  ksync->agent()->task_scheduler()->GetTaskId(kTaskFlowAudit),
                  0)),
    audit_timeout_(0),
    audit_yield_(0),
    audit_interval_(0),
    audit_idx_(0),
    audit_list_() {
}

KSyncMemory::~KSyncMemory() {
    TimerManager::DeleteTimer(audit_timer_);
}

void KSyncMemory::Init() {
    audit_interval_ = kAuditYieldTimer;
    audit_timeout_ = kAuditTimeout;
    uint32_t table_count = table_entries_count_;
    // Compute number of entries to visit per timer interval so that complete
    // table can be visited in kAuditSweepTime
    uint32_t timer_per_sec = 1000 / kAuditYieldTimer;
    uint32_t timer_per_sweep = kAuditSweepTime * timer_per_sec;
    audit_yield_ = table_count / timer_per_sweep;
    if (audit_yield_ > kAuditYieldMax)
        audit_yield_ = kAuditYieldMax;
    if (audit_yield_ < kAuditYieldMin)
        audit_yield_ = kAuditYieldMin;

    audit_timer_->Start(audit_interval_,
                        boost::bind(&KSyncMemory::AuditProcess, this));
}

void KSyncMemory::Mmap(bool unlink_node) {
    // Remove the existing /dev/ file first. We will add it again in vr_table_map
    if (unlink_node) {
        const char *error_msg = vr_table_unlink(table_path_.c_str());
        if (error_msg) {
            LOG(DEBUG, "Error unmapping KSync memory: " << error_msg);
            assert(0);
        }
    }

    const char *mmap_error_msg = vr_table_map(major_devid_, minor_devid_, table_path_.c_str(),
                                              table_size_, &table_);
    if (mmap_error_msg) {
        LOG(DEBUG, "Error mapping KSync memory. Device: " << table_path_ << "; " << mmap_error_msg);
        assert(0);
    }

    table_entries_count_ = table_size_ / get_entry_size();
    SetTableSize();
}

// Steps to map  table entry
// - Query the  table parameters from kernel
// - Create device /dev/ with major-num and minor-num
// - Map device memory
void KSyncMemory::InitMem() {
    struct nl_client *cl;
    int attr_len;
    int encode_len, ret;

    assert((cl = nl_register_client()) != NULL);

#ifdef _WIN32
    cl->cl_win_pipe = CreateFile(KSYNC_PATH, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
    assert(cl->cl_win_pipe != INVALID_HANDLE_VALUE);
    cl->cl_recvmsg = win_nl_client_recvmsg;
#else
    assert(nl_socket(cl, AF_NETLINK, SOCK_DGRAM, NETLINK_GENERIC) > 0);
    assert(nl_connect(cl, 0, 0) == 0);
#endif

    assert(vrouter_obtain_family_id(cl) > 0);

    assert(nl_build_nlh(cl, cl->cl_genl_family_id, NLM_F_REQUEST) == 0);
    assert(nl_build_genlh(cl, SANDESH_REQUEST, 0) == 0);

    attr_len = nl_get_attr_hdr_size();

    encode_len = EncodeReq(cl, attr_len);
    nl_build_attr(cl, encode_len, NL_ATTR_VR_MESSAGE_PROTOCOL);
    nl_update_nlh(cl);

    if ((ret = nl_sendmsg(cl)) < 0) {
        LOG(DEBUG, "Error requesting  Table message. Error : " << ret);
        assert(0);
    }

    while ((ret = nl_recvmsg(cl)) > 0) {
        KSyncSockNetlink::NetlinkDecoder(cl->cl_buf,
                                         KSyncSock::GetAgentSandeshContext(0));
    }
    nl_free_client(cl);

    Mmap(true);
    return;
}

void KSyncMemory::InitTest() {
    assert(0);
}

void KSyncMemory::Shutdown() {
    assert(0);
}

bool KSyncMemory::AuditProcess() {
    // Get current time
    uint64_t t = UTCTimestampUsec();

    while (!audit_list_.empty()) {
        AuditEntry list_entry = audit_list_.front();
        // audit_list_ is sorted on last time of insertion in the list
        // So, break on finding first  entry that cannot be aged
        if ((t - list_entry.timeout) < audit_timeout_) {
            /* Wait for audit_timeout_ to create short  for the entry */
            break;
        }
        uint32_t idx = list_entry.audit_idx;
        uint32_t gen_id = list_entry.audit_gen_id;
        audit_list_.pop_front();
        DecrementHoldFlowCounter();
        CreateProtoAuditEntry(idx, gen_id);
    }

    uint32_t count = 0;
    uint8_t gen_id;
    assert(audit_yield_);
    while (count < audit_yield_) {
        if (IsInactiveEntry(audit_idx_, gen_id)) {
            IncrementHoldFlowCounter();
            audit_list_.push_back(AuditEntry(audit_idx_, gen_id, t));
        }

        count++;
        audit_idx_++;
        if (audit_idx_ == table_entries_count_) {
            UpdateAgentHoldFlowCounter();
            audit_idx_ = 0;
        }
    }
    return true;
}

#ifndef _WIN32
void KSyncMemory::GetTableSize() {
    struct nl_client *cl;
    int attr_len;
    int encode_len;

    assert((cl = nl_register_client()) != NULL);
    cl->cl_genl_family_id = KSyncSock::GetNetlinkFamilyId();
    assert(nl_build_nlh(cl, cl->cl_genl_family_id, NLM_F_REQUEST) == 0);
    assert(nl_build_genlh(cl, SANDESH_REQUEST, 0) == 0);

    attr_len = nl_get_attr_hdr_size();
    encode_len = EncodeReq(cl, attr_len);
    nl_build_attr(cl, encode_len, NL_ATTR_VR_MESSAGE_PROTOCOL);
    nl_update_nlh(cl);

#ifdef AGENT_VROUTER_TCP
    tcp::socket socket(*(ksync_->agent()->event_manager()->io_service()));
    tcp::endpoint endpoint(ksync_->agent()->vrouter_server_ip(),
                           ksync_->agent()->vrouter_server_port());
#else
    boost::asio::local::stream_protocol::socket
        socket(*(ksync_->agent()->event_manager()->io_service()));
    boost::asio::local::stream_protocol::endpoint
        endpoint(KSYNC_AGENT_VROUTER_SOCK_PATH);
#endif
    boost::system::error_code ec;
    socket.connect(endpoint, ec);
    if (ec) {
        assert(0);
    }

    socket.send(boost::asio::buffer(cl->cl_buf, cl->cl_buf_offset), 0, ec);
    if (ec) {
        assert(0);
    }

    uint32_t len_read = 0;
    uint32_t data_len = sizeof(struct nlmsghdr);
    while (len_read < data_len) {
        len_read = socket.read_some(boost::asio::buffer(cl->cl_buf + len_read,
                                                        cl->cl_buf_len), ec);
        if (ec) {
            assert(0);
        }

        if (len_read > sizeof(struct nlmsghdr)) {
            const struct nlmsghdr *nlh =
                (const struct nlmsghdr *)((cl->cl_buf));
            data_len = nlh->nlmsg_len;
        }
    }

    KSyncSockNetlink::NetlinkDecoder(cl->cl_buf,
                                     KSyncSock::GetAgentSandeshContext(0));
    nl_free_client(cl);
}

void KSyncMemory::MapSharedMemory() {
    GetTableSize();
    Mmap(false);
}
#endif
<commit_msg>Committing on behalf of Naveen<commit_after>/*
 * Copyright (c) 2015 Juniper Networks, Inc. All rights reserved.
 */

#include <sys/socket.h>
#if defined(__linux__)
#include <linux/netlink.h>
#elif defined(__FreeBSD__)
#include "vr_os.h"
#endif
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <asm/types.h>
#include <boost/asio.hpp>

#include <base/timer.h>
#include <base/task_trigger.h>
#include <net/address_util.h>
#include <cmn/agent_cmn.h>
#include <services/services_init.h>
#include <uve/stats_collector.h>
#include <services/icmp_error_proto.h>
#include <pkt/flow_proto.h>
#include <ksync/ksync_index.h>
#include <ksync/ksync_entry.h>
#include <ksync/ksync_object.h>
#include <ksync/ksync_netlink.h>
#include <ksync/ksync_sock.h>
#include <ksync/ksync_sock_user.h>

#include <vr_types.h>
#include <nl_util.h>
#include <vr_flow.h>
#include <ini_parser.h>
#include <vr_genetlink.h>

#include "ksync_init.h"
#include "ksync_flow_memory.h"
#include "sandesh_ksync.h"

#ifdef _WIN32
#include <windows_shmem_ioctl.h>
#endif

using namespace boost::asio::ip;
static const int kTestFlowTableSize = 131072 * sizeof(vr_flow_entry);

KSyncMemory::KSyncMemory(KSync *ksync, uint32_t minor_id) :
    ksync_(ksync),
    table_path_(),
    major_devid_(0),
    minor_devid_(minor_id),
    table_size_(0),
    table_entries_count_(0),
    audit_timer_(TimerManager::CreateTimer
                 (*(ksync->agent()->event_manager())->io_service(),
                  " Audit Timer",
                  ksync->agent()->task_scheduler()->GetTaskId(kTaskFlowAudit),
                  0)),
    audit_timeout_(0),
    audit_yield_(0),
    audit_interval_(0),
    audit_idx_(0),
    audit_list_() {
}

KSyncMemory::~KSyncMemory() {
    TimerManager::DeleteTimer(audit_timer_);
}

void KSyncMemory::Init() {
    audit_interval_ = kAuditYieldTimer;
    audit_timeout_ = kAuditTimeout;
    uint32_t table_count = table_entries_count_;
    // Compute number of entries to visit per timer interval so that complete
    // table can be visited in kAuditSweepTime
    uint32_t timer_per_sec = 1000 / kAuditYieldTimer;
    uint32_t timer_per_sweep = kAuditSweepTime * timer_per_sec;
    audit_yield_ = table_count / timer_per_sweep;
    if (audit_yield_ > kAuditYieldMax)
        audit_yield_ = kAuditYieldMax;
    if (audit_yield_ < kAuditYieldMin)
        audit_yield_ = kAuditYieldMin;

    audit_timer_->Start(audit_interval_,
                        boost::bind(&KSyncMemory::AuditProcess, this));
}

void KSyncMemory::Mmap(bool unlink_node) {
    // Remove the existing /dev/ file first. We will add it again in vr_table_map
    if (unlink_node) {
        const char *error_msg = vr_table_unlink(table_path_.c_str());
        if (error_msg) {
            LOG(DEBUG, "Error unmapping KSync memory: " << error_msg);
            assert(0);
        }
    }

    parse_ini_file();
    const char *mmap_error_msg = vr_table_map(major_devid_, minor_devid_, table_path_.c_str(),
                                              table_size_, &table_);
    if (mmap_error_msg) {
        LOG(DEBUG, "Error mapping KSync memory. Device: " << table_path_ << "; " << mmap_error_msg);
        assert(0);
    }

    table_entries_count_ = table_size_ / get_entry_size();
    SetTableSize();
}

// Steps to map  table entry
// - Query the  table parameters from kernel
// - Create device /dev/ with major-num and minor-num
// - Map device memory
void KSyncMemory::InitMem() {
    struct nl_client *cl;
    int attr_len;
    int encode_len, ret;

    assert((cl = nl_register_client()) != NULL);

#ifdef _WIN32
    cl->cl_win_pipe = CreateFile(KSYNC_PATH, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
    assert(cl->cl_win_pipe != INVALID_HANDLE_VALUE);
    cl->cl_recvmsg = win_nl_client_recvmsg;
#else
    assert(nl_socket(cl, AF_NETLINK, SOCK_DGRAM, NETLINK_GENERIC) > 0);
    assert(nl_connect(cl, 0, 0) == 0);
#endif

    assert(vrouter_obtain_family_id(cl) > 0);

    assert(nl_build_nlh(cl, cl->cl_genl_family_id, NLM_F_REQUEST) == 0);
    assert(nl_build_genlh(cl, SANDESH_REQUEST, 0) == 0);

    attr_len = nl_get_attr_hdr_size();

    encode_len = EncodeReq(cl, attr_len);
    nl_build_attr(cl, encode_len, NL_ATTR_VR_MESSAGE_PROTOCOL);
    nl_update_nlh(cl);

    if ((ret = nl_sendmsg(cl)) < 0) {
        LOG(DEBUG, "Error requesting  Table message. Error : " << ret);
        assert(0);
    }

    while ((ret = nl_recvmsg(cl)) > 0) {
        KSyncSockNetlink::NetlinkDecoder(cl->cl_buf,
                                         KSyncSock::GetAgentSandeshContext(0));
    }
    nl_free_client(cl);

    Mmap(true);
    return;
}

void KSyncMemory::InitTest() {
    assert(0);
}

void KSyncMemory::Shutdown() {
    assert(0);
}

bool KSyncMemory::AuditProcess() {
    // Get current time
    uint64_t t = UTCTimestampUsec();

    while (!audit_list_.empty()) {
        AuditEntry list_entry = audit_list_.front();
        // audit_list_ is sorted on last time of insertion in the list
        // So, break on finding first  entry that cannot be aged
        if ((t - list_entry.timeout) < audit_timeout_) {
            /* Wait for audit_timeout_ to create short  for the entry */
            break;
        }
        uint32_t idx = list_entry.audit_idx;
        uint32_t gen_id = list_entry.audit_gen_id;
        audit_list_.pop_front();
        DecrementHoldFlowCounter();
        CreateProtoAuditEntry(idx, gen_id);
    }

    uint32_t count = 0;
    uint8_t gen_id;
    assert(audit_yield_);
    while (count < audit_yield_) {
        if (IsInactiveEntry(audit_idx_, gen_id)) {
            IncrementHoldFlowCounter();
            audit_list_.push_back(AuditEntry(audit_idx_, gen_id, t));
        }

        count++;
        audit_idx_++;
        if (audit_idx_ == table_entries_count_) {
            UpdateAgentHoldFlowCounter();
            audit_idx_ = 0;
        }
    }
    return true;
}

#ifndef _WIN32
void KSyncMemory::GetTableSize() {
    struct nl_client *cl;
    int attr_len;
    int encode_len;

    assert((cl = nl_register_client()) != NULL);
    cl->cl_genl_family_id = KSyncSock::GetNetlinkFamilyId();
    assert(nl_build_nlh(cl, cl->cl_genl_family_id, NLM_F_REQUEST) == 0);
    assert(nl_build_genlh(cl, SANDESH_REQUEST, 0) == 0);

    attr_len = nl_get_attr_hdr_size();
    encode_len = EncodeReq(cl, attr_len);
    nl_build_attr(cl, encode_len, NL_ATTR_VR_MESSAGE_PROTOCOL);
    nl_update_nlh(cl);

#ifdef AGENT_VROUTER_TCP
    tcp::socket socket(*(ksync_->agent()->event_manager()->io_service()));
    tcp::endpoint endpoint(ksync_->agent()->vrouter_server_ip(),
                           ksync_->agent()->vrouter_server_port());
#else
    boost::asio::local::stream_protocol::socket
        socket(*(ksync_->agent()->event_manager()->io_service()));
    boost::asio::local::stream_protocol::endpoint
        endpoint(KSYNC_AGENT_VROUTER_SOCK_PATH);
#endif
    boost::system::error_code ec;
    socket.connect(endpoint, ec);
    if (ec) {
        assert(0);
    }

    socket.send(boost::asio::buffer(cl->cl_buf, cl->cl_buf_offset), 0, ec);
    if (ec) {
        assert(0);
    }

    uint32_t len_read = 0;
    uint32_t data_len = sizeof(struct nlmsghdr);
    while (len_read < data_len) {
        len_read = socket.read_some(boost::asio::buffer(cl->cl_buf + len_read,
                                                        cl->cl_buf_len), ec);
        if (ec) {
            assert(0);
        }

        if (len_read > sizeof(struct nlmsghdr)) {
            const struct nlmsghdr *nlh =
                (const struct nlmsghdr *)((cl->cl_buf));
            data_len = nlh->nlmsg_len;
        }
    }

    KSyncSockNetlink::NetlinkDecoder(cl->cl_buf,
                                     KSyncSock::GetAgentSandeshContext(0));
    nl_free_client(cl);
}

void KSyncMemory::MapSharedMemory() {
    GetTableSize();
    Mmap(false);
}
#endif
<|endoftext|>


<commit_before><commit_msg>bnc#887225: OOXML import: Correctly apply table style for lastRow.<commit_after><|endoftext|>


<commit_before>#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMessageBox>

MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
{}

void MainWindow::setIP(QHostAddress myIP, QHostAddress partnerIP)
{
    ui->setupUi(this);

    ui->ErrorLabel->setText("No error :)");

    //Camera and image processer settings
    CaptureCamera.open(0);
    if(CaptureCamera.isOpened() == false)
    {
        ui->ErrorLabel->setText("Camera Error");
        std::cerr<< "Camera open error" <<std::endl;
    }

    CamSize = OriginalImageMat.size();
    Processer = new ImageProcesser(CamSize);
    ProcessTimer = new QTimer(this);
    connect(ProcessTimer, SIGNAL(timeout()), this, SLOT(processVideoAndUpdateQUI()));

    ProcessTimer->start(100); //tested with QElapsedTimer, 50 was too low... it generated runtime between 60-90 msec
                              //with this we have ~12 msec :)

    //Add the graphics to graphicsview
    scene = new QGraphicsScene(0,0,Settings::SCREEN_WIDTH,Settings::SCREEN_HEIGHT,ui->graphicsView);
    ui->graphicsView->setScene(scene);

    //Other initializations
    myRoad = new Road();
    lives = Settings::STARTLIFE;
    ui->MyLifeLCD->display(lives);
    distance = 0;
    QObject::connect(myRoad, SIGNAL(sendLifeNumber(int)), this, SLOT(receiveLifeNumber(int)));
    QObject::connect(myRoad, SIGNAL(sendDistanceNumber(int)), this, SLOT(receiveDistanceNumber(int)));
    QObject::connect(myRoad, SIGNAL(stopGame()), this, SLOT(lose()));
    scene->addItem(myRoad);

    //Start the game
    QObject::connect(&timer, SIGNAL(timeout()), scene, SLOT(advance()));

    MyIpAddr=myIP;
    ui->MyIP->setText("My IP: " + MyIpAddr.toString());
    PartnerIpAddr=partnerIP;
    ui->PartnerIP->setText("Partner IP: " + PartnerIpAddr.toString());
    n = new Network();
    n->setIp(MyIpAddr,PartnerIpAddr);
    n->startBinding();
    QObject::connect(n, SIGNAL(receivedImage(QImage)), this, SLOT(receiveNetworkImage(QImage)));
    gameStarted = false;
    this->show();
}

void MainWindow::receiveLifeNumber(int i)
{
    lives = i;
    if(lives>=0) ui->MyLifeLCD->display(lives);
}

void MainWindow::receiveDistanceNumber(int i)
{
    distance = i;
    ui->MyDistLCD->display(distance);
}

void MainWindow::lose(){
    timer.stop();
    QMessageBox::StandardButton reply;
      reply = QMessageBox::question(this, "Rematch", "Would you like to restart the game?",
                                    QMessageBox::Yes|QMessageBox::No);
      if (reply == QMessageBox::Yes) {
          restart();
      } else {
          closeVideoStream();
          close();
          exit(0);
      }
}

void MainWindow::processVideoAndUpdateQUI()
{
    ProcUpdateElapsedTime.start();
    CaptureCamera.read(OriginalImageMat);

    if (OriginalImageMat.empty()) return;

    cv::resize(OriginalImageMat, ResizedImageMat, cv::Size(352,220), 0, 0, cv::INTER_CUBIC); //resizing the image to fit in the UI
    cv::flip(ResizedImageMat, ResizedImageMat, 1); //eliminating the mirror effect

    //Add the picture to the processer
    int move = Processer->getMove(ResizedImageMat);
    //std::cout << "move: " << move <<std::endl;

    //Move the car
    if(prevmove == 0)
    {
        myRoad->moveCar(move);
    }
    prevmove = move;

    cv::cvtColor(ResizedImageMat, ResizedImageMat, CV_BGR2RGB); //converting the image to RGB
    cv::rectangle(ResizedImageMat,cv::Rect(0, 0, 100, 130),cv::Scalar(200));
    cv::rectangle(ResizedImageMat,cv::Rect(250,0,102,130),cv::Scalar(200));

    QImage OriginalImage((uchar*)ResizedImageMat.data,
                         ResizedImageMat.cols,
                         ResizedImageMat.rows,
                         ResizedImageMat.step,
                         QImage::Format_RGB888); //Creating the QImage for the label
    NetworkSendImage = OriginalImage;
    NetworkSendImage = NetworkSendImage.scaledToHeight(165);

    ui->MyVideoLabel->setPixmap(QPixmap::fromImage(OriginalImage));

    //Sending number of lives and distance embedded in the image
    NetworkSendImage.setText("lives", QString::number(lives));
    NetworkSendImage.setText("distance", QString::number(distance));

    n->sendData(NetworkSendImage); //sending the image over the network
    if(lives < 0)
    {
        lose();
    }

//    std::cerr << "processVideoAndUpdateQUI() elapsed time: " << ProcUpdateElapsedTime.elapsed() << " msec" << std::endl << std::endl;
}

//Public slot that receives the image from the networking thread
void MainWindow::receiveNetworkImage(QImage q)
{
    if (!gameStarted)
    {
        //Start the game
        timer.start(Settings::FREQUENCY);
        gameStarted = true;
    }
    ui->NetworkCamVideo->setPixmap(QPixmap::fromImage(q)); //putting the received image to the gui
    std::cout << "network lives: " << q.text("lives").toInt() << std::endl;
    if(q.text("lives").toInt()>=0) ui->NetworkLifeLCD->display(q.text("lives"));
    else{
        lose();
    }
    //else timer.stop();
    ui->NetworkDistLCD->display(q.text("distance"));
}

MainWindow::~MainWindow()
{
    delete ui;
    delete ProcessTimer;
    delete Processer;
    delete n;
    delete scene;
    delete myCar;
    delete myRoad;
}

void MainWindow::closeVideoStream()
{
    ProcessTimer->stop();
    //std::cout << "Video process timer stopped" <<std::endl;
    CaptureCamera.release();
    //std::cout << "Camera released" <<std::endl;
}

void MainWindow::restart()
{
        delete myRoad;
        myRoad = new Road();
        lives = Settings::STARTLIFE;
        ui->MyLifeLCD->display(lives);
        distance = 0;
        ui->MyDistLCD->display(distance);
        scene->addItem(myRoad);
        timer.start(Settings::FREQUENCY);
}

// Kezeli a billentyűlenyomást
void MainWindow::keyPressEvent(QKeyEvent *event){
    switch (event->key())
    {
        case Qt::Key_Right:
                myRoad->moveCar(1); //turn right;
            break;
        case Qt::Key_Left:
                myRoad->moveCar(-1); //turn left;
            break;
        case Qt::Key_Escape:
            closeVideoStream();
            close();
            exit(0);
            break;
        default:
            break;
    }
}
<commit_msg>done for today hopefully :)<commit_after>#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMessageBox>

MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
{}

void MainWindow::setIP(QHostAddress myIP, QHostAddress partnerIP)
{
    ui->setupUi(this);

    ui->ErrorLabel->setText("No error :)");

    //Camera and image processer settings
    CaptureCamera.open(0);
    if(CaptureCamera.isOpened() == false)
    {
        ui->ErrorLabel->setText("Camera Error");
        std::cerr<< "Camera open error" <<std::endl;
    }

    CamSize = OriginalImageMat.size();
    Processer = new ImageProcesser(CamSize);
    ProcessTimer = new QTimer(this);
    connect(ProcessTimer, SIGNAL(timeout()), this, SLOT(processVideoAndUpdateQUI()));

    ProcessTimer->start(100); //tested with QElapsedTimer, 50 was too low... it generated runtime between 60-90 msec
                              //with this we have ~12 msec :)

    //Add the graphics to graphicsview
    scene = new QGraphicsScene(0,0,Settings::SCREEN_WIDTH,Settings::SCREEN_HEIGHT,ui->graphicsView);
    ui->graphicsView->setScene(scene);

    //Other initializations
    myRoad = new Road();
    lives = Settings::STARTLIFE;
    ui->MyLifeLCD->display(lives);
    distance = 0;
    QObject::connect(myRoad, SIGNAL(sendLifeNumber(int)), this, SLOT(receiveLifeNumber(int)));
    QObject::connect(myRoad, SIGNAL(sendDistanceNumber(int)), this, SLOT(receiveDistanceNumber(int)));
    scene->addItem(myRoad);

    //Start the game
    QObject::connect(&timer, SIGNAL(timeout()), scene, SLOT(advance()));

    MyIpAddr=myIP;
    ui->MyIP->setText("My IP: " + MyIpAddr.toString());
    PartnerIpAddr=partnerIP;
    ui->PartnerIP->setText("Partner IP: " + PartnerIpAddr.toString());
    n = new Network();
    n->setIp(MyIpAddr,PartnerIpAddr);
    n->startBinding();
    QObject::connect(n, SIGNAL(receivedImage(QImage)), this, SLOT(receiveNetworkImage(QImage)));
    gameStarted = false;
    this->show();
}

void MainWindow::receiveLifeNumber(int i)
{
    lives = i;
    if(lives>=0) ui->MyLifeLCD->display(lives);
}

void MainWindow::receiveDistanceNumber(int i)
{
    distance = i;
    ui->MyDistLCD->display(distance);
}

void MainWindow::lose(){
    timer.stop();
    QString msg;
    if (lives <0)
        msg = "You lost, I'm sorry...\n\nWould you like to restart the game?";
    else
        msg = "YOU WON, congratulations!\n\nWould you like to restart the game?";
    QMessageBox::StandardButton reply;
      reply = QMessageBox::question(this, "Rematch", msg,
                                    QMessageBox::Yes|QMessageBox::No);
      if (reply == QMessageBox::Yes) {
          restart();
      } else {
          closeVideoStream();
          close();
          exit(0);
      }
}

void MainWindow::processVideoAndUpdateQUI()
{
    ProcUpdateElapsedTime.start();
    CaptureCamera.read(OriginalImageMat);

    if (OriginalImageMat.empty()) return;

    cv::resize(OriginalImageMat, ResizedImageMat, cv::Size(352,220), 0, 0, cv::INTER_CUBIC); //resizing the image to fit in the UI
    cv::flip(ResizedImageMat, ResizedImageMat, 1); //eliminating the mirror effect

    //Add the picture to the processer
    int move = Processer->getMove(ResizedImageMat);
    //std::cout << "move: " << move <<std::endl;

    //Move the car
    if(prevmove == 0)
    {
        myRoad->moveCar(move);
    }
    prevmove = move;

    cv::cvtColor(ResizedImageMat, ResizedImageMat, CV_BGR2RGB); //converting the image to RGB
    cv::rectangle(ResizedImageMat,cv::Rect(0, 0, 100, 130),cv::Scalar(200));
    cv::rectangle(ResizedImageMat,cv::Rect(250,0,102,130),cv::Scalar(200));

    QImage OriginalImage((uchar*)ResizedImageMat.data,
                         ResizedImageMat.cols,
                         ResizedImageMat.rows,
                         ResizedImageMat.step,
                         QImage::Format_RGB888); //Creating the QImage for the label
    NetworkSendImage = OriginalImage;
    NetworkSendImage = NetworkSendImage.scaledToHeight(165);

    ui->MyVideoLabel->setPixmap(QPixmap::fromImage(OriginalImage));

    //Sending number of lives and distance embedded in the image
    NetworkSendImage.setText("lives", QString::number(lives));
    NetworkSendImage.setText("distance", QString::number(distance));

    n->sendData(NetworkSendImage); //sending the image over the network
    if(lives < 0)
    {
        lose();
    }

//    std::cerr << "processVideoAndUpdateQUI() elapsed time: " << ProcUpdateElapsedTime.elapsed() << " msec" << std::endl << std::endl;
}

//Public slot that receives the image from the networking thread
void MainWindow::receiveNetworkImage(QImage q)
{
    if (!gameStarted)
    {
        //Start the game
        timer.start(Settings::FREQUENCY);
        gameStarted = true;
    }
    ui->NetworkCamVideo->setPixmap(QPixmap::fromImage(q)); //putting the received image to the gui
    //std::cout << "network lives: " << q.text("lives").toInt() << std::endl;
    if(q.text("lives").toInt()>=0) ui->NetworkLifeLCD->display(q.text("lives"));
    else{
        lose();
    }
    //else timer.stop();
    ui->NetworkDistLCD->display(q.text("distance"));
}

MainWindow::~MainWindow()
{
    delete ui;
    delete ProcessTimer;
    delete Processer;
    delete n;
    delete scene;
    delete myCar;
    delete myRoad;
}

void MainWindow::closeVideoStream()
{
    ProcessTimer->stop();
    //std::cout << "Video process timer stopped" <<std::endl;
    CaptureCamera.release();
    //std::cout << "Camera released" <<std::endl;
}

void MainWindow::restart()
{
        delete myRoad;
        myRoad = new Road();
        lives = Settings::STARTLIFE;
        ui->MyLifeLCD->display(lives);
        distance = 0;
        ui->MyDistLCD->display(distance);
        scene->addItem(myRoad);
        timer.start(Settings::FREQUENCY);
}

// Kezeli a billentyűlenyomást
void MainWindow::keyPressEvent(QKeyEvent *event){
    switch (event->key())
    {
        case Qt::Key_Right:
                myRoad->moveCar(1); //turn right;
            break;
        case Qt::Key_Left:
                myRoad->moveCar(-1); //turn left;
            break;
        case Qt::Key_Escape:
            closeVideoStream();
            close();
            exit(0);
            break;
        default:
            break;
    }
}
<|endoftext|>


<commit_before>/*
Copyright (c) 2016 Barrett Adair

Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)

HEADER GUARDS INTENTIONALLY OMITTED
DO NOT INCLUDE THIS HEADER DIRECTLY
*/

#define BOOST_CLBL_TRTS_NOEXCEPT_SPEC
#define BOOST_CLBL_TRTS_IS_NOEXCEPT std::false_type
#include <boost/callable_traits/detail/unguarded/pmf_4.hpp>
#undef BOOST_CLBL_TRTS_NOEXCEPT_SPEC
#undef BOOST_CLBL_TRTS_IS_NOEXCEPT

#ifdef BOOST_CLBL_TRTS_ENABLE_NOEXCEPT_TYPES
#define BOOST_CLBL_TRTS_NOEXCEPT_SPEC noexcept
#define BOOST_CLBL_TRTS_IS_NOEXCEPT std::true_type
#include <boost/callable_traits/detail/unguarded/pmf_4.hpp>
#undef BOOST_CLBL_TRTS_NOEXCEPT_SPEC
#undef BOOST_CLBL_TRTS_IS_NOEXCEPT
#endif // #ifdef BOOST_CLBL_TRTS_ENABLE_NOEXCEPT_TYPES<commit_msg>Delete pmf_3.hpp<commit_after><|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: StaticSet.hxx,v $
 *
 *  $Revision: 1.8 $
 *
 *  last change: $Author: rt $ $Date: 2005-09-08 10:04:12 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

#ifndef DBACCESS_CORE_API_STATICSET_HXX
#define DBACCESS_CORE_API_STATICSET_HXX

#ifndef DBACCESS_CORE_API_CACHESET_HXX
#include "CacheSet.hxx"
#endif

namespace dbaccess
{
    // is used when nothing is supported by the driver
    // we use a snapshot
    class OStaticSet : public OCacheSet
    {
        ORowSetMatrix           m_aSet;
        ORowSetMatrix::iterator m_aSetIter;
        sal_Bool                m_bEnd;
        sal_Bool fetchRow();
        void fillAllRows();
    public:
        OStaticSet()
            : m_aSetIter(m_aSet.end())
            , m_bEnd(sal_False)
        {
            m_aSet.push_back(NULL); // this is the beforefirst record
        }

        virtual void fillValueRow(ORowSetRow& _rRow,sal_Int32 _nPosition);
        // ::com::sun::star::sdbcx::XRowLocate
        virtual ::com::sun::star::uno::Any SAL_CALL getBookmark( const ORowSetRow& _rRow ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Bool SAL_CALL moveToBookmark( const ::com::sun::star::uno::Any& bookmark ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Bool SAL_CALL moveRelativeToBookmark( const ::com::sun::star::uno::Any& bookmark, sal_Int32 rows ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Int32 SAL_CALL compareBookmarks( const ::com::sun::star::uno::Any& first, const ::com::sun::star::uno::Any& second ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Bool SAL_CALL hasOrderedBookmarks(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Int32 SAL_CALL hashBookmark( const ::com::sun::star::uno::Any& bookmark ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);

        // ::com::sun::star::sdbc::XResultSet
        virtual sal_Bool SAL_CALL next(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Bool SAL_CALL isBeforeFirst(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Bool SAL_CALL isAfterLast(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Bool SAL_CALL isFirst(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Bool SAL_CALL isLast(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual void SAL_CALL beforeFirst(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual void SAL_CALL afterLast(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Bool SAL_CALL first(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Bool SAL_CALL last(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Int32 SAL_CALL getRow(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Bool SAL_CALL absolute( sal_Int32 row ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Bool SAL_CALL relative( sal_Int32 rows ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Bool SAL_CALL previous(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual void SAL_CALL refreshRow(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Bool SAL_CALL rowUpdated(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Bool SAL_CALL rowInserted(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Bool SAL_CALL rowDeleted(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        // ::com::sun::star::sdbcx::XDeleteRows
        virtual ::com::sun::star::uno::Sequence< sal_Int32 > SAL_CALL deleteRows( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& rows,const connectivity::OSQLTable& _xTable ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        // ::com::sun::star::sdbc::XResultSetUpdate
        virtual void SAL_CALL insertRow( const ORowSetRow& _rInsertRow,const connectivity::OSQLTable& _xTable ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual void SAL_CALL updateRow(const ORowSetRow& _rInsertRow,const ORowSetRow& _rOrginalRow,const connectivity::OSQLTable& _xTable  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual void SAL_CALL deleteRow(const ORowSetRow& _rInsertRow,const connectivity::OSQLTable& _xTable  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual void SAL_CALL cancelRowUpdates(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual void SAL_CALL moveToInsertRow(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual void SAL_CALL moveToCurrentRow(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
    };
}
#endif //DBACCESS_CORE_API_STATICSET_HXX

<commit_msg>INTEGRATION: CWS warnings01 (1.8.50); FILE MERGED 2006/03/24 15:35:47 fs 1.8.50.1: #i57457# warning-free code (unxlngi6/.pro + unxsoli4.pro)<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: StaticSet.hxx,v $
 *
 *  $Revision: 1.9 $
 *
 *  last change: $Author: hr $ $Date: 2006-06-20 02:38:06 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

#ifndef DBACCESS_CORE_API_STATICSET_HXX
#define DBACCESS_CORE_API_STATICSET_HXX

#ifndef DBACCESS_CORE_API_CACHESET_HXX
#include "CacheSet.hxx"
#endif

namespace dbaccess
{
    // is used when nothing is supported by the driver
    // we use a snapshot
    class OStaticSet : public OCacheSet
    {
        ORowSetMatrix           m_aSet;
        ORowSetMatrix::iterator m_aSetIter;
        sal_Bool                m_bEnd;
        sal_Bool fetchRow();
        void fillAllRows();
    public:
        OStaticSet()
            : m_aSetIter(m_aSet.end())
            , m_bEnd(sal_False)
        {
            m_aSet.push_back(NULL); // this is the beforefirst record
        }

        virtual void fillValueRow(ORowSetRow& _rRow,sal_Int32 _nPosition);
        // ::com::sun::star::sdbcx::XRowLocate
        virtual ::com::sun::star::uno::Any SAL_CALL getBookmark() throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Bool SAL_CALL moveToBookmark( const ::com::sun::star::uno::Any& bookmark ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Bool SAL_CALL moveRelativeToBookmark( const ::com::sun::star::uno::Any& bookmark, sal_Int32 rows ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Int32 SAL_CALL compareBookmarks( const ::com::sun::star::uno::Any& first, const ::com::sun::star::uno::Any& second ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Bool SAL_CALL hasOrderedBookmarks(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Int32 SAL_CALL hashBookmark( const ::com::sun::star::uno::Any& bookmark ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);

        // ::com::sun::star::sdbc::XResultSet
        virtual sal_Bool SAL_CALL next(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Bool SAL_CALL isBeforeFirst(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Bool SAL_CALL isAfterLast(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Bool SAL_CALL isFirst(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Bool SAL_CALL isLast(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual void SAL_CALL beforeFirst(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual void SAL_CALL afterLast(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Bool SAL_CALL first(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Bool SAL_CALL last(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Int32 SAL_CALL getRow(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Bool SAL_CALL absolute( sal_Int32 row ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Bool SAL_CALL relative( sal_Int32 rows ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Bool SAL_CALL previous(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual void SAL_CALL refreshRow(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Bool SAL_CALL rowUpdated(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Bool SAL_CALL rowInserted(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Bool SAL_CALL rowDeleted(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        // ::com::sun::star::sdbcx::XDeleteRows
        virtual ::com::sun::star::uno::Sequence< sal_Int32 > SAL_CALL deleteRows( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& rows,const connectivity::OSQLTable& _xTable ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        // ::com::sun::star::sdbc::XResultSetUpdate
        virtual void SAL_CALL insertRow( const ORowSetRow& _rInsertRow,const connectivity::OSQLTable& _xTable ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual void SAL_CALL updateRow(const ORowSetRow& _rInsertRow,const ORowSetRow& _rOrginalRow,const connectivity::OSQLTable& _xTable  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual void SAL_CALL deleteRow(const ORowSetRow& _rInsertRow,const connectivity::OSQLTable& _xTable  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual void SAL_CALL cancelRowUpdates(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual void SAL_CALL moveToInsertRow(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual void SAL_CALL moveToCurrentRow(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
    };
}
#endif //DBACCESS_CORE_API_STATICSET_HXX

<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  $RCSfile: RelationDlg.hxx,v $
 *
 *  $Revision: 1.4 $
 *
 *  last change: $Author: oj $ $Date: 2001-10-08 07:26:30 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the License); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an AS IS basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/
#ifndef DBAUI_RELATIONDIALOG_HXX
#define DBAUI_RELATIONDIALOG_HXX

#ifndef _DIALOG_HXX //autogen
#include <vcl/dialog.hxx>
#endif

#ifndef _BUTTON_HXX //autogen
#include <vcl/button.hxx>
#endif

#ifndef _FIXED_HXX //autogen
#include <vcl/fixed.hxx>
#endif

#ifndef _EDIT_HXX //autogen
#include <vcl/edit.hxx>
#endif

#ifndef _SV_LSTBOX_HXX //autogen
#include <vcl/lstbox.hxx>
#endif

#ifndef _SVTOOLS_EDITBROWSEBOX_HXX_
#include <svtools/editbrowsebox.hxx>
#endif

#ifndef _SV_MSGBOX_HXX
#include <vcl/msgbox.hxx>
#endif
#ifndef DBAUI_RTABLECONNECTIONDATA_HXX
#include "RTableConnectionData.hxx"
#endif
#ifndef _COM_SUN_STAR_SDBC_XCONNECTION_HPP_
#include <com/sun/star/sdbc/XConnection.hpp>
#endif

namespace dbaui
{
    //========================================================================
    class ORelationDialog;
    typedef ::svt::EditBrowseBox ORelationControl_Base;
    class ORelationControl : public ORelationControl_Base
    {
        friend class ORelationDialog;

        ULONG                                                                           m_nDeActivateEvent;
        ::svt::ListBoxControl*                                                          m_pListCell;
        ORelationTableConnectionData*                                                   m_pConnData;
        long                                                                            m_nDataPos;
        ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>        m_xSourceDef;
        ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>        m_xDestDef;

        void SetDef(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& xDest,sal_Int32 _nPos);
        void fillListBox(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _xDest);
    public:
        ORelationControl( ORelationDialog* pParent );
        virtual ~ORelationControl();

        void SetSourceDef(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _xNewSource);
        void SetDestDef(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _xNewDest);

    protected:
        virtual void Resize();

        virtual long PreNotify(NotifyEvent& rNEvt );

        virtual BOOL IsTabAllowed(BOOL bForward) const;

        virtual void Init(ORelationTableConnectionData* _pConnData);
        virtual void Init() { ORelationControl_Base::Init(); }
        virtual void InitController( ::svt::CellControllerRef& rController, long nRow, USHORT nCol );
        virtual ::svt::CellController* GetController( long nRow, USHORT nCol );
        virtual void PaintCell( OutputDevice& rDev, const Rectangle& rRect, USHORT nColId ) const;
        virtual BOOL SeekRow( long nRow );
        virtual BOOL SaveModified();
        virtual String GetCellText( long nRow, USHORT nColId );

        virtual void CellModified();

    private:

        DECL_LINK( AsynchActivate, void* );
        DECL_LINK( AsynchDeactivate, void* );
    };

    class OJoinTableView;
    //========================================================================
    class ORelationDialog : public ModalDialog
    {
        FixedLine   aFL_InvolvedTables;
        ListBox     m_lmbLeftTable,
                    m_lmbRightTable;

        FixedLine    aFL_InvolvedFields;

        FixedLine    aFL_CascUpd;
        RadioButton aRB_NoCascUpd,
                    aRB_CascUpd,
                    aRB_CascUpdNull,
                    aRB_CascUpdDefault;
        FixedLine    aFL_CascDel;
        RadioButton aRB_NoCascDel,
                    aRB_CascDel,
                    aRB_CascDelNull,
                    aRB_CascDelDefault;

        OKButton    aPB_OK;
        CancelButton aPB_CANCEL;
        HelpButton  aPB_HELP;

        ORelationControl*                                                       m_pRC_Tables;
        ORelationTableConnectionData*                                           m_pConnData;
        ORelationTableConnectionData*                                           m_pOrigConnData;
        ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > m_xConnection;

        String                                                                  m_strCurrentLeft;
        String                                                                  m_strCurrentRight;
        BOOL                                                                    m_bTriedOneUpdate;

    public:
        ORelationDialog(OJoinTableView* pParent,
                        ORelationTableConnectionData* pConnectionData,
                        BOOL bAllowTableSelect = FALSE );
        virtual ~ORelationDialog();

        ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > getConnection(){ return m_xConnection; }

        void NotifyCellChange();

        virtual short Execute();

    protected:
        void Init(ORelationTableConnectionData* _pConnData);

    private:
        DECL_LINK( OKClickHdl, Button* );
        DECL_LINK( OnTableChanged, ListBox* );
    };
}
#endif // DBAUI_RELATIONDIALOG_HXX

<commit_msg>#86640# fillListBox signature changed<commit_after>/*************************************************************************
 *
 *  $RCSfile: RelationDlg.hxx,v $
 *
 *  $Revision: 1.5 $
 *
 *  last change: $Author: fs $ $Date: 2001-10-16 15:12:29 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the License); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an AS IS basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/
#ifndef DBAUI_RELATIONDIALOG_HXX
#define DBAUI_RELATIONDIALOG_HXX

#ifndef _DIALOG_HXX //autogen
#include <vcl/dialog.hxx>
#endif

#ifndef _BUTTON_HXX //autogen
#include <vcl/button.hxx>
#endif

#ifndef _FIXED_HXX //autogen
#include <vcl/fixed.hxx>
#endif

#ifndef _EDIT_HXX //autogen
#include <vcl/edit.hxx>
#endif

#ifndef _SV_LSTBOX_HXX //autogen
#include <vcl/lstbox.hxx>
#endif

#ifndef _SVTOOLS_EDITBROWSEBOX_HXX_
#include <svtools/editbrowsebox.hxx>
#endif

#ifndef _SV_MSGBOX_HXX
#include <vcl/msgbox.hxx>
#endif
#ifndef DBAUI_RTABLECONNECTIONDATA_HXX
#include "RTableConnectionData.hxx"
#endif
#ifndef _COM_SUN_STAR_SDBC_XCONNECTION_HPP_
#include <com/sun/star/sdbc/XConnection.hpp>
#endif

namespace dbaui
{
    //========================================================================
    class ORelationDialog;
    typedef ::svt::EditBrowseBox ORelationControl_Base;
    class ORelationControl : public ORelationControl_Base
    {
        friend class ORelationDialog;

        ULONG                                                                           m_nDeActivateEvent;
        ::svt::ListBoxControl*                                                          m_pListCell;
        ORelationTableConnectionData*                                                   m_pConnData;
        long                                                                            m_nDataPos;
        ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>        m_xSourceDef;
        ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>        m_xDestDef;

        void SetDef(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& xDest,sal_Int32 _nPos);
        void fillListBox(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _xDest,long nRow,USHORT nColumnId);
    public:
        ORelationControl( ORelationDialog* pParent );
        virtual ~ORelationControl();

        void SetSourceDef(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _xNewSource);
        void SetDestDef(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _xNewDest);

    protected:
        virtual void Resize();

        virtual long PreNotify(NotifyEvent& rNEvt );

        virtual BOOL IsTabAllowed(BOOL bForward) const;

        virtual void Init(ORelationTableConnectionData* _pConnData);
        virtual void Init() { ORelationControl_Base::Init(); }
        virtual void InitController( ::svt::CellControllerRef& rController, long nRow, USHORT nCol );
        virtual ::svt::CellController* GetController( long nRow, USHORT nCol );
        virtual void PaintCell( OutputDevice& rDev, const Rectangle& rRect, USHORT nColId ) const;
        virtual BOOL SeekRow( long nRow );
        virtual BOOL SaveModified();
        virtual String GetCellText( long nRow, USHORT nColId );

        virtual void CellModified();

    private:

        DECL_LINK( AsynchActivate, void* );
        DECL_LINK( AsynchDeactivate, void* );
    };

    class OJoinTableView;
    //========================================================================
    class ORelationDialog : public ModalDialog
    {
        FixedLine   aFL_InvolvedTables;
        ListBox     m_lmbLeftTable,
                    m_lmbRightTable;

        FixedLine    aFL_InvolvedFields;

        FixedLine    aFL_CascUpd;
        RadioButton aRB_NoCascUpd,
                    aRB_CascUpd,
                    aRB_CascUpdNull,
                    aRB_CascUpdDefault;
        FixedLine    aFL_CascDel;
        RadioButton aRB_NoCascDel,
                    aRB_CascDel,
                    aRB_CascDelNull,
                    aRB_CascDelDefault;

        OKButton    aPB_OK;
        CancelButton aPB_CANCEL;
        HelpButton  aPB_HELP;

        ORelationControl*                                                       m_pRC_Tables;
        ORelationTableConnectionData*                                           m_pConnData;
        ORelationTableConnectionData*                                           m_pOrigConnData;
        ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > m_xConnection;

        String                                                                  m_strCurrentLeft;
        String                                                                  m_strCurrentRight;
        BOOL                                                                    m_bTriedOneUpdate;

    public:
        ORelationDialog(OJoinTableView* pParent,
                        ORelationTableConnectionData* pConnectionData,
                        BOOL bAllowTableSelect = FALSE );
        virtual ~ORelationDialog();

        ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > getConnection(){ return m_xConnection; }

        void NotifyCellChange();

        virtual short Execute();

    protected:
        void Init(ORelationTableConnectionData* _pConnData);

    private:
        DECL_LINK( OKClickHdl, Button* );
        DECL_LINK( OnTableChanged, ListBox* );
    };
}
#endif // DBAUI_RELATIONDIALOG_HXX

<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  $RCSfile: undosqledit.hxx,v $
 *
 *  $Revision: 1.4 $
 *
 *  last change: $Author: oj $ $Date: 2002-08-19 07:28:27 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the License); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an AS IS basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/
#ifndef DBAUI_UNDOSQLEDIT_HXX
#define DBAUI_UNDOSQLEDIT_HXX

#ifndef DBAUI_GENERALUNDO_HXX
#include "GeneralUndo.hxx"
#endif
#ifndef _DBU_CONTROL_HRC_
#include "dbu_control.hrc"
#endif

namespace dbaui
{
    class OSqlEdit;
    // ================================================================================================
    // OSqlEditUndoAct - Undo-class for changing sql text
    //------------------------------------------------------------------------
    class OSqlEditUndoAct : public OCommentUndoAction
    {
    protected:
        OSqlEdit*   m_pOwner;
        String      m_strNextText;

        virtual void    Undo() { ToggleText(); }
        virtual void    Redo() { ToggleText(); }

        void ToggleText();
    public:
        OSqlEditUndoAct(OSqlEdit* pEdit) : OCommentUndoAction(STR_QUERY_UNDO_MODIFYSQLEDIT), m_pOwner(pEdit) { }

        void SetOriginalText(const String& strText) { m_strNextText = strText; }
    };
}
#endif // DBAUI_UNDOSQLEDIT_HXX

<commit_msg>INTEGRATION: CWS insight01 (1.4.108); FILE MERGED 2004/07/09 13:44:05 oj 1.4.108.1: resource changes<commit_after>/*************************************************************************
 *
 *  $RCSfile: undosqledit.hxx,v $
 *
 *  $Revision: 1.5 $
 *
 *  last change: $Author: hr $ $Date: 2004-08-02 16:03:20 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the License); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an AS IS basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/
#ifndef DBAUI_UNDOSQLEDIT_HXX
#define DBAUI_UNDOSQLEDIT_HXX

#ifndef DBAUI_GENERALUNDO_HXX
#include "GeneralUndo.hxx"
#endif
#ifndef _DBU_CONTROL_HRC_
#include "dbu_control.hrc"
#endif

namespace dbaui
{
    class OSqlEdit;
    // ================================================================================================
    // OSqlEditUndoAct - Undo-class for changing sql text
    //------------------------------------------------------------------------
    class OSqlEditUndoAct : public OCommentUndoAction
    {
    protected:
        OSqlEdit*   m_pOwner;
        String      m_strNextText;

        virtual void    Undo() { ToggleText(); }
        virtual void    Redo() { ToggleText(); }

        void ToggleText();
    public:
        OSqlEditUndoAct(OSqlEdit* pEdit) : OCommentUndoAction(STR_QUERY_UNDO_MODIFYSQLEDIT), m_pOwner(pEdit) { }

        void SetOriginalText(const String& strText) { m_strNextText =strText; }
    };
}
#endif // DBAUI_UNDOSQLEDIT_HXX

<|endoftext|>


<commit_before><commit_msg>unused parameter<commit_after><|endoftext|>