diff --git a/examples/cpp/costas_array.cc b/examples/cpp/costas_array.cc index e87c755e48..2ccd99f31c 100644 --- a/examples/cpp/costas_array.cc +++ b/examples/cpp/costas_array.cc @@ -86,17 +86,16 @@ bool CheckCostas(const std::vector& vars) { } // Cycles all possible permutations -class OrderedLNS: public BaseLNS { +class OrderedLNS : public BaseLNS { public: - OrderedLNS(const std::vector& vars, int free_elements) : - BaseLNS(vars), - free_elements_(free_elements) { + OrderedLNS(const std::vector& vars, int free_elements) + : BaseLNS(vars), free_elements_(free_elements) { index_ = 0; // Start of with the first free_elements_ as a permutations, eg. 0,1,2,3,... for (int i = 0; i < free_elements; ++i) { - index_ += i * pow(static_cast(vars.size()), - free_elements - i - 1); + index_ += + i * pow(static_cast(vars.size()), free_elements - i - 1); } } @@ -114,8 +113,7 @@ class OrderedLNS: public BaseLNS { int current_index = work_index % dim; work_index = work_index / dim; - std::pair::iterator, bool> ret = - fragment_set.insert(current_index); + std::pair::iterator, bool> ret = fragment_set.insert(current_index); // Check if element has been used before if (ret.second) { @@ -127,7 +125,7 @@ class OrderedLNS: public BaseLNS { // Go to next possible permutation ++index_; - // Try again if a duplicate index is used + // Try again if a duplicate index is used } while (fragment_set.size() < free_elements_); return true; @@ -140,13 +138,12 @@ class OrderedLNS: public BaseLNS { // RandomLNS is used for the local search and frees the // number of elements specified in 'free_elements' randomly. -class RandomLNS: public BaseLNS { +class RandomLNS : public BaseLNS { public: - RandomLNS(const std::vector& vars, int free_elements) : - BaseLNS(vars), - free_elements_(free_elements), - rand_(ACMRandom::HostnamePidTimeSeed()) { - } + RandomLNS(const std::vector& vars, int free_elements) + : BaseLNS(vars), + free_elements_(free_elements), + rand_(ACMRandom::HostnamePidTimeSeed()) {} virtual bool NextFragment(std::vector* const fragment) { std::vector weighted_elements; @@ -172,7 +169,7 @@ class RandomLNS: public BaseLNS { // Remove all elements with this index from weighted_elements for (std::vector::iterator pos = weighted_elements.begin(); - pos != weighted_elements.end(); ) { + pos != weighted_elements.end();) { if (*pos == index) { // Try to erase as many elements as possible at the same time std::vector::iterator end = pos; @@ -203,9 +200,7 @@ class Evaluator { explicit Evaluator(const std::vector& vars) : vars_(vars) {} // Prefer the value with the smallest domain - int64 VarEvaluator(int64 index) { - return vars_[index]->Size(); - } + int64 VarEvaluator(int64 index) { return vars_[index]->Size(); } // Penalize for each time the value appears in a different domain, // as values have to be unique @@ -220,6 +215,7 @@ class Evaluator { return appearance; } + private: std::vector vars_; }; @@ -263,15 +259,14 @@ void CostasSoft(const int dim) { // them to be unique. std::vector matrix_count; solver.MakeIntVarArray(2 * dim + 1, 0, dim, "matrix_count_", &matrix_count); - solver.AddConstraint(solver.MakeDistribute(matrix, possible_values, - matrix_count)); + solver.AddConstraint( + solver.MakeDistribute(matrix, possible_values, matrix_count)); // Here we only consider the elements from 1 to dim. for (int64 j = dim + 1; j <= 2 * dim; ++j) { // Penalize if an element occurs more than once. - vars[index] - = solver.MakeSemiContinuousExpr(solver.MakeSum(matrix_count[j], -1), - 0, 1)->Var(); + vars[index] = solver.MakeSemiContinuousExpr( + solver.MakeSum(matrix_count[j], -1), 0, 1)->Var(); occurences.push_back(vars[index++]); } @@ -289,15 +284,14 @@ void CostasSoft(const int dim) { // Count the number of occurrences for all possible values std::vector domain_count; solver.MakeIntVarArray(2 * dim + 1, 0, dim, "domain_count_", &domain_count); - solver.AddConstraint(solver.MakeDistribute(subset, - possible_values, - domain_count)); + solver.AddConstraint( + solver.MakeDistribute(subset, possible_values, domain_count)); // Penalize occurrences of more than one for (int64 j = 0; j <= 2 * dim; ++j) { vars[index] = - solver.MakeSemiContinuousExpr(solver.MakeSum(domain_count[j], -1), - 0, dim - i)->Var(); + solver.MakeSemiContinuousExpr(solver.MakeSum(domain_count[j], -1), 0, + dim - i)->Var(); occurences.push_back(vars[index++]); } @@ -315,19 +309,16 @@ void CostasSoft(const int dim) { // The first solution that the local optimization is based on Evaluator evaluator(matrix); - DecisionBuilder* const first_solution = - solver.MakePhase(matrix, - NewPermanentCallback(&evaluator, - &Evaluator::VarEvaluator), - NewPermanentCallback(&evaluator, - &Evaluator::ValueEvaluator)); + DecisionBuilder* const first_solution = solver.MakePhase( + matrix, NewPermanentCallback(&evaluator, &Evaluator::VarEvaluator), + NewPermanentCallback(&evaluator, &Evaluator::ValueEvaluator)); SearchLimit* const search_time_limit = solver.MakeLimit(FLAGS_timelimit, kint64max, kint64max, kint64max); // Locally optimize solutions for LNS - SearchLimit* const fail_limit = solver.MakeLimit(kint64max, kint64max, - FLAGS_sublimit, kint64max); + SearchLimit* const fail_limit = + solver.MakeLimit(kint64max, kint64max, FLAGS_sublimit, kint64max); DecisionBuilder* const subdecision_builder = solver.MakeSolveOnce(first_solution, fail_limit); @@ -351,10 +342,7 @@ void CostasSoft(const int dim) { solver.MakeLocalSearchPhase(matrix, first_solution, ls_params); // Try to find a solution - solver.Solve(second_phase, - collector, - log, - total_duplicates, + solver.Solve(second_phase, collector, log, total_duplicates, search_time_limit); if (collector->solution_count() > 0) { @@ -407,9 +395,8 @@ void CostasHard(const int dim) { solver.AddConstraint(solver.MakeAllDifferent(subset)); } - DecisionBuilder* const db = solver.MakePhase(vars, - Solver::CHOOSE_FIRST_UNBOUND, - Solver::ASSIGN_MIN_VALUE); + DecisionBuilder* const db = solver.MakePhase( + vars, Solver::CHOOSE_FIRST_UNBOUND, Solver::ASSIGN_MIN_VALUE); solver.NewSearch(db); if (solver.NextSolution()) { @@ -424,8 +411,8 @@ void CostasHard(const int dim) { LOG(INFO) << output << " (" << solver.wall_time() << "ms)"; - CHECK(CheckCostas(costas_matrix)) << - ": Solution is not a valid Costas Matrix."; + CHECK(CheckCostas(costas_matrix)) + << ": Solution is not a valid Costas Matrix."; } else { LOG(INFO) << "No solution found."; } @@ -435,7 +422,7 @@ void CostasHard(const int dim) { } } // namespace operations_research -int main(int argc, char **argv) { +int main(int argc, char** argv) { google::ParseCommandLineFlags( &argc, &argv, true); int min = 1; int max = 10; diff --git a/examples/cpp/cryptarithm.cc b/examples/cpp/cryptarithm.cc index fef78ee610..5f600bde69 100644 --- a/examples/cpp/cryptarithm.cc +++ b/examples/cpp/cryptarithm.cc @@ -74,9 +74,8 @@ void Cryptoarithmetics() { v2 = solver.MakeSum(o, solver.MakeProd(m, 10))->Var(); solver.AddConstraint(solver.MakeEquality(v1, v2)); - DecisionBuilder* const db = solver.MakePhase(letters, - Solver::CHOOSE_FIRST_UNBOUND, - Solver::ASSIGN_MIN_VALUE); + DecisionBuilder* const db = solver.MakePhase( + letters, Solver::CHOOSE_FIRST_UNBOUND, Solver::ASSIGN_MIN_VALUE); solver.NewSearch(db); if (solver.NextSolution()) { CHECK_EQ(s->Value(), 9); @@ -103,9 +102,9 @@ void Cryptoarithmetics() { solver.EndSearch(); } -} // namespace operations_research +} // namespace operations_research -int main(int argc, char **argv) { +int main(int argc, char** argv) { google::ParseCommandLineFlags( &argc, &argv, true); operations_research::Cryptoarithmetics(); return 0; diff --git a/examples/cpp/cvrptw.cc b/examples/cpp/cvrptw.cc index 806d747390..e3a76aaac6 100644 --- a/examples/cpp/cvrptw.cc +++ b/examples/cpp/cvrptw.cc @@ -71,9 +71,7 @@ class LocationContainer { : randomizer_(GetSeed()), speed_(speed) { CHECK_LT(0, speed_); } - void AddLocation(int64 x, int64 y) { - locations_.push_back(Location(x, y)); - } + void AddLocation(int64 x, int64 y) { locations_.push_back(Location(x, y)); } void AddRandomLocation(int64 x_max, int64 y_max) { AddLocation(randomizer_.Uniform(x_max + 1), randomizer_.Uniform(y_max + 1)); } @@ -94,6 +92,7 @@ class LocationContainer { int64 DistanceTo(const Location& location) const { return Abs(x_ - location.x_) + Abs(y_ - location.y_); } + private: static int64 Abs(int64 value) { return std::max(value, -value); } @@ -127,8 +126,7 @@ class RandomDemand { } } } - int64 Demand(RoutingModel::NodeIndex from, - RoutingModel::NodeIndex to) const { + int64 Demand(RoutingModel::NodeIndex from, RoutingModel::NodeIndex to) const { return demand_[from.value()]; } @@ -149,9 +147,10 @@ class ServiceTimePlusTransition { transition_time_(transition_time) {} int64 Compute(RoutingModel::NodeIndex from, RoutingModel::NodeIndex to) const { - return time_per_demand_unit_ * demand_->Run(from, to) - + transition_time_->Run(from, to); + return time_per_demand_unit_ * demand_->Run(from, to) + + transition_time_->Run(from, to); } + private: const int64 time_per_demand_unit_; std::unique_ptr demand_; @@ -183,8 +182,7 @@ void DisplayPlan(const RoutingModel& routing, const Assignment& plan) { const RoutingDimension& capacity_dimension = routing.GetDimensionOrDie(kCapacity); const RoutingDimension& time_dimension = routing.GetDimensionOrDie(kTime); - for (int route_number = 0; - route_number < routing.vehicles(); + for (int route_number = 0; route_number < routing.vehicles(); ++route_number) { int64 order = routing.Start(route_number); StringAppendF(&plan_output, "Route %d: ", route_number); @@ -195,9 +193,7 @@ void DisplayPlan(const RoutingModel& routing, const Assignment& plan) { IntVar* const load_var = capacity_dimension.CumulVar(order); IntVar* const time_var = time_dimension.CumulVar(order); StringAppendF(&plan_output, "%lld Load(%lld) Time(%lld, %lld) -> ", - order, - plan.Value(load_var), - plan.Min(time_var), + order, plan.Value(load_var), plan.Min(time_var), plan.Max(time_var)); if (routing.IsEnd(order)) break; order = plan.Value(routing.NextVar(order)); @@ -207,7 +203,7 @@ void DisplayPlan(const RoutingModel& routing, const Assignment& plan) { LOG(INFO) << plan_output; } -int main(int argc, char **argv) { +int main(int argc, char** argv) { google::ParseCommandLineFlags( &argc, &argv, true); CHECK_LT(0, FLAGS_vrp_orders) << "Specify an instance size greater than 0."; CHECK_LT(0, FLAGS_vrp_vehicles) << "Specify a non-null vehicle fleet size."; @@ -242,19 +238,17 @@ int main(int argc, char **argv) { demand.Initialize(); routing.AddDimension(NewPermanentCallback(&demand, &RandomDemand::Demand), kNullCapacitySlack, kVehicleCapacity, - /*fix_start_cumul_to_zero=*/ true, kCapacity); + /*fix_start_cumul_to_zero=*/true, kCapacity); // Adding time dimension constraints. const int64 kTimePerDemandUnit = 300; const int64 kHorizon = 24 * 3600; ServiceTimePlusTransition time( - kTimePerDemandUnit, - NewPermanentCallback(&demand, &RandomDemand::Demand), + kTimePerDemandUnit, NewPermanentCallback(&demand, &RandomDemand::Demand), NewPermanentCallback(&locations, &LocationContainer::ManhattanTime)); routing.AddDimension( - NewPermanentCallback(&time, - &ServiceTimePlusTransition::Compute), - kHorizon, kHorizon, /*fix_start_cumul_to_zero=*/ true, kTime); + NewPermanentCallback(&time, &ServiceTimePlusTransition::Compute), + kHorizon, kHorizon, /*fix_start_cumul_to_zero=*/true, kTime); const RoutingDimension& time_dimension = routing.GetDimensionOrDie(kTime); // Adding time windows. ACMRandom randomizer(GetSeed()); diff --git a/examples/cpp/dimacs_assignment.cc b/examples/cpp/dimacs_assignment.cc index ba90e41aed..478a906cd4 100644 --- a/examples/cpp/dimacs_assignment.cc +++ b/examples/cpp/dimacs_assignment.cc @@ -46,7 +46,8 @@ namespace operations_research { typedef ForwardStarStaticGraph GraphType; -template CostValue BuildAndSolveHungarianInstance( +template +CostValue BuildAndSolveHungarianInstance( const LinearSumAssignment& assignment) { const GraphType& graph = assignment.Graph(); typedef std::vector HungarianRow; @@ -56,19 +57,16 @@ template CostValue BuildAndSolveHungarianInstance( // First we have to find the biggest cost magnitude so we can // initialize the arc costs that aren't really there. CostValue largest_cost_magnitude = 0; - for (typename GraphType::ArcIterator arc_it(graph); - arc_it.Ok(); + for (typename GraphType::ArcIterator arc_it(graph); arc_it.Ok(); arc_it.Next()) { ArcIndex arc = arc_it.Index(); CostValue cost_magnitude = abs(assignment.ArcCost(arc)); largest_cost_magnitude = std::max(largest_cost_magnitude, cost_magnitude); } - double missing_arc_cost = static_cast((assignment.NumLeftNodes() * - largest_cost_magnitude) + - 1); + double missing_arc_cost = static_cast( + (assignment.NumLeftNodes() * largest_cost_magnitude) + 1); for (HungarianProblem::iterator row = hungarian_cost.begin(); - row != hungarian_cost.end(); - ++row) { + row != hungarian_cost.end(); ++row) { row->resize(assignment.NumNodes() - assignment.NumLeftNodes(), missing_arc_cost); } @@ -79,17 +77,15 @@ template CostValue BuildAndSolveHungarianInstance( // hungarian algorithm). We opt for the alternative of iterating // over hte arcs via adjacency lists, which gives us the arc tails // implicitly. - for (typename GraphType::NodeIterator node_it(graph); - node_it.Ok(); + for (typename GraphType::NodeIterator node_it(graph); node_it.Ok(); node_it.Next()) { NodeIndex node = node_it.Index(); NodeIndex tail = (node - GraphType::kFirstNode); for (typename GraphType::OutgoingArcIterator arc_it(graph, node); - arc_it.Ok(); - arc_it.Next()) { + arc_it.Ok(); arc_it.Next()) { ArcIndex arc = arc_it.Index(); - NodeIndex head = (graph.Head(arc) - assignment.NumLeftNodes() - - GraphType::kFirstNode); + NodeIndex head = + (graph.Head(arc) - assignment.NumLeftNodes() - GraphType::kFirstNode); double cost = static_cast(assignment.ArcCost(arc)); hungarian_cost[tail][head] = cost; } @@ -110,21 +106,20 @@ template CostValue BuildAndSolveHungarianInstance( return static_cast(result_cost); } -template void DisplayAssignment( - const LinearSumAssignment& assignment) { +template +void DisplayAssignment(const LinearSumAssignment& assignment) { for (typename LinearSumAssignment::BipartiteLeftNodeIterator node_it(assignment); - node_it.Ok(); - node_it.Next()) { + node_it.Ok(); node_it.Next()) { const NodeIndex left_node = node_it.Index(); const ArcIndex matching_arc = assignment.GetAssignmentArc(left_node); const NodeIndex right_node = assignment.Head(matching_arc); - VLOG(5) << "assigned (" << left_node << ", " << right_node << "): " - << assignment.ArcCost(matching_arc); + VLOG(5) << "assigned (" << left_node << ", " << right_node + << "): " << assignment.ArcCost(matching_arc); } } -template +template int SolveDimacsAssignment(int argc, char* argv[]) { std::string error_message; // Handle on the graph we will need to delete because the diff --git a/examples/cpp/dobble_ls.cc b/examples/cpp/dobble_ls.cc index 68ed91f0c9..049c7ce33a 100644 --- a/examples/cpp/dobble_ls.cc +++ b/examples/cpp/dobble_ls.cc @@ -42,15 +42,16 @@ #include "base/random.h" DEFINE_int32(symbols_per_card, 8, "Number of symbols per card."); -DEFINE_int32(ls_seed, 1, "Seed for the random number generator (used by " +DEFINE_int32(ls_seed, 1, + "Seed for the random number generator (used by " "the Local Neighborhood Search)."); DEFINE_bool(use_filter, true, "Use filter in the local search to prune moves."); -DEFINE_int32(num_swaps, 4, "If num_swap > 0, the search for an optimal " +DEFINE_int32(num_swaps, 4, + "If num_swap > 0, the search for an optimal " "solution will be allowed to use an operator that swaps the " "symbols of up to num_swap pairs ((card1, symbol on card1), " "(card2, symbol on card2))."); -DEFINE_int32(time_limit_in_ms, - 60000, +DEFINE_int32(time_limit_in_ms, 60000, "Time limit for the global search in ms."); namespace operations_research { @@ -196,12 +197,9 @@ IntVar* CreateViolationVar(Solver* const solver, IntVar* const num_symbols_in_common_var = solver->MakeIntVar(0, num_symbols_per_card); // RevAlloc transfers the ownership of the constraint to the solver. - solver->AddConstraint( - solver->RevAlloc( - new SymbolsSharedByTwoCardsConstraint(solver, - card1_symbol_vars, - card2_symbol_vars, - num_symbols_in_common_var))); + solver->AddConstraint(solver->RevAlloc(new SymbolsSharedByTwoCardsConstraint( + solver, card1_symbol_vars, card2_symbol_vars, + num_symbols_in_common_var))); return solver->MakeAbs(solver->MakeSum(num_symbols_in_common_var, -1))->Var(); } @@ -237,10 +235,8 @@ IntVar* CreateViolationVar(Solver* const solver, // compact representation of which symbols appeal on each cards. class DobbleOperator : public IntVarLocalSearchOperator { public: - DobbleOperator(const std::vector& card_symbol_vars, - int num_cards, - int num_symbols, - int num_symbols_per_card) + DobbleOperator(const std::vector& card_symbol_vars, int num_cards, + int num_symbols, int num_symbols_per_card) : IntVarLocalSearchOperator(card_symbol_vars), num_cards_(num_cards), num_symbols_(num_symbols), @@ -277,9 +273,7 @@ class DobbleOperator : public IntVarLocalSearchOperator { // Find the index of the variable corresponding to the given symbol // on the given card. - int VarIndex(int card, int symbol) { - return card * num_symbols_ + symbol; - } + int VarIndex(int card, int symbol) { return card * num_symbols_ + symbol; } // Move symbol1 from card1 to card2, and symbol2 from card2 to card1. void SwapTwoSymbolsOnCards(int card1, int symbol1, int card2, int symbol2) { @@ -306,19 +300,14 @@ class DobbleOperator : public IntVarLocalSearchOperator { // below to see how we filter those out. class SwapSymbols : public DobbleOperator { public: - SwapSymbols(const std::vector& card_symbol_vars, - int num_cards, - int num_symbols, - int num_symbols_per_card) - : DobbleOperator(card_symbol_vars, - num_cards, - num_symbols, + SwapSymbols(const std::vector& card_symbol_vars, int num_cards, + int num_symbols, int num_symbols_per_card) + : DobbleOperator(card_symbol_vars, num_cards, num_symbols, num_symbols_per_card), current_card1_(-1), current_card2_(-1), current_symbol1_(-1), - current_symbol2_(-1) { - } + current_symbol2_(-1) {} virtual ~SwapSymbols() {} @@ -381,14 +370,10 @@ class SwapSymbols : public DobbleOperator { // one. class SwapSymbolsOnCardPairs : public DobbleOperator { public: - SwapSymbolsOnCardPairs(const std::vector& card_symbol_vars, - int num_cards, - int num_symbols, - int num_symbols_per_card, + SwapSymbolsOnCardPairs(const std::vector& card_symbol_vars, int num_cards, + int num_symbols, int num_symbols_per_card, int max_num_swaps) - : DobbleOperator(card_symbol_vars, - num_cards, - num_symbols, + : DobbleOperator(card_symbol_vars, num_cards, num_symbols, num_symbols_per_card), rand_(FLAGS_ls_seed), max_num_swaps_(max_num_swaps) { @@ -448,10 +433,8 @@ class SwapSymbolsOnCardPairs : public DobbleOperator { // of symbols per card to 8. class DobbleFilter : public IntVarLocalSearchFilter { public: - DobbleFilter(const std::vector& card_symbol_vars, - int num_cards, - int num_symbols, - int num_symbols_per_card) + DobbleFilter(const std::vector& card_symbol_vars, int num_cards, + int num_symbols, int num_symbols_per_card) : IntVarLocalSearchFilter(card_symbol_vars), num_cards_(num_cards), num_symbols_(num_symbols), @@ -473,9 +456,8 @@ class DobbleFilter : public IntVarLocalSearchFilter { } for (int card1 = 0; card1 < num_cards_; ++card1) { for (int card2 = 0; card2 < num_cards_; ++card2) { - violation_costs_[card1][card2] = - ViolationCost(BitCount64(symbol_bitmask_per_card_[card1] & - symbol_bitmask_per_card_[card2])); + violation_costs_[card1][card2] = ViolationCost(BitCount64( + symbol_bitmask_per_card_[card1] & symbol_bitmask_per_card_[card2])); } } DCHECK(CheckCards()); @@ -508,12 +490,11 @@ class DobbleFilter : public IntVarLocalSearchFilter { // of this file. for (int i = 0; i < solution_delta_size; ++i) { if (!solution_delta.Element(i).Activated()) { - VLOG(1) - << "Element #" << i << " of the delta assignment given to" - << " DobbleFilter::Accept() is not activated (i.e. its variable" - << " is not bound to a single value anymore). This means that" - << " we are in a LNS phase, and the DobbleFilter won't be able" - << " to filter anything. Returning true."; + VLOG(1) << "Element #" << i << " of the delta assignment given to" + << " DobbleFilter::Accept() is not activated (i.e. its variable" + << " is not bound to a single value anymore). This means that" + << " we are in a LNS phase, and the DobbleFilter won't be able" + << " to filter anything. Returning true."; return true; } } @@ -553,13 +534,9 @@ class DobbleFilter : public IntVarLocalSearchFilter { uint64 bitset; }; - int VarIndex(int card, int symbol) { - return card * num_symbols_ + symbol; - } + int VarIndex(int card, int symbol) { return card * num_symbols_ + symbol; } - void ClearBitset() { - temporary_bitset_ = 0; - } + void ClearBitset() { temporary_bitset_ = 0; } // For each touched card, compare against all others to compute the // delta in term of cost. We use an bitset to avoid counting twice @@ -574,9 +551,8 @@ class DobbleFilter : public IntVarLocalSearchFilter { const std::vector& row_cost = violation_costs_[touched]; for (int other_card = 0; other_card < num_cards_; ++other_card) { if (!IsBitSet64(&temporary_bitset_, other_card)) { - cost_delta += - ViolationCost(BitCount64(card_bitset & - symbol_bitmask_per_card_[other_card])); + cost_delta += ViolationCost( + BitCount64(card_bitset & symbol_bitmask_per_card_[other_card])); cost_delta -= row_cost[other_card]; } } @@ -621,8 +597,8 @@ class DobbleFilter : public IntVarLocalSearchFilter { // Stores undo information for a given card. void SaveRestoreInformation(int card) { - restore_information_.push_back(UndoChange(card, - symbol_bitmask_per_card_[card])); + restore_information_.push_back( + UndoChange(card, symbol_bitmask_per_card_[card])); } // Checks that after the local search move, each card would still have @@ -631,7 +607,7 @@ class DobbleFilter : public IntVarLocalSearchFilter { for (int i = 0; i < num_cards_; ++i) { if (num_symbols_per_card_ != BitCount64(symbol_bitmask_per_card_[i])) { VLOG(1) << "card " << i << " has bitset of size " - << BitCount64(symbol_bitmask_per_card_[i]); + << BitCount64(symbol_bitmask_per_card_[i]); return false; } } @@ -665,12 +641,9 @@ void SolveDobble(int num_cards, int num_symbols, int num_symbols_per_card) { std::vector > card_symbol_vars(num_cards); std::vector all_card_symbol_vars; for (int card_index = 0; card_index < num_cards; ++card_index) { - solver.MakeBoolVarArray(num_symbols, - StringPrintf("card_%i_", card_index), + solver.MakeBoolVarArray(num_symbols, StringPrintf("card_%i_", card_index), &card_symbol_vars[card_index]); - for (int symbol_index = 0; - symbol_index < num_symbols; - ++symbol_index) { + for (int symbol_index = 0; symbol_index < num_symbols; ++symbol_index) { all_card_symbol_vars.push_back( card_symbol_vars[card_index][symbol_index]); } @@ -681,10 +654,9 @@ void SolveDobble(int num_cards, int num_symbols, int num_symbols_per_card) { for (int card1 = 0; card1 < num_cards; ++card1) { for (int card2 = 0; card2 < num_cards; ++card2) { if (card1 != card2) { - violation_vars.push_back(CreateViolationVar(&solver, - card_symbol_vars[card1], - card_symbol_vars[card2], - num_symbols_per_card)); + violation_vars.push_back( + CreateViolationVar(&solver, card_symbol_vars[card1], + card_symbol_vars[card2], num_symbols_per_card)); } } } @@ -694,8 +666,8 @@ void SolveDobble(int num_cards, int num_symbols, int num_symbols_per_card) { // Add constraint: there must be exactly num_symbols_per_card // symbols per card. for (int card = 0; card < num_cards; ++card) { - solver.AddConstraint(solver.MakeSumEquality(card_symbol_vars[card], - num_symbols_per_card)); + solver.AddConstraint( + solver.MakeSumEquality(card_symbol_vars[card], num_symbols_per_card)); } // IMPORTANT OPTIMIZATION: @@ -708,7 +680,7 @@ void SolveDobble(int num_cards, int num_symbols, int num_symbols_per_card) { std::vector tmp; for (int card_index = 0; card_index < num_cards; ++card_index) { tmp.push_back(card_symbol_vars[card_index][symbol_index]); - } + } solver.AddConstraint(solver.MakeSumEquality(tmp, num_symbols_per_card)); } @@ -720,56 +692,43 @@ void SolveDobble(int num_cards, int num_symbols, int num_symbols_per_card) { // strategy "Pick some random, yet unassigned card symbol variable // and set its value to 1". DecisionBuilder* const build_db = solver.MakePhase( - all_card_symbol_vars, - Solver::CHOOSE_RANDOM, // Solver::IntVarStrategy - Solver::ASSIGN_MAX_VALUE); // Solver::IntValueStrategy + all_card_symbol_vars, Solver::CHOOSE_RANDOM, // Solver::IntVarStrategy + Solver::ASSIGN_MAX_VALUE); // Solver::IntValueStrategy // Creates local search operators. std::vector operators; - LocalSearchOperator* const switch_operator = - solver.RevAlloc(new SwapSymbols(all_card_symbol_vars, - num_cards, - num_symbols, - num_symbols_per_card)); + LocalSearchOperator* const switch_operator = solver.RevAlloc(new SwapSymbols( + all_card_symbol_vars, num_cards, num_symbols, num_symbols_per_card)); operators.push_back(switch_operator); LOG(INFO) << " - add switch operator"; if (FLAGS_num_swaps > 0) { - LocalSearchOperator* const swaps_operator = - solver.RevAlloc(new SwapSymbolsOnCardPairs(all_card_symbol_vars, - num_cards, - num_symbols, - num_symbols_per_card, - FLAGS_num_swaps)); + LocalSearchOperator* const swaps_operator = solver.RevAlloc( + new SwapSymbolsOnCardPairs(all_card_symbol_vars, num_cards, num_symbols, + num_symbols_per_card, FLAGS_num_swaps)); operators.push_back(swaps_operator); - LOG(INFO) << " - add swaps operator with at most " - << FLAGS_num_swaps << " swaps"; + LOG(INFO) << " - add swaps operator with at most " << FLAGS_num_swaps + << " swaps"; } // Creates filter. std::vector filters; if (FLAGS_use_filter) { - filters.push_back(solver.RevAlloc( - new DobbleFilter(all_card_symbol_vars, - num_cards, - num_symbols, - num_symbols_per_card))); + filters.push_back(solver.RevAlloc(new DobbleFilter( + all_card_symbol_vars, num_cards, num_symbols, num_symbols_per_card))); } // Main decision builder that regroups the first solution decision // builder and the combination of local search operators and // filters. - DecisionBuilder* const final_db = - solver.MakeLocalSearchPhase( - all_card_symbol_vars, - build_db, - solver.MakeLocalSearchPhaseParameters( - solver.ConcatenateOperators(operators, true), - NULL, // Sub decision builder, not needed here. - NULL, // Limit the search for improving move, we will stop - // the exploration of the local search at the first - // improving solution (first accept). - filters)); - + DecisionBuilder* const final_db = solver.MakeLocalSearchPhase( + all_card_symbol_vars, build_db, + solver.MakeLocalSearchPhaseParameters( + solver.ConcatenateOperators(operators, true), + NULL, // Sub decision builder, not needed here. + NULL, // Limit the search for improving move, we will stop + // the exploration of the local search at the first + // improving solution (first accept). + filters)); std::vector monitors; // Optimize var search monitor. @@ -790,15 +749,13 @@ void SolveDobble(int num_cards, int num_symbols, int num_symbols_per_card) { } } // namespace operations_research -int main(int argc, char **argv) { +int main(int argc, char** argv) { google::ParseCommandLineFlags( &argc, &argv, true); // These constants comes directly from the dobble game. // There are actually 55 cards, but we can create up to 57 cards. const int kSymbolsPerCard = FLAGS_symbols_per_card; const int kCards = kSymbolsPerCard * (kSymbolsPerCard - 1) + 1; const int kSymbols = kCards; - operations_research::SolveDobble(kCards, - kSymbols, - kSymbolsPerCard); + operations_research::SolveDobble(kCards, kSymbols, kSymbolsPerCard); return 0; } diff --git a/examples/cpp/flow_api.cc b/examples/cpp/flow_api.cc index 18b6bcb622..ddeed9880f 100644 --- a/examples/cpp/flow_api.cc +++ b/examples/cpp/flow_api.cc @@ -27,12 +27,10 @@ void MinCostFlowOn4x4Matrix() { LOG(INFO) << "Min Cost Flow on 4x4 Matrix"; const int kNumSources = 4; const int kNumTargets = 4; - const CostValue kCost[kNumSources][kNumTargets] = { - { 90, 75, 75, 80 }, - { 35, 85, 55, 65 }, - { 125, 95, 90, 105 }, - { 45, 110, 95, 115 } - }; + const CostValue kCost[kNumSources][kNumTargets] = {{90, 75, 75, 80}, + {35, 85, 55, 65}, + {125, 95, 90, 105}, + {45, 110, 95, 115}}; const CostValue kExpectedCost = 275; StarGraph graph(kNumSources + kNumTargets, kNumSources * kNumTargets); MinCostFlow min_cost_flow(&graph); @@ -61,10 +59,10 @@ void MaxFeasibleFlow() { LOG(INFO) << "Max Feasible Flow"; const int kNumNodes = 6; const int kNumArcs = 9; - const NodeIndex kTail[kNumArcs] = { 0, 0, 0, 0, 1, 2, 3, 3, 4 }; - const NodeIndex kHead[kNumArcs] = { 1, 2, 3, 4, 3, 4, 4, 5, 5 }; - const FlowQuantity kCapacity[kNumArcs] = { 5, 8, 5, 3, 4, 5, 6, 6, 4 }; - const FlowQuantity kExpectedFlow[kNumArcs] = { 1, 1, 5, 3, 1, 1, 0, 6, 4 }; + const NodeIndex kTail[kNumArcs] = {0, 0, 0, 0, 1, 2, 3, 3, 4}; + const NodeIndex kHead[kNumArcs] = {1, 2, 3, 4, 3, 4, 4, 5, 5}; + const FlowQuantity kCapacity[kNumArcs] = {5, 8, 5, 3, 4, 5, 6, 6, 4}; + const FlowQuantity kExpectedFlow[kNumArcs] = {1, 1, 5, 3, 1, 1, 0, 6, 4}; const FlowQuantity kExpectedTotalFlow = 10; StarGraph graph(kNumNodes, kNumArcs); MaxFlow max_flow(&graph, 0, kNumNodes - 1); @@ -82,10 +80,9 @@ void MaxFeasibleFlow() { } } // namespace operations_research -int main(int argc, char **argv) { +int main(int argc, char** argv) { google::ParseCommandLineFlags( &argc, &argv, true); operations_research::MinCostFlowOn4x4Matrix(); operations_research::MaxFeasibleFlow(); return 0; } - diff --git a/examples/cpp/golomb.cc b/examples/cpp/golomb.cc index f0e429eed3..34defdb19d 100644 --- a/examples/cpp/golomb.cc +++ b/examples/cpp/golomb.cc @@ -34,14 +34,14 @@ #include "constraint_solver/constraint_solver.h" DEFINE_bool(print, false, "If true, print the minimal solution."); -DEFINE_int32(size, 0, - "Size of the problem. If equal to 0, will test several increasing sizes."); +DEFINE_int32( + size, 0, + "Size of the problem. If equal to 0, will test several increasing sizes."); -static const int kBestSolutions[] = { - 0, 1, 3, 6, 11, 17, 25, 34, 44, 55, 72, 85, - // just for the optimistics ones, the rest: - 106, 127, 151, 177, 199, 216, 246 -}; +static const int kBestSolutions[] = {0, 1, 3, 6, 11, 17, 25, + 34, 44, 55, 72, 85, + // just for the optimistics ones, the rest: + 106, 127, 151, 177, 199, 216, 246}; static const int kKnownSolutions = 19; @@ -53,7 +53,7 @@ void GolombRuler(int size) { // model std::vector ticks(size); - ticks[0] = s.MakeIntConst(0); // X(0) = 0 + ticks[0] = s.MakeIntConst(0); // X(0) = 0 const int64 max = 1 + size * size * size; for (int i = 1; i < size; ++i) { ticks[i] = s.MakeIntVar(1, max, StringPrintf("X%02d", i)); @@ -68,18 +68,17 @@ void GolombRuler(int size) { } s.AddConstraint(s.MakeAllDifferent(diffs)); - OptimizeVar* const length = s.MakeMinimize(ticks[size-1], 1); + OptimizeVar* const length = s.MakeMinimize(ticks[size - 1], 1); SolutionCollector* const collector = s.MakeLastSolutionCollector(); collector->Add(ticks); - DecisionBuilder* const db = s.MakePhase(ticks, - Solver::CHOOSE_FIRST_UNBOUND, + DecisionBuilder* const db = s.MakePhase(ticks, Solver::CHOOSE_FIRST_UNBOUND, Solver::ASSIGN_MIN_VALUE); s.Solve(db, collector, length); // go! CHECK_EQ(collector->solution_count(), 1); - const int64 result = collector->Value(0, ticks[size-1]); + const int64 result = collector->Value(0, ticks[size - 1]); const int num_failures = collector->failures(0); - printf("N = %d, optimal length = %d (fails:%d)\n", - size, static_cast(result), num_failures); + printf("N = %d, optimal length = %d (fails:%d)\n", size, + static_cast(result), num_failures); if (size - 1 < kKnownSolutions) { CHECK_EQ(result, kBestSolutions[size - 1]); } @@ -92,9 +91,9 @@ void GolombRuler(int size) { } } -} // namespace operations_research +} // namespace operations_research -int main(int argc, char **argv) { +int main(int argc, char** argv) { google::ParseCommandLineFlags( &argc, &argv, true); if (FLAGS_size != 0) { operations_research::GolombRuler(FLAGS_size); diff --git a/examples/cpp/integer_programming.cc b/examples/cpp/integer_programming.cc index 026e7b882f..66a2dd125c 100644 --- a/examples/cpp/integer_programming.cc +++ b/examples/cpp/integer_programming.cc @@ -27,8 +27,9 @@ void RunIntegerProgrammingExample( MPVariable* const x2 = solver.MakeIntVar(0.0, infinity, "x2"); // Minimize x1 + 2 * x2. - solver.SetObjectiveCoefficient(x1, 1); - solver.SetObjectiveCoefficient(x2, 2); + MPObjective* const objective = solver.MutableObjective(); + objective->SetCoefficient(x1, 1); + objective->SetCoefficient(x2, 2); // 2 * x2 + 3 * x1 >= 17. MPConstraint* const c0 = solver.MakeRowConstraint(17, infinity); @@ -45,7 +46,7 @@ void RunIntegerProgrammingExample( LOG(INFO) << "Problem solved in " << solver.wall_time() << " milliseconds"; // The objective value of the solution. - LOG(INFO) << "Optimal objective value = " << solver.objective_value(); + LOG(INFO) << "Optimal objective value = " << objective->Value(); // The value of each variable in the solution. LOG(INFO) << "x1 = " << x1->solution_value(); @@ -56,7 +57,6 @@ void RunIntegerProgrammingExample( << " branch-and-bound nodes"; } - void RunAllExamples() { #if defined(USE_GLPK) LOG(INFO) << "---- Integer programming example with GLPK ----"; @@ -77,8 +77,8 @@ void RunAllExamples() { } } // namespace operations_research -int main(int argc, char **argv) { - google::ParseCommandLineFlags(&argc, &argv, true); +int main(int argc, char** argv) { + google::ParseCommandLineFlags( &argc, &argv, true); operations_research::RunAllExamples(); return 0; } diff --git a/examples/cpp/jobshop.cc b/examples/cpp/jobshop.cc index 5a3c02e9c1..fba141f2ed 100644 --- a/examples/cpp/jobshop.cc +++ b/examples/cpp/jobshop.cc @@ -45,8 +45,7 @@ #include "util/string_array.h" DEFINE_string( - data_file, - "", + data_file, "", "Required: input file description the scheduling problem to solve, " "in our jssp format:\n" " - the first line is \"instance \"\n" @@ -77,17 +76,11 @@ void Jobshop(const JobShopData& data) { for (int task_index = 0; task_index < tasks.size(); ++task_index) { const JobShopData::Task& task = tasks[task_index]; CHECK_EQ(job_id, task.job_id); - const std::string name = StringPrintf("J%dM%dI%dD%d", - task.job_id, - task.machine_id, - task_index, - task.duration); - IntervalVar* const one_task = - solver.MakeFixedDurationIntervalVar(0, - horizon, - task.duration, - false, - name); + const std::string name = + StringPrintf("J%dM%dI%dD%d", task.job_id, task.machine_id, task_index, + task.duration); + IntervalVar* const one_task = solver.MakeFixedDurationIntervalVar( + 0, horizon, task.duration, false, name); jobs_to_tasks[task.job_id].push_back(one_task); machines_to_tasks[task.machine_id].push_back(one_task); } @@ -144,15 +137,12 @@ void Jobshop(const JobShopData& data) { // we can schedule each task at its earliest start time. This is // conveniently done by fixing the objective variable to its // minimum value. - DecisionBuilder* const obj_phase = - solver.MakePhase(objective_var, - Solver::CHOOSE_FIRST_UNBOUND, - Solver::ASSIGN_MIN_VALUE); + DecisionBuilder* const obj_phase = solver.MakePhase( + objective_var, Solver::CHOOSE_FIRST_UNBOUND, Solver::ASSIGN_MIN_VALUE); // The main decision builder (ranks all tasks, then fixes the // objective_variable). - DecisionBuilder* const main_phase = - solver.Compose(sequence_phase, obj_phase); + DecisionBuilder* const main_phase = solver.Compose(sequence_phase, obj_phase); // Search log. const int kLogFrequency = 1000000; @@ -164,15 +154,11 @@ void Jobshop(const JobShopData& data) { limit = solver.MakeTimeLimit(FLAGS_time_limit_in_ms); } - SolutionCollector* const collector = - solver.MakeLastSolutionCollector(); + SolutionCollector* const collector = solver.MakeLastSolutionCollector(); collector->Add(all_sequences); // Search. - if (solver.Solve(main_phase, - search_log, - objective_monitor, - limit, + if (solver.Solve(main_phase, search_log, objective_monitor, limit, collector)) { for (int m = 0; m < machine_count; ++m) { SequenceVar* const seq = all_sequences[m]; @@ -187,7 +173,7 @@ static const char kUsage[] = "Usage: see flags.\nThis program runs a simple job shop optimization " "output besides the debug LOGs of the solver."; -int main(int argc, char **argv) { +int main(int argc, char** argv) { google::SetUsageMessage(kUsage); google::ParseCommandLineFlags(&argc, &argv, true); if (FLAGS_data_file.empty()) { diff --git a/examples/cpp/jobshop.h b/examples/cpp/jobshop.h index f1b4785a85..a45670b16d 100644 --- a/examples/cpp/jobshop.h +++ b/examples/cpp/jobshop.h @@ -92,9 +92,8 @@ class JobShopData { // behavior. void Load(const std::string& filename) { FileLineReader reader(filename.c_str()); - reader.set_line_callback(NewPermanentCallback( - this, - &JobShopData::ProcessNewLine)); + reader.set_line_callback( + NewPermanentCallback(this, &JobShopData::ProcessNewLine)); reader.Reload(); if (!reader.loaded_successfully()) { LOG(ERROR) << "Could not open jobshop file"; @@ -146,8 +145,8 @@ class JobShopData { machine_count_ = atoi32(words[1]); CHECK_GT(machine_count_, 0); CHECK_GT(job_count_, 0); - LOG(INFO) << machine_count_ << " machines and " - << job_count_ << " jobs"; + LOG(INFO) << machine_count_ << " machines and " << job_count_ + << " jobs"; all_tasks_.resize(job_count_); } diff --git a/examples/cpp/jobshop_ls.cc b/examples/cpp/jobshop_ls.cc index 0b387d3043..025da4f7a4 100644 --- a/examples/cpp/jobshop_ls.cc +++ b/examples/cpp/jobshop_ls.cc @@ -47,8 +47,7 @@ #include "cpp/jobshop.h" DEFINE_string( - data_file, - "", + data_file, "", "Required: input file description the scheduling problem to solve, " "in our jssp format:\n" " - the first line is \"instance \"\n" @@ -64,7 +63,6 @@ DEFINE_int32(lns_seed, 1, "Seed of the LNS random search"); DEFINE_int32(lns_limit, 30, "Limit the size of the search tree in a LNS fragment"); - namespace operations_research { // ----- Model and Solve ----- @@ -88,17 +86,11 @@ void JobshopLs(const JobShopData& data) { for (int task_index = 0; task_index < tasks.size(); ++task_index) { const JobShopData::Task& task = tasks[task_index]; CHECK_EQ(job_id, task.job_id); - const std::string name = StringPrintf("J%dM%dI%dD%d", - task.job_id, - task.machine_id, - task_index, - task.duration); - IntervalVar* const one_task = - solver.MakeFixedDurationIntervalVar(0, - horizon, - task.duration, - false, - name); + const std::string name = + StringPrintf("J%dM%dI%dD%d", task.job_id, task.machine_id, task_index, + task.duration); + IntervalVar* const one_task = solver.MakeFixedDurationIntervalVar( + 0, horizon, task.duration, false, name); jobs_to_tasks[task.job_id].push_back(one_task); machines_to_tasks[task.machine_id].push_back(one_task); } @@ -154,10 +146,8 @@ void JobshopLs(const JobShopData& data) { // we can schedule each task at its earliest start time. This is // conveniently done by fixing the objective variable to its // minimum value. - DecisionBuilder* const obj_phase = - solver.MakePhase(objective_var, - Solver::CHOOSE_FIRST_UNBOUND, - Solver::ASSIGN_MIN_VALUE); + DecisionBuilder* const obj_phase = solver.MakePhase( + objective_var, Solver::CHOOSE_FIRST_UNBOUND, Solver::ASSIGN_MIN_VALUE); Assignment* const first_solution = solver.MakeAssignment(); first_solution->Add(all_sequences); @@ -178,16 +168,13 @@ void JobshopLs(const JobShopData& data) { operators.push_back(swap_operator); LOG(INFO) << " - use shuffle operator with a max length of " << FLAGS_shuffle_length; - LocalSearchOperator* const shuffle_operator = - solver.RevAlloc(new ShuffleIntervals(all_sequences, - FLAGS_shuffle_length)); + LocalSearchOperator* const shuffle_operator = solver.RevAlloc( + new ShuffleIntervals(all_sequences, FLAGS_shuffle_length)); operators.push_back(shuffle_operator); LOG(INFO) << " - use free sub sequences of length " << FLAGS_sub_sequence_length << " lns operator"; - LocalSearchOperator* const lns_operator = - solver.RevAlloc(new SequenceLns(all_sequences, - FLAGS_lns_seed, - FLAGS_sub_sequence_length)); + LocalSearchOperator* const lns_operator = solver.RevAlloc(new SequenceLns( + all_sequences, FLAGS_lns_seed, FLAGS_sub_sequence_length)); operators.push_back(lns_operator); // Creates the local search decision builder. @@ -198,9 +185,8 @@ void JobshopLs(const JobShopData& data) { solver.MakeLimit(kint64max, FLAGS_lns_limit, kint64max, kint64max); DecisionBuilder* const random_sequence_phase = solver.MakePhase(all_sequences, Solver::CHOOSE_RANDOM_RANK_FORWARD); - DecisionBuilder* const ls_db = - solver.MakeSolveOnce(solver.Compose(random_sequence_phase, obj_phase), - ls_limit); + DecisionBuilder* const ls_db = solver.MakeSolveOnce( + solver.Compose(random_sequence_phase, obj_phase), ls_limit); LocalSearchPhaseParameters* const parameters = solver.MakeLocalSearchPhaseParameters(concat, ls_db); @@ -214,9 +200,9 @@ void JobshopLs(const JobShopData& data) { SearchMonitor* const search_log = solver.MakeSearchLog(kLogFrequency, objective_monitor); - SearchLimit* const limit = FLAGS_time_limit_in_ms > 0 ? - solver.MakeTimeLimit(FLAGS_time_limit_in_ms) : - NULL; + SearchLimit* const limit = FLAGS_time_limit_in_ms > 0 + ? solver.MakeTimeLimit(FLAGS_time_limit_in_ms) + : NULL; // Search. solver.Solve(final_db, search_log, objective_monitor, limit); @@ -227,7 +213,7 @@ static const char kUsage[] = "Usage: see flags.\nThis program runs a simple job shop optimization " "output besides the debug LOGs of the solver."; -int main(int argc, char **argv) { +int main(int argc, char** argv) { google::SetUsageMessage(kUsage); google::ParseCommandLineFlags(&argc, &argv, true); if (FLAGS_data_file.empty()) { diff --git a/examples/cpp/jobshop_ls.h b/examples/cpp/jobshop_ls.h index 79752b8d5c..474fa61679 100644 --- a/examples/cpp/jobshop_ls.h +++ b/examples/cpp/jobshop_ls.h @@ -137,8 +137,7 @@ class ShuffleIntervals : public SequenceVarLocalSearchOperator { sequence_backup[i] = sequence[i + current_first_]; } for (int i = 0; i < current_length_; ++i) { - sequence[i + current_first_] = - sequence_backup[current_permutation_[i]]; + sequence[i + current_first_] = sequence_backup[current_permutation_[i]]; } SetForwardSequence(current_var_, sequence); if (ApplyChanges(delta, deltadelta)) { @@ -191,9 +190,7 @@ class ShuffleIntervals : public SequenceVarLocalSearchOperator { class SequenceLns : public SequenceVarLocalSearchOperator { public: - SequenceLns(const std::vector& vars, - int seed, - int max_length) + SequenceLns(const std::vector& vars, int seed, int max_length) : SequenceVarLocalSearchOperator(vars), random_(seed), max_length_(max_length) {} @@ -230,8 +227,7 @@ class SequenceLns : public SequenceVarLocalSearchOperator { forward.push_back(sequence[j]); } std::vector backward; - for (int j = sequence.size() - 1; - j >= start_position + current_length; + for (int j = sequence.size() - 1; j >= start_position + current_length; --j) { backward.push_back(sequence[j]); } diff --git a/examples/cpp/linear_assignment_api.cc b/examples/cpp/linear_assignment_api.cc index a5135c8ab9..5d803f01ac 100644 --- a/examples/cpp/linear_assignment_api.cc +++ b/examples/cpp/linear_assignment_api.cc @@ -25,16 +25,13 @@ void AssignmentOn4x4Matrix() { LOG(INFO) << "Assignment on 4x4 Matrix"; const int kNumSources = 4; const int kNumTargets = 4; - const CostValue kCost[kNumSources][kNumTargets] = { - { 90, 76, 75, 80 }, - { 35, 85, 55, 65 }, - { 125, 95, 90, 105 }, - { 45, 110, 95, 115 } - }; + const CostValue kCost[kNumSources][kNumTargets] = {{90, 76, 75, 80}, + {35, 85, 55, 65}, + {125, 95, 90, 105}, + {45, 110, 95, 115}}; const CostValue kExpectedCost = kCost[0][3] + kCost[1][2] + kCost[2][1] + kCost[3][0]; - ForwardStarGraph graph( - kNumSources + kNumTargets, kNumSources * kNumTargets); + ForwardStarGraph graph(kNumSources + kNumTargets, kNumSources * kNumTargets); LinearSumAssignment assignment(graph, kNumSources); for (NodeIndex source = 0; source < kNumSources; ++source) { for (NodeIndex target = 0; target < kNumTargets; ++target) { @@ -49,7 +46,7 @@ void AssignmentOn4x4Matrix() { } // namespace operations_research -int main(int argc, char **argv) { +int main(int argc, char** argv) { google::ParseCommandLineFlags( &argc, &argv, true); operations_research::AssignmentOn4x4Matrix(); return 0; diff --git a/examples/cpp/linear_programming.cc b/examples/cpp/linear_programming.cc index 30014877c4..c50933cea8 100644 --- a/examples/cpp/linear_programming.cc +++ b/examples/cpp/linear_programming.cc @@ -30,10 +30,11 @@ void RunLinearProgrammingExample( MPVariable* const x3 = solver.MakeNumVar(0.0, infinity, "x3"); // Maximize 10 * x1 + 6 * x2 + 4 * x3. - solver.SetObjectiveCoefficient(x1, 10); - solver.SetObjectiveCoefficient(x2, 6); - solver.SetObjectiveCoefficient(x3, 4); - solver.SetMaximization(); + MPObjective* const objective = solver.MutableObjective(); + objective->SetCoefficient(x1, 10); + objective->SetCoefficient(x2, 6); + objective->SetCoefficient(x3, 4); + objective->SetMaximization(); // x1 + x2 + x3 <= 100. MPConstraint* const c0 = solver.MakeRowConstraint(-infinity, 100.0); @@ -68,7 +69,7 @@ void RunLinearProgrammingExample( LOG(INFO) << "Problem solved in " << solver.wall_time() << " milliseconds"; // The objective value of the solution. - LOG(INFO) << "Optimal objective value = " << solver.objective_value(); + LOG(INFO) << "Optimal objective value = " << objective->Value(); // The value of each variable in the solution. LOG(INFO) << "x1 = " << x1->solution_value(); @@ -89,27 +90,27 @@ void RunLinearProgrammingExample( } void RunAllExamples() { -#if defined(USE_GLPK) + #if defined(USE_GLPK) LOG(INFO) << "---- Linear programming example with GLPK ----"; RunLinearProgrammingExample(MPSolver::GLPK_LINEAR_PROGRAMMING); -#endif // USE_GLPK -#if defined(USE_CLP) + #endif // USE_GLPK + #if defined(USE_CLP) LOG(INFO) << "---- Linear programming example with CLP ----"; RunLinearProgrammingExample(MPSolver::CLP_LINEAR_PROGRAMMING); -#endif // USE_CLP -#if defined(USE_SLM) + #endif // USE_CLP + #if defined(USE_SLM) LOG(INFO) << "---- Linear programming example with Sulum ----"; RunLinearProgrammingExample(MPSolver::SULUM_LINEAR_PROGRAMMING); -#endif // USE_SLM -#if defined(USE_GUROBI) + #endif // USE_SLM + #if defined(USE_GUROBI) LOG(INFO) << "---- Linear programming example with Gurobi ----"; RunLinearProgrammingExample(MPSolver::GUROBI_LINEAR_PROGRAMMING); -#endif // USE_GUROBI + #endif // USE_GUROBI } } // namespace operations_research -int main(int argc, char **argv) { - google::ParseCommandLineFlags(&argc, &argv, true); +int main(int argc, char** argv) { + google::ParseCommandLineFlags( &argc, &argv, true); operations_research::RunAllExamples(); return 0; } diff --git a/examples/cpp/linear_solver_protocol_buffers.cc b/examples/cpp/linear_solver_protocol_buffers.cc index b686595f76..855ed5919e 100644 --- a/examples/cpp/linear_solver_protocol_buffers.cc +++ b/examples/cpp/linear_solver_protocol_buffers.cc @@ -28,8 +28,7 @@ void BuildLinearProgrammingMaxExample(MPSolver::OptimizationProblemType type) { const double kConstraintCoef1[] = {1.0, 1.0, 1.0}; const double kConstraintCoef2[] = {10.0, 4.0, 5.0}; const double kConstraintCoef3[] = {2.0, 2.0, 6.0}; - const double* kConstraintCoef[] = {kConstraintCoef1, - kConstraintCoef2, + const double* kConstraintCoef[] = {kConstraintCoef1, kConstraintCoef2, kConstraintCoef3}; const double kConstraintUb[] = {100.0, 600.0, 300.0}; @@ -43,7 +42,7 @@ void BuildLinearProgrammingMaxExample(MPSolver::OptimizationProblemType type) { x->set_name(kVarName[j]); // Could be skipped (optional). x->set_lower_bound(0.0); x->set_upper_bound(infinity); // Could be skipped (default value). - x->set_is_integer(false); // Could be skipped (default value). + x->set_is_integer(false); // Could be skipped (default value). x->set_objective_coefficient(kObjCoef[j]); } model_proto.set_maximize(true); @@ -53,7 +52,7 @@ void BuildLinearProgrammingMaxExample(MPSolver::OptimizationProblemType type) { new_proto::MPConstraintProto* constraint_proto = model_proto.add_constraint(); constraint_proto->set_name(kConstraintName[i]); // Could be skipped. - constraint_proto->set_lower_bound(-infinity); // Could be skipped. + constraint_proto->set_lower_bound(-infinity); // Could be skipped. constraint_proto->set_upper_bound(kConstraintUb[i]); for (int j = 0; j < numVars; ++j) { // These two lines may be skipped when the coefficient is zero. @@ -81,7 +80,7 @@ void BuildLinearProgrammingMaxExample(MPSolver::OptimizationProblemType type) { // The problem has an optimal solution. CHECK_EQ(new_proto::MPSolutionResponse::OPTIMAL, solution_response.status()); - LOG(INFO) << "objective = " << solution_response.objective_value(); + LOG(INFO) << "objective = " << solution_response.objective_value(); for (int j = 0; j < numVars; ++j) { LOG(INFO) << model_proto.variable(j).name() << " = " << solution_response.variable_value(j); @@ -100,7 +99,7 @@ void RunAllExamples() { } } // namespace operations_research -int main(int argc, char **argv) { +int main(int argc, char** argv) { google::ParseCommandLineFlags( &argc, &argv, true); operations_research::RunAllExamples(); return 0; diff --git a/examples/cpp/ls_api.cc b/examples/cpp/ls_api.cc index 146710a3cd..6708a54e18 100644 --- a/examples/cpp/ls_api.cc +++ b/examples/cpp/ls_api.cc @@ -26,8 +26,7 @@ namespace operations_research { class OneVarLns : public BaseLNS { public: - explicit OneVarLns(const std::vector& vars) - : BaseLNS(vars), index_(0) {} + explicit OneVarLns(const std::vector& vars) : BaseLNS(vars), index_(0) {} ~OneVarLns() {} @@ -48,7 +47,7 @@ class OneVarLns : public BaseLNS { int index_; }; -class MoveOneVar: public IntVarLocalSearchOperator { +class MoveOneVar : public IntVarLocalSearchOperator { public: explicit MoveOneVar(const std::vector& variables) : IntVarLocalSearchOperator(variables), @@ -62,10 +61,10 @@ class MoveOneVar: public IntVarLocalSearchOperator { virtual bool MakeOneNeighbor() { const int64 current_value = OldValue(variable_index_); if (move_up_) { - SetValue(variable_index_, current_value + 1); + SetValue(variable_index_, current_value + 1); variable_index_ = (variable_index_ + 1) % Size(); } else { - SetValue(variable_index_, current_value - 1); + SetValue(variable_index_, current_value - 1); } move_up_ = !move_up_; return true; @@ -85,8 +84,8 @@ class MoveOneVar: public IntVarLocalSearchOperator { class SumFilter : public IntVarLocalSearchFilter { public: - explicit SumFilter(const std::vector& vars) : - IntVarLocalSearchFilter(vars), sum_(0) {} + explicit SumFilter(const std::vector& vars) + : IntVarLocalSearchFilter(vars), sum_(0) {} ~SumFilter() {} @@ -121,12 +120,11 @@ class SumFilter : public IntVarLocalSearchFilter { // of this file. for (int i = 0; i < solution_delta_size; ++i) { if (!solution_delta.Element(i).Activated()) { - VLOG(1) - << "Element #" << i << " of the delta assignment given to" - << " SumFilter::Accept() is not activated (i.e. its variable" - << " is not bound to a single value anymore). This means that" - << " we are in a LNS phase, and the DobbleFilter won't be able" - << " to filter anything. Returning true."; + VLOG(1) << "Element #" << i << " of the delta assignment given to" + << " SumFilter::Accept() is not activated (i.e. its variable" + << " is not bound to a single value anymore). This means that" + << " we are in a LNS phase, and the DobbleFilter won't be able" + << " to filter anything. Returning true."; return true; } } @@ -160,15 +158,12 @@ void SolveProblem(SolveType solve_type) { IntVar* const sum_var = s.MakeSum(vars)->Var(); OptimizeVar* const obj = s.MakeMinimize(sum_var, 1); DecisionBuilder* const db = - s.MakePhase(vars, - Solver::CHOOSE_FIRST_UNBOUND, - Solver::ASSIGN_MAX_VALUE); + s.MakePhase(vars, Solver::CHOOSE_FIRST_UNBOUND, Solver::ASSIGN_MAX_VALUE); DecisionBuilder* ls = NULL; switch (solve_type) { case LNS: { LOG(INFO) << "Large Neighborhood Search"; - OneVarLns* const one_var_lns = - s.RevAlloc(new OneVarLns(vars)); + OneVarLns* const one_var_lns = s.RevAlloc(new OneVarLns(vars)); LocalSearchPhaseParameters* const ls_params = s.MakeLocalSearchPhaseParameters(one_var_lns, db); ls = s.MakeLocalSearchPhase(vars, db, ls_params); diff --git a/examples/cpp/magic_square.cc b/examples/cpp/magic_square.cc index 76f2114dac..9e893d436f 100644 --- a/examples/cpp/magic_square.cc +++ b/examples/cpp/magic_square.cc @@ -33,7 +33,7 @@ DEFINE_bool(luby, false, DEFINE_bool(run_all_heuristics, false, "Run all heuristics."); DEFINE_int32(heuristics_period, 200, "Frequency to run all heuristics."); DEFINE_int32(choose_var_strategy, 0, - "Selection strategy for variable: 0 = max sum impact, " + "Selection strategy for variable: 0 = max sum impact, " "1 = max average impact, " "2 = max individual impact."); DEFINE_bool(select_max_impact_value, false, @@ -59,9 +59,9 @@ void MagicSquare(int grid_size) { std::vector diag1(grid_size); std::vector diag2(grid_size); for (int n = 0; n < grid_size; ++n) { - std::vector sub_set(grid_size); + std::vector sub_set(grid_size); - for (int m = 0; m < grid_size; ++m) { // extract row indices + for (int m = 0; m < grid_size; ++m) { // extract row indices sub_set[m] = vars[m + n * grid_size]; } solver.AddConstraint(solver.MakeSumEquality(sub_set, sum)); @@ -70,7 +70,7 @@ void MagicSquare(int grid_size) { sub_set[m] = vars[m * grid_size + n]; // extract column indices } solver.AddConstraint(solver.MakeSumEquality(sub_set, sum)); - diag1[n] = vars[n + n * grid_size]; // extract first diagonal indices + diag1[n] = vars[n + n * grid_size]; // extract first diagonal indices diag2[n] = vars[(grid_size - 1 - n) + n * grid_size]; // second diagonal } solver.AddConstraint(solver.MakeSumEquality(diag1, sum)); @@ -78,17 +78,17 @@ void MagicSquare(int grid_size) { // To break a simple symmetry: the upper right corner // must be less than the lower left corner - solver.AddConstraint(solver.MakeLess(vars[grid_size - 1], - vars[(grid_size - 1) * grid_size])); + solver.AddConstraint( + solver.MakeLess(vars[grid_size - 1], vars[(grid_size - 1) * grid_size])); // TODO(user) use local search DefaultPhaseParameters parameters; parameters.run_all_heuristics = FLAGS_run_all_heuristics; parameters.heuristic_period = FLAGS_heuristics_period; parameters.restart_log_size = FLAGS_restart_log_size; - parameters.display_level = FLAGS_verbose_impact ? - DefaultPhaseParameters::VERBOSE : - DefaultPhaseParameters::NORMAL; + parameters.display_level = FLAGS_verbose_impact + ? DefaultPhaseParameters::VERBOSE + : DefaultPhaseParameters::NORMAL; parameters.use_no_goods = FLAGS_use_nogoods; switch (FLAGS_choose_var_strategy) { case 0: { @@ -106,28 +106,25 @@ void MagicSquare(int grid_size) { DefaultPhaseParameters::CHOOSE_MAX_VALUE_IMPACT; break; } - default: { - LOG(FATAL) << "Should not be here"; - } + default: { LOG(FATAL) << "Should not be here"; } } - parameters.value_selection_schema = FLAGS_select_max_impact_value? - DefaultPhaseParameters::SELECT_MAX_IMPACT: - DefaultPhaseParameters::SELECT_MIN_IMPACT; + parameters.value_selection_schema = + FLAGS_select_max_impact_value ? DefaultPhaseParameters::SELECT_MAX_IMPACT + : DefaultPhaseParameters::SELECT_MIN_IMPACT; - DecisionBuilder* const db = FLAGS_impact? - solver.MakeDefaultPhase(vars, parameters): - solver.MakePhase(vars, - Solver::CHOOSE_FIRST_UNBOUND, - Solver::ASSIGN_MIN_VALUE); + DecisionBuilder* const db = + FLAGS_impact ? solver.MakeDefaultPhase(vars, parameters) + : solver.MakePhase(vars, Solver::CHOOSE_FIRST_UNBOUND, + Solver::ASSIGN_MIN_VALUE); std::vector monitors; SearchMonitor* const log = solver.MakeSearchLog(100000); monitors.push_back(log); - SearchMonitor* const restart = FLAGS_restart != -1? - (FLAGS_luby? - solver.MakeLubyRestart(FLAGS_restart): - solver.MakeConstantRestart(FLAGS_restart)): - NULL; + SearchMonitor* const restart = + FLAGS_restart != -1 + ? (FLAGS_luby ? solver.MakeLubyRestart(FLAGS_restart) + : solver.MakeConstantRestart(FLAGS_restart)) + : NULL; if (restart) { monitors.push_back(restart); } @@ -135,7 +132,7 @@ void MagicSquare(int grid_size) { if (solver.NextSolution()) { for (int n = 0; n < grid_size; ++n) { std::string output; - for (int m = 0; m < grid_size; ++m) { // extract row indices + for (int m = 0; m < grid_size; ++m) { // extract row indices int64 v = vars[n * grid_size + m]->Value(); StringAppendF(&output, "%3lld ", v); } @@ -150,7 +147,7 @@ void MagicSquare(int grid_size) { } // namespace operations_research -int main(int argc, char **argv) { +int main(int argc, char** argv) { google::ParseCommandLineFlags( &argc, &argv, true); if (FLAGS_size != 0) { operations_research::MagicSquare(FLAGS_size); diff --git a/examples/cpp/model_util.cc b/examples/cpp/model_util.cc index 821b20f637..888182c0ae 100644 --- a/examples/cpp/model_util.cc +++ b/examples/cpp/model_util.cc @@ -61,56 +61,41 @@ static const char kYellow[] = "#FFF68F"; static const char kRed[] = "#A52A2A"; // Creates node labels. -std::string ExprLabel(int index) { - return StringPrintf("expr_%i", index); -} +std::string ExprLabel(int index) { return StringPrintf("expr_%i", index); } -std::string IntervalLabel(int index) { - return StringPrintf("interval_%i", index); -} +std::string IntervalLabel(int index) { return StringPrintf("interval_%i", index); } -std::string SequenceLabel(int index) { - return StringPrintf("sequence_%i", index); -} +std::string SequenceLabel(int index) { return StringPrintf("sequence_%i", index); } -std::string ConstraintLabel(int index) { - return StringPrintf("ct_%i", index); -} +std::string ConstraintLabel(int index) { return StringPrintf("ct_%i", index); } // Scans argument to add links in the graph. -template void ExportLinks(const CPModelProto& model, - const std::string& source, - const T& proto, - GraphExporter* const exporter) { +template +void ExportLinks(const CPModelProto& model, const std::string& source, + const T& proto, GraphExporter* const exporter) { const std::string& arg_name = model.tags(proto.argument_index()); if (proto.has_integer_expression_index()) { - exporter->WriteLink(source, - ExprLabel(proto.integer_expression_index()), + exporter->WriteLink(source, ExprLabel(proto.integer_expression_index()), arg_name); } for (int i = 0; i < proto.integer_expression_array_size(); ++i) { - exporter->WriteLink(source, - ExprLabel(proto.integer_expression_array(i)), + exporter->WriteLink(source, ExprLabel(proto.integer_expression_array(i)), arg_name); } if (proto.has_interval_index()) { - exporter->WriteLink(source, - IntervalLabel(proto.interval_index()), + exporter->WriteLink(source, IntervalLabel(proto.interval_index()), arg_name); } for (int i = 0; i < proto.interval_array_size(); ++i) { - exporter->WriteLink(source, - IntervalLabel(proto.interval_array(i)), + exporter->WriteLink(source, IntervalLabel(proto.interval_array(i)), arg_name); } if (proto.has_sequence_index()) { - exporter->WriteLink(source, - SequenceLabel(proto.sequence_index()), + exporter->WriteLink(source, SequenceLabel(proto.sequence_index()), arg_name); } for (int i = 0; i < proto.sequence_array_size(); ++i) { - exporter->WriteLink(source, - SequenceLabel(proto.sequence_array(i)), + exporter->WriteLink(source, SequenceLabel(proto.sequence_array(i)), arg_name); } } @@ -147,8 +132,7 @@ bool GetValueIfConstant(const CPModelProto& model, } // Declares a labelled expression in the graph file. -void DeclareExpression(int index, - const CPModelProto& proto, +void DeclareExpression(int index, const CPModelProto& proto, GraphExporter* const exporter) { const CPIntegerExpressionProto& expr = proto.expressions(index); const std::string label = ExprLabel(index); @@ -156,18 +140,14 @@ void DeclareExpression(int index, if (expr.has_name()) { exporter->WriteNode(label, expr.name(), "oval", kGreen1); } else if (GetValueIfConstant(proto, expr, &value)) { - exporter->WriteNode(label, - StringPrintf("%lld", value), - "oval", - kYellow); + exporter->WriteNode(label, StringPrintf("%lld", value), "oval", kYellow); } else { const std::string& type = proto.tags(expr.type_index()); exporter->WriteNode(label, type, "oval", kWhite); } } -void DeclareInterval(int index, - const CPModelProto& proto, +void DeclareInterval(int index, const CPModelProto& proto, GraphExporter* const exporter) { const CPIntervalVariableProto& interval = proto.intervals(index); const std::string label = IntervalLabel(index); @@ -179,8 +159,7 @@ void DeclareInterval(int index, } } -void DeclareSequence(int index, - const CPModelProto& proto, +void DeclareSequence(int index, const CPModelProto& proto, GraphExporter* const exporter) { const CPSequenceVariableProto& sequence = proto.sequences(index); const std::string label = SequenceLabel(index); @@ -192,8 +171,7 @@ void DeclareSequence(int index, } } -void DeclareConstraint(int index, - const CPModelProto& proto, +void DeclareConstraint(int index, const CPModelProto& proto, GraphExporter* const exporter) { const CPConstraintProto& ct = proto.constraints(index); const std::string& type = proto.tags(ct.type_index()); @@ -202,8 +180,7 @@ void DeclareConstraint(int index, } // Parses the proto and exports it to a graph file. -void ExportToGraphFile(const CPModelProto& proto, - File* const file, +void ExportToGraphFile(const CPModelProto& proto, File* const file, GraphExporter::GraphFormat format) { std::unique_ptr exporter( GraphExporter::MakeFileExporter(file, format)); @@ -264,8 +241,7 @@ void ExportToGraphFile(const CPModelProto& proto, if (proto.has_objective()) { const CPObjectiveProto& obj = proto.objective(); - exporter->WriteLink(kObjLabel, - ExprLabel(obj.objective_index()), + exporter->WriteLink(kObjLabel, ExprLabel(obj.objective_index()), ModelVisitor::kExpressionArgument); } exporter->WriteFooter(); @@ -336,9 +312,7 @@ int Run() { if (FLAGS_print_proto) { LOG(INFO) << model_proto.DebugString(); } - if (FLAGS_test_proto || - FLAGS_model_stats || - FLAGS_print_model || + if (FLAGS_test_proto || FLAGS_model_stats || FLAGS_print_model || FLAGS_collect_variables) { Solver solver(model_proto.model()); std::vector monitors; @@ -364,16 +338,15 @@ int Run() { std::vector interval_variables; solver.CollectDecisionVariables(&primary_integer_variables, &secondary_integer_variables, - &sequence_variables, - &interval_variables); + &sequence_variables, &interval_variables); LOG(INFO) << "Primary integer variables = " << JoinDebugStringPtr(primary_integer_variables, ", "); LOG(INFO) << "Secondary integer variables = " << JoinDebugStringPtr(secondary_integer_variables, ", "); - LOG(INFO) << "Sequence variables = " - << JoinDebugStringPtr(sequence_variables, ", "); - LOG(INFO) << "Interval variables = " - << JoinDebugStringPtr(interval_variables, ", "); + LOG(INFO) << "Sequence variables = " << JoinDebugStringPtr( + sequence_variables, ", "); + LOG(INFO) << "Interval variables = " << JoinDebugStringPtr( + interval_variables, ", "); } } @@ -416,7 +389,7 @@ int Run() { } } // namespace operations_research -int main(int argc, char **argv) { +int main(int argc, char** argv) { google::ParseCommandLineFlags( &argc, &argv, true); if (FLAGS_input.empty()) { LOG(FATAL) << "Filename not specified"; diff --git a/examples/cpp/multidim_knapsack.cc b/examples/cpp/multidim_knapsack.cc index 1989cb1643..ef38fc90c6 100644 --- a/examples/cpp/multidim_knapsack.cc +++ b/examples/cpp/multidim_knapsack.cc @@ -28,14 +28,14 @@ #include "constraint_solver/constraint_solver.h" DEFINE_string( - data_file, - "", + data_file, "", "Required: input file description the muldi-dimensional knapsack problem\n " "to solve. It supports two file format as described in:\n" " - http://elib.zib.de/pub/Packages/mp-testdata/ip/sac94-suite/readme\n" " - http://hces.bus.olemiss.edu/tools.html\n"); DEFINE_int32(time_limit_in_ms, 0, "Time limit in ms, <= 0 means no limit."); -DEFINE_int32(simplex_frequency, 0, "Number of nodes explored between each" +DEFINE_int32(simplex_frequency, 0, + "Number of nodes explored between each" " call to the simplex optimizer."); DEFINE_bool(display_search_log, true, "Display search log."); @@ -46,16 +46,20 @@ namespace operations_research { class MultiDimKnapsackData { public: MultiDimKnapsackData() - : name_(""), line_read_(0), mode_(0), num_dims_(-1), num_items_(-1), - current_bin_(0), current_item_(0), optimal_value_(0), + : name_(""), + line_read_(0), + mode_(0), + num_dims_(-1), + num_items_(-1), + current_bin_(0), + current_item_(0), + optimal_value_(0), problem_type_(-1) {} - void Load(const std::string& filename) { FileLineReader reader(filename.c_str()); - reader.set_line_callback(NewPermanentCallback( - this, - &MultiDimKnapsackData::ProcessNewLine)); + reader.set_line_callback( + NewPermanentCallback(this, &MultiDimKnapsackData::ProcessNewLine)); reader.Reload(); if (!reader.loaded_successfully()) { LOG(ERROR) << "Could not open multi dimensional knapsack file"; @@ -168,9 +172,7 @@ class MultiDimKnapsackData { } break; } - case 6: { - break; - } + case 6: { break; } } } else { // 0 = init @@ -292,15 +294,12 @@ void SolveKnapsack(MultiDimKnapsackData* const data) { monitors.push_back(search_log); } DecisionBuilder* const db = - solver.MakePhase(assign, - NewPermanentCallback(&EvaluateItem, data), + solver.MakePhase(assign, NewPermanentCallback(&EvaluateItem, data), Solver::CHOOSE_STATIC_GLOBAL_BEST); if (FLAGS_time_limit_in_ms != 0) { LOG(INFO) << "adding time limit of " << FLAGS_time_limit_in_ms << " ms"; - SearchLimit* const limit = solver.MakeLimit(FLAGS_time_limit_in_ms, - kint64max, - kint64max, - kint64max); + SearchLimit* const limit = solver.MakeLimit( + FLAGS_time_limit_in_ms, kint64max, kint64max, kint64max); monitors.push_back(limit); } @@ -320,7 +319,7 @@ static const char kUsage[] = "Usage: see flags.\n" "This program runs a multi-dimensional knapsack problem."; -int main(int argc, char **argv) { +int main(int argc, char** argv) { google::SetUsageMessage(kUsage); google::ParseCommandLineFlags(&argc, &argv, true); if (FLAGS_data_file.empty()) { diff --git a/examples/cpp/network_routing.cc b/examples/cpp/network_routing.cc index fa520598df..70e3fcfd9f 100644 --- a/examples/cpp/network_routing.cc +++ b/examples/cpp/network_routing.cc @@ -47,7 +47,8 @@ #include "base/random.h" // ----- Data Generator ----- -DEFINE_int32(clients, 0, "Number of network clients nodes. If equal to zero, " +DEFINE_int32(clients, 0, + "Number of network clients nodes. If equal to zero, " "then all backbones nodes are also client nodes."); DEFINE_int32(backbones, 0, "Number of backbone nodes"); DEFINE_int32(demands, 0, "Number of network demands."); @@ -69,7 +70,8 @@ DEFINE_int32(seed, 0, "Random seed"); // ----- Reporting ----- DEFINE_bool(print_model, false, "Print model."); -DEFINE_int32(report, 1, "Report which links and which demands are " +DEFINE_int32(report, 1, + "Report which links and which demands are " "responsible for the congestion."); DEFINE_int32(log_period, 100000, "Period for the search log"); @@ -102,10 +104,7 @@ static const int64 kDisconnectedDistance = -1LL; class NetworkRoutingData { public: NetworkRoutingData() - : name_(""), - num_nodes_(-1), - max_capacity_(-1), - fixed_charge_cost_(-1) {} + : name_(""), num_nodes_(-1), max_capacity_(-1), fixed_charge_cost_(-1) {} // Name of the problem. const std::string& name() const { return name_; } @@ -120,23 +119,19 @@ class NetworkRoutingData { // Returns the capacity of an arc, and 0 if the arc is not defined. int Capacity(int node1, int node2) const { return FindWithDefault(all_arcs_, - std::make_pair(std::min(node1, node2), - std::max(node1, node2)), - 0); + std::make_pair(std::min(node1, node2), std::max(node1, node2)), 0); } // Returns the demand between the source and the destination, and 0 if // there are no demands between the source and the destination. int Demand(int source, int destination) const { - return FindWithDefault(all_demands_, - std::make_pair(source, destination), 0); + return FindWithDefault(all_demands_, std::make_pair(source, destination), 0); } // External building API. void set_num_nodes(int num_nodes) { num_nodes_ = num_nodes; } void AddArc(int node1, int node2, int capacity) { - all_arcs_[std::make_pair(std::min(node1, node2), - std::max(node1, node2))] = capacity; + all_arcs_[std::make_pair(std::min(node1, node2), std::max(node1, node2))] = capacity; } void AddDemand(int source, int destination, int traffic) { all_demands_[std::make_pair(source, destination)] = traffic; @@ -176,25 +171,18 @@ class NetworkRoutingDataBuilder { public: NetworkRoutingDataBuilder() : random_(0) {} - void BuildModelFromParameters(int num_clients, - int num_backbones, - int num_demands, - int traffic_min, - int traffic_max, - int min_client_degree, - int max_client_degree, - int min_backbone_degree, - int max_backbone_degree, - int max_capacity, - int fixed_charge_cost, - int seed, + void BuildModelFromParameters(int num_clients, int num_backbones, + int num_demands, int traffic_min, + int traffic_max, int min_client_degree, + int max_client_degree, int min_backbone_degree, + int max_backbone_degree, int max_capacity, + int fixed_charge_cost, int seed, NetworkRoutingData* const data) { CHECK_GE(num_backbones, 1); CHECK_GE(num_clients, 0); CHECK_GE(num_demands, 1); - CHECK_LE(num_demands, num_clients == 0 - ? num_backbones * num_backbones : - num_clients * num_backbones); + CHECK_LE(num_demands, num_clients == 0 ? num_backbones * num_backbones + : num_clients * num_backbones); CHECK_GE(max_client_degree, min_client_degree); CHECK_GE(max_backbone_degree, min_backbone_degree); CHECK_GE(traffic_max, 1); @@ -208,31 +196,13 @@ class NetworkRoutingDataBuilder { const int size = num_backbones + num_clients; InitData(size, seed); - BuildGraph(num_clients, - num_backbones, - min_client_degree, - max_client_degree, - min_backbone_degree, - max_backbone_degree); - CreateDemands(num_clients, - num_backbones, - num_demands, - traffic_min, - traffic_max, - data); - FillData(num_clients, - num_backbones, - num_demands, - traffic_min, - traffic_max, - min_client_degree, - max_client_degree, - min_backbone_degree, - max_backbone_degree, - max_capacity, - fixed_charge_cost, - seed, - data); + BuildGraph(num_clients, num_backbones, min_client_degree, max_client_degree, + min_backbone_degree, max_backbone_degree); + CreateDemands(num_clients, num_backbones, num_demands, traffic_min, + traffic_max, data); + FillData(num_clients, num_backbones, num_demands, traffic_min, traffic_max, + min_client_degree, max_client_degree, min_backbone_degree, + max_backbone_degree, max_capacity, fixed_charge_cost, seed, data); } private: @@ -247,11 +217,8 @@ class NetworkRoutingDataBuilder { random_.Reset(seed); } - void BuildGraph(int num_clients, - int num_backbones, - int min_client_degree, - int max_client_degree, - int min_backbone_degree, + void BuildGraph(int num_clients, int num_backbones, int min_client_degree, + int max_client_degree, int min_backbone_degree, int max_backbone_degree) { const int size = num_backbones + num_clients; @@ -306,11 +273,8 @@ class NetworkRoutingDataBuilder { } } - void CreateDemands(int num_clients, - int num_backbones, - int num_demands, - int traffic_min, - int traffic_max, + void CreateDemands(int num_clients, int num_backbones, int num_demands, + int traffic_min, int traffic_max, NetworkRoutingData* const data) { while (data->num_demands() < num_demands) { const int source = RandomClient(num_clients, num_backbones); @@ -323,35 +287,19 @@ class NetworkRoutingDataBuilder { } } - void FillData(int num_clients, - int num_backbones, - int num_demands, - int traffic_min, - int traffic_max, - int min_client_degree, - int max_client_degree, - int min_backbone_degree, - int max_backbone_degree, - int max_capacity, - int fixed_charge_cost, - int seed, + void FillData(int num_clients, int num_backbones, int num_demands, + int traffic_min, int traffic_max, int min_client_degree, + int max_client_degree, int min_backbone_degree, + int max_backbone_degree, int max_capacity, + int fixed_charge_cost, int seed, NetworkRoutingData* const data) { const int size = num_backbones + num_clients; - const std::string name = - StringPrintf("mp_c%i_b%i_d%i.t%i-%i.cd%i-%i.bd%i-%i.mc%i.fc%i.s%i", - num_clients, - num_backbones, - num_demands, - traffic_min, - traffic_max, - min_client_degree, - max_client_degree, - min_backbone_degree, - max_backbone_degree, - max_capacity, - fixed_charge_cost, - seed); + const std::string name = StringPrintf( + "mp_c%i_b%i_d%i.t%i-%i.cd%i-%i.bd%i-%i.mc%i.fc%i.s%i", num_clients, + num_backbones, num_demands, traffic_min, traffic_max, min_client_degree, + max_client_degree, min_backbone_degree, max_backbone_degree, + max_capacity, fixed_charge_cost, seed); data->set_name(name); data->set_num_nodes(size); @@ -381,9 +329,8 @@ class NetworkRoutingDataBuilder { } int RandomClient(int num_clients, int num_backbones) { - return (num_clients == 0) ? - random_.Uniform(num_backbones) : - random_.Uniform(num_clients) + num_backbones; + return (num_clients == 0) ? random_.Uniform(num_backbones) + : random_.Uniform(num_clients) + num_backbones; } std::vector > network_; @@ -431,13 +378,12 @@ class NetworkRoutingSolver { const Demand& demand = demands_array_[demand_index]; solver.AddConstraint(solver.MakeEquality(node_vars[0], demand.source)); - solver.AddConstraint(solver.MakeEquality(node_vars[max_length - 1], - demand.destination)); + solver.AddConstraint( + solver.MakeEquality(node_vars[max_length - 1], demand.destination)); solver.AddConstraint(solver.MakeAllDifferent(arc_vars)); solver.AddConstraint(solver.MakeAllDifferent(node_vars)); - DecisionBuilder* const db = solver.MakePhase(node_vars, - Solver::CHOOSE_FIRST_UNBOUND, - Solver::ASSIGN_MIN_VALUE); + DecisionBuilder* const db = solver.MakePhase( + node_vars, Solver::CHOOSE_FIRST_UNBOUND, Solver::ASSIGN_MIN_VALUE); solver.NewSearch(db); while (solver.NextSolution()) { const int path_id = all_paths_[demand_index].size(); @@ -458,15 +404,12 @@ class NetworkRoutingSolver { // a hash_set of arc indices. int ComputeAllPaths(int extra_hops, int max_paths) { int num_paths = 0; - for (int demand_index = 0; - demand_index < demands_array_.size(); + for (int demand_index = 0; demand_index < demands_array_.size(); ++demand_index) { const int min_path_length = all_min_path_lengths_[demand_index]; for (int max_length = min_path_length + 1; - max_length <= min_path_length + extra_hops + 1; - ++max_length) { - ComputeAllPathsForOneDemandAndOnePathLength(demand_index, - max_length, + max_length <= min_path_length + extra_hops + 1; ++max_length) { + ComputeAllPathsForOneDemandAndOnePathLength(demand_index, max_length, max_paths); if (all_paths_[demand_index].size() > max_paths) { break; @@ -500,8 +443,8 @@ class NetworkRoutingSolver { capacity_[i][j] = capacity; capacity_[j][i] = capacity; if (FLAGS_print_model) { - LOG(INFO) << "Arc " << i << " <-> " << j - << " with capacity " << capacity; + LOG(INFO) << "Arc " << i << " <-> " << j << " with capacity " + << capacity; } } } @@ -535,11 +478,8 @@ class NetworkRoutingSolver { const Demand& demand = demands_array_[demand_index]; ResultCallback2* const graph_callback = NewPermanentCallback(this, &NetworkRoutingSolver::HasArc); - CHECK(DijkstraShortestPath(num_nodes_, - demand.source, - demand.destination, - graph_callback, - kDisconnectedDistance, + CHECK(DijkstraShortestPath(num_nodes_, demand.source, demand.destination, + graph_callback, kDisconnectedDistance, &paths)); all_min_path_lengths_.push_back(paths.size() - 1); } @@ -551,9 +491,7 @@ class NetworkRoutingSolver { return total_cumulated_traffic; } - int InitPaths(const NetworkRoutingData& data, - int extra_hops, - int max_paths) { + int InitPaths(const NetworkRoutingData& data, int extra_hops, int max_paths) { const int num_demands = data.num_demands(); LOG(INFO) << "Computing all possible paths "; LOG(INFO) << " - extra hops = " << extra_hops; @@ -565,9 +503,8 @@ class NetworkRoutingSolver { if (FLAGS_print_model) { for (int demand_index = 0; demand_index < num_demands; ++demand_index) { const Demand& demand = demands_array_[demand_index]; - LOG(INFO) << "Demand from " << demand.source - << " to " << demand.destination - << " with traffic " << demand.traffic + LOG(INFO) << "Demand from " << demand.source << " to " + << demand.destination << " with traffic " << demand.traffic << ", and " << all_paths_[demand_index].size() << " possible paths."; } @@ -631,8 +568,7 @@ class NetworkRoutingSolver { // Build traffic variable summing all traffic from all demands // going through a single arc. - void BuildTrafficVariable(Solver* const solver, - int arc_index, + void BuildTrafficVariable(Solver* const solver, int arc_index, const std::vector >& path_vars, IntVar** const traffic) { std::vector terms; @@ -647,10 +583,8 @@ class NetworkRoutingSolver { class PathBasedLns : public BaseLNS { public: - PathBasedLns(const std::vector& vars, - int fragment_size, - const std::vector >& all_paths, - int num_arcs, + PathBasedLns(const std::vector& vars, int fragment_size, + const std::vector >& all_paths, int num_arcs, const std::vector& actual_usage_costs) : BaseLNS(vars), rand_(FLAGS_lns_seed), @@ -706,8 +640,7 @@ class NetworkRoutingSolver { const int demands = all_paths_.size(); for (int i = 0; i < demands; ++i) { const OnePath& path = all_paths_[i][Value(i)]; - for (ConstIter > it(arcs_to_release); - !it.at_end(); + for (ConstIter > it(arcs_to_release); !it.at_end(); ++it) { if (ContainsKey(path, *it)) { fragment->push_back(i); @@ -725,9 +658,9 @@ class NetworkRoutingSolver { int arc_id; int64 cost; bool operator<(const ArcWrapper& other_arc_wrapper) const { - return cost > other_arc_wrapper.cost - || (cost == other_arc_wrapper.cost - && arc_id < other_arc_wrapper.arc_id); + return cost > other_arc_wrapper.cost || + (cost == other_arc_wrapper.cost && + arc_id < other_arc_wrapper.arc_id); } }; @@ -743,8 +676,7 @@ class NetworkRoutingSolver { static const int kOneThousand = 1000; - int64 EvaluateMarginalCost(std::vector* path_costs, - int64 var, + int64 EvaluateMarginalCost(std::vector* path_costs, int64 var, int64 val) { int64 best_cost = 0; const int64 traffic = demands_array_[var].traffic; @@ -780,14 +712,12 @@ class NetworkRoutingSolver { return NULL; } - virtual std::string DebugString() const { - return "ApplyMaxDiscrepancy"; - } + virtual std::string DebugString() const { return "ApplyMaxDiscrepancy"; } }; // ----- Auxilliary Decision Builder to Store the Cost of a Solution ----- - class StoreUsageCosts : public DecisionBuilder { + class StoreUsageCosts : public DecisionBuilder { public: StoreUsageCosts(const std::vector& vars, std::vector* values) : vars_(vars), values_(values) {} @@ -799,6 +729,7 @@ class NetworkRoutingSolver { } return NULL; } + private: const std::vector& vars_; std::vector* const values_; @@ -830,18 +761,13 @@ class NetworkRoutingSolver { solver.MakeBoolVarArray(num_arcs, StringPrintf("path_vars_%i_", demand_index), &path_vars[demand_index]); - BuildNodePathConstraint(&solver, - path_vars[demand_index], - demand_index, + BuildNodePathConstraint(&solver, path_vars[demand_index], demand_index, &decision_vars); } // Traffic variables. std::vector vtraffic(num_arcs); for (int arc_index = 0; arc_index < num_arcs; ++arc_index) { - BuildTrafficVariable(&solver, - arc_index, - path_vars, - &vtraffic[arc_index]); + BuildTrafficVariable(&solver, arc_index, path_vars, &vtraffic[arc_index]); vtraffic[arc_index]->set_name(StringPrintf("traffic_%i", arc_index)); } @@ -850,17 +776,14 @@ class NetworkRoutingSolver { std::vector usage_costs; std::vector comfort_costs; for (int arc_index = 0; arc_index < num_arcs; ++arc_index) { - const int capacity = - capacity_[arcs_data_.Value(2 * arc_index, 0)] - [arcs_data_.Value(2 * arc_index, 1)]; + const int capacity = capacity_[arcs_data_.Value( + 2 * arc_index, 0)][arcs_data_.Value(2 * arc_index, 1)]; IntVar* const usage_cost = solver.MakeDiv(solver.MakeProd(vtraffic[arc_index], kOneThousand), capacity)->Var(); usage_costs.push_back(usage_cost); - IntVar* const comfort_cost = - solver.MakeIsGreaterCstVar( - vtraffic[arc_index], - capacity * FLAGS_comfort_zone / kOneThousand); + IntVar* const comfort_cost = solver.MakeIsGreaterCstVar( + vtraffic[arc_index], capacity * FLAGS_comfort_zone / kOneThousand); comfort_costs.push_back(comfort_cost); } IntVar* const max_usage_cost = solver.MakeMax(usage_costs)->Var(); @@ -879,30 +802,22 @@ class NetworkRoutingSolver { } // DecisionBuilder. - DecisionBuilder* const db = - solver.MakePhase(decision_vars, - Solver::CHOOSE_RANDOM, - NewPermanentCallback( - this, - &NetworkRoutingSolver::EvaluateMarginalCost, + DecisionBuilder* const db = solver.MakePhase( + decision_vars, Solver::CHOOSE_RANDOM, + NewPermanentCallback(this, &NetworkRoutingSolver::EvaluateMarginalCost, &usage_costs)); // Limits. if (time_limit != 0 || fail_limit != 0) { if (time_limit != 0) { - LOG(INFO) << "adding time limit of " << time_limit - << " ms"; + LOG(INFO) << "adding time limit of " << time_limit << " ms"; } if (fail_limit != 0) { LOG(INFO) << "adding fail limit of " << fail_limit; } - monitors.push_back( - solver.MakeLimit(time_limit != 0 ? - time_limit : kint64max, - kint64max, - fail_limit != 0 ? - fail_limit : kint64max, - kint64max)); + monitors.push_back(solver.MakeLimit( + time_limit != 0 ? time_limit : kint64max, kint64max, + fail_limit != 0 ? fail_limit : kint64max, kint64max)); } // Lns Decision Builder. @@ -912,36 +827,25 @@ class NetworkRoutingSolver { DecisionBuilder* const store_info = solver.RevAlloc(new StoreUsageCosts(usage_costs, &actual_usage_costs)); - LocalSearchOperator* const local_search_operator = - solver.RevAlloc(new PathBasedLns(decision_vars, - FLAGS_lns_size, - all_paths_, - num_arcs, - actual_usage_costs)); + LocalSearchOperator* const local_search_operator = solver.RevAlloc( + new PathBasedLns(decision_vars, FLAGS_lns_size, all_paths_, num_arcs, + actual_usage_costs)); SearchLimit* const lns_limit = solver.MakeLimit(kint64max, kint64max, FLAGS_lns_limit, kint64max); - DecisionBuilder* const inner_db = - solver.MakePhase(decision_vars, - Solver::CHOOSE_RANDOM, - NewPermanentCallback( - this, - &NetworkRoutingSolver::EvaluateMarginalCost, + DecisionBuilder* const inner_db = solver.MakePhase( + decision_vars, Solver::CHOOSE_RANDOM, + NewPermanentCallback(this, &NetworkRoutingSolver::EvaluateMarginalCost, &usage_costs)); - DecisionBuilder* const apply = solver.RevAlloc(new ApplyMaxDiscrepancy); DecisionBuilder* const max_discrepency_db = solver.Compose(apply, inner_db); - DecisionBuilder* const ls_db = solver.MakeSolveOnce(max_discrepency_db, - lns_limit); + DecisionBuilder* const ls_db = + solver.MakeSolveOnce(max_discrepency_db, lns_limit); LocalSearchPhaseParameters* const parameters = - solver.MakeLocalSearchPhaseParameters(local_search_operator, - solver.Compose(ls_db, - store_info)); - DecisionBuilder* const final_db = - solver.Compose(solver.MakeLocalSearchPhase(decision_vars, - db, - parameters), - store_info); + solver.MakeLocalSearchPhaseParameters( + local_search_operator, solver.Compose(ls_db, store_info)); + DecisionBuilder* const final_db = solver.Compose( + solver.MakeLocalSearchPhase(decision_vars, db, parameters), store_info); // And Now Solve. int64 best_cost = kint64max; @@ -960,23 +864,17 @@ class NetworkRoutingSolver { } best_cost = objective_var->Value(); if (FLAGS_report > 1) { - DisplaySolution(num_arcs, - max_usage_cost->Value(), - usage_costs, - path_vars, - FLAGS_report > 2, - FLAGS_comfort_zone); + DisplaySolution(num_arcs, max_usage_cost->Value(), usage_costs, + path_vars, FLAGS_report > 2, FLAGS_comfort_zone); } } solver.EndSearch(); return best_cost; } - void DisplaySolution(int num_arcs, - int64 max_usage_cost, + void DisplaySolution(int num_arcs, int64 max_usage_cost, const std::vector& usage_costs, - const std::vector >& path_vars, - bool precise, + const std::vector >& path_vars, bool precise, int64 comfort_zone) { // We will show paths above the comfort zone, or above the max // utilization minus 5%. @@ -988,23 +886,18 @@ class NetworkRoutingSolver { if (arc_usage >= cutoff) { const int source_index = arcs_data_.Value(2 * i, 0); const int destination_index = arcs_data_.Value(2 * i, 1); - LOG(INFO) << " + Arc " << source_index - << " <-> " << destination_index - << " has a usage = " << arc_usage / 10.0 - << "%, capacity = " + LOG(INFO) << " + Arc " << source_index << " <-> " << destination_index + << " has a usage = " << arc_usage / 10.0 << "%, capacity = " << capacity_[source_index][destination_index]; if (precise) { const int num_demands = demands_array_.size(); - for (int demand_index = 0; - demand_index < num_demands; + for (int demand_index = 0; demand_index < num_demands; ++demand_index) { if (path_vars[demand_index][i]->Value() == 1) { const Demand& demand = demands_array_[demand_index]; LOG(INFO) << " - " - << StringPrintf("%i -> %i (%i)", - demand.source, - demand.destination, - demand.traffic); + << StringPrintf("%i -> %i (%i)", demand.source, + demand.destination, demand.traffic); } } } @@ -1026,26 +919,18 @@ class NetworkRoutingSolver { } // namespace operations_research -int main(int argc, char **argv) { +int main(int argc, char** argv) { google::ParseCommandLineFlags( &argc, &argv, true); operations_research::NetworkRoutingData data; operations_research::NetworkRoutingDataBuilder builder; - builder.BuildModelFromParameters(FLAGS_clients, - FLAGS_backbones, - FLAGS_demands, - FLAGS_traffic_min, - FLAGS_traffic_max, - FLAGS_min_client_degree, - FLAGS_max_client_degree, - FLAGS_min_backbone_degree, - FLAGS_max_backbone_degree, - FLAGS_max_capacity, - FLAGS_fixed_charge_cost, - FLAGS_seed, - &data); + builder.BuildModelFromParameters( + FLAGS_clients, FLAGS_backbones, FLAGS_demands, FLAGS_traffic_min, + FLAGS_traffic_max, FLAGS_min_client_degree, FLAGS_max_client_degree, + FLAGS_min_backbone_degree, FLAGS_max_backbone_degree, FLAGS_max_capacity, + FLAGS_fixed_charge_cost, FLAGS_seed, &data); operations_research::NetworkRoutingSolver solver; solver.Init(data, FLAGS_extra_hops, FLAGS_max_paths); - LOG(INFO) << "Final cost = " - << solver.LnsSolve(FLAGS_time_limit, FLAGS_fail_limit); + LOG(INFO) << "Final cost = " << solver.LnsSolve(FLAGS_time_limit, + FLAGS_fail_limit); return 0; } diff --git a/examples/cpp/nqueens.cc b/examples/cpp/nqueens.cc index a7a2c828ef..efac256c62 100644 --- a/examples/cpp/nqueens.cc +++ b/examples/cpp/nqueens.cc @@ -31,22 +31,20 @@ DEFINE_bool(print, false, "If true, print one of the solution."); DEFINE_bool(print_all, false, "If true, print all the solutions."); DEFINE_int32(nb_loops, 1, - "Number of solving loops to perform, for performance timing."); -DEFINE_int32(size, 0, - "Size of the problem. If equal to 0, will test several increasing sizes."); + "Number of solving loops to perform, for performance timing."); +DEFINE_int32( + size, 0, + "Size of the problem. If equal to 0, will test several increasing sizes."); DEFINE_bool(use_symmetry, false, "Use Symmetry Breaking methods"); DECLARE_bool(cp_no_solve); static const int kNumSolutions[] = { - 1, 0, 0, 2, 10, 4, 40, 92, 352, 724, - 2680, 14200, 73712, 365596, 2279184 -}; + 1, 0, 0, 2, 10, 4, 40, 92, 352, 724, 2680, 14200, 73712, 365596, 2279184}; static const int kKnownSolutions = 15; static const int kNumUniqueSolutions[] = { - 1, 0, 0, 1, 2, 1, 6, 12, 46, 92, 341, 1787, 9233, 45752, - 285053, 1846955, 11977939, 83263591, 621012754 -}; + 1, 0, 0, 1, 2, 1, 6, 12, 46, 92, + 341, 1787, 9233, 45752, 285053, 1846955, 11977939, 83263591, 621012754}; static const int kKnownUniqueSolutions = 19; namespace operations_research { @@ -215,8 +213,7 @@ void NQueens(int size) { std::vector monitors; monitors.push_back(solution_counter); monitors.push_back(collector); - DecisionBuilder* const db = s.MakePhase(queens, - Solver::CHOOSE_FIRST_UNBOUND, + DecisionBuilder* const db = s.MakePhase(queens, Solver::CHOOSE_FIRST_UNBOUND, Solver::ASSIGN_MIN_VALUE); if (FLAGS_use_symmetry) { std::vector breakers; @@ -260,9 +257,9 @@ void NQueens(int size) { printf("========= number of solutions:%d\n", num_solutions); printf(" number of failures: %lld\n", s.failures()); } -} // namespace operations_research +} // namespace operations_research -int main(int argc, char **argv) { +int main(int argc, char** argv) { google::ParseCommandLineFlags( &argc, &argv, true); if (FLAGS_size != 0) { operations_research::NQueens(FLAGS_size); diff --git a/examples/cpp/opb_reader.h b/examples/cpp/opb_reader.h index 1a11d6478d..5fb21bd525 100644 --- a/examples/cpp/opb_reader.h +++ b/examples/cpp/opb_reader.h @@ -24,7 +24,6 @@ #include "sat/boolean_problem.pb.h" #include "util/filelineiter.h" - namespace operations_research { namespace sat { @@ -59,8 +58,8 @@ class OpbReader { // the file name. static std::string ExtractProblemName(const std::string& filename) { const int found = filename.find_last_of("/"); - const std::string problem_name = found != std::string::npos ? - filename.substr(found + 1) : filename; + const std::string problem_name = + found != std::string::npos ? filename.substr(found + 1) : filename; return problem_name; } @@ -98,12 +97,12 @@ class OpbReader { CHECK(!word.empty()); if (word == ">=") { CHECK_LT(i + 1, words.size()); - constraint->set_lower_bound(atoi64(words[i+1])); + constraint->set_lower_bound(atoi64(words[i + 1])); break; } else if (word == "=") { CHECK_LT(i + 1, words.size()); - constraint->set_upper_bound(atoi64(words[i+1])); - constraint->set_lower_bound(atoi64(words[i+1])); + constraint->set_upper_bound(atoi64(words[i + 1])); + constraint->set_lower_bound(atoi64(words[i + 1])); break; } else { if (word[0] == 'x') { diff --git a/examples/cpp/parse_dimacs_assignment.h b/examples/cpp/parse_dimacs_assignment.h index b245f1590a..7ed41e6091 100644 --- a/examples/cpp/parse_dimacs_assignment.h +++ b/examples/cpp/parse_dimacs_assignment.h @@ -36,14 +36,14 @@ DECLARE_bool(assignment_optimize_layout); namespace operations_research { -template class LinearSumAssignment; +template +class LinearSumAssignment; -template class DimacsAssignmentParser { +template +class DimacsAssignmentParser { public: explicit DimacsAssignmentParser(const std::string filename) - : filename_(filename), - graph_builder_(NULL), - assignment_(NULL) { } + : filename_(filename), graph_builder_(NULL), assignment_(NULL) {} // Reads an assignment problem description from the given file in // DIMACS format and returns a LinearSumAssignment object representing @@ -82,7 +82,7 @@ template class DimacsAssignmentParser { nodes_described(false), reason(NULL), num_left_nodes(0), - num_arcs(0) { } + num_arcs(0) {} bool bad; bool expect_last_line; @@ -102,8 +102,7 @@ template class DimacsAssignmentParser { // Implementation is below here. template -void DimacsAssignmentParser::ParseProblemLine( - const char* line) { +void DimacsAssignmentParser::ParseProblemLine(const char* line) { static const char* kIncorrectProblemLine = "Incorrect assignment problem line."; static const char* kAssignmentProblemType = "asn"; @@ -111,12 +110,8 @@ void DimacsAssignmentParser::ParseProblemLine( NodeIndex num_nodes; ArcIndex num_arcs; - if ((sscanf(line, "%*c%3s%d%d", - problem_type, - &num_nodes, - &num_arcs) != 3) || - (strncmp(kAssignmentProblemType, - problem_type, + if ((sscanf(line, "%*c%3s%d%d", problem_type, &num_nodes, &num_arcs) != 3) || + (strncmp(kAssignmentProblemType, problem_type, strlen(kAssignmentProblemType)) != 0)) { state_.bad = true; state_.reason = kIncorrectProblemLine; @@ -148,8 +143,7 @@ void DimacsAssignmentParser::ParseNodeLine(const char* line) { } template -void DimacsAssignmentParser::ParseArcLine( - const char* line) { +void DimacsAssignmentParser::ParseArcLine(const char* line) { if (graph_builder_ == NULL) { state_.bad = true; state_.reason = @@ -160,8 +154,8 @@ void DimacsAssignmentParser::ParseArcLine( if (!state_.nodes_described) { state_.nodes_described = true; DCHECK(assignment_ == NULL); - assignment_ = new LinearSumAssignment( - state_.num_left_nodes, state_.num_arcs); + assignment_ = new LinearSumAssignment(state_.num_left_nodes, + state_.num_arcs); } NodeIndex tail; NodeIndex head; @@ -225,7 +219,7 @@ void DimacsAssignmentParser::ParseOneLine(char* line) { } case '0': case '\n': - break; + break; default: { state_.bad = true; state_.reason = "Unknown line type in the input."; @@ -270,13 +264,11 @@ void DimacsAssignmentParser::ParseFileByLines( // LinearAssignment instance). template LinearSumAssignment* DimacsAssignmentParser::Parse( - std::string* error_message, - GraphType** graph_handle) { + std::string* error_message, GraphType** graph_handle) { CHECK_NOTNULL(error_message); CHECK_NOTNULL(graph_handle); - Callback1* cb = - NewPermanentCallback( - this, &DimacsAssignmentParser::ParseOneLine); + Callback1* cb = NewPermanentCallback( + this, &DimacsAssignmentParser::ParseOneLine); // ParseFileByLines takes ownership of cb and deletes it. ParseFileByLines(filename_, cb); diff --git a/examples/cpp/pdptw.cc b/examples/cpp/pdptw.cc index 05fb3be51a..8a019213ee 100644 --- a/examples/cpp/pdptw.cc +++ b/examples/cpp/pdptw.cc @@ -66,12 +66,10 @@ typedef std::vector > Coordinates; // Returns the scaled Euclidean distance between two nodes, coords holding the // coordinates of the nodes. -int64 Travel(const Coordinates* const coords, - RoutingModel::NodeIndex from, +int64 Travel(const Coordinates* const coords, RoutingModel::NodeIndex from, RoutingModel::NodeIndex to) { DCHECK(coords != NULL); - const int xd = - coords->at(from.value()).first - coords->at(to.value()).first; + const int xd = coords->at(from.value()).first - coords->at(to.value()).first; const int yd = coords->at(from.value()).second - coords->at(to.value()).second; return static_cast(kScalingFactor * sqrt(1.0L * xd * xd + yd * yd)); @@ -97,22 +95,20 @@ int64 TravelPlusServiceTime(const Coordinates* const coords, // Returns the demand (quantity picked up or delivered) of a node, demands // holds the demand of each node. -int64 Demand(const std::vector* const demands, - RoutingModel::NodeIndex from, +int64 Demand(const std::vector* const demands, RoutingModel::NodeIndex from, RoutingModel::NodeIndex to) { return demands->at(from.value()); } // Outputs a solution to the current model in a std::string. -std::string VerboseOutput(const RoutingModel& routing, - const Assignment& assignment, +std::string VerboseOutput(const RoutingModel& routing, const Assignment& assignment, const Coordinates& coords, const std::vector& service_times) { std::string output; const RoutingDimension& time_dimension = routing.GetDimensionOrDie("time"); const RoutingDimension& load_dimension = routing.GetDimensionOrDie("demand"); for (int i = 0; i < routing.vehicles(); ++i) { - StringAppendF(&output, "Vehicle %d: ", i); + StringAppendF(&output, "Vehicle %d: ", i); int64 index = routing.Start(i); if (routing.IsEnd(assignment.Value(routing.NextVar(index)))) { StringAppendF(&output, "empty"); @@ -123,30 +119,24 @@ std::string VerboseOutput(const RoutingModel& routing, const IntVar* vehicle = routing.VehicleVar(index); StringAppendF(&output, "Vehicle(%lld) ", assignment.Value(vehicle)); const IntVar* arrival = time_dimension.CumulVar(index); - StringAppendF(&output, "Time(%lld..%lld) ", - assignment.Min(arrival), + StringAppendF(&output, "Time(%lld..%lld) ", assignment.Min(arrival), assignment.Max(arrival)); const IntVar* load = load_dimension.CumulVar(index); - StringAppendF(&output, "Load(%lld..%lld) ", - assignment.Min(load), + StringAppendF(&output, "Load(%lld..%lld) ", assignment.Min(load), assignment.Max(load)); index = assignment.Value(routing.NextVar(index)); StringAppendF(&output, "Transit(%lld) ", - TravelPlusServiceTime(&coords, - &service_times, - real_node, + TravelPlusServiceTime(&coords, &service_times, real_node, routing.IndexToNode(index))); } StringAppendF(&output, "Route end "); const IntVar* vehicle = routing.VehicleVar(index); StringAppendF(&output, "Vehicle(%lld) ", assignment.Value(vehicle)); const IntVar* arrival = time_dimension.CumulVar(index); - StringAppendF(&output, "Time(%lld..%lld) ", - assignment.Min(arrival), + StringAppendF(&output, "Time(%lld..%lld) ", assignment.Min(arrival), assignment.Max(arrival)); const IntVar* load = load_dimension.CumulVar(index); - StringAppendF(&output, "Load(%lld..%lld) ", - assignment.Min(load), + StringAppendF(&output, "Load(%lld..%lld) ", assignment.Min(load), assignment.Max(load)); } StringAppendF(&output, "\n"); @@ -164,7 +154,7 @@ bool SafeParseInt64Array(const std::string& str, std::vector* parsed_int) parsed_int->assign(items.size(), 0); for (int i = 0; i < items.size(); ++i) { const char* item = items[i].c_str(); - char *endptr = NULL; + char* endptr = NULL; (*parsed_int)[i] = strto64(item, &endptr, 10); // NOLINT // The whole item should have been consumed. if (*endptr != '\0') return false; @@ -185,9 +175,8 @@ bool LoadAndSolve(const std::string& pdp_file) { data_file->ReadToString(&contents, kMaxInputFileSize); data_file->Close(); if (contents.size() == kMaxInputFileSize) { - LOG(WARNING) - << "Input file '" << pdp_file << "' is too large (>" - << kMaxInputFileSize << " bytes)."; + LOG(WARNING) << "Input file '" << pdp_file << "' is too large (>" + << kMaxInputFileSize << " bytes)."; return false; } SplitStringUsing(contents, "\n", &lines); @@ -199,16 +188,13 @@ bool LoadAndSolve(const std::string& pdp_file) { } // Parse file header. std::vector parsed_int; - if (!SafeParseInt64Array(lines[0], &parsed_int) - || parsed_int.size() != 3 - || parsed_int[0] < 0 - || parsed_int[1] < 0 - || parsed_int[2] < 0) { + if (!SafeParseInt64Array(lines[0], &parsed_int) || parsed_int.size() != 3 || + parsed_int[0] < 0 || parsed_int[1] < 0 || parsed_int[2] < 0) { LOG(WARNING) << "Malformed header: " << lines[0]; return false; } - const int num_vehicles = FLAGS_pdp_force_vehicles > 0 ? - FLAGS_pdp_force_vehicles : parsed_int[0]; + const int num_vehicles = + FLAGS_pdp_force_vehicles > 0 ? FLAGS_pdp_force_vehicles : parsed_int[0]; const int64 capacity = parsed_int[1]; // We do not care about the 'speed' field, in third position. @@ -223,16 +209,12 @@ bool LoadAndSolve(const std::string& pdp_file) { std::vector deliveries; int64 horizon = 0; for (int line_index = 1; line_index < lines.size(); ++line_index) { - if (!SafeParseInt64Array(lines[line_index], &parsed_int) - || parsed_int.size() != 9 - || parsed_int[0] < 0 - || parsed_int[4] < 0 - || parsed_int[5] < 0 - || parsed_int[6] < 0 - || parsed_int[7] < 0 - || parsed_int[8] < 0) { - LOG(WARNING) - << "Malformed line #" << line_index << ": " << lines[line_index]; + if (!SafeParseInt64Array(lines[line_index], &parsed_int) || + parsed_int.size() != 9 || parsed_int[0] < 0 || parsed_int[4] < 0 || + parsed_int[5] < 0 || parsed_int[6] < 0 || parsed_int[7] < 0 || + parsed_int[8] < 0) { + LOG(WARNING) << "Malformed line #" << line_index << ": " + << lines[line_index]; return false; } const int customer_id = parsed_int[0]; @@ -262,15 +244,13 @@ bool LoadAndSolve(const std::string& pdp_file) { NewPermanentCallback(Travel, const_cast(&coords))); routing.AddDimension( NewPermanentCallback(&Demand, const_cast*>(&demands)), - 0, capacity, /*fix_start_cumul_to_zero=*/ true, "demand"); + 0, capacity, /*fix_start_cumul_to_zero=*/true, "demand"); routing.AddDimension( NewPermanentCallback(&TravelPlusServiceTime, const_cast(&coords), const_cast*>(&service_times)), - kScalingFactor * horizon, - kScalingFactor * horizon, - /*fix_start_cumul_to_zero=*/ true, - "time"); + kScalingFactor * horizon, kScalingFactor * horizon, + /*fix_start_cumul_to_zero=*/true, "time"); const RoutingDimension& time_dimension = routing.GetDimensionOrDie("time"); Solver* const solver = routing.solver(); for (RoutingModel::NodeIndex i(0); i < num_nodes; ++i) { @@ -281,11 +261,10 @@ bool LoadAndSolve(const std::string& pdp_file) { } else { const int64 delivery_index = routing.NodeToIndex(deliveries[i.value()]); solver->AddConstraint(solver->MakeEquality( - routing.VehicleVar(index), - routing.VehicleVar(delivery_index))); - solver->AddConstraint(solver->MakeLessOrEqual( - time_dimension.CumulVar(index), - time_dimension.CumulVar(delivery_index))); + routing.VehicleVar(index), routing.VehicleVar(delivery_index))); + solver->AddConstraint( + solver->MakeLessOrEqual(time_dimension.CumulVar(index), + time_dimension.CumulVar(delivery_index))); routing.AddPickupAndDelivery(i, deliveries[i.value()]); } } @@ -295,8 +274,7 @@ bool LoadAndSolve(const std::string& pdp_file) { } // Adding penalty costs to allow skipping orders. const int64 kPenalty = 10000000; - for (RoutingModel::NodeIndex order(1); - order < routing.nodes(); ++order) { + for (RoutingModel::NodeIndex order(1); order < routing.nodes(); ++order) { std::vector orders(1, order); routing.AddDisjunction(orders, kPenalty); } @@ -306,7 +284,7 @@ bool LoadAndSolve(const std::string& pdp_file) { FLAGS_routing_no_lns = true; // Solve pickup and delivery problem. - const Assignment* assignment = routing.Solve(NULL); + const Assignment* assignment = routing.Solve(NULL); if (NULL != assignment) { LOG(INFO) << "Cost: " << assignment->ObjectiveValue(); LOG(INFO) << VerboseOutput(routing, *assignment, coords, service_times); @@ -317,7 +295,7 @@ bool LoadAndSolve(const std::string& pdp_file) { } // namespace operations_research -int main(int argc, char **argv) { +int main(int argc, char** argv) { google::ParseCommandLineFlags( &argc, &argv, true); if (!operations_research::LoadAndSolve(FLAGS_pdp_file)) { LOG(INFO) << "Error solving " << FLAGS_pdp_file; diff --git a/examples/cpp/print_dimacs_assignment.h b/examples/cpp/print_dimacs_assignment.h index 59534edd99..ab79eddbca 100644 --- a/examples/cpp/print_dimacs_assignment.h +++ b/examples/cpp/print_dimacs_assignment.h @@ -27,13 +27,14 @@ namespace operations_research { -template class LinearSumAssignment; +template +class LinearSumAssignment; // Given a LinearSumAssigment object representing an assignment problem // description, outputs the problem in DIMACS format in the output file. // For a description of the format, see // http://lpsolve.sourceforge.net/5.5/DIMACS_asn.htm -template +template void PrintDimacsAssignmentProblem( const LinearSumAssignment& assignment, const TailArrayManager& tail_array_manager, @@ -56,23 +57,21 @@ void WriteOrDie(const char* buffer, } // namespace internal -template +template void PrintDimacsAssignmentProblem( const LinearSumAssignment& assignment, const TailArrayManager& tail_array_manager, const std::string& output_filename) { FILE* output = fopen(output_filename.c_str(), "w"); const GraphType& graph(assignment.Graph()); - std::string output_line = StringPrintf("p asn %d %d\n", - graph.num_nodes(), - graph.num_arcs()); + std::string output_line = + StringPrintf("p asn %d %d\n", graph.num_nodes(), graph.num_arcs()); internal::WriteOrDie(output_line.c_str(), 1, output_line.length(), output); for (typename LinearSumAssignment::BipartiteLeftNodeIterator node_it(assignment); - node_it.Ok(); - node_it.Next()) { + node_it.Ok(); node_it.Next()) { output_line = StringPrintf("n %d\n", node_it.Index() + 1); internal::WriteOrDie(output_line.c_str(), 1, output_line.length(), output); @@ -80,14 +79,11 @@ void PrintDimacsAssignmentProblem( tail_array_manager.BuildTailArrayFromAdjacencyListsIfForwardGraph(); - for (typename GraphType::ArcIterator arc_it(assignment.Graph()); - arc_it.Ok(); + for (typename GraphType::ArcIterator arc_it(assignment.Graph()); arc_it.Ok(); arc_it.Next()) { ArcIndex arc = arc_it.Index(); - output_line = StringPrintf("a %d %d %lld\n", - graph.Tail(arc) + 1, - graph.Head(arc) + 1, - assignment.ArcCost(arc)); + output_line = StringPrintf("a %d %d %lld\n", graph.Tail(arc) + 1, + graph.Head(arc) + 1, assignment.ArcCost(arc)); internal::WriteOrDie(output_line.c_str(), 1, output_line.length(), output); } diff --git a/examples/cpp/sat_cnf_reader.h b/examples/cpp/sat_cnf_reader.h index 58dd80b197..6af722392d 100644 --- a/examples/cpp/sat_cnf_reader.h +++ b/examples/cpp/sat_cnf_reader.h @@ -23,7 +23,6 @@ #include "sat/boolean_problem.pb.h" #include "util/filelineiter.h" - namespace operations_research { namespace sat { @@ -52,8 +51,7 @@ class SatCnfReader { if (num_lines == 0) { LOG(FATAL) << "File '" << filename << "' is empty or can't be read."; } - problem->set_num_variables( - num_variables_ + slack_variable_weights_.size()); + problem->set_num_variables(num_variables_ + slack_variable_weights_.size()); // Add the slack variables (to convert max-sat to an pseudo-Boolean // optimization problem). @@ -79,8 +77,8 @@ class SatCnfReader { // the file name. static std::string ExtractProblemName(const std::string& filename) { const int found = filename.find_last_of("/"); - const std::string problem_name = found != std::string::npos ? - filename.substr(found + 1) : filename; + const std::string problem_name = + found != std::string::npos ? filename.substr(found + 1) : filename; return problem_name; } diff --git a/examples/cpp/sat_runner.cc b/examples/cpp/sat_runner.cc index f882deeea9..d9e60221b1 100644 --- a/examples/cpp/sat_runner.cc +++ b/examples/cpp/sat_runner.cc @@ -30,47 +30,38 @@ #include "sat/sat_solver.h" DEFINE_string( - input, - "", + input, "", "Required: input file of the problem to solve. Many format are supported:" ".cnf (sat, max-sat, weighted max-sat), .opb (pseudo-boolean sat/optim) " "and by default the LinearBooleanProblem proto (binary or text)."); DEFINE_string( - output, - "", + output, "", "If non-empty, write the input problem as a LinearBooleanProblem proto to " "this file. By default it uses the binary format except if the file " "extension is '.txt'. If the problem is SAT, a satisfiable assignment is " "also writen to the file."); DEFINE_string( - expected_result, - "undefined", + expected_result, "undefined", "Checks the result against expected. Possible values are undefined, " "sat, unsat"); -DEFINE_string( - params, - "", - "Parameters for the sat solver in a text format of the " - "SatParameters proto, example: --params=use_conflicts:true."); +DEFINE_string(params, "", + "Parameters for the sat solver in a text format of the " + "SatParameters proto, example: --params=use_conflicts:true."); DEFINE_string( - lower_bound, - "", + lower_bound, "", "If not empty, look for a solution with an objective value >= this bound."); DEFINE_string( - upper_bound, - "", + upper_bound, "", "If not empty, look for a solution with an objective value <= this bound."); -DEFINE_bool( - search_optimal, - false, - "If true, search for the optimal solution. " - "The algorithm is currently really basic."); +DEFINE_bool(search_optimal, false, + "If true, search for the optimal solution. " + "The algorithm is currently really basic."); // TODO(user): Adds minisat to the mix. @@ -97,13 +88,13 @@ int Run() { // Read the problem. LinearBooleanProblem problem; if (HasSuffixString(FLAGS_input, ".opb") || - HasSuffixString(FLAGS_input, ".opb.bz2")) { + HasSuffixString(FLAGS_input, ".opb.bz2")) { OpbReader reader; if (!reader.Load(FLAGS_input, &problem)) { LOG(FATAL) << "Cannot load file '" << FLAGS_input << "'."; } - } else if (HasSuffixString(FLAGS_input, ".cnf") - || HasSuffixString(FLAGS_input, ".wcnf")) { + } else if (HasSuffixString(FLAGS_input, ".cnf") || + HasSuffixString(FLAGS_input, ".wcnf")) { SatCnfReader reader; if (!reader.Load(FLAGS_input, &problem)) { LOG(FATAL) << "Cannot load file '" << FLAGS_input << "'."; @@ -117,16 +108,14 @@ int Run() { LOG(FATAL) << "Couldn't load problem '" << FLAGS_input << "'."; } if (!AddObjectiveConstraint( - problem, - !FLAGS_lower_bound.empty(), atoi64(FLAGS_lower_bound), - !FLAGS_upper_bound.empty(), atoi64(FLAGS_upper_bound), - &solver)) { + problem, !FLAGS_lower_bound.empty(), atoi64(FLAGS_lower_bound), + !FLAGS_upper_bound.empty(), atoi64(FLAGS_upper_bound), &solver)) { LOG(FATAL) << "Issue when setting the objective bounds."; } // Basic search for the optimal value by calling multiple times the solver. - if (FLAGS_search_optimal - && problem.type() == LinearBooleanProblem::MINIMIZATION) { + if (FLAGS_search_optimal && + problem.type() == LinearBooleanProblem::MINIMIZATION) { Coefficient objective = std::numeric_limits::max(); while (solver.Solve() == SatSolver::MODEL_SAT) { CHECK(IsAssignmentValid(problem, solver.Assignment())); @@ -134,8 +123,8 @@ int Run() { objective = ComputeObjectiveValue(problem, solver.Assignment()); CHECK_LT(objective, old_objective); solver.Backtrack(0); - if (!AddObjectiveConstraint( - problem, false, 0, true, objective - 1, &solver)) { + if (!AddObjectiveConstraint(problem, false, 0, true, objective - 1, + &solver)) { LOG(INFO) << "UNSAT (when tightenning the objective constraint)."; break; } @@ -152,8 +141,7 @@ int Run() { if (!FLAGS_output.empty()) { if (result == SatSolver::MODEL_SAT) { - StoreAssignment( - solver.Assignment(), problem.mutable_assignment()); + StoreAssignment(solver.Assignment(), problem.mutable_assignment()); } if (HasSuffixString(FLAGS_output, ".txt")) { file::WriteProtoToASCIIFileOrDie(problem, FLAGS_output); @@ -175,7 +163,7 @@ static const char kUsage[] = "Usage: see flags.\n" "This program solves a given sat problem."; -int main(int argc, char **argv) { +int main(int argc, char** argv) { google::SetUsageMessage(kUsage); google::ParseCommandLineFlags(&argc, &argv, true); return operations_research::sat::Run(); diff --git a/examples/cpp/sports_scheduling.cc b/examples/cpp/sports_scheduling.cc index 0e397ae136..f1ded2404a 100644 --- a/examples/cpp/sports_scheduling.cc +++ b/examples/cpp/sports_scheduling.cc @@ -70,16 +70,13 @@ DEFINE_int32(num_teams, 10, "Number of teams in the problem."); DEFINE_int32(time_limit, 20000, "Time limit in ms."); // Search tweaking parameters. These are defined to illustrate their effect. -DEFINE_bool(run_all_heuristics, - true, +DEFINE_bool(run_all_heuristics, true, "Run all heuristics in impact search, see DefaultPhaseParameters" " in constraint_solver/constraint_solver.h for details."); -DEFINE_int32(heuristics_period, - 30, +DEFINE_int32(heuristics_period, 30, "Frequency to run all heuristics, see DefaultPhaseParameters" " in constraint_solver/constraint_solver.h for details."); -DEFINE_double(restart_log_size, - 8.0, +DEFINE_double(restart_log_size, 8.0, "Threshold for automatic restarting the search in default phase," " see DefaultPhaseParameters in " "constraint_solver/constraint_solver.h for details."); @@ -99,8 +96,7 @@ void ComputeOneDayOneTeamTuples(int num_teams, IntTupleSet* const tuples) { } } -void AddOneDayOneTeamConstraint(Solver* const solver, - IntVar* const opponent, +void AddOneDayOneTeamConstraint(Solver* const solver, IntVar* const opponent, IntVar* const home_away, IntVar* const signed_opponent, const IntTupleSet& intra_day_tuples) { @@ -126,10 +122,7 @@ void ComputeOneDayTuples(int num_teams, IntTupleSet* const day_tuples) { std::vector signed_opponents; solver.MakeIntVarArray(num_teams, 0, num_teams - 1, "opponent_", &opponents); solver.MakeBoolVarArray(num_teams, "home_away_", &home_aways); - solver.MakeIntVarArray(num_teams, - 0, - 2 * num_teams - 1, - "signed_opponent_", + solver.MakeIntVarArray(num_teams, 0, 2 * num_teams - 1, "signed_opponent_", &signed_opponents); // All Diff constraint. @@ -178,9 +171,8 @@ void ComputeOneDayTuples(int num_teams, IntTupleSet* const day_tuples) { } // Search for solutions and fill day_tuples. - DecisionBuilder* const db = solver.MakePhase(signed_opponents, - Solver::CHOOSE_FIRST_UNBOUND, - Solver::ASSIGN_MIN_VALUE); + DecisionBuilder* const db = solver.MakePhase( + signed_opponents, Solver::CHOOSE_FIRST_UNBOUND, Solver::ASSIGN_MIN_VALUE); solver.NewSearch(db); while (solver.NextSolution()) { std::vector solution; @@ -200,8 +192,7 @@ void AddOneTeamConstraints(Solver* const solver, const std::vector& home_aways, const std::vector& signed_opponents, const IntTupleSet& home_away_tuples, - IntVar* const break_var, - int num_teams) { + IntVar* const break_var, int num_teams) { const int half_season = num_teams - 1; // Each team meet all opponents once by half season. @@ -250,9 +241,8 @@ void ComputeOneTeamHomeAwayTuples(int num_teams, IntVar* const partial_sum = solver.MakeSum(tmp_vars)->Var(); solver.AddConstraint(solver.MakeBetweenCt(partial_sum, 1, 2)); } - DecisionBuilder* const db = solver.MakePhase(home_aways, - Solver::CHOOSE_FIRST_UNBOUND, - Solver::ASSIGN_MIN_VALUE); + DecisionBuilder* const db = solver.MakePhase( + home_aways, Solver::CHOOSE_FIRST_UNBOUND, Solver::ASSIGN_MIN_VALUE); solver.NewSearch(db); while (solver.NextSolution()) { std::vector solution; @@ -290,17 +280,13 @@ void SportsScheduling(int num_teams) { // home_away result. std::vector > signed_opponents(num_teams); for (int team_index = 0; team_index < num_teams; ++team_index) { - solver.MakeIntVarArray(full_season, - 0, - num_teams - 1, + solver.MakeIntVarArray(full_season, 0, num_teams - 1, StringPrintf("opponent_%d_", team_index), &opponents[team_index]); solver.MakeBoolVarArray(full_season, StringPrintf("home_away_%d_", team_index), &home_aways[team_index]); - solver.MakeIntVarArray(full_season, - 0, - 2 * num_teams - 1, + solver.MakeIntVarArray(full_season, 0, 2 * num_teams - 1, StringPrintf("signed_opponent_%d", team_index), &signed_opponents[team_index]); } @@ -323,11 +309,9 @@ void SportsScheduling(int num_teams) { ComputeOneDayOneTeamTuples(num_teams, &one_day_one_team_tuples); for (int day = 0; day < full_season; ++day) { for (int team_index = 0; team_index < num_teams; ++team_index) { - AddOneDayOneTeamConstraint(&solver, - opponents[team_index][day], - home_aways[team_index][day], - signed_opponents[team_index][day], - one_day_one_team_tuples); + AddOneDayOneTeamConstraint( + &solver, opponents[team_index][day], home_aways[team_index][day], + signed_opponents[team_index][day], one_day_one_team_tuples); } } @@ -335,19 +319,12 @@ void SportsScheduling(int num_teams) { IntTupleSet home_away_tuples(full_season + 1); ComputeOneTeamHomeAwayTuples(num_teams, &home_away_tuples); std::vector team_breaks; - solver.MakeIntVarArray(num_teams, - 0, - full_season, - "team_break_", + solver.MakeIntVarArray(num_teams, 0, full_season, "team_break_", &team_breaks); for (int team = 0; team < num_teams; ++team) { - AddOneTeamConstraints(&solver, - opponents[team], - home_aways[team], - signed_opponents[team], - home_away_tuples, - team_breaks[team], - num_teams); + AddOneTeamConstraints(&solver, opponents[team], home_aways[team], + signed_opponents[team], home_away_tuples, + team_breaks[team], num_teams); } // ----- Search ----- @@ -385,7 +362,7 @@ void SportsScheduling(int num_teams) { monitors.push_back(limit); // Solution collector. - SolutionCollector* const collector = solver.MakeLastSolutionCollector(); + SolutionCollector* const collector = solver.MakeLastSolutionCollector(); for (int team_index = 0; team_index < num_teams; ++team_index) { collector->Add(opponents[team_index]); collector->Add(home_aways[team_index]); @@ -416,7 +393,7 @@ static const char kUsage[] = "Usage: see flags.\nThis program runs a sports scheduling problem." "There is no output besides the debug LOGs of the solver."; -int main(int argc, char **argv) { +int main(int argc, char** argv) { google::SetUsageMessage(kUsage); google::ParseCommandLineFlags(&argc, &argv, true); CHECK_EQ(0, FLAGS_num_teams % 2) << "The number of teams must be even"; diff --git a/examples/cpp/strawberry_fields_with_column_generation.cc b/examples/cpp/strawberry_fields_with_column_generation.cc index d6a0b554dc..38992fcab7 100644 --- a/examples/cpp/strawberry_fields_with_column_generation.cc +++ b/examples/cpp/strawberry_fields_with_column_generation.cc @@ -66,7 +66,6 @@ #include "base/stringprintf.h" #include "linear_solver/linear_solver.h" - DEFINE_bool(colgen_verbose, false, "print verbosely"); DEFINE_bool(colgen_complete, false, "generate all columns initially"); DEFINE_int32(colgen_max_iterations, 500, "max iterations"); @@ -82,172 +81,160 @@ struct Instance { const char* grid; }; -Instance kInstances[] = { - { 4, 22, 6, - "..@@@@@..............." - "..@@@@@@........@@@..." - ".....@@@@@......@@@..." - ".......@@@@@@@@@@@@..." - ".........@@@@@........" - ".........@@@@@........" - }, - { 3, 13, 10, - "............." - "............." - "............." - "...@@@@......" - "...@@@@......" - "...@@@@......" - ".......@@@..." - ".......@@@..." - ".......@@@..." - "............." - }, - { 4, 13, 9, - "............." - "..@.@.@......" - "...@.@.@....." - "..@.@.@......" - "..@.@.@......" - "...@.@.@....." - "....@.@......" - "..........@@@" - "..........@@@" - }, - { 4, 13, 9, - ".........@..." - ".........@..." - "@@@@@@@@@@..." - "..@......@..." - "..@......@..." - "..@......@..." - "..@@@@@@@@@@@" - "..@.........." - "..@.........." - }, - { 7, 25, 14, - "........................." - "..@@@@@@@@@@@@@@@@@@@@..." - "..@@@@@@@@@@@@@@@@@@@@..." - "..@@.................@..." - "..@@.................@..." - "..@@.......@@@.......@.@." - "..@@.......@@@.......@..." - "..@@...@@@@@@@@@@@@@@@..." - "..@@...@@@@@@@@@@@@@@@..." - "..@@.......@@@.......@..." - "..@@.......@@@.......@..." - "..@@.................@..." - "..@@.................@..." - "........................." - }, - { 6, 25, 16, - "........................." - "......@@@@@@@@@@@@@......" - "........................." - ".....@..........@........" - ".....@..........@........" - ".....@......@............" - ".....@......@.@@@@@@@...." - ".....@......@............" - ".....@......@.@@@@@@@...." - ".....@......@............" - "....@@@@....@............" - "....@@@@....@............" - "..@@@@@@....@............" - "..@@@.......@............" - "..@@@...................." - "..@@@@@@@@@@@@@@@@@@@@@@@" - }, - { 5, 40, 18, - "........................................" - "........................................" - "...@@@@@@..............................." - "...@@@@@@..............................." - "...@@@@@@..............................." - "...@@@@@@.........@@@@@@@@@@............" - "...@@@@@@.........@@@@@@@@@@............" - "..................@@@@@@@@@@............" - "..................@@@@@@@@@@............" - ".............@@@@@@@@@@@@@@@............" - ".............@@@@@@@@@@@@@@@............" - "........@@@@@@@@@@@@...................." - "........@@@@@@@@@@@@...................." - "........@@@@@@.........................." - "........@@@@@@.........................." - "........................................" - "........................................" - "........................................" - }, - { 8, 40, 18, - "........................................" - "..@@.@.@.@.............................." - "..@@.@.@.@...............@.............." - "..@@.@.@.@............@................." - "..@@.@.@.@.............................." - "..@@.@.@.@.................@............" - "..@@.@..................@..............." - "..@@.@.................................." - "..@@.@.................................." - "..@@.@................@@@@.............." - "..@@.@..............@@@@@@@@............" - "..@@.@.................................." - "..@@.@..............@@@@@@@@............" - "..@@.@.................................." - "..@@.@................@@@@.............." - "..@@.@.................................." - "..@@.@.................................." - "........................................" - }, - { 10, 40, 19, - "@@@@@..................................." - "@@@@@..................................." - "@@@@@..................................." - "@@@@@..................................." - "@@@@@..................................." - "@@@@@...........@@@@@@@@@@@............." - "@@@@@...........@@@@@@@@@@@............." - "....................@@@@................" - "....................@@@@................" - "....................@@@@................" - "....................@@@@................" - "....................@@@@................" - "...............@@@@@@@@@@@@@@..........." - "...............@@@@@@@@@@@@@@..........." - ".......@@@@@@@@@@@@@@@@@@@@@@..........." - ".......@@@@@@@@@........................" - "........................................" - "........................................" - "........................................" - }, - { 10, 40, 25, - "...................@...................." - "...............@@@@@@@@@................" - "............@@@.........@@@............." - "...........@...............@............" - "..........@.................@..........." - ".........@...................@.........." - ".........@...................@.........." - ".........@.....@@......@@....@.........." - "........@.....@@@@....@@@@....@........." - "........@.....................@........." - "........@.....................@........." - "........@..........@@.........@........." - ".......@@..........@@.........@@........" - "........@.....................@........." - "........@.....................@........." - "........@......@@@@@@@@@......@........." - "........@......@@@@@@@@@......@........." - ".........@...................@.........." - ".........@...................@.........." - ".........@...................@.........." - "..........@.................@..........." - "...........@...............@............" - "............@@@.........@@@............." - "...............@@@@@@@@@................" - "...................@...................." - } -}; +Instance kInstances[] = {{4, 22, 6, + "..@@@@@..............." + "..@@@@@@........@@@..." + ".....@@@@@......@@@..." + ".......@@@@@@@@@@@@..." + ".........@@@@@........" + ".........@@@@@........"}, + {3, 13, 10, + "............." + "............." + "............." + "...@@@@......" + "...@@@@......" + "...@@@@......" + ".......@@@..." + ".......@@@..." + ".......@@@..." + "............."}, + {4, 13, 9, + "............." + "..@.@.@......" + "...@.@.@....." + "..@.@.@......" + "..@.@.@......" + "...@.@.@....." + "....@.@......" + "..........@@@" + "..........@@@"}, + {4, 13, 9, + ".........@..." + ".........@..." + "@@@@@@@@@@..." + "..@......@..." + "..@......@..." + "..@......@..." + "..@@@@@@@@@@@" + "..@.........." + "..@.........."}, + {7, 25, 14, + "........................." + "..@@@@@@@@@@@@@@@@@@@@..." + "..@@@@@@@@@@@@@@@@@@@@..." + "..@@.................@..." + "..@@.................@..." + "..@@.......@@@.......@.@." + "..@@.......@@@.......@..." + "..@@...@@@@@@@@@@@@@@@..." + "..@@...@@@@@@@@@@@@@@@..." + "..@@.......@@@.......@..." + "..@@.......@@@.......@..." + "..@@.................@..." + "..@@.................@..." + "........................."}, + {6, 25, 16, + "........................." + "......@@@@@@@@@@@@@......" + "........................." + ".....@..........@........" + ".....@..........@........" + ".....@......@............" + ".....@......@.@@@@@@@...." + ".....@......@............" + ".....@......@.@@@@@@@...." + ".....@......@............" + "....@@@@....@............" + "....@@@@....@............" + "..@@@@@@....@............" + "..@@@.......@............" + "..@@@...................." + "..@@@@@@@@@@@@@@@@@@@@@@@"}, + {5, 40, 18, + "........................................" + "........................................" + "...@@@@@@..............................." + "...@@@@@@..............................." + "...@@@@@@..............................." + "...@@@@@@.........@@@@@@@@@@............" + "...@@@@@@.........@@@@@@@@@@............" + "..................@@@@@@@@@@............" + "..................@@@@@@@@@@............" + ".............@@@@@@@@@@@@@@@............" + ".............@@@@@@@@@@@@@@@............" + "........@@@@@@@@@@@@...................." + "........@@@@@@@@@@@@...................." + "........@@@@@@.........................." + "........@@@@@@.........................." + "........................................" + "........................................" + "........................................"}, + {8, 40, 18, + "........................................" + "..@@.@.@.@.............................." + "..@@.@.@.@...............@.............." + "..@@.@.@.@............@................." + "..@@.@.@.@.............................." + "..@@.@.@.@.................@............" + "..@@.@..................@..............." + "..@@.@.................................." + "..@@.@.................................." + "..@@.@................@@@@.............." + "..@@.@..............@@@@@@@@............" + "..@@.@.................................." + "..@@.@..............@@@@@@@@............" + "..@@.@.................................." + "..@@.@................@@@@.............." + "..@@.@.................................." + "..@@.@.................................." + "........................................"}, + {10, 40, 19, + "@@@@@..................................." + "@@@@@..................................." + "@@@@@..................................." + "@@@@@..................................." + "@@@@@..................................." + "@@@@@...........@@@@@@@@@@@............." + "@@@@@...........@@@@@@@@@@@............." + "....................@@@@................" + "....................@@@@................" + "....................@@@@................" + "....................@@@@................" + "....................@@@@................" + "...............@@@@@@@@@@@@@@..........." + "...............@@@@@@@@@@@@@@..........." + ".......@@@@@@@@@@@@@@@@@@@@@@..........." + ".......@@@@@@@@@........................" + "........................................" + "........................................" + "........................................"}, + {10, 40, 25, + "...................@...................." + "...............@@@@@@@@@................" + "............@@@.........@@@............." + "...........@...............@............" + "..........@.................@..........." + ".........@...................@.........." + ".........@...................@.........." + ".........@.....@@......@@....@.........." + "........@.....@@@@....@@@@....@........." + "........@.....................@........." + "........@.....................@........." + "........@..........@@.........@........." + ".......@@..........@@.........@@........" + "........@.....................@........." + "........@.....................@........." + "........@......@@@@@@@@@......@........." + "........@......@@@@@@@@@......@........." + ".........@...................@.........." + ".........@...................@.........." + ".........@...................@.........." + "..........@.................@..........." + "...........@...............@............" + "............@@@.........@@@............." + "...............@@@@@@@@@................" + "...................@...................."}}; const int kInstanceCount = 10; @@ -284,13 +271,13 @@ class Box { } int Cost() const { - return kAreaCost * (x_max() - x_min() + 1) * (y_max() - y_min() + 1) - + kFixedCost; + return kAreaCost * (x_max() - x_min() + 1) * (y_max() - y_min() + 1) + + kFixedCost; } std::string DebugString() const { - return StringPrintf("[%d,%dx%d,%d]c%d", - x_min(), y_min(), x_max(), y_max(), Cost()); + return StringPrintf("[%d,%dx%d,%d]c%d", x_min(), y_min(), x_max(), y_max(), + Cost()); } private: @@ -333,10 +320,10 @@ class CoveringProblem { if ((c != '@') && (c != '.')) return false; } - AddCellConstraints(); // sum for every cell is <=1 or =1 + AddCellConstraints(); // sum for every cell is <=1 or =1 AddMaxBoxesConstraint(); // sum of box variables is <= max_boxes() if (!FLAGS_colgen_complete) { - AddBox(Box(0, width()-1, 0, height()-1)); // grid-covering box + AddBox(Box(0, width() - 1, 0, height() - 1)); // grid-covering box } else { // Naive alternative to column generation - generate all boxes; // works fine for smaller problems, too slow for big. @@ -398,16 +385,16 @@ class CoveringProblem { for (int x_max = x_min; x_max < width(); ++x_max) { Box box(x_min, x_max, y_min, y_max); const double cell_coverage_dual = // inclusion-exclusion - + zero_access(upper_left_sums, x_max, y_max) - - zero_access(upper_left_sums, x_max, y_min - 1) - - zero_access(upper_left_sums, x_min - 1, y_max) - + zero_access(upper_left_sums, x_min - 1, y_min - 1); + +zero_access(upper_left_sums, x_max, y_max) - + zero_access(upper_left_sums, x_max, y_min - 1) - + zero_access(upper_left_sums, x_min - 1, y_max) + + zero_access(upper_left_sums, x_min - 1, y_min - 1); // All coefficients for new column are 1, so no need to // multiply constraint duals by any coefficients when // computing the reduced cost. - const double reduced_cost = box.Cost() - - (cell_coverage_dual + max_boxes_dual); + const double reduced_cost = + box.Cost() - (cell_coverage_dual + max_boxes_dual); if (reduced_cost < best_reduced_cost) { // Even with negative reduced cost, the box may already @@ -443,7 +430,7 @@ class CoveringProblem { MPVariable* AddBox(const Box& box) { CHECK(boxes_.find(box) == boxes_.end()); MPVariable* const var = solver_->MakeNumVar(0., 1., box.DebugString()); - solver_->SetObjectiveCoefficient(var, box.Cost()); + solver_->MutableObjective()->SetCoefficient(var, box.Cost()); max_boxes_constraint_->SetCoefficient(var, 1.0); for (int y = box.y_min(); y <= box.y_max(); ++y) { for (int x = box.x_min(); x <= box.x_max(); ++x) { @@ -456,12 +443,9 @@ class CoveringProblem { std::string PrintGrid() const { std::string output = StringPrintf("width = %d, height = %d, max_boxes = %d\n", - width_, - height_, - max_boxes_); + width_, height_, max_boxes_); for (int y = 0; y < height_; ++y) { - StringAppendF(&output, - "%s\n", + StringAppendF(&output, "%s\n", std::string(grid_ + width_ * y, width_).c_str()); } return output; @@ -473,11 +457,10 @@ class CoveringProblem { // of fractional boxes. std::string PrintCovering() const { static const double kTolerance = 1e-5; - std::string output = StringPrintf("cost = %lf\n", solver_->objective_value()); + std::string output = StringPrintf("cost = %lf\n", solver_->Objective().Value()); std::unique_ptr display(new char[(width_ + 1) * height_ + 1]); for (int y = 0; y < height_; ++y) { - memcpy(display.get() + y * (width_ + 1), - grid_ + width_ * y, + memcpy(display.get() + y * (width_ + 1), grid_ + width_ * y, width_); // Copy the original line. display[y * (width_ + 1) + width_] = '\n'; } @@ -489,10 +472,8 @@ class CoveringProblem { const char box_character = (i->second->solution_value() >= (1. - kTolerance) ? 'A' : 'a') + active_box_index++; - StringAppendF(&output, "%c: box %s with value %lf\n", - box_character, - i->first.DebugString().c_str(), - value); + StringAppendF(&output, "%c: box %s with value %lf\n", box_character, + i->first.DebugString().c_str(), value); const Box& box = i->first; for (int x = box.x_min(); x <= box.x_max(); ++x) { for (int y = box.y_min(); y <= box.y_max(); ++y) { @@ -516,8 +497,8 @@ class CoveringProblem { cells_.resize(area()); for (int y = 0; y < height(); ++y) { for (int x = 0; x < width(); ++x) { - cells_[index(x, y)] = solver_->MakeRowConstraint - (IsCellOccupied(x, y) ? 1. : 0., 1.); + cells_[index(x, y)] = + solver_->MakeRowConstraint(IsCellOccupied(x, y) ? 1. : 0., 1.); } } } @@ -541,10 +522,9 @@ class CoveringProblem { for (int y = 0; y < height(); ++y) { for (int x = 0; x < width(); ++x) { upper_left_sums->operator[](index(x, y)) = - cell(x, y)->dual_value() - + zero_access(*upper_left_sums, x - 1, y) - + zero_access(*upper_left_sums, x, y - 1) - - zero_access(*upper_left_sums, x - 1, y - 1); + cell(x, y)->dual_value() + zero_access(*upper_left_sums, x - 1, y) + + zero_access(*upper_left_sums, x, y - 1) - + zero_access(*upper_left_sums, x - 1, y - 1); } } } @@ -569,7 +549,7 @@ void SolveInstance(const Instance& instance, // Prepares the solver. MPSolver solver("ColumnGeneration", solver_type); solver.SuppressOutput(); - solver.SetMinimization(); + solver.MutableObjective()->SetMinimization(); // Construct problem. CoveringProblem problem(&solver, instance); @@ -625,24 +605,18 @@ int main(int argc, char** argv) { operations_research::MPSolver::OptimizationProblemType solver_type; bool found = false; -#if defined(USE_CLP) + #if defined(USE_CLP) if (FLAGS_colgen_solver == "clp") { solver_type = operations_research::MPSolver::CLP_LINEAR_PROGRAMMING; found = true; } -#endif // USE_CLP -#if defined(USE_GLPK) + #endif // USE_CLP + #if defined(USE_GLPK) if (FLAGS_colgen_solver == "glpk") { solver_type = operations_research::MPSolver::GLPK_LINEAR_PROGRAMMING; found = true; } -#endif // USE_GLPK -#if defined(USE_SLM) - if (FLAGS_colgen_solver == "sulum") { - solver_type = operations_research::MPSolver::SULUM_LINEAR_PROGRAMMING; - found = true; - } -#endif // USE_SLM + #endif // USE_GLPK if (!found) { LOG(ERROR) << "Unknown solver " << FLAGS_colgen_solver; return 1; diff --git a/examples/cpp/tsp.cc b/examples/cpp/tsp.cc index ca10652fa7..1e143fadfc 100644 --- a/examples/cpp/tsp.cc +++ b/examples/cpp/tsp.cc @@ -102,7 +102,7 @@ class RandomMatrix { const int size_; }; -int main(int argc, char **argv) { +int main(int argc, char** argv) { google::ParseCommandLineFlags( &argc, &argv, true); if (FLAGS_tsp_size > 0) { // TSP of size FLAGS_tsp_size. @@ -149,8 +149,7 @@ int main(int argc, char **argv) { // Only one route here; otherwise iterate from 0 to routing.vehicles() - 1 const int route_number = 0; std::string route; - for (int64 node = routing.Start(route_number); - !routing.IsEnd(node); + for (int64 node = routing.Start(route_number); !routing.IsEnd(node); node = solution->Value(routing.NextVar(node))) { route = StrCat(route, StrCat(node, " -> ")); } diff --git a/makefiles/Makefile.cpp.mk b/makefiles/Makefile.cpp.mk index 5e4f534a28..ab8f3479e6 100644 --- a/makefiles/Makefile.cpp.mk +++ b/makefiles/Makefile.cpp.mk @@ -48,7 +48,7 @@ DYNAMIC_ROUTING_DEPS = $(DYNAMIC_ROUTING_LIBS) $(DYNAMIC_CP_LIBS) $(DYNAMIC_LP_L DYNAMIC_FLATZINC_DEPS = $(DYNAMIC_FLATZINC_LIBS) $(DYNAMIC_CP_LIBS) $(DYNAMIC_LP_LIBS) $(DYNAMIC_BASE_LIBS) -DYNAMIC_DIMACS_DEPS = $(DYNAMIC_DIMACS_LIBS) $(DYNAMIC_GRAPH_LIBS) $(DYNAMIC_ALGORITHMS_LIBS) $(DYNAMIC_BASE_LIBS) +DYNAMIC_DIMACS_DEPS = $(DYNAMIC_DIMACS_LIBS) $(DYNAMIC_LP_LIBS) $(DYNAMIC_GRAPH_LIBS) $(DYNAMIC_ALGORITHMS_LIBS) $(DYNAMIC_BASE_LIBS) DYNAMIC_FAP_DEPS = \ $(DYNAMIC_FAP_LIBS) \ @@ -558,6 +558,7 @@ UTIL_LIB_OBJS=\ $(OBJ_DIR)/piecewise_linear_function.$O \ $(OBJ_DIR)/saturated_arithmetic.$O \ $(OBJ_DIR)/stats.$O \ + $(OBJ_DIR)/time_limit.$O \ $(OBJ_DIR)/xml_helper.$O $(OBJ_DIR)/bitset.$O:$(SRC_DIR)/util/bitset.cc @@ -578,6 +579,9 @@ $(OBJ_DIR)/saturated_arithmetic.$O:$(SRC_DIR)/util/saturated_arithmetic.cc $(OBJ_DIR)/stats.$O:$(SRC_DIR)/util/stats.cc $(CCC) $(CFLAGS) -c $(SRC_DIR)/util/stats.cc $(OBJ_OUT)$(OBJ_DIR)$Sstats.$O +$(OBJ_DIR)/time_limit.$O:$(SRC_DIR)/util/time_limit.cc + $(CCC) $(CFLAGS) -c $(SRC_DIR)/util/time_limit.cc $(OBJ_OUT)$(OBJ_DIR)$Stime_limit.$O + $(OBJ_DIR)/xml_helper.$O:$(SRC_DIR)/util/xml_helper.cc $(CCC) $(CFLAGS) -c $(SRC_DIR)/util/xml_helper.cc $(OBJ_OUT)$(OBJ_DIR)$Sxml_helper.$O diff --git a/src/algorithms/hungarian.cc b/src/algorithms/hungarian.cc index c1e6348036..f759d71703 100644 --- a/src/algorithms/hungarian.cc +++ b/src/algorithms/hungarian.cc @@ -61,9 +61,7 @@ class HungarianOptimizer { void FindAssignments(std::vector* agent, std::vector* task); // Is the cell (row, col) starred? - bool IsStarred(int row, int col) const { - return marks_[row][col] == STAR; - } + bool IsStarred(int row, int col) const { return marks_[row][col] == STAR; } // Mark cell (row, col) with a star void Star(int row, int col) { @@ -86,14 +84,10 @@ class HungarianOptimizer { int FindStarInCol(int col) const; // Is cell (row, col) marked with a prime? - bool IsPrimed(int row, int col) const { - return marks_[row][col] == PRIME; - } + bool IsPrimed(int row, int col) const { return marks_[row][col] == PRIME; } // Mark cell (row, col) with a prime. - void Prime(int row, int col) { - marks_[row][col] = PRIME; - } + void Prime(int row, int col) { marks_[row][col] = PRIME; } // Find a column in row containing a prime, or return // kHungarianOptimizerColNotFound if no such column exists. @@ -103,39 +97,25 @@ class HungarianOptimizer { void ClearPrimes(); // Does column col contain a star? - bool ColContainsStar(int col) const { - return stars_in_col_[col] > 0; - } + bool ColContainsStar(int col) const { return stars_in_col_[col] > 0; } // Is row 'row' covered? - bool RowCovered(int row) const { - return rows_covered_[row]; - } + bool RowCovered(int row) const { return rows_covered_[row]; } // Cover row 'row'. - void CoverRow(int row) { - rows_covered_[row] = true; - } + void CoverRow(int row) { rows_covered_[row] = true; } // Uncover row 'row'. - void UncoverRow(int row) { - rows_covered_[row] = false; - } + void UncoverRow(int row) { rows_covered_[row] = false; } // Is column col covered? - bool ColCovered(int col) const { - return cols_covered_[col]; - } + bool ColCovered(int col) const { return cols_covered_[col]; } // Cover column col. - void CoverCol(int col) { - cols_covered_[col] = true; - } + void CoverCol(int col) { cols_covered_[col] = true; } // Uncover column col. - void UncoverCol(int col) { - cols_covered_[col] = false; - } + void UncoverCol(int col) { cols_covered_[col] = false; } // Uncover ever row and column in the matrix. void ClearCovers(); @@ -215,8 +195,8 @@ class HungarianOptimizer { std::vector stars_in_col_; // Representation of a path_ through the matrix - used in step 5. - std::vector preimage_; // i.e. the agents - std::vector image_; // i.e. the tasks + std::vector preimage_; // i.e. the agents + std::vector image_; // i.e. the tasks // The locations of a zero found in step 4. int zero_col_, zero_row_; @@ -280,7 +260,7 @@ HungarianOptimizer::HungarianOptimizer(const std::vector >& for (int row = 0; row < matrix_size_; ++row) { marks_[row].resize(matrix_size_); for (int col = 0; col < matrix_size_; ++col) { - marks_[row][col]=NONE; + marks_[row][col] = NONE; } } @@ -307,7 +287,6 @@ void HungarianOptimizer::Maximize(std::vector* preimage, std::vector* Minimize(preimage, image); } - // Find an assignment which minimizes the total cost. // Return an array of pairs of integers. Each pair (i, j) corresponds to // assigning agent i to task j. @@ -615,7 +594,7 @@ void HungarianOptimizer::MakeAugmentingPath() { if (row != kHungarianOptimizerRowNotFound) { count++; preimage_[count] = row; - image_[count] = image_[count-1]; + image_[count] = image_[count - 1]; } else { done = true; } @@ -623,7 +602,7 @@ void HungarianOptimizer::MakeAugmentingPath() { if (!done) { int col = FindPrimeInRow(preimage_[count]); count++; - preimage_[count] = preimage_[count-1]; + preimage_[count] = preimage_[count - 1]; image_[count] = col; } } @@ -667,7 +646,6 @@ void HungarianOptimizer::AugmentPath() { state_ = &HungarianOptimizer::PrimeZeroes; } - void MinimizeLinearAssignment(const std::vector >& cost, hash_map* direct_assignment, hash_map* reverse_assignment) { diff --git a/src/algorithms/knapsack_solver.cc b/src/algorithms/knapsack_solver.cc index 8201a8dd92..cf60628437 100644 --- a/src/algorithms/knapsack_solver.cc +++ b/src/algorithms/knapsack_solver.cc @@ -35,10 +35,9 @@ const int kMaxNumberOf64Items = 64; // (see KnapsackCapacityPropagator). struct CompareKnapsackItemsInDecreasingEfficiencyOrder { explicit CompareKnapsackItemsInDecreasingEfficiencyOrder(int64 _profit_max) - : profit_max(_profit_max) { - } - bool operator() (const KnapsackItemPtr& item1, - const KnapsackItemPtr& item2) const { + : profit_max(_profit_max) {} + bool operator()(const KnapsackItemPtr& item1, + const KnapsackItemPtr& item2) const { return item1->GetEfficiency(profit_max) > item2->GetEfficiency(profit_max); } const int64 profit_max; @@ -61,10 +60,9 @@ struct CompareKnapsackSearchNodePtrInDecreasingUpperBoundOrder { } }; -typedef std::priority_queue< - KnapsackSearchNode*, - std::vector, - CompareKnapsackSearchNodePtrInDecreasingUpperBoundOrder> SearchQueue; +typedef std::priority_queue, + CompareKnapsackSearchNodePtrInDecreasingUpperBoundOrder> + SearchQueue; // Returns true when value_1 * value_2 may overflow int64. inline bool WillProductOverflow(int64 value_1, int64 value_2) { @@ -77,8 +75,7 @@ inline bool WillProductOverflow(int64 value_1, int64 value_2) { } // Returns an upper bound of (numerator_1 * numerator_2) / denominator -int64 UpperBoundOfRatio(int64 numerator_1, - int64 numerator_2, +int64 UpperBoundOfRatio(int64 numerator_1, int64 numerator_2, int64 denominator) { DCHECK_GT(denominator, 0LL); if (!WillProductOverflow(numerator_1, numerator_2)) { @@ -87,9 +84,9 @@ int64 UpperBoundOfRatio(int64 numerator_1, const int64 result = numerator / denominator; return result; } else { - const double ratio = (static_cast(numerator_1) - * static_cast(numerator_2)) - / static_cast(denominator); + const double ratio = + (static_cast(numerator_1) * static_cast(numerator_2)) / + static_cast(denominator); // Round near. const int64 result = static_cast(floor(ratio + 0.5)); return result; @@ -106,16 +103,12 @@ KnapsackSearchNode::KnapsackSearchNode(const KnapsackSearchNode* const parent, assignment_(assignment), current_profit_(0), profit_upper_bound_(kint64max), - next_item_id_(kNoSelection) { -} + next_item_id_(kNoSelection) {} // ----- KnapsackSearchPath ----- KnapsackSearchPath::KnapsackSearchPath(const KnapsackSearchNode& from, const KnapsackSearchNode& to) - : from_(from), - via_(NULL), - to_(to) { -} + : from_(from), via_(NULL), to_(to) {} void KnapsackSearchPath::Init() { const KnapsackSearchNode* node_from = MoveUpToDepth(from_, to_.depth()); @@ -131,8 +124,7 @@ void KnapsackSearchPath::Init() { } const KnapsackSearchNode* KnapsackSearchPath::MoveUpToDepth( - const KnapsackSearchNode& node, - int depth) const { + const KnapsackSearchNode& node, int depth) const { const KnapsackSearchNode* current_node = &node; while (current_node->depth() > depth) { current_node = current_node->parent(); @@ -154,8 +146,8 @@ bool KnapsackState::UpdateState(bool revert, if (revert) { is_bound_[assignment.item_id] = false; } else { - if (is_bound_[assignment.item_id] - && is_in_[assignment.item_id] != assignment.is_in) { + if (is_bound_[assignment.item_id] && + is_in_[assignment.item_id] != assignment.is_in) { return false; } is_bound_[assignment.item_id] = true; @@ -170,12 +162,9 @@ KnapsackPropagator::KnapsackPropagator(const KnapsackState& state) current_profit_(0), profit_lower_bound_(0), profit_upper_bound_(kint64max), - state_(state) { -} + state_(state) {} -KnapsackPropagator::~KnapsackPropagator() { - STLDeleteElements(&items_); -} +KnapsackPropagator::~KnapsackPropagator() { STLDeleteElements(&items_); } void KnapsackPropagator::Init(const std::vector& profits, const std::vector& weights) { @@ -203,8 +192,7 @@ bool KnapsackPropagator::Update(bool revert, } void KnapsackPropagator::CopyCurrentStateToSolution( - bool has_one_propagator, - std::vector* solution) const { + bool has_one_propagator, std::vector* solution) const { CHECK_NOTNULL(solution); for (ConstIter > it(items_); !it.at_end(); ++it) { const KnapsackItem* const item = *it; @@ -216,21 +204,17 @@ void KnapsackPropagator::CopyCurrentStateToSolution( } } - // ----- KnapsackCapacityPropagator ----- KnapsackCapacityPropagator::KnapsackCapacityPropagator( - const KnapsackState& state, - int64 capacity) + const KnapsackState& state, int64 capacity) : KnapsackPropagator(state), capacity_(capacity), consumed_capacity_(0), break_item_id_(kNoSelection), sorted_items_(), - profit_max_(0) { -} + profit_max_(0) {} -KnapsackCapacityPropagator::~KnapsackCapacityPropagator() { -} +KnapsackCapacityPropagator::~KnapsackCapacityPropagator() {} // TODO(user): Make it more incremental, by saving the break item in a // search node for instance. @@ -259,8 +243,8 @@ void KnapsackCapacityPropagator::ComputeProfitBounds() { set_profit_upper_bound(profit_lower_bound()); if (break_sorted_item_id != kNoSelection) { - const int64 additional_profit = GetAdditionalProfit(remaining_capacity, - break_sorted_item_id); + const int64 additional_profit = + GetAdditionalProfit(remaining_capacity, break_sorted_item_id); set_profit_upper_bound(profit_upper_bound() + additional_profit); } } @@ -270,8 +254,8 @@ void KnapsackCapacityPropagator::InitPropagator() { break_item_id_ = kNoSelection; sorted_items_ = items(); profit_max_ = 0; - for (ConstIter > it(sorted_items_); - !it.at_end(); ++it) { + for (ConstIter > it(sorted_items_); !it.at_end(); + ++it) { profit_max_ = std::max(profit_max_, (*it)->profit); } ++profit_max_; @@ -281,8 +265,7 @@ void KnapsackCapacityPropagator::InitPropagator() { // Returns false when the propagator fails. bool KnapsackCapacityPropagator::UpdatePropagator( - bool revert, - const KnapsackAssignment& assignment) { + bool revert, const KnapsackAssignment& assignment) { if (assignment.is_in) { if (revert) { consumed_capacity_ -= items()[assignment.item_id]->weight; @@ -300,8 +283,8 @@ void KnapsackCapacityPropagator::CopyCurrentStateToSolutionPropagator( std::vector* solution) const { CHECK_NOTNULL(solution); int64 remaining_capacity = capacity_ - consumed_capacity_; - for (ConstIter > it(sorted_items_); - !it.at_end(); ++it) { + for (ConstIter > it(sorted_items_); !it.at_end(); + ++it) { const KnapsackItem* const item = *it; if (!state().is_bound(item->id)) { if (remaining_capacity >= item->weight) { @@ -323,8 +306,8 @@ int64 KnapsackCapacityPropagator::GetAdditionalProfit(int64 remaining_capacity, // weight is non-zero, the next_weight is non-zero too. const int64 next_weight = sorted_items_[after_break_item_id]->weight; const int64 next_profit = sorted_items_[after_break_item_id]->profit; - additional_profit_when_no_break_item = UpperBoundOfRatio( - remaining_capacity, next_profit, next_weight); + additional_profit_when_no_break_item = + UpperBoundOfRatio(remaining_capacity, next_profit, next_weight); } const int before_break_item_id = break_item_id - 1; @@ -336,12 +319,12 @@ int64 KnapsackCapacityPropagator::GetAdditionalProfit(int64 remaining_capacity, // of a solution of the local one dimension problem. if (previous_weight != 0) { const int64 previous_profit = sorted_items_[before_break_item_id]->profit; - const int64 overused_capacity = sorted_items_[break_item_id]->weight - - remaining_capacity; - const int64 ratio = UpperBoundOfRatio( - overused_capacity, previous_profit, previous_weight); - additional_profit_when_break_item = sorted_items_[break_item_id]->profit - - ratio; + const int64 overused_capacity = + sorted_items_[break_item_id]->weight - remaining_capacity; + const int64 ratio = UpperBoundOfRatio(overused_capacity, previous_profit, + previous_weight); + additional_profit_when_break_item = + sorted_items_[break_item_id]->profit - ratio; } } @@ -359,12 +342,9 @@ KnapsackGenericSolver::KnapsackGenericSolver(const std::string& solver_name) search_nodes_(), state_(), best_solution_profit_(0), - best_solution_() { -} + best_solution_() {} -KnapsackGenericSolver::~KnapsackGenericSolver() { - Clear(); -} +KnapsackGenericSolver::~KnapsackGenericSolver() { Clear(); } void KnapsackGenericSolver::Init(const std::vector& profits, const std::vector >& weights, @@ -399,8 +379,9 @@ void KnapsackGenericSolver::GetLowerAndUpperBoundWhenItem(int item_id, *lower_bound = 0LL; *upper_bound = 0LL; } else { - *lower_bound = (HasOnePropagator()) ? - propagators_[master_propagator_id_]->profit_lower_bound() : 0LL; + *lower_bound = (HasOnePropagator()) ? propagators_[master_propagator_id_] + ->profit_lower_bound() + : 0LL; *upper_bound = GetAggregatedProfitUpperBound(); } @@ -479,8 +460,8 @@ bool KnapsackGenericSolver::UpdatePropagators(const KnapsackSearchPath& path) { int64 KnapsackGenericSolver::GetAggregatedProfitUpperBound() const { int64 upper_bound = kint64max; - for (ConstIter > it(propagators_); - !it.at_end(); ++it) { + for (ConstIter > it(propagators_); !it.at_end(); + ++it) { (*it)->ComputeProfitBounds(); const int64 propagator_upper_bound = (*it)->profit_upper_bound(); upper_bound = std::min(upper_bound, propagator_upper_bound); @@ -526,28 +507,27 @@ bool KnapsackGenericSolver::MakeNewNode(const KnapsackSearchNode& node, } bool KnapsackGenericSolver::IncrementalUpdate( - bool revert, - const KnapsackAssignment& assignment) { + bool revert, const KnapsackAssignment& assignment) { // Do not stop on a failure: To be able to be incremental on the update, // partial solution (state) and propagators must all be in the same state. bool no_fail = state_.UpdateState(revert, assignment); - for (ConstIter > it(propagators_); - !it.at_end(); ++it) { + for (ConstIter > it(propagators_); !it.at_end(); + ++it) { no_fail = (*it)->Update(revert, assignment) && no_fail; } return no_fail; } void KnapsackGenericSolver::UpdateBestSolution() { - const int64 profit_lower_bound = (HasOnePropagator()) ? - propagators_[master_propagator_id_]->profit_lower_bound() : - propagators_[master_propagator_id_]->current_profit(); + const int64 profit_lower_bound = + (HasOnePropagator()) + ? propagators_[master_propagator_id_]->profit_lower_bound() + : propagators_[master_propagator_id_]->current_profit(); if (best_solution_profit_ < profit_lower_bound) { best_solution_profit_ = profit_lower_bound; - propagators_[master_propagator_id_]->CopyCurrentStateToSolution( - HasOnePropagator(), - &best_solution_); + propagators_[master_propagator_id_] + ->CopyCurrentStateToSolution(HasOnePropagator(), &best_solution_); } } @@ -561,8 +541,7 @@ class KnapsackBruteForceSolver : public BaseKnapsackSolver { explicit KnapsackBruteForceSolver(const std::string& solver_name); // Initializes the solver and enters the problem to be solved. - void Init(const std::vector& profits, - const std::vector >& weights, + void Init(const std::vector& profits, const std::vector >& weights, const std::vector& capacities); // Solves the problem and returns the profit of the optimal solution. @@ -588,8 +567,7 @@ KnapsackBruteForceSolver::KnapsackBruteForceSolver(const std::string& solver_nam num_items_(0), capacity_(0LL), best_solution_profit_(0LL), - best_solution_(0U) { -} + best_solution_(0U) {} void KnapsackBruteForceSolver::Init(const std::vector& profits, const std::vector >& weights, @@ -603,7 +581,7 @@ void KnapsackBruteForceSolver::Init(const std::vector& profits, CHECK_EQ(num_items_, weights.at(0).size()); CHECK_LE(num_items_, kMaxNumberOfBruteForceItems) << "To use KnapsackBruteForceSolver the number of items should be " - << "less than " << kMaxNumberOfBruteForceItems + << "less than " << kMaxNumberOfBruteForceItems << ". Current value: " << num_items_ << "."; for (int i = 0; i < num_items_; ++i) { @@ -626,20 +604,20 @@ int64 KnapsackBruteForceSolver::Solve() { int item_id = 0; // This loop starts at 1, because state = 0 was already considered previously, // ie. when no items are in, sum_profit = 0. - for (uint32 state = 1U ; state < num_states; ++state, ++prev_state) { + for (uint32 state = 1U; state < num_states; ++state, ++prev_state) { diff_state = state ^ prev_state; local_state = state; item_id = 0; while (diff_state) { - if (diff_state & 1U) { // There is a diff. + if (diff_state & 1U) { // There is a diff. if (local_state & 1U) { // This item is now in the knapsack. sum_profit += profits_weights_[item_id]; sum_weight += profits_weights_[item_id + 1]; - CHECK_LT(item_id +1 , 2 * num_items_); + CHECK_LT(item_id + 1, 2 * num_items_); } else { // This item has been removed of the knapsack. sum_profit -= profits_weights_[item_id]; sum_weight -= profits_weights_[item_id + 1]; - CHECK_LT(item_id + 1 , 2 * num_items_); + CHECK_LT(item_id + 1, 2 * num_items_); } } item_id += 2; @@ -663,17 +641,14 @@ int64 KnapsackBruteForceSolver::Solve() { // with one dimension, that's more efficient to store 'efficiency' than // computing it on the fly. struct KnapsackItemWithEfficiency { - KnapsackItemWithEfficiency(int _id, - int64 _profit, - int64 _weight, + KnapsackItemWithEfficiency(int _id, int64 _profit, int64 _weight, int64 _profit_max) : id(_id), profit(_profit), weight(_weight), - efficiency((weight > 0) ? - static_cast(_profit) / static_cast(_weight) : - static_cast(_profit_max)) { - } + efficiency((weight > 0) ? static_cast(_profit) / + static_cast(_weight) + : static_cast(_profit_max)) {} int id; int64 profit; @@ -690,8 +665,7 @@ class Knapsack64ItemsSolver : public BaseKnapsackSolver { explicit Knapsack64ItemsSolver(const std::string& solver_name); // Initializes the solver and enters the problem to be solved. - void Init(const std::vector& profits, - const std::vector >& weights, + void Init(const std::vector& profits, const std::vector >& weights, const std::vector& capacities); // Solves the problem and returns the profit of the optimal solution. @@ -731,7 +705,7 @@ class Knapsack64ItemsSolver : public BaseKnapsackSolver { bool CompareKnapsackItemWithEfficiencyInDecreasingEfficiencyOrder( const KnapsackItemWithEfficiency& item1, const KnapsackItemWithEfficiency& item2) { - return item1.efficiency > item2.efficiency; + return item1.efficiency > item2.efficiency; } // ----- Knapsack64ItemsSolver ----- @@ -748,8 +722,7 @@ Knapsack64ItemsSolver::Knapsack64ItemsSolver(const std::string& solver_name) best_solution_depth_(0), state_weight_(0LL), rejected_items_profit_(0LL), - rejected_items_weight_(0LL) { -} + rejected_items_weight_(0LL) {} void Knapsack64ItemsSolver::Init(const std::vector& profits, const std::vector >& weights, @@ -766,15 +739,13 @@ void Knapsack64ItemsSolver::Init(const std::vector& profits, const int num_items = profits.size(); CHECK_LE(num_items, kMaxNumberOf64Items) << "To use Knapsack64ItemsSolver the number of items should be " - << "less than " << kMaxNumberOf64Items - << ". Current value: " << num_items << "."; + << "less than " << kMaxNumberOf64Items << ". Current value: " << num_items + << "."; int64 profit_max = *max_element(profits.begin(), profits.end()); for (int i = 0; i < num_items; ++i) { - sorted_items_.push_back(KnapsackItemWithEfficiency(i, - profits[i], - weights[0][i], - profit_max)); + sorted_items_.push_back( + KnapsackItemWithEfficiency(i, profits[i], weights[0][i], profit_max)); } std::sort(sorted_items_.begin(), sorted_items_.end(), @@ -829,11 +800,8 @@ int64 Knapsack64ItemsSolver::Solve() { int Knapsack64ItemsSolver::GetBreakItemId(int64 capacity) const { std::vector::const_iterator binary_search_iterator = - upper_bound(sum_weights_.begin(), - sum_weights_.end(), - capacity); - return static_cast(binary_search_iterator - - sum_weights_.begin()) -1; + upper_bound(sum_weights_.begin(), sum_weights_.end(), capacity); + return static_cast(binary_search_iterator - sum_weights_.begin()) - 1; } // This method is called for each possible state. @@ -949,17 +917,14 @@ class KnapsackDynamicProgrammingSolver : public BaseKnapsackSolver { explicit KnapsackDynamicProgrammingSolver(const std::string& solver_name); // Initializes the solver and enters the problem to be solved. - void Init(const std::vector& profits, - const std::vector >& weights, + void Init(const std::vector& profits, const std::vector >& weights, const std::vector& capacities); // Solves the problem and returns the profit of the optimal solution. int64 Solve(); // Returns true if the item 'item_id' is packed in the optimal knapsack. - bool best_solution(int item_id) const { - return best_solution_.at(item_id); - } + bool best_solution(int item_id) const { return best_solution_.at(item_id); } private: int64 SolveSubProblem(int64 capacity, int num_items); @@ -974,18 +939,17 @@ class KnapsackDynamicProgrammingSolver : public BaseKnapsackSolver { // ----- KnapsackDynamicProgrammingSolver ----- KnapsackDynamicProgrammingSolver::KnapsackDynamicProgrammingSolver( - const std::string& solver_name) : BaseKnapsackSolver(solver_name), - profits_(), - weights_(), - capacity_(0), - computed_profits_(), - selected_item_ids_(), - best_solution_() { -} + const std::string& solver_name) + : BaseKnapsackSolver(solver_name), + profits_(), + weights_(), + capacity_(0), + computed_profits_(), + selected_item_ids_(), + best_solution_() {} void KnapsackDynamicProgrammingSolver::Init( - const std::vector& profits, - const std::vector >& weights, + const std::vector& profits, const std::vector >& weights, const std::vector& capacities) { CHECK_EQ(weights.size(), 1) << "Current implementation of the dynamic programming solver only deals" @@ -1005,8 +969,7 @@ int64 KnapsackDynamicProgrammingSolver::SolveSubProblem(int64 capacity, for (int item_id = 0; item_id < num_items; ++item_id) { const int64 item_weight = weights_[item_id]; const int64 item_profit = profits_[item_id]; - for (int64 used_capacity = capacity; - used_capacity >= item_weight; + for (int64 used_capacity = capacity; used_capacity >= item_weight; --used_capacity) { if (computed_profits_[used_capacity - item_weight] + item_profit > computed_profits_[used_capacity]) { @@ -1043,22 +1006,18 @@ int64 KnapsackDynamicProgrammingSolver::Solve() { // ----- KnapsackMIPSolver ----- class KnapsackMIPSolver : public BaseKnapsackSolver { public: - KnapsackMIPSolver( - MPSolver::OptimizationProblemType problem_type, - const std::string& solver_name); + KnapsackMIPSolver(MPSolver::OptimizationProblemType problem_type, + const std::string& solver_name); // Initializes the solver and enters the problem to be solved. - void Init(const std::vector& profits, - const std::vector >& weights, + void Init(const std::vector& profits, const std::vector >& weights, const std::vector& capacities); // Solves the problem and returns the profit of the optimal solution. int64 Solve(); // Returns true if the item 'item_id' is packed in the optimal knapsack. - bool best_solution(int item_id) const { - return best_solution_.at(item_id); - } + bool best_solution(int item_id) const { return best_solution_.at(item_id); } private: MPSolver::OptimizationProblemType problem_type_; @@ -1075,8 +1034,7 @@ KnapsackMIPSolver::KnapsackMIPSolver( profits_(), weights_(), capacities_(), - best_solution_() { -} + best_solution_() {} void KnapsackMIPSolver::Init(const std::vector& profits, const std::vector >& weights, @@ -1096,8 +1054,7 @@ int64 KnapsackMIPSolver::Solve() { // Add constraints. const int num_dimensions = capacities_.size(); for (int i = 0; i < num_dimensions; ++i) { - MPConstraint* const ct = - solver.MakeRowConstraint(0LL, capacities_.at(i)); + MPConstraint* const ct = solver.MakeRowConstraint(0LL, capacities_.at(i)); for (int j = 0; j < num_items; ++j) { ct->SetCoefficient(variables.at(j), weights_.at(i).at(j)); } @@ -1106,9 +1063,11 @@ int64 KnapsackMIPSolver::Solve() { // Define objective to minimize. Minimization is used instead of maximization // because of an issue with CBC solver which does not always find the optimal // solution on maximization problems. + MPObjective* const objective = solver.MutableObjective(); for (int j = 0; j < num_items; ++j) { - solver.SetObjectiveCoefficient(variables.at(j), -profits_.at(j)); + objective->SetCoefficient(variables.at(j), -profits_.at(j)); } + objective->SetMinimization(); solver.SuppressOutput(); solver.Solve(); @@ -1121,7 +1080,7 @@ int64 KnapsackMIPSolver::Solve() { best_solution_.at(j) = value >= kRoundNear; } - return -solver.objective_value() + kRoundNear; + return -objective->Value() + kRoundNear; } // ----- KnapsackSolver ----- @@ -1132,8 +1091,7 @@ KnapsackSolver::KnapsackSolver(const std::string& solver_name) mapping_reduced_item_id_(), is_problem_solved_(false), additional_profit_(0LL), - use_reduction_(true) { -} + use_reduction_(true) {} KnapsackSolver::KnapsackSolver(SolverType solver_type, const std::string& solver_name) @@ -1157,27 +1115,24 @@ KnapsackSolver::KnapsackSolver(SolverType solver_type, case KNAPSACK_MULTIDIMENSION_BRANCH_AND_BOUND_SOLVER: solver_.reset(new KnapsackGenericSolver(solver_name)); break; -#if defined(USE_CBC) + #if defined(USE_CBC) case KNAPSACK_MULTIDIMENSION_CBC_MIP_SOLVER: solver_.reset(new KnapsackMIPSolver( - MPSolver::CBC_MIXED_INTEGER_PROGRAMMING, - solver_name)); + MPSolver::CBC_MIXED_INTEGER_PROGRAMMING, solver_name)); break; -#endif // USE_CBC -#if defined(USE_GLPK) + #endif // USE_CBC + #if defined(USE_GLPK) case KNAPSACK_MULTIDIMENSION_GLPK_MIP_SOLVER: solver_.reset(new KnapsackMIPSolver( - MPSolver::GLPK_MIXED_INTEGER_PROGRAMMING, - solver_name)); + MPSolver::GLPK_MIXED_INTEGER_PROGRAMMING, solver_name)); break; -#endif // USE_GLPK + #endif // USE_GLPK default: LOG(FATAL) << "Unknown knapsack solver type."; } } -KnapsackSolver::~KnapsackSolver() { -} +KnapsackSolver::~KnapsackSolver() {} void KnapsackSolver::Init(const std::vector& profits, const std::vector >& weights, @@ -1216,16 +1171,12 @@ int KnapsackSolver::ReduceProblem(int num_items) { for (int item_id = 0; item_id < num_items; ++item_id) { int64 lower_bound = 0LL; int64 upper_bound = kint64max; - solver_->GetLowerAndUpperBoundWhenItem(item_id, - false, - &lower_bound, + solver_->GetLowerAndUpperBoundWhenItem(item_id, false, &lower_bound, &upper_bound); J1_upper_bounds.at(item_id) = upper_bound; best_lower_bound = std::max(best_lower_bound, lower_bound); - solver_->GetLowerAndUpperBoundWhenItem(item_id, - true, - &lower_bound, + solver_->GetLowerAndUpperBoundWhenItem(item_id, true, &lower_bound, &upper_bound); J0_upper_bounds.at(item_id) = upper_bound; best_lower_bound = std::max(best_lower_bound, lower_bound); @@ -1283,8 +1234,7 @@ void KnapsackSolver::InitReducedProblem(const std::vector& profits, reduced_capacities[dim] -= one_dimension_weights[item_id]; } } else { - one_dimension_reduced_weights.push_back( - one_dimension_weights[item_id]); + one_dimension_reduced_weights.push_back(one_dimension_weights[item_id]); } } reduced_weights.push_back(one_dimension_reduced_weights); @@ -1297,15 +1247,14 @@ int64 KnapsackSolver::Solve() { } bool KnapsackSolver::BestSolutionContains(int item_id) const { - const int mapped_item_id = (use_reduction_) ? - mapping_reduced_item_id_[item_id] : item_id; - return (use_reduction_ && known_value_[item_id]) ? best_solution_[item_id] - : solver_->best_solution(mapped_item_id); + const int mapped_item_id = + (use_reduction_) ? mapping_reduced_item_id_[item_id] : item_id; + return (use_reduction_ && known_value_[item_id]) + ? best_solution_[item_id] + : solver_->best_solution(mapped_item_id); } -std::string KnapsackSolver::GetName() const { - return solver_->GetName(); -} +std::string KnapsackSolver::GetName() const { return solver_->GetName(); } // ----- BaseKnapsackSolver ----- void BaseKnapsackSolver::GetLowerAndUpperBoundWhenItem(int item_id, diff --git a/src/algorithms/knapsack_solver.h b/src/algorithms/knapsack_solver.h index 5c27ecf65a..f92c62f1fb 100644 --- a/src/algorithms/knapsack_solver.h +++ b/src/algorithms/knapsack_solver.h @@ -53,7 +53,6 @@ // solver.Init(profits, weights, capacities); // int64 profit = solver.Solve(); - #ifndef OR_TOOLS_ALGORITHMS_KNAPSACK_SOLVER_H_ #define OR_TOOLS_ALGORITHMS_KNAPSACK_SOLVER_H_ @@ -68,7 +67,6 @@ #include "base/macros.h" #include "base/scoped_ptr.h" - namespace operations_research { // ----- KnapsackSolver ----- @@ -115,12 +113,12 @@ class KnapsackSolver { KNAPSACK_BRUTE_FORCE_SOLVER, KNAPSACK_64ITEMS_SOLVER, KNAPSACK_DYNAMIC_PROGRAMMING_SOLVER, -#if defined(USE_CBC) + #if defined(USE_CBC) KNAPSACK_MULTIDIMENSION_CBC_MIP_SOLVER, -#endif // USE_CBC -#if defined(USE_GLPK) + #endif // USE_CBC + #if defined(USE_GLPK) KNAPSACK_MULTIDIMENSION_GLPK_MIP_SOLVER, -#endif // USE_GLPK + #endif // USE_GLPK KNAPSACK_MULTIDIMENSION_BRANCH_AND_BOUND_SOLVER }; @@ -129,8 +127,7 @@ class KnapsackSolver { virtual ~KnapsackSolver(); // Initializes the solver and enters the problem to be solved. - void Init(const std::vector& profits, - const std::vector >& weights, + void Init(const std::vector& profits, const std::vector >& weights, const std::vector& capacities); // Solves the problem and returns the profit of the optimal solution. @@ -190,9 +187,7 @@ class KnapsackSolver { // assignment. It is mainly used for search nodes and updates. struct KnapsackAssignment { KnapsackAssignment(int _item_id, bool _is_in) - : item_id(_item_id), - is_in(_is_in) { - } + : item_id(_item_id), is_in(_is_in) {} int item_id; bool is_in; }; @@ -211,14 +206,11 @@ struct KnapsackAssignment { // issue. struct KnapsackItem { KnapsackItem(int _id, int64 _weight, int64 _profit) - : id(_id), - weight(_weight), - profit(_profit) { - } + : id(_id), weight(_weight), profit(_profit) {} double GetEfficiency(int64 profit_max) const { - return (weight > 0) ? - static_cast(profit) / static_cast(weight) : - static_cast(profit_max); + return (weight > 0) + ? static_cast(profit) / static_cast(weight) + : static_cast(profit_max); } // The 'id' field is used to retrieve the initial item in order to @@ -299,6 +291,7 @@ class KnapsackSearchPath { const KnapsackSearchNode& to() const { return to_; } const KnapsackSearchNode* MoveUpToDepth(const KnapsackSearchNode& node, int depth) const; + private: const KnapsackSearchNode& from_; const KnapsackSearchNode* via_; // Computed in 'Init'. @@ -348,8 +341,7 @@ class KnapsackPropagator { virtual ~KnapsackPropagator(); // Initializes data structure and then calls InitPropagator. - void Init(const std::vector& profits, - const std::vector& weights); + void Init(const std::vector& profits, const std::vector& weights); // Updates data structure and then calls UpdatePropagator. // Returns false when failure. @@ -389,8 +381,8 @@ class KnapsackPropagator { // called with current state. // This method is useful when a propagator is able to find a better solution // than the blind instantiation to false of unbound items. - virtual void CopyCurrentStateToSolutionPropagator( - std::vector* solution) const = 0; + virtual void CopyCurrentStateToSolutionPropagator(std::vector* solution) + const = 0; const KnapsackState& state() const { return state_; } const std::vector& items() const { return items_; } @@ -441,8 +433,8 @@ class KnapsackCapacityPropagator : public KnapsackPropagator { // to avoid a O(number_of_items) scan. virtual bool UpdatePropagator(bool revert, const KnapsackAssignment& assignment); - virtual void CopyCurrentStateToSolutionPropagator( - std::vector* solution) const; + virtual void CopyCurrentStateToSolutionPropagator(std::vector* solution) + const; private: // An obvious additional profit upper bound corresponds to the linear @@ -469,7 +461,7 @@ class KnapsackCapacityPropagator : public KnapsackPropagator { class BaseKnapsackSolver { public: explicit BaseKnapsackSolver(const std::string& solver_name) - : solver_name_(solver_name) {} + : solver_name_(solver_name) {} virtual ~BaseKnapsackSolver() {} // Initializes the solver and enters the problem to be solved. @@ -480,8 +472,7 @@ class BaseKnapsackSolver { // Gets the lower and upper bound when the item is in or out of the knapsack. // To ensure objects are correctly initialized, this method should not be // called before ::Init. - virtual void GetLowerAndUpperBoundWhenItem(int item_id, - bool is_item_in, + virtual void GetLowerAndUpperBoundWhenItem(int item_id, bool is_item_in, int64* lower_bound, int64* upper_bound); @@ -516,10 +507,8 @@ class KnapsackGenericSolver : public BaseKnapsackSolver { const std::vector >& weights, const std::vector& capacities); int GetNumberOfItems() const { return state_.GetNumberOfItems(); } - void GetLowerAndUpperBoundWhenItem(int item_id, - bool is_item_in, - int64* lower_bound, - int64* upper_bound); + void GetLowerAndUpperBoundWhenItem(int item_id, bool is_item_in, + int64* lower_bound, int64* upper_bound); // Sets which propagator should be used to guide the search. // 'master_propagator_id' should be in 0..p-1 with p the number of diff --git a/src/base/accurate_sum.h b/src/base/accurate_sum.h index 091eb900ce..3f5e61a2f7 100644 --- a/src/base/accurate_sum.h +++ b/src/base/accurate_sum.h @@ -20,7 +20,7 @@ namespace operations_research { // Kahan summation compensation algorithm. // // http://en.wikipedia.org/wiki/Kahan_summation_algorithm -template +template class AccurateSum { public: // You may copy-construct an AccurateSum. diff --git a/src/base/adjustable_priority_queue.h b/src/base/adjustable_priority_queue.h index 119521debd..9aaa97364c 100644 --- a/src/base/adjustable_priority_queue.h +++ b/src/base/adjustable_priority_queue.h @@ -23,7 +23,8 @@ namespace operations_research { -template class AdjustablePriorityQueue { +template +class AdjustablePriorityQueue { public: AdjustablePriorityQueue() {} @@ -117,9 +118,9 @@ template class AdjustablePriorityQueue { } const int right_child = left_child + 1; const int next_i = (right_child < elems_.size() && - *elems_[left_child] < *elems_[right_child]) ? - right_child : - left_child; + *elems_[left_child] < *elems_[right_child]) + ? right_child + : left_child; if (!(*t < *elems_[next_i])) { break; } diff --git a/src/base/base.swig b/src/base/base.swig index e0af8e5dc3..c78789fee6 100644 --- a/src/base/base.swig +++ b/src/base/base.swig @@ -82,7 +82,7 @@ namespace std { Py_ssize_t len; if (PyString_AsStringAndSize($input, &buf, &len) == -1) return NULL; - $1 = std::string(buf, len); + $1 = string(buf, len); } %typemap(in) const string & (string temp) { @@ -90,7 +90,7 @@ namespace std { Py_ssize_t len; if (PyString_AsStringAndSize($input, &buf, &len) == -1) return NULL; - temp = std::string(buf, len); + temp = string(buf, len); $1 = &temp; } @@ -103,7 +103,7 @@ namespace std { } %typemap(in, numinputs = 0) string * OUTPUT (string temp) { - temp = std::string(); + temp = string(); $1 = &temp; } @@ -146,7 +146,7 @@ class string; Py_ssize_t len; if (PyString_AsStringAndSize($input, &buf, &len) == -1) return NULL; - $1 = std::string(buf, len); + $1 = string(buf, len); } %typemap(in) const string & (string temp) { @@ -154,7 +154,7 @@ class string; Py_ssize_t len; if (PyString_AsStringAndSize($input, &buf, &len) == -1) return NULL; - temp = std::string(buf, len); + temp = string(buf, len); $1 = &temp; } @@ -167,7 +167,7 @@ class string; } %typemap(in, numinputs = 0) string * OUTPUT (string temp) { - temp = std::string(); + temp = string(); $1 = &temp; } diff --git a/src/base/bitmap.cc b/src/base/bitmap.cc index 7ef43f3e75..d14c0db179 100644 --- a/src/base/bitmap.cc +++ b/src/base/bitmap.cc @@ -30,7 +30,7 @@ void Bitmap::Resize(uint32 size, bool fill) { max_size_ = size; uint64* new_map = new uint64[array_size_]; memcpy(new_map, map_, old_array_size * sizeof(*map_)); - delete [] map_; + delete[] map_; map_ = new_map; } // TODO(user) : optimize next loop. diff --git a/src/base/bitmap.h b/src/base/bitmap.h index 11fd397553..24ec80ae6f 100644 --- a/src/base/bitmap.h +++ b/src/base/bitmap.h @@ -33,9 +33,7 @@ class Bitmap { } // Destructor : clean up if we allocated - ~Bitmap() { - delete [] map_; - } + ~Bitmap() { delete[] map_; } // Resizes the bitmap. // If size < bits(), the extra bits will be discarded. @@ -48,7 +46,7 @@ class Bitmap { } void Set(uint32 index, bool value) { assert(max_size_ == 0 || index < max_size_); - if ( value ) { + if (value) { SetBit64(map_, index); } else { ClearBit64(map_, index); @@ -64,9 +62,9 @@ class Bitmap { void Clear() { SetAll(false); } private: - uint32 max_size_; // the upper bound of the bitmap + uint32 max_size_; // the upper bound of the bitmap uint32 array_size_; - uint64* map_; // the bitmap + uint64* map_; // the bitmap }; } // namespace operations_research diff --git a/src/base/callback.h b/src/base/callback.h index 8cad094bbd..dc91c8deac 100644 --- a/src/base/callback.h +++ b/src/base/callback.h @@ -30,109 +30,109 @@ using operations_research::CallbackUtils_; class Closure { public: - virtual ~Closure() { } + virtual ~Closure() {} virtual bool IsRepeatable() const { return false; } - virtual void CheckIsRepeatable() const { } + virtual void CheckIsRepeatable() const {} virtual void Run() = 0; }; template class ResultCallback { public: - virtual ~ResultCallback() { } + virtual ~ResultCallback() {} virtual bool IsRepeatable() const { return false; } - virtual void CheckIsRepeatable() const { } + virtual void CheckIsRepeatable() const {} virtual R Run() = 0; }; template class Callback1 { public: - virtual ~Callback1() { } + virtual ~Callback1() {} virtual bool IsRepeatable() const { return false; } - virtual void CheckIsRepeatable() const { } + virtual void CheckIsRepeatable() const {} virtual void Run(A1) = 0; }; template class ResultCallback1 { public: - virtual ~ResultCallback1() { } + virtual ~ResultCallback1() {} virtual bool IsRepeatable() const { return false; } - virtual void CheckIsRepeatable() const { } + virtual void CheckIsRepeatable() const {} virtual R Run(A1) = 0; }; -template +template class Callback2 { public: - virtual ~Callback2() { } + virtual ~Callback2() {} virtual bool IsRepeatable() const { return false; } - virtual void CheckIsRepeatable() const { } - virtual void Run(A1,A2) = 0; + virtual void CheckIsRepeatable() const {} + virtual void Run(A1, A2) = 0; }; -template +template class ResultCallback2 { public: - virtual ~ResultCallback2() { } + virtual ~ResultCallback2() {} virtual bool IsRepeatable() const { return false; } - virtual void CheckIsRepeatable() const { } - virtual R Run(A1,A2) = 0; + virtual void CheckIsRepeatable() const {} + virtual R Run(A1, A2) = 0; }; -template +template class Callback3 { public: - virtual ~Callback3() { } + virtual ~Callback3() {} virtual bool IsRepeatable() const { return false; } - virtual void CheckIsRepeatable() const { } - virtual void Run(A1,A2,A3) = 0; + virtual void CheckIsRepeatable() const {} + virtual void Run(A1, A2, A3) = 0; }; -template +template class ResultCallback3 { public: - virtual ~ResultCallback3() { } + virtual ~ResultCallback3() {} virtual bool IsRepeatable() const { return false; } - virtual void CheckIsRepeatable() const { } - virtual R Run(A1,A2,A3) = 0; + virtual void CheckIsRepeatable() const {} + virtual R Run(A1, A2, A3) = 0; }; -template +template class Callback4 { public: - virtual ~Callback4() { } + virtual ~Callback4() {} virtual bool IsRepeatable() const { return false; } - virtual void CheckIsRepeatable() const { } - virtual void Run(A1,A2,A3,A4) = 0; + virtual void CheckIsRepeatable() const {} + virtual void Run(A1, A2, A3, A4) = 0; }; -template +template class ResultCallback4 { public: - virtual ~ResultCallback4() { } + virtual ~ResultCallback4() {} virtual bool IsRepeatable() const { return false; } - virtual void CheckIsRepeatable() const { } - virtual R Run(A1,A2,A3,A4) = 0; + virtual void CheckIsRepeatable() const {} + virtual R Run(A1, A2, A3, A4) = 0; }; -template +template class Callback5 { public: - virtual ~Callback5() { } + virtual ~Callback5() {} virtual bool IsRepeatable() const { return false; } - virtual void CheckIsRepeatable() const { } - virtual void Run(A1,A2,A3,A4,A5) = 0; + virtual void CheckIsRepeatable() const {} + virtual void Run(A1, A2, A3, A4, A5) = 0; }; -template +template class ResultCallback5 { public: - virtual ~ResultCallback5() { } + virtual ~ResultCallback5() {} virtual bool IsRepeatable() const { return false; } - virtual void CheckIsRepeatable() const { } - virtual R Run(A1,A2,A3,A4,A5) = 0; + virtual void CheckIsRepeatable() const {} + virtual R Run(A1, A2, A3, A4, A5) = 0; }; // ----- Utility template code used by the callback specializations ----- @@ -141,8 +141,12 @@ class ResultCallback5 { // "If B is true, the member typedef type shall equal T; otherwise, there // shall be no member typedef type." // Specified by 20.9.7.6 [Other transformations] -template struct c_enable_if { typedef T type; }; -template struct c_enable_if {}; +template +struct c_enable_if { + typedef T type; +}; +template +struct c_enable_if {}; typedef char small_; @@ -150,14 +154,23 @@ struct big_ { char dummy[2]; }; -template struct is_class_or_union { - template static small_ tester(void (U::*)()); - template static big_ tester(...); +template +struct is_class_or_union { + template + static small_ tester(void (U::*)()); + template + static big_ tester(...); static const bool value = sizeof(tester(0)) == sizeof(small_); }; -template struct remove_reference { typedef T type; }; -template struct remove_reference { typedef T type; }; +template +struct remove_reference { + typedef T type; +}; +template +struct remove_reference { + typedef T type; +}; template struct ConstRef { @@ -180,13 +193,9 @@ class _ConstMemberResultCallback_0_0 : public ResultCallback { public: inline _ConstMemberResultCallback_0_0(const T* object, MemberSignature member) - : ResultCallback(), - object_(object), - member_(member) { } + : ResultCallback(), object_(object), member_(member) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback"); @@ -207,11 +216,9 @@ class _ConstMemberResultCallback_0_0 : public ResultCallback { }; template -class _ConstMemberResultCallback_0_0::value - >::type> - : public Closure { +class _ConstMemberResultCallback_0_0< + del, void, T, + typename c_enable_if::value>::type> : public Closure { public: typedef Closure base; typedef void (T::*MemberSignature)() const; @@ -222,13 +229,9 @@ class _ConstMemberResultCallback_0_0 -inline typename _ConstMemberResultCallback_0_0::base* -NewCallback(const T1* obj, R (T2::*member)() const) { - return new _ConstMemberResultCallback_0_0(obj, member); +inline typename _ConstMemberResultCallback_0_0::base* NewCallback( + const T1* obj, R (T2::*member)() const) { + return new _ConstMemberResultCallback_0_0(obj, member); } #endif #ifndef SWIG template -inline typename _ConstMemberResultCallback_0_0::base* +inline typename _ConstMemberResultCallback_0_0::base* NewPermanentCallback(const T1* obj, R (T2::*member)() const) { - return new _ConstMemberResultCallback_0_0(obj, member); + return new _ConstMemberResultCallback_0_0(obj, member); } #endif -template ::value - >::type> +template ::value>::type> class _MemberResultCallback_0_0 : public ResultCallback { public: typedef ResultCallback base; - typedef R (T::*MemberSignature)() ; + typedef R (T::*MemberSignature)(); private: - T* object_; + T* object_; MemberSignature member_; public: - inline _MemberResultCallback_0_0( T* object, MemberSignature member) - : ResultCallback(), - object_(object), - member_(member) { } + inline _MemberResultCallback_0_0(T* object, MemberSignature member) + : ResultCallback(), object_(object), member_(member) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback"); @@ -304,28 +301,22 @@ class _MemberResultCallback_0_0 : public ResultCallback { }; template -class _MemberResultCallback_0_0::value - >::type> - : public Closure { +class _MemberResultCallback_0_0< + del, void, T, + typename c_enable_if::value>::type> : public Closure { public: typedef Closure base; - typedef void (T::*MemberSignature)() ; + typedef void (T::*MemberSignature)(); private: - T* object_; + T* object_; MemberSignature member_; public: - inline _MemberResultCallback_0_0( T* object, MemberSignature member) - : Closure(), - object_(object), - member_(member) { } + inline _MemberResultCallback_0_0(T* object, MemberSignature member) + : Closure(), object_(object), member_(member) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Closure"); @@ -345,17 +336,17 @@ class _MemberResultCallback_0_0 -inline typename _MemberResultCallback_0_0::base* -NewCallback( T1* obj, R (T2::*member)() ) { - return new _MemberResultCallback_0_0(obj, member); +inline typename _MemberResultCallback_0_0::base* NewCallback( + T1* obj, R (T2::*member)()) { + return new _MemberResultCallback_0_0(obj, member); } #endif #ifndef SWIG template -inline typename _MemberResultCallback_0_0::base* -NewPermanentCallback( T1* obj, R (T2::*member)() ) { - return new _MemberResultCallback_0_0(obj, member); +inline typename _MemberResultCallback_0_0::base* +NewPermanentCallback(T1* obj, R (T2::*member)()) { + return new _MemberResultCallback_0_0(obj, member); } #endif @@ -370,12 +361,9 @@ class _FunctionResultCallback_0_0 : public ResultCallback { public: inline _FunctionResultCallback_0_0(FunctionSignature function) - : ResultCallback(), - function_(function) { } + : ResultCallback(), function_(function) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback"); @@ -406,12 +394,9 @@ class _FunctionResultCallback_0_0 : public Closure { public: inline _FunctionResultCallback_0_0(FunctionSignature function) - : Closure(), - function_(function) { } + : Closure(), function_(function) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Closure"); @@ -430,21 +415,20 @@ class _FunctionResultCallback_0_0 : public Closure { }; template -inline typename _FunctionResultCallback_0_0::base* -NewCallback(R (*function)()) { - return new _FunctionResultCallback_0_0(function); +inline typename _FunctionResultCallback_0_0::base* NewCallback( + R (*function)()) { + return new _FunctionResultCallback_0_0(function); } template -inline typename _FunctionResultCallback_0_0::base* +inline typename _FunctionResultCallback_0_0::base* NewPermanentCallback(R (*function)()) { - return new _FunctionResultCallback_0_0(function); + return new _FunctionResultCallback_0_0(function); } -template ::value - >::type> +template < + bool del, class R, class T, class P1, + class OnlyIf = typename c_enable_if::value>::type> class _ConstMemberResultCallback_1_0 : public ResultCallback { public: typedef ResultCallback base; @@ -456,14 +440,11 @@ class _ConstMemberResultCallback_1_0 : public ResultCallback { typename remove_reference::type p1_; public: - inline _ConstMemberResultCallback_1_0(const T* object, MemberSignature member, typename ConstRef::type p1) - : ResultCallback(), - object_(object), - member_(member), p1_(p1) { } + inline _ConstMemberResultCallback_1_0(const T* object, MemberSignature member, + typename ConstRef::type p1) + : ResultCallback(), object_(object), member_(member), p1_(p1) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback"); @@ -484,11 +465,9 @@ class _ConstMemberResultCallback_1_0 : public ResultCallback { }; template -class _ConstMemberResultCallback_1_0::value - >::type> - : public Closure { +class _ConstMemberResultCallback_1_0< + del, void, T, P1, + typename c_enable_if::value>::type> : public Closure { public: typedef Closure base; typedef void (T::*MemberSignature)(P1) const; @@ -499,14 +478,11 @@ class _ConstMemberResultCallback_1_0::type p1_; public: - inline _ConstMemberResultCallback_1_0(const T* object, MemberSignature member, typename ConstRef::type p1) - : Closure(), - object_(object), - member_(member), p1_(p1) { } + inline _ConstMemberResultCallback_1_0(const T* object, MemberSignature member, + typename ConstRef::type p1) + : Closure(), object_(object), member_(member), p1_(p1) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Closure"); @@ -526,43 +502,41 @@ class _ConstMemberResultCallback_1_0 -inline typename _ConstMemberResultCallback_1_0::base* -NewCallback(const T1* obj, R (T2::*member)(P1) const, typename ConstRef::type p1) { - return new _ConstMemberResultCallback_1_0(obj, member, p1); +inline typename _ConstMemberResultCallback_1_0::base* +NewCallback(const T1* obj, R (T2::*member)(P1) const, + typename ConstRef::type p1) { + return new _ConstMemberResultCallback_1_0(obj, member, p1); } #endif #ifndef SWIG template -inline typename _ConstMemberResultCallback_1_0::base* -NewPermanentCallback(const T1* obj, R (T2::*member)(P1) const, typename ConstRef::type p1) { - return new _ConstMemberResultCallback_1_0(obj, member, p1); +inline typename _ConstMemberResultCallback_1_0::base* +NewPermanentCallback(const T1* obj, R (T2::*member)(P1) const, + typename ConstRef::type p1) { + return new _ConstMemberResultCallback_1_0(obj, member, p1); } #endif -template ::value - >::type> +template < + bool del, class R, class T, class P1, + class OnlyIf = typename c_enable_if::value>::type> class _MemberResultCallback_1_0 : public ResultCallback { public: typedef ResultCallback base; - typedef R (T::*MemberSignature)(P1) ; + typedef R (T::*MemberSignature)(P1); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; public: - inline _MemberResultCallback_1_0( T* object, MemberSignature member, typename ConstRef::type p1) - : ResultCallback(), - object_(object), - member_(member), p1_(p1) { } + inline _MemberResultCallback_1_0(T* object, MemberSignature member, + typename ConstRef::type p1) + : ResultCallback(), object_(object), member_(member), p1_(p1) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback"); @@ -583,29 +557,24 @@ class _MemberResultCallback_1_0 : public ResultCallback { }; template -class _MemberResultCallback_1_0::value - >::type> - : public Closure { +class _MemberResultCallback_1_0< + del, void, T, P1, + typename c_enable_if::value>::type> : public Closure { public: typedef Closure base; - typedef void (T::*MemberSignature)(P1) ; + typedef void (T::*MemberSignature)(P1); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; public: - inline _MemberResultCallback_1_0( T* object, MemberSignature member, typename ConstRef::type p1) - : Closure(), - object_(object), - member_(member), p1_(p1) { } + inline _MemberResultCallback_1_0(T* object, MemberSignature member, + typename ConstRef::type p1) + : Closure(), object_(object), member_(member), p1_(p1) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Closure"); @@ -625,17 +594,18 @@ class _MemberResultCallback_1_0 -inline typename _MemberResultCallback_1_0::base* -NewCallback( T1* obj, R (T2::*member)(P1) , typename ConstRef::type p1) { - return new _MemberResultCallback_1_0(obj, member, p1); +inline typename _MemberResultCallback_1_0::base* NewCallback( + T1* obj, R (T2::*member)(P1), typename ConstRef::type p1) { + return new _MemberResultCallback_1_0(obj, member, p1); } #endif #ifndef SWIG template -inline typename _MemberResultCallback_1_0::base* -NewPermanentCallback( T1* obj, R (T2::*member)(P1) , typename ConstRef::type p1) { - return new _MemberResultCallback_1_0(obj, member, p1); +inline typename _MemberResultCallback_1_0::base* +NewPermanentCallback(T1* obj, R (T2::*member)(P1), + typename ConstRef::type p1) { + return new _MemberResultCallback_1_0(obj, member, p1); } #endif @@ -650,13 +620,11 @@ class _FunctionResultCallback_1_0 : public ResultCallback { typename remove_reference::type p1_; public: - inline _FunctionResultCallback_1_0(FunctionSignature function, typename ConstRef::type p1) - : ResultCallback(), - function_(function), p1_(p1) { } + inline _FunctionResultCallback_1_0(FunctionSignature function, + typename ConstRef::type p1) + : ResultCallback(), function_(function), p1_(p1) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback"); @@ -687,13 +655,11 @@ class _FunctionResultCallback_1_0 : public Closure { typename remove_reference::type p1_; public: - inline _FunctionResultCallback_1_0(FunctionSignature function, typename ConstRef::type p1) - : Closure(), - function_(function), p1_(p1) { } + inline _FunctionResultCallback_1_0(FunctionSignature function, + typename ConstRef::type p1) + : Closure(), function_(function), p1_(p1) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Closure"); @@ -712,25 +678,24 @@ class _FunctionResultCallback_1_0 : public Closure { }; template -inline typename _FunctionResultCallback_1_0::base* -NewCallback(R (*function)(P1), typename ConstRef::type p1) { - return new _FunctionResultCallback_1_0(function, p1); +inline typename _FunctionResultCallback_1_0::base* NewCallback( + R (*function)(P1), typename ConstRef::type p1) { + return new _FunctionResultCallback_1_0(function, p1); } template -inline typename _FunctionResultCallback_1_0::base* +inline typename _FunctionResultCallback_1_0::base* NewPermanentCallback(R (*function)(P1), typename ConstRef::type p1) { - return new _FunctionResultCallback_1_0(function, p1); + return new _FunctionResultCallback_1_0(function, p1); } -template ::value - >::type> +template < + bool del, class R, class T, class P1, class P2, + class OnlyIf = typename c_enable_if::value>::type> class _ConstMemberResultCallback_2_0 : public ResultCallback { public: typedef ResultCallback base; - typedef R (T::*MemberSignature)(P1,P2) const; + typedef R (T::*MemberSignature)(P1, P2) const; private: const T* object_; @@ -739,14 +704,16 @@ class _ConstMemberResultCallback_2_0 : public ResultCallback { typename remove_reference::type p2_; public: - inline _ConstMemberResultCallback_2_0(const T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2) - : ResultCallback(), - object_(object), - member_(member), p1_(p1), p2_(p2) { } + inline _ConstMemberResultCallback_2_0(const T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2) + : ResultCallback(), + object_(object), + member_(member), + p1_(p1), + p2_(p2) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback"); @@ -754,10 +721,10 @@ class _ConstMemberResultCallback_2_0 : public ResultCallback { virtual R Run() { if (!del) { - R result = (object_->*member_)(p1_,p2_); + R result = (object_->*member_)(p1_, p2_); return result; } else { - R result = (object_->*member_)(p1_,p2_); + R result = (object_->*member_)(p1_, p2_); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -767,14 +734,12 @@ class _ConstMemberResultCallback_2_0 : public ResultCallback { }; template -class _ConstMemberResultCallback_2_0::value - >::type> - : public Closure { +class _ConstMemberResultCallback_2_0< + del, void, T, P1, P2, + typename c_enable_if::value>::type> : public Closure { public: typedef Closure base; - typedef void (T::*MemberSignature)(P1,P2) const; + typedef void (T::*MemberSignature)(P1, P2) const; private: const T* object_; @@ -783,14 +748,12 @@ class _ConstMemberResultCallback_2_0::type p2_; public: - inline _ConstMemberResultCallback_2_0(const T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2) - : Closure(), - object_(object), - member_(member), p1_(p1), p2_(p2) { } + inline _ConstMemberResultCallback_2_0(const T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2) + : Closure(), object_(object), member_(member), p1_(p1), p2_(p2) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Closure"); @@ -798,9 +761,9 @@ class _ConstMemberResultCallback_2_0*member_)(p1_,p2_); + (object_->*member_)(p1_, p2_); } else { - (object_->*member_)(p1_,p2_); + (object_->*member_)(p1_, p2_); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -810,44 +773,50 @@ class _ConstMemberResultCallback_2_0 -inline typename _ConstMemberResultCallback_2_0::base* -NewCallback(const T1* obj, R (T2::*member)(P1,P2) const, typename ConstRef::type p1, typename ConstRef::type p2) { - return new _ConstMemberResultCallback_2_0(obj, member, p1, p2); +inline typename _ConstMemberResultCallback_2_0::base* +NewCallback(const T1* obj, R (T2::*member)(P1, P2) const, + typename ConstRef::type p1, typename ConstRef::type p2) { + return new _ConstMemberResultCallback_2_0(obj, member, + p1, p2); } #endif #ifndef SWIG template -inline typename _ConstMemberResultCallback_2_0::base* -NewPermanentCallback(const T1* obj, R (T2::*member)(P1,P2) const, typename ConstRef::type p1, typename ConstRef::type p2) { - return new _ConstMemberResultCallback_2_0(obj, member, p1, p2); +inline typename _ConstMemberResultCallback_2_0::base* +NewPermanentCallback(const T1* obj, R (T2::*member)(P1, P2) const, + typename ConstRef::type p1, + typename ConstRef::type p2) { + return new _ConstMemberResultCallback_2_0(obj, member, + p1, p2); } #endif -template ::value - >::type> +template < + bool del, class R, class T, class P1, class P2, + class OnlyIf = typename c_enable_if::value>::type> class _MemberResultCallback_2_0 : public ResultCallback { public: typedef ResultCallback base; - typedef R (T::*MemberSignature)(P1,P2) ; + typedef R (T::*MemberSignature)(P1, P2); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; typename remove_reference::type p2_; public: - inline _MemberResultCallback_2_0( T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2) - : ResultCallback(), - object_(object), - member_(member), p1_(p1), p2_(p2) { } + inline _MemberResultCallback_2_0(T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2) + : ResultCallback(), + object_(object), + member_(member), + p1_(p1), + p2_(p2) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback"); @@ -855,10 +824,10 @@ class _MemberResultCallback_2_0 : public ResultCallback { virtual R Run() { if (!del) { - R result = (object_->*member_)(p1_,p2_); + R result = (object_->*member_)(p1_, p2_); return result; } else { - R result = (object_->*member_)(p1_,p2_); + R result = (object_->*member_)(p1_, p2_); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -868,30 +837,26 @@ class _MemberResultCallback_2_0 : public ResultCallback { }; template -class _MemberResultCallback_2_0::value - >::type> - : public Closure { +class _MemberResultCallback_2_0< + del, void, T, P1, P2, + typename c_enable_if::value>::type> : public Closure { public: typedef Closure base; - typedef void (T::*MemberSignature)(P1,P2) ; + typedef void (T::*MemberSignature)(P1, P2); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; typename remove_reference::type p2_; public: - inline _MemberResultCallback_2_0( T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2) - : Closure(), - object_(object), - member_(member), p1_(p1), p2_(p2) { } + inline _MemberResultCallback_2_0(T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2) + : Closure(), object_(object), member_(member), p1_(p1), p2_(p2) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Closure"); @@ -899,9 +864,9 @@ class _MemberResultCallback_2_0*member_)(p1_,p2_); + (object_->*member_)(p1_, p2_); } else { - (object_->*member_)(p1_,p2_); + (object_->*member_)(p1_, p2_); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -911,17 +876,22 @@ class _MemberResultCallback_2_0 -inline typename _MemberResultCallback_2_0::base* -NewCallback( T1* obj, R (T2::*member)(P1,P2) , typename ConstRef::type p1, typename ConstRef::type p2) { - return new _MemberResultCallback_2_0(obj, member, p1, p2); +inline typename _MemberResultCallback_2_0::base* +NewCallback(T1* obj, R (T2::*member)(P1, P2), typename ConstRef::type p1, + typename ConstRef::type p2) { + return new _MemberResultCallback_2_0(obj, member, p1, + p2); } #endif #ifndef SWIG template -inline typename _MemberResultCallback_2_0::base* -NewPermanentCallback( T1* obj, R (T2::*member)(P1,P2) , typename ConstRef::type p1, typename ConstRef::type p2) { - return new _MemberResultCallback_2_0(obj, member, p1, p2); +inline typename _MemberResultCallback_2_0::base* +NewPermanentCallback(T1* obj, R (T2::*member)(P1, P2), + typename ConstRef::type p1, + typename ConstRef::type p2) { + return new _MemberResultCallback_2_0(obj, member, p1, + p2); } #endif @@ -929,7 +899,7 @@ template class _FunctionResultCallback_2_0 : public ResultCallback { public: typedef ResultCallback base; - typedef R (*FunctionSignature)(P1,P2); + typedef R (*FunctionSignature)(P1, P2); private: FunctionSignature function_; @@ -937,13 +907,12 @@ class _FunctionResultCallback_2_0 : public ResultCallback { typename remove_reference::type p2_; public: - inline _FunctionResultCallback_2_0(FunctionSignature function, typename ConstRef::type p1, typename ConstRef::type p2) - : ResultCallback(), - function_(function), p1_(p1), p2_(p2) { } + inline _FunctionResultCallback_2_0(FunctionSignature function, + typename ConstRef::type p1, + typename ConstRef::type p2) + : ResultCallback(), function_(function), p1_(p1), p2_(p2) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback"); @@ -951,10 +920,10 @@ class _FunctionResultCallback_2_0 : public ResultCallback { virtual R Run() { if (!del) { - R result = (*function_)(p1_,p2_); + R result = (*function_)(p1_, p2_); return result; } else { - R result = (*function_)(p1_,p2_); + R result = (*function_)(p1_, p2_); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -967,7 +936,7 @@ template class _FunctionResultCallback_2_0 : public Closure { public: typedef Closure base; - typedef void (*FunctionSignature)(P1,P2); + typedef void (*FunctionSignature)(P1, P2); private: FunctionSignature function_; @@ -975,13 +944,12 @@ class _FunctionResultCallback_2_0 : public Closure { typename remove_reference::type p2_; public: - inline _FunctionResultCallback_2_0(FunctionSignature function, typename ConstRef::type p1, typename ConstRef::type p2) - : Closure(), - function_(function), p1_(p1), p2_(p2) { } + inline _FunctionResultCallback_2_0(FunctionSignature function, + typename ConstRef::type p1, + typename ConstRef::type p2) + : Closure(), function_(function), p1_(p1), p2_(p2) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Closure"); @@ -989,9 +957,9 @@ class _FunctionResultCallback_2_0 : public Closure { virtual void Run() { if (!del) { - (*function_)(p1_,p2_); + (*function_)(p1_, p2_); } else { - (*function_)(p1_,p2_); + (*function_)(p1_, p2_); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -1000,25 +968,26 @@ class _FunctionResultCallback_2_0 : public Closure { }; template -inline typename _FunctionResultCallback_2_0::base* -NewCallback(R (*function)(P1,P2), typename ConstRef::type p1, typename ConstRef::type p2) { - return new _FunctionResultCallback_2_0(function, p1, p2); +inline typename _FunctionResultCallback_2_0::base* NewCallback( + R (*function)(P1, P2), typename ConstRef::type p1, + typename ConstRef::type p2) { + return new _FunctionResultCallback_2_0(function, p1, p2); } template -inline typename _FunctionResultCallback_2_0::base* -NewPermanentCallback(R (*function)(P1,P2), typename ConstRef::type p1, typename ConstRef::type p2) { - return new _FunctionResultCallback_2_0(function, p1, p2); +inline typename _FunctionResultCallback_2_0::base* +NewPermanentCallback(R (*function)(P1, P2), typename ConstRef::type p1, + typename ConstRef::type p2) { + return new _FunctionResultCallback_2_0(function, p1, p2); } -template ::value - >::type> +template < + bool del, class R, class T, class P1, class P2, class P3, + class OnlyIf = typename c_enable_if::value>::type> class _ConstMemberResultCallback_3_0 : public ResultCallback { public: typedef ResultCallback base; - typedef R (T::*MemberSignature)(P1,P2,P3) const; + typedef R (T::*MemberSignature)(P1, P2, P3) const; private: const T* object_; @@ -1028,14 +997,18 @@ class _ConstMemberResultCallback_3_0 : public ResultCallback { typename remove_reference::type p3_; public: - inline _ConstMemberResultCallback_3_0(const T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) - : ResultCallback(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3) { } + inline _ConstMemberResultCallback_3_0(const T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3) + : ResultCallback(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback"); @@ -1043,10 +1016,10 @@ class _ConstMemberResultCallback_3_0 : public ResultCallback { virtual R Run() { if (!del) { - R result = (object_->*member_)(p1_,p2_,p3_); + R result = (object_->*member_)(p1_, p2_, p3_); return result; } else { - R result = (object_->*member_)(p1_,p2_,p3_); + R result = (object_->*member_)(p1_, p2_, p3_); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -1056,14 +1029,12 @@ class _ConstMemberResultCallback_3_0 : public ResultCallback { }; template -class _ConstMemberResultCallback_3_0::value - >::type> - : public Closure { +class _ConstMemberResultCallback_3_0< + del, void, T, P1, P2, P3, + typename c_enable_if::value>::type> : public Closure { public: typedef Closure base; - typedef void (T::*MemberSignature)(P1,P2,P3) const; + typedef void (T::*MemberSignature)(P1, P2, P3) const; private: const T* object_; @@ -1073,14 +1044,18 @@ class _ConstMemberResultCallback_3_0::type p3_; public: - inline _ConstMemberResultCallback_3_0(const T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) - : Closure(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3) { } + inline _ConstMemberResultCallback_3_0(const T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3) + : Closure(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Closure"); @@ -1088,9 +1063,9 @@ class _ConstMemberResultCallback_3_0*member_)(p1_,p2_,p3_); + (object_->*member_)(p1_, p2_, p3_); } else { - (object_->*member_)(p1_,p2_,p3_); + (object_->*member_)(p1_, p2_, p3_); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -1100,45 +1075,55 @@ class _ConstMemberResultCallback_3_0 -inline typename _ConstMemberResultCallback_3_0::base* -NewCallback(const T1* obj, R (T2::*member)(P1,P2,P3) const, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) { - return new _ConstMemberResultCallback_3_0(obj, member, p1, p2, p3); +inline typename _ConstMemberResultCallback_3_0::base* +NewCallback(const T1* obj, R (T2::*member)(P1, P2, P3) const, + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3) { + return new _ConstMemberResultCallback_3_0( + obj, member, p1, p2, p3); } #endif #ifndef SWIG template -inline typename _ConstMemberResultCallback_3_0::base* -NewPermanentCallback(const T1* obj, R (T2::*member)(P1,P2,P3) const, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) { - return new _ConstMemberResultCallback_3_0(obj, member, p1, p2, p3); +inline typename _ConstMemberResultCallback_3_0::base* +NewPermanentCallback(const T1* obj, R (T2::*member)(P1, P2, P3) const, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3) { + return new _ConstMemberResultCallback_3_0( + obj, member, p1, p2, p3); } #endif -template ::value - >::type> +template < + bool del, class R, class T, class P1, class P2, class P3, + class OnlyIf = typename c_enable_if::value>::type> class _MemberResultCallback_3_0 : public ResultCallback { public: typedef ResultCallback base; - typedef R (T::*MemberSignature)(P1,P2,P3) ; + typedef R (T::*MemberSignature)(P1, P2, P3); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; typename remove_reference::type p2_; typename remove_reference::type p3_; public: - inline _MemberResultCallback_3_0( T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) - : ResultCallback(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3) { } + inline _MemberResultCallback_3_0(T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3) + : ResultCallback(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback"); @@ -1146,10 +1131,10 @@ class _MemberResultCallback_3_0 : public ResultCallback { virtual R Run() { if (!del) { - R result = (object_->*member_)(p1_,p2_,p3_); + R result = (object_->*member_)(p1_, p2_, p3_); return result; } else { - R result = (object_->*member_)(p1_,p2_,p3_); + R result = (object_->*member_)(p1_, p2_, p3_); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -1159,31 +1144,33 @@ class _MemberResultCallback_3_0 : public ResultCallback { }; template -class _MemberResultCallback_3_0::value - >::type> - : public Closure { +class _MemberResultCallback_3_0< + del, void, T, P1, P2, P3, + typename c_enable_if::value>::type> : public Closure { public: typedef Closure base; - typedef void (T::*MemberSignature)(P1,P2,P3) ; + typedef void (T::*MemberSignature)(P1, P2, P3); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; typename remove_reference::type p2_; typename remove_reference::type p3_; public: - inline _MemberResultCallback_3_0( T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) - : Closure(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3) { } + inline _MemberResultCallback_3_0(T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3) + : Closure(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Closure"); @@ -1191,9 +1178,9 @@ class _MemberResultCallback_3_0*member_)(p1_,p2_,p3_); + (object_->*member_)(p1_, p2_, p3_); } else { - (object_->*member_)(p1_,p2_,p3_); + (object_->*member_)(p1_, p2_, p3_); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -1203,17 +1190,24 @@ class _MemberResultCallback_3_0 -inline typename _MemberResultCallback_3_0::base* -NewCallback( T1* obj, R (T2::*member)(P1,P2,P3) , typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) { - return new _MemberResultCallback_3_0(obj, member, p1, p2, p3); +inline typename _MemberResultCallback_3_0::base* +NewCallback(T1* obj, R (T2::*member)(P1, P2, P3), + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3) { + return new _MemberResultCallback_3_0(obj, member, p1, + p2, p3); } #endif #ifndef SWIG template -inline typename _MemberResultCallback_3_0::base* -NewPermanentCallback( T1* obj, R (T2::*member)(P1,P2,P3) , typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) { - return new _MemberResultCallback_3_0(obj, member, p1, p2, p3); +inline typename _MemberResultCallback_3_0::base* +NewPermanentCallback(T1* obj, R (T2::*member)(P1, P2, P3), + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3) { + return new _MemberResultCallback_3_0(obj, member, + p1, p2, p3); } #endif @@ -1221,7 +1215,7 @@ template class _FunctionResultCallback_3_0 : public ResultCallback { public: typedef ResultCallback base; - typedef R (*FunctionSignature)(P1,P2,P3); + typedef R (*FunctionSignature)(P1, P2, P3); private: FunctionSignature function_; @@ -1230,13 +1224,13 @@ class _FunctionResultCallback_3_0 : public ResultCallback { typename remove_reference::type p3_; public: - inline _FunctionResultCallback_3_0(FunctionSignature function, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) - : ResultCallback(), - function_(function), p1_(p1), p2_(p2), p3_(p3) { } + inline _FunctionResultCallback_3_0(FunctionSignature function, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3) + : ResultCallback(), function_(function), p1_(p1), p2_(p2), p3_(p3) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback"); @@ -1244,10 +1238,10 @@ class _FunctionResultCallback_3_0 : public ResultCallback { virtual R Run() { if (!del) { - R result = (*function_)(p1_,p2_,p3_); + R result = (*function_)(p1_, p2_, p3_); return result; } else { - R result = (*function_)(p1_,p2_,p3_); + R result = (*function_)(p1_, p2_, p3_); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -1260,7 +1254,7 @@ template class _FunctionResultCallback_3_0 : public Closure { public: typedef Closure base; - typedef void (*FunctionSignature)(P1,P2,P3); + typedef void (*FunctionSignature)(P1, P2, P3); private: FunctionSignature function_; @@ -1269,13 +1263,13 @@ class _FunctionResultCallback_3_0 : public Closure { typename remove_reference::type p3_; public: - inline _FunctionResultCallback_3_0(FunctionSignature function, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) - : Closure(), - function_(function), p1_(p1), p2_(p2), p3_(p3) { } + inline _FunctionResultCallback_3_0(FunctionSignature function, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3) + : Closure(), function_(function), p1_(p1), p2_(p2), p3_(p3) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Closure"); @@ -1283,9 +1277,9 @@ class _FunctionResultCallback_3_0 : public Closure { virtual void Run() { if (!del) { - (*function_)(p1_,p2_,p3_); + (*function_)(p1_, p2_, p3_); } else { - (*function_)(p1_,p2_,p3_); + (*function_)(p1_, p2_, p3_); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -1294,25 +1288,29 @@ class _FunctionResultCallback_3_0 : public Closure { }; template -inline typename _FunctionResultCallback_3_0::base* -NewCallback(R (*function)(P1,P2,P3), typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) { - return new _FunctionResultCallback_3_0(function, p1, p2, p3); +inline typename _FunctionResultCallback_3_0::base* +NewCallback(R (*function)(P1, P2, P3), typename ConstRef::type p1, + typename ConstRef::type p2, typename ConstRef::type p3) { + return new _FunctionResultCallback_3_0(function, p1, p2, + p3); } template -inline typename _FunctionResultCallback_3_0::base* -NewPermanentCallback(R (*function)(P1,P2,P3), typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) { - return new _FunctionResultCallback_3_0(function, p1, p2, p3); +inline typename _FunctionResultCallback_3_0::base* +NewPermanentCallback(R (*function)(P1, P2, P3), typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3) { + return new _FunctionResultCallback_3_0(function, p1, p2, + p3); } -template ::value - >::type> +template < + bool del, class R, class T, class P1, class P2, class P3, class P4, + class OnlyIf = typename c_enable_if::value>::type> class _ConstMemberResultCallback_4_0 : public ResultCallback { public: typedef ResultCallback base; - typedef R (T::*MemberSignature)(P1,P2,P3,P4) const; + typedef R (T::*MemberSignature)(P1, P2, P3, P4) const; private: const T* object_; @@ -1323,14 +1321,20 @@ class _ConstMemberResultCallback_4_0 : public ResultCallback { typename remove_reference::type p4_; public: - inline _ConstMemberResultCallback_4_0(const T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) - : ResultCallback(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4) { } + inline _ConstMemberResultCallback_4_0(const T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4) + : ResultCallback(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback"); @@ -1338,10 +1342,10 @@ class _ConstMemberResultCallback_4_0 : public ResultCallback { virtual R Run() { if (!del) { - R result = (object_->*member_)(p1_,p2_,p3_,p4_); + R result = (object_->*member_)(p1_, p2_, p3_, p4_); return result; } else { - R result = (object_->*member_)(p1_,p2_,p3_,p4_); + R result = (object_->*member_)(p1_, p2_, p3_, p4_); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -1351,14 +1355,12 @@ class _ConstMemberResultCallback_4_0 : public ResultCallback { }; template -class _ConstMemberResultCallback_4_0::value - >::type> - : public Closure { +class _ConstMemberResultCallback_4_0< + del, void, T, P1, P2, P3, P4, + typename c_enable_if::value>::type> : public Closure { public: typedef Closure base; - typedef void (T::*MemberSignature)(P1,P2,P3,P4) const; + typedef void (T::*MemberSignature)(P1, P2, P3, P4) const; private: const T* object_; @@ -1369,14 +1371,20 @@ class _ConstMemberResultCallback_4_0::type p4_; public: - inline _ConstMemberResultCallback_4_0(const T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) - : Closure(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4) { } + inline _ConstMemberResultCallback_4_0(const T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4) + : Closure(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Closure"); @@ -1384,9 +1392,9 @@ class _ConstMemberResultCallback_4_0*member_)(p1_,p2_,p3_,p4_); + (object_->*member_)(p1_, p2_, p3_, p4_); } else { - (object_->*member_)(p1_,p2_,p3_,p4_); + (object_->*member_)(p1_, p2_, p3_, p4_); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -1396,31 +1404,40 @@ class _ConstMemberResultCallback_4_0 -inline typename _ConstMemberResultCallback_4_0::base* -NewCallback(const T1* obj, R (T2::*member)(P1,P2,P3,P4) const, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) { - return new _ConstMemberResultCallback_4_0(obj, member, p1, p2, p3, p4); +inline typename _ConstMemberResultCallback_4_0::base* +NewCallback(const T1* obj, R (T2::*member)(P1, P2, P3, P4) const, + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3, typename ConstRef::type p4) { + return new _ConstMemberResultCallback_4_0( + obj, member, p1, p2, p3, p4); } #endif #ifndef SWIG template -inline typename _ConstMemberResultCallback_4_0::base* -NewPermanentCallback(const T1* obj, R (T2::*member)(P1,P2,P3,P4) const, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) { - return new _ConstMemberResultCallback_4_0(obj, member, p1, p2, p3, p4); +inline typename _ConstMemberResultCallback_4_0::base* +NewPermanentCallback(const T1* obj, R (T2::*member)(P1, P2, P3, P4) const, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4) { + return new _ConstMemberResultCallback_4_0( + obj, member, p1, p2, p3, p4); } #endif -template ::value - >::type> +template < + bool del, class R, class T, class P1, class P2, class P3, class P4, + class OnlyIf = typename c_enable_if::value>::type> class _MemberResultCallback_4_0 : public ResultCallback { public: typedef ResultCallback base; - typedef R (T::*MemberSignature)(P1,P2,P3,P4) ; + typedef R (T::*MemberSignature)(P1, P2, P3, P4); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; typename remove_reference::type p2_; @@ -1428,14 +1445,20 @@ class _MemberResultCallback_4_0 : public ResultCallback { typename remove_reference::type p4_; public: - inline _MemberResultCallback_4_0( T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) - : ResultCallback(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4) { } + inline _MemberResultCallback_4_0(T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4) + : ResultCallback(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback"); @@ -1443,10 +1466,10 @@ class _MemberResultCallback_4_0 : public ResultCallback { virtual R Run() { if (!del) { - R result = (object_->*member_)(p1_,p2_,p3_,p4_); + R result = (object_->*member_)(p1_, p2_, p3_, p4_); return result; } else { - R result = (object_->*member_)(p1_,p2_,p3_,p4_); + R result = (object_->*member_)(p1_, p2_, p3_, p4_); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -1456,17 +1479,15 @@ class _MemberResultCallback_4_0 : public ResultCallback { }; template -class _MemberResultCallback_4_0::value - >::type> - : public Closure { +class _MemberResultCallback_4_0< + del, void, T, P1, P2, P3, P4, + typename c_enable_if::value>::type> : public Closure { public: typedef Closure base; - typedef void (T::*MemberSignature)(P1,P2,P3,P4) ; + typedef void (T::*MemberSignature)(P1, P2, P3, P4); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; typename remove_reference::type p2_; @@ -1474,14 +1495,20 @@ class _MemberResultCallback_4_0::type p4_; public: - inline _MemberResultCallback_4_0( T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) - : Closure(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4) { } + inline _MemberResultCallback_4_0(T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4) + : Closure(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Closure"); @@ -1489,9 +1516,9 @@ class _MemberResultCallback_4_0*member_)(p1_,p2_,p3_,p4_); + (object_->*member_)(p1_, p2_, p3_, p4_); } else { - (object_->*member_)(p1_,p2_,p3_,p4_); + (object_->*member_)(p1_, p2_, p3_, p4_); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -1501,17 +1528,25 @@ class _MemberResultCallback_4_0 -inline typename _MemberResultCallback_4_0::base* -NewCallback( T1* obj, R (T2::*member)(P1,P2,P3,P4) , typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) { - return new _MemberResultCallback_4_0(obj, member, p1, p2, p3, p4); +inline typename _MemberResultCallback_4_0::base* +NewCallback(T1* obj, R (T2::*member)(P1, P2, P3, P4), + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3, typename ConstRef::type p4) { + return new _MemberResultCallback_4_0( + obj, member, p1, p2, p3, p4); } #endif #ifndef SWIG template -inline typename _MemberResultCallback_4_0::base* -NewPermanentCallback( T1* obj, R (T2::*member)(P1,P2,P3,P4) , typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) { - return new _MemberResultCallback_4_0(obj, member, p1, p2, p3, p4); +inline typename _MemberResultCallback_4_0::base* +NewPermanentCallback(T1* obj, R (T2::*member)(P1, P2, P3, P4), + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4) { + return new _MemberResultCallback_4_0( + obj, member, p1, p2, p3, p4); } #endif @@ -1519,7 +1554,7 @@ template class _FunctionResultCallback_4_0 : public ResultCallback { public: typedef ResultCallback base; - typedef R (*FunctionSignature)(P1,P2,P3,P4); + typedef R (*FunctionSignature)(P1, P2, P3, P4); private: FunctionSignature function_; @@ -1529,13 +1564,19 @@ class _FunctionResultCallback_4_0 : public ResultCallback { typename remove_reference::type p4_; public: - inline _FunctionResultCallback_4_0(FunctionSignature function, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) - : ResultCallback(), - function_(function), p1_(p1), p2_(p2), p3_(p3), p4_(p4) { } + inline _FunctionResultCallback_4_0(FunctionSignature function, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4) + : ResultCallback(), + function_(function), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback"); @@ -1543,10 +1584,10 @@ class _FunctionResultCallback_4_0 : public ResultCallback { virtual R Run() { if (!del) { - R result = (*function_)(p1_,p2_,p3_,p4_); + R result = (*function_)(p1_, p2_, p3_, p4_); return result; } else { - R result = (*function_)(p1_,p2_,p3_,p4_); + R result = (*function_)(p1_, p2_, p3_, p4_); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -1559,7 +1600,7 @@ template class _FunctionResultCallback_4_0 : public Closure { public: typedef Closure base; - typedef void (*FunctionSignature)(P1,P2,P3,P4); + typedef void (*FunctionSignature)(P1, P2, P3, P4); private: FunctionSignature function_; @@ -1569,13 +1610,14 @@ class _FunctionResultCallback_4_0 : public Closure { typename remove_reference::type p4_; public: - inline _FunctionResultCallback_4_0(FunctionSignature function, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) - : Closure(), - function_(function), p1_(p1), p2_(p2), p3_(p3), p4_(p4) { } + inline _FunctionResultCallback_4_0(FunctionSignature function, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4) + : Closure(), function_(function), p1_(p1), p2_(p2), p3_(p3), p4_(p4) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Closure"); @@ -1583,9 +1625,9 @@ class _FunctionResultCallback_4_0 : public Closure { virtual void Run() { if (!del) { - (*function_)(p1_,p2_,p3_,p4_); + (*function_)(p1_, p2_, p3_, p4_); } else { - (*function_)(p1_,p2_,p3_,p4_); + (*function_)(p1_, p2_, p3_, p4_); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -1594,25 +1636,32 @@ class _FunctionResultCallback_4_0 : public Closure { }; template -inline typename _FunctionResultCallback_4_0::base* -NewCallback(R (*function)(P1,P2,P3,P4), typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) { - return new _FunctionResultCallback_4_0(function, p1, p2, p3, p4); +inline typename _FunctionResultCallback_4_0::base* +NewCallback(R (*function)(P1, P2, P3, P4), typename ConstRef::type p1, + typename ConstRef::type p2, typename ConstRef::type p3, + typename ConstRef::type p4) { + return new _FunctionResultCallback_4_0(function, p1, + p2, p3, p4); } template -inline typename _FunctionResultCallback_4_0::base* -NewPermanentCallback(R (*function)(P1,P2,P3,P4), typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) { - return new _FunctionResultCallback_4_0(function, p1, p2, p3, p4); +inline typename _FunctionResultCallback_4_0::base* +NewPermanentCallback(R (*function)(P1, P2, P3, P4), + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4) { + return new _FunctionResultCallback_4_0(function, p1, + p2, p3, p4); } -template ::value - >::type> +template ::value>::type> class _ConstMemberResultCallback_5_0 : public ResultCallback { public: typedef ResultCallback base; - typedef R (T::*MemberSignature)(P1,P2,P3,P4,P5) const; + typedef R (T::*MemberSignature)(P1, P2, P3, P4, P5) const; private: const T* object_; @@ -1624,14 +1673,22 @@ class _ConstMemberResultCallback_5_0 : public ResultCallback { typename remove_reference::type p5_; public: - inline _ConstMemberResultCallback_5_0(const T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) - : ResultCallback(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5) { } + inline _ConstMemberResultCallback_5_0(const T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5) + : ResultCallback(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback"); @@ -1639,10 +1696,10 @@ class _ConstMemberResultCallback_5_0 : public ResultCallback { virtual R Run() { if (!del) { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,p5_); + R result = (object_->*member_)(p1_, p2_, p3_, p4_, p5_); return result; } else { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,p5_); + R result = (object_->*member_)(p1_, p2_, p3_, p4_, p5_); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -1652,14 +1709,12 @@ class _ConstMemberResultCallback_5_0 : public ResultCallback { }; template -class _ConstMemberResultCallback_5_0::value - >::type> - : public Closure { +class _ConstMemberResultCallback_5_0< + del, void, T, P1, P2, P3, P4, P5, + typename c_enable_if::value>::type> : public Closure { public: typedef Closure base; - typedef void (T::*MemberSignature)(P1,P2,P3,P4,P5) const; + typedef void (T::*MemberSignature)(P1, P2, P3, P4, P5) const; private: const T* object_; @@ -1671,14 +1726,22 @@ class _ConstMemberResultCallback_5_0::type p5_; public: - inline _ConstMemberResultCallback_5_0(const T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) - : Closure(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5) { } + inline _ConstMemberResultCallback_5_0(const T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5) + : Closure(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Closure"); @@ -1686,9 +1749,9 @@ class _ConstMemberResultCallback_5_0*member_)(p1_,p2_,p3_,p4_,p5_); + (object_->*member_)(p1_, p2_, p3_, p4_, p5_); } else { - (object_->*member_)(p1_,p2_,p3_,p4_,p5_); + (object_->*member_)(p1_, p2_, p3_, p4_, p5_); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -1697,32 +1760,45 @@ class _ConstMemberResultCallback_5_0 -inline typename _ConstMemberResultCallback_5_0::base* -NewCallback(const T1* obj, R (T2::*member)(P1,P2,P3,P4,P5) const, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) { - return new _ConstMemberResultCallback_5_0(obj, member, p1, p2, p3, p4, p5); +template +inline typename _ConstMemberResultCallback_5_0::base* +NewCallback(const T1* obj, R (T2::*member)(P1, P2, P3, P4, P5) const, + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3, typename ConstRef::type p4, + typename ConstRef::type p5) { + return new _ConstMemberResultCallback_5_0( + obj, member, p1, p2, p3, p4, p5); } #endif #ifndef SWIG -template -inline typename _ConstMemberResultCallback_5_0::base* -NewPermanentCallback(const T1* obj, R (T2::*member)(P1,P2,P3,P4,P5) const, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) { - return new _ConstMemberResultCallback_5_0(obj, member, p1, p2, p3, p4, p5); +template +inline typename _ConstMemberResultCallback_5_0::base* +NewPermanentCallback(const T1* obj, R (T2::*member)(P1, P2, P3, P4, P5) const, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5) { + return new _ConstMemberResultCallback_5_0( + obj, member, p1, p2, p3, p4, p5); } #endif -template ::value - >::type> +template ::value>::type> class _MemberResultCallback_5_0 : public ResultCallback { public: typedef ResultCallback base; - typedef R (T::*MemberSignature)(P1,P2,P3,P4,P5) ; + typedef R (T::*MemberSignature)(P1, P2, P3, P4, P5); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; typename remove_reference::type p2_; @@ -1731,14 +1807,22 @@ class _MemberResultCallback_5_0 : public ResultCallback { typename remove_reference::type p5_; public: - inline _MemberResultCallback_5_0( T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) - : ResultCallback(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5) { } + inline _MemberResultCallback_5_0(T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5) + : ResultCallback(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback"); @@ -1746,10 +1830,10 @@ class _MemberResultCallback_5_0 : public ResultCallback { virtual R Run() { if (!del) { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,p5_); + R result = (object_->*member_)(p1_, p2_, p3_, p4_, p5_); return result; } else { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,p5_); + R result = (object_->*member_)(p1_, p2_, p3_, p4_, p5_); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -1759,17 +1843,15 @@ class _MemberResultCallback_5_0 : public ResultCallback { }; template -class _MemberResultCallback_5_0::value - >::type> - : public Closure { +class _MemberResultCallback_5_0< + del, void, T, P1, P2, P3, P4, P5, + typename c_enable_if::value>::type> : public Closure { public: typedef Closure base; - typedef void (T::*MemberSignature)(P1,P2,P3,P4,P5) ; + typedef void (T::*MemberSignature)(P1, P2, P3, P4, P5); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; typename remove_reference::type p2_; @@ -1778,14 +1860,22 @@ class _MemberResultCallback_5_0::type p5_; public: - inline _MemberResultCallback_5_0( T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) - : Closure(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5) { } + inline _MemberResultCallback_5_0(T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5) + : Closure(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Closure"); @@ -1793,9 +1883,9 @@ class _MemberResultCallback_5_0*member_)(p1_,p2_,p3_,p4_,p5_); + (object_->*member_)(p1_, p2_, p3_, p4_, p5_); } else { - (object_->*member_)(p1_,p2_,p3_,p4_,p5_); + (object_->*member_)(p1_, p2_, p3_, p4_, p5_); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -1804,18 +1894,32 @@ class _MemberResultCallback_5_0 -inline typename _MemberResultCallback_5_0::base* -NewCallback( T1* obj, R (T2::*member)(P1,P2,P3,P4,P5) , typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) { - return new _MemberResultCallback_5_0(obj, member, p1, p2, p3, p4, p5); +template +inline typename _MemberResultCallback_5_0::base* +NewCallback(T1* obj, R (T2::*member)(P1, P2, P3, P4, P5), + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3, typename ConstRef::type p4, + typename ConstRef::type p5) { + return new _MemberResultCallback_5_0( + obj, member, p1, p2, p3, p4, p5); } #endif #ifndef SWIG -template -inline typename _MemberResultCallback_5_0::base* -NewPermanentCallback( T1* obj, R (T2::*member)(P1,P2,P3,P4,P5) , typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) { - return new _MemberResultCallback_5_0(obj, member, p1, p2, p3, p4, p5); +template +inline typename _MemberResultCallback_5_0::base* +NewPermanentCallback(T1* obj, R (T2::*member)(P1, P2, P3, P4, P5), + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5) { + return new _MemberResultCallback_5_0( + obj, member, p1, p2, p3, p4, p5); } #endif @@ -1823,7 +1927,7 @@ template class _FunctionResultCallback_5_0 : public ResultCallback { public: typedef ResultCallback base; - typedef R (*FunctionSignature)(P1,P2,P3,P4,P5); + typedef R (*FunctionSignature)(P1, P2, P3, P4, P5); private: FunctionSignature function_; @@ -1834,13 +1938,21 @@ class _FunctionResultCallback_5_0 : public ResultCallback { typename remove_reference::type p5_; public: - inline _FunctionResultCallback_5_0(FunctionSignature function, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) - : ResultCallback(), - function_(function), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5) { } + inline _FunctionResultCallback_5_0(FunctionSignature function, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5) + : ResultCallback(), + function_(function), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback"); @@ -1848,10 +1960,10 @@ class _FunctionResultCallback_5_0 : public ResultCallback { virtual R Run() { if (!del) { - R result = (*function_)(p1_,p2_,p3_,p4_,p5_); + R result = (*function_)(p1_, p2_, p3_, p4_, p5_); return result; } else { - R result = (*function_)(p1_,p2_,p3_,p4_,p5_); + R result = (*function_)(p1_, p2_, p3_, p4_, p5_); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -1861,10 +1973,11 @@ class _FunctionResultCallback_5_0 : public ResultCallback { }; template -class _FunctionResultCallback_5_0 : public Closure { +class _FunctionResultCallback_5_0 : public Closure { public: typedef Closure base; - typedef void (*FunctionSignature)(P1,P2,P3,P4,P5); + typedef void (*FunctionSignature)(P1, P2, P3, P4, P5); private: FunctionSignature function_; @@ -1875,13 +1988,21 @@ class _FunctionResultCallback_5_0 : public Closur typename remove_reference::type p5_; public: - inline _FunctionResultCallback_5_0(FunctionSignature function, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) - : Closure(), - function_(function), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5) { } + inline _FunctionResultCallback_5_0(FunctionSignature function, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5) + : Closure(), + function_(function), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Closure"); @@ -1889,9 +2010,9 @@ class _FunctionResultCallback_5_0 : public Closur virtual void Run() { if (!del) { - (*function_)(p1_,p2_,p3_,p4_,p5_); + (*function_)(p1_, p2_, p3_, p4_, p5_); } else { - (*function_)(p1_,p2_,p3_,p4_,p5_); + (*function_)(p1_, p2_, p3_, p4_, p5_); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -1900,25 +2021,33 @@ class _FunctionResultCallback_5_0 : public Closur }; template -inline typename _FunctionResultCallback_5_0::base* -NewCallback(R (*function)(P1,P2,P3,P4,P5), typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) { - return new _FunctionResultCallback_5_0(function, p1, p2, p3, p4, p5); +inline typename _FunctionResultCallback_5_0::base* +NewCallback(R (*function)(P1, P2, P3, P4, P5), typename ConstRef::type p1, + typename ConstRef::type p2, typename ConstRef::type p3, + typename ConstRef::type p4, typename ConstRef::type p5) { + return new _FunctionResultCallback_5_0( + function, p1, p2, p3, p4, p5); } template -inline typename _FunctionResultCallback_5_0::base* -NewPermanentCallback(R (*function)(P1,P2,P3,P4,P5), typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) { - return new _FunctionResultCallback_5_0(function, p1, p2, p3, p4, p5); +inline typename _FunctionResultCallback_5_0::base* +NewPermanentCallback(R (*function)(P1, P2, P3, P4, P5), + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5) { + return new _FunctionResultCallback_5_0( + function, p1, p2, p3, p4, p5); } -template ::value - >::type> +template ::value>::type> class _ConstMemberResultCallback_6_0 : public ResultCallback { public: typedef ResultCallback base; - typedef R (T::*MemberSignature)(P1,P2,P3,P4,P5,P6) const; + typedef R (T::*MemberSignature)(P1, P2, P3, P4, P5, P6) const; private: const T* object_; @@ -1931,14 +2060,24 @@ class _ConstMemberResultCallback_6_0 : public ResultCallback { typename remove_reference::type p6_; public: - inline _ConstMemberResultCallback_6_0(const T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) - : ResultCallback(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5), p6_(p6) { } + inline _ConstMemberResultCallback_6_0(const T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5, + typename ConstRef::type p6) + : ResultCallback(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5), + p6_(p6) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback"); @@ -1946,10 +2085,10 @@ class _ConstMemberResultCallback_6_0 : public ResultCallback { virtual R Run() { if (!del) { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,p5_,p6_); + R result = (object_->*member_)(p1_, p2_, p3_, p4_, p5_, p6_); return result; } else { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,p5_,p6_); + R result = (object_->*member_)(p1_, p2_, p3_, p4_, p5_, p6_); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -1958,15 +2097,14 @@ class _ConstMemberResultCallback_6_0 : public ResultCallback { } }; -template -class _ConstMemberResultCallback_6_0::value - >::type> - : public Closure { +template +class _ConstMemberResultCallback_6_0< + del, void, T, P1, P2, P3, P4, P5, P6, + typename c_enable_if::value>::type> : public Closure { public: typedef Closure base; - typedef void (T::*MemberSignature)(P1,P2,P3,P4,P5,P6) const; + typedef void (T::*MemberSignature)(P1, P2, P3, P4, P5, P6) const; private: const T* object_; @@ -1979,14 +2117,24 @@ class _ConstMemberResultCallback_6_0::type p6_; public: - inline _ConstMemberResultCallback_6_0(const T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) - : Closure(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5), p6_(p6) { } + inline _ConstMemberResultCallback_6_0(const T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5, + typename ConstRef::type p6) + : Closure(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5), + p6_(p6) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Closure"); @@ -1994,9 +2142,9 @@ class _ConstMemberResultCallback_6_0*member_)(p1_,p2_,p3_,p4_,p5_,p6_); + (object_->*member_)(p1_, p2_, p3_, p4_, p5_, p6_); } else { - (object_->*member_)(p1_,p2_,p3_,p4_,p5_,p6_); + (object_->*member_)(p1_, p2_, p3_, p4_, p5_, p6_); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -2005,32 +2153,45 @@ class _ConstMemberResultCallback_6_0 -inline typename _ConstMemberResultCallback_6_0::base* -NewCallback(const T1* obj, R (T2::*member)(P1,P2,P3,P4,P5,P6) const, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) { - return new _ConstMemberResultCallback_6_0(obj, member, p1, p2, p3, p4, p5, p6); +template +inline typename _ConstMemberResultCallback_6_0::base* +NewCallback(const T1* obj, R (T2::*member)(P1, P2, P3, P4, P5, P6) const, + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3, typename ConstRef::type p4, + typename ConstRef::type p5, typename ConstRef::type p6) { + return new _ConstMemberResultCallback_6_0< + true, R, T1, P1, P2, P3, P4, P5, P6>(obj, member, p1, p2, p3, p4, p5, p6); } #endif #ifndef SWIG -template -inline typename _ConstMemberResultCallback_6_0::base* -NewPermanentCallback(const T1* obj, R (T2::*member)(P1,P2,P3,P4,P5,P6) const, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) { - return new _ConstMemberResultCallback_6_0(obj, member, p1, p2, p3, p4, p5, p6); +template +inline typename _ConstMemberResultCallback_6_0::base* +NewPermanentCallback( + const T1* obj, R (T2::*member)(P1, P2, P3, P4, P5, P6) const, + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3, typename ConstRef::type p4, + typename ConstRef::type p5, typename ConstRef::type p6) { + return new _ConstMemberResultCallback_6_0(obj, member, p1, p2, p3, p4, p5, + p6); } #endif -template ::value - >::type> +template ::value>::type> class _MemberResultCallback_6_0 : public ResultCallback { public: typedef ResultCallback base; - typedef R (T::*MemberSignature)(P1,P2,P3,P4,P5,P6) ; + typedef R (T::*MemberSignature)(P1, P2, P3, P4, P5, P6); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; typename remove_reference::type p2_; @@ -2040,14 +2201,24 @@ class _MemberResultCallback_6_0 : public ResultCallback { typename remove_reference::type p6_; public: - inline _MemberResultCallback_6_0( T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) - : ResultCallback(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5), p6_(p6) { } + inline _MemberResultCallback_6_0(T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5, + typename ConstRef::type p6) + : ResultCallback(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5), + p6_(p6) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback"); @@ -2055,10 +2226,10 @@ class _MemberResultCallback_6_0 : public ResultCallback { virtual R Run() { if (!del) { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,p5_,p6_); + R result = (object_->*member_)(p1_, p2_, p3_, p4_, p5_, p6_); return result; } else { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,p5_,p6_); + R result = (object_->*member_)(p1_, p2_, p3_, p4_, p5_, p6_); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -2067,18 +2238,17 @@ class _MemberResultCallback_6_0 : public ResultCallback { } }; -template -class _MemberResultCallback_6_0::value - >::type> - : public Closure { +template +class _MemberResultCallback_6_0< + del, void, T, P1, P2, P3, P4, P5, P6, + typename c_enable_if::value>::type> : public Closure { public: typedef Closure base; - typedef void (T::*MemberSignature)(P1,P2,P3,P4,P5,P6) ; + typedef void (T::*MemberSignature)(P1, P2, P3, P4, P5, P6); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; typename remove_reference::type p2_; @@ -2088,14 +2258,24 @@ class _MemberResultCallback_6_0::type p6_; public: - inline _MemberResultCallback_6_0( T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) - : Closure(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5), p6_(p6) { } + inline _MemberResultCallback_6_0(T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5, + typename ConstRef::type p6) + : Closure(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5), + p6_(p6) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Closure"); @@ -2103,9 +2283,9 @@ class _MemberResultCallback_6_0*member_)(p1_,p2_,p3_,p4_,p5_,p6_); + (object_->*member_)(p1_, p2_, p3_, p4_, p5_, p6_); } else { - (object_->*member_)(p1_,p2_,p3_,p4_,p5_,p6_); + (object_->*member_)(p1_, p2_, p3_, p4_, p5_, p6_); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -2114,26 +2294,42 @@ class _MemberResultCallback_6_0 -inline typename _MemberResultCallback_6_0::base* -NewCallback( T1* obj, R (T2::*member)(P1,P2,P3,P4,P5,P6) , typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) { - return new _MemberResultCallback_6_0(obj, member, p1, p2, p3, p4, p5, p6); +template +inline typename _MemberResultCallback_6_0::base* +NewCallback(T1* obj, R (T2::*member)(P1, P2, P3, P4, P5, P6), + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3, typename ConstRef::type p4, + typename ConstRef::type p5, typename ConstRef::type p6) { + return new _MemberResultCallback_6_0( + obj, member, p1, p2, p3, p4, p5, p6); } #endif #ifndef SWIG -template -inline typename _MemberResultCallback_6_0::base* -NewPermanentCallback( T1* obj, R (T2::*member)(P1,P2,P3,P4,P5,P6) , typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) { - return new _MemberResultCallback_6_0(obj, member, p1, p2, p3, p4, p5, p6); +template +inline typename _MemberResultCallback_6_0::base* +NewPermanentCallback(T1* obj, R (T2::*member)(P1, P2, P3, P4, P5, P6), + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5, + typename ConstRef::type p6) { + return new _MemberResultCallback_6_0( + obj, member, p1, p2, p3, p4, p5, p6); } #endif -template +template class _FunctionResultCallback_6_0 : public ResultCallback { public: typedef ResultCallback base; - typedef R (*FunctionSignature)(P1,P2,P3,P4,P5,P6); + typedef R (*FunctionSignature)(P1, P2, P3, P4, P5, P6); private: FunctionSignature function_; @@ -2145,13 +2341,23 @@ class _FunctionResultCallback_6_0 : public ResultCallback { typename remove_reference::type p6_; public: - inline _FunctionResultCallback_6_0(FunctionSignature function, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) - : ResultCallback(), - function_(function), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5), p6_(p6) { } + inline _FunctionResultCallback_6_0(FunctionSignature function, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5, + typename ConstRef::type p6) + : ResultCallback(), + function_(function), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5), + p6_(p6) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback"); @@ -2159,10 +2365,10 @@ class _FunctionResultCallback_6_0 : public ResultCallback { virtual R Run() { if (!del) { - R result = (*function_)(p1_,p2_,p3_,p4_,p5_,p6_); + R result = (*function_)(p1_, p2_, p3_, p4_, p5_, p6_); return result; } else { - R result = (*function_)(p1_,p2_,p3_,p4_,p5_,p6_); + R result = (*function_)(p1_, p2_, p3_, p4_, p5_, p6_); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -2172,10 +2378,11 @@ class _FunctionResultCallback_6_0 : public ResultCallback { }; template -class _FunctionResultCallback_6_0 : public Closure { +class _FunctionResultCallback_6_0 : public Closure { public: typedef Closure base; - typedef void (*FunctionSignature)(P1,P2,P3,P4,P5,P6); + typedef void (*FunctionSignature)(P1, P2, P3, P4, P5, P6); private: FunctionSignature function_; @@ -2187,13 +2394,23 @@ class _FunctionResultCallback_6_0 : public Cl typename remove_reference::type p6_; public: - inline _FunctionResultCallback_6_0(FunctionSignature function, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) - : Closure(), - function_(function), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5), p6_(p6) { } + inline _FunctionResultCallback_6_0(FunctionSignature function, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5, + typename ConstRef::type p6) + : Closure(), + function_(function), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5), + p6_(p6) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Closure"); @@ -2201,9 +2418,9 @@ class _FunctionResultCallback_6_0 : public Cl virtual void Run() { if (!del) { - (*function_)(p1_,p2_,p3_,p4_,p5_,p6_); + (*function_)(p1_, p2_, p3_, p4_, p5_, p6_); } else { - (*function_)(p1_,p2_,p3_,p4_,p5_,p6_); + (*function_)(p1_, p2_, p3_, p4_, p5_, p6_); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -2212,24 +2429,36 @@ class _FunctionResultCallback_6_0 : public Cl }; template -inline typename _FunctionResultCallback_6_0::base* -NewCallback(R (*function)(P1,P2,P3,P4,P5,P6), typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) { - return new _FunctionResultCallback_6_0(function, p1, p2, p3, p4, p5, p6); +inline typename _FunctionResultCallback_6_0::base* +NewCallback(R (*function)(P1, P2, P3, P4, P5, P6), + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3, typename ConstRef::type p4, + typename ConstRef::type p5, typename ConstRef::type p6) { + return new _FunctionResultCallback_6_0( + function, p1, p2, p3, p4, p5, p6); } template -inline typename _FunctionResultCallback_6_0::base* -NewPermanentCallback(R (*function)(P1,P2,P3,P4,P5,P6), typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) { - return new _FunctionResultCallback_6_0(function, p1, p2, p3, p4, p5, p6); +inline typename _FunctionResultCallback_6_0::base* +NewPermanentCallback(R (*function)(P1, P2, P3, P4, P5, P6), + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5, + typename ConstRef::type p6) { + return new _FunctionResultCallback_6_0( + function, p1, p2, p3, p4, p5, p6); } -template ::value - >::type> -class _ConstMemberResultCallback_0_1 : public ResultCallback1 { +template < + bool del, class R, class T, class A1, + class OnlyIf = typename c_enable_if::value>::type> +class _ConstMemberResultCallback_0_1 : public ResultCallback1 { public: - typedef ResultCallback1 base; + typedef ResultCallback1 base; typedef R (T::*MemberSignature)(A1) const; private: @@ -2238,13 +2467,9 @@ class _ConstMemberResultCallback_0_1 : public ResultCallback1 { public: inline _ConstMemberResultCallback_0_1(const T* object, MemberSignature member) - : ResultCallback1(), - object_(object), - member_(member) { } + : ResultCallback1(), object_(object), member_(member) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback1"); @@ -2265,11 +2490,9 @@ class _ConstMemberResultCallback_0_1 : public ResultCallback1 { }; template -class _ConstMemberResultCallback_0_1::value - >::type> - : public Callback1 { +class _ConstMemberResultCallback_0_1< + del, void, T, A1, typename c_enable_if::value>::type> : public Callback1 { public: typedef Callback1 base; typedef void (T::*MemberSignature)(A1) const; @@ -2280,13 +2503,9 @@ class _ConstMemberResultCallback_0_1(), - object_(object), - member_(member) { } + : Callback1(), object_(object), member_(member) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback1"); @@ -2306,42 +2525,37 @@ class _ConstMemberResultCallback_0_1 -inline typename _ConstMemberResultCallback_0_1::base* +inline typename _ConstMemberResultCallback_0_1::base* NewCallback(const T1* obj, R (T2::*member)(A1) const) { - return new _ConstMemberResultCallback_0_1(obj, member); + return new _ConstMemberResultCallback_0_1(obj, member); } #endif #ifndef SWIG template -inline typename _ConstMemberResultCallback_0_1::base* +inline typename _ConstMemberResultCallback_0_1::base* NewPermanentCallback(const T1* obj, R (T2::*member)(A1) const) { - return new _ConstMemberResultCallback_0_1(obj, member); + return new _ConstMemberResultCallback_0_1(obj, member); } #endif -template ::value - >::type> -class _MemberResultCallback_0_1 : public ResultCallback1 { +template < + bool del, class R, class T, class A1, + class OnlyIf = typename c_enable_if::value>::type> +class _MemberResultCallback_0_1 : public ResultCallback1 { public: - typedef ResultCallback1 base; - typedef R (T::*MemberSignature)(A1) ; + typedef ResultCallback1 base; + typedef R (T::*MemberSignature)(A1); private: - T* object_; + T* object_; MemberSignature member_; public: - inline _MemberResultCallback_0_1( T* object, MemberSignature member) - : ResultCallback1(), - object_(object), - member_(member) { } + inline _MemberResultCallback_0_1(T* object, MemberSignature member) + : ResultCallback1(), object_(object), member_(member) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback1"); @@ -2363,27 +2577,21 @@ class _MemberResultCallback_0_1 : public ResultCallback1 { template class _MemberResultCallback_0_1::value - >::type> - : public Callback1 { + typename c_enable_if::value>::type> : public Callback1 { public: typedef Callback1 base; - typedef void (T::*MemberSignature)(A1) ; + typedef void (T::*MemberSignature)(A1); private: - T* object_; + T* object_; MemberSignature member_; public: - inline _MemberResultCallback_0_1( T* object, MemberSignature member) - : Callback1(), - object_(object), - member_(member) { } + inline _MemberResultCallback_0_1(T* object, MemberSignature member) + : Callback1(), object_(object), member_(member) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback1"); @@ -2403,24 +2611,24 @@ class _MemberResultCallback_0_1 -inline typename _MemberResultCallback_0_1::base* -NewCallback( T1* obj, R (T2::*member)(A1) ) { - return new _MemberResultCallback_0_1(obj, member); +inline typename _MemberResultCallback_0_1::base* NewCallback( + T1* obj, R (T2::*member)(A1)) { + return new _MemberResultCallback_0_1(obj, member); } #endif #ifndef SWIG template -inline typename _MemberResultCallback_0_1::base* -NewPermanentCallback( T1* obj, R (T2::*member)(A1) ) { - return new _MemberResultCallback_0_1(obj, member); +inline typename _MemberResultCallback_0_1::base* +NewPermanentCallback(T1* obj, R (T2::*member)(A1)) { + return new _MemberResultCallback_0_1(obj, member); } #endif template -class _FunctionResultCallback_0_1 : public ResultCallback1 { +class _FunctionResultCallback_0_1 : public ResultCallback1 { public: - typedef ResultCallback1 base; + typedef ResultCallback1 base; typedef R (*FunctionSignature)(A1); private: @@ -2428,12 +2636,9 @@ class _FunctionResultCallback_0_1 : public ResultCallback1 { public: inline _FunctionResultCallback_0_1(FunctionSignature function) - : ResultCallback1(), - function_(function) { } + : ResultCallback1(), function_(function) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback1"); @@ -2464,12 +2669,9 @@ class _FunctionResultCallback_0_1 : public Callback1 { public: inline _FunctionResultCallback_0_1(FunctionSignature function) - : Callback1(), - function_(function) { } + : Callback1(), function_(function) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback1"); @@ -2488,25 +2690,24 @@ class _FunctionResultCallback_0_1 : public Callback1 { }; template -inline typename _FunctionResultCallback_0_1::base* -NewCallback(R (*function)(A1)) { - return new _FunctionResultCallback_0_1(function); +inline typename _FunctionResultCallback_0_1::base* NewCallback( + R (*function)(A1)) { + return new _FunctionResultCallback_0_1(function); } template -inline typename _FunctionResultCallback_0_1::base* +inline typename _FunctionResultCallback_0_1::base* NewPermanentCallback(R (*function)(A1)) { - return new _FunctionResultCallback_0_1(function); + return new _FunctionResultCallback_0_1(function); } -template ::value - >::type> -class _ConstMemberResultCallback_1_1 : public ResultCallback1 { +template < + bool del, class R, class T, class P1, class A1, + class OnlyIf = typename c_enable_if::value>::type> +class _ConstMemberResultCallback_1_1 : public ResultCallback1 { public: - typedef ResultCallback1 base; - typedef R (T::*MemberSignature)(P1,A1) const; + typedef ResultCallback1 base; + typedef R (T::*MemberSignature)(P1, A1) const; private: const T* object_; @@ -2514,14 +2715,11 @@ class _ConstMemberResultCallback_1_1 : public ResultCallback1 { typename remove_reference::type p1_; public: - inline _ConstMemberResultCallback_1_1(const T* object, MemberSignature member, typename ConstRef::type p1) - : ResultCallback1(), - object_(object), - member_(member), p1_(p1) { } + inline _ConstMemberResultCallback_1_1(const T* object, MemberSignature member, + typename ConstRef::type p1) + : ResultCallback1(), object_(object), member_(member), p1_(p1) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback1"); @@ -2529,10 +2727,10 @@ class _ConstMemberResultCallback_1_1 : public ResultCallback1 { virtual R Run(A1 a1) { if (!del) { - R result = (object_->*member_)(p1_,a1); + R result = (object_->*member_)(p1_, a1); return result; } else { - R result = (object_->*member_)(p1_,a1); + R result = (object_->*member_)(p1_, a1); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -2542,14 +2740,12 @@ class _ConstMemberResultCallback_1_1 : public ResultCallback1 { }; template -class _ConstMemberResultCallback_1_1::value - >::type> - : public Callback1 { +class _ConstMemberResultCallback_1_1< + del, void, T, P1, A1, typename c_enable_if::value>::type> : public Callback1 { public: typedef Callback1 base; - typedef void (T::*MemberSignature)(P1,A1) const; + typedef void (T::*MemberSignature)(P1, A1) const; private: const T* object_; @@ -2557,14 +2753,11 @@ class _ConstMemberResultCallback_1_1::type p1_; public: - inline _ConstMemberResultCallback_1_1(const T* object, MemberSignature member, typename ConstRef::type p1) - : Callback1(), - object_(object), - member_(member), p1_(p1) { } + inline _ConstMemberResultCallback_1_1(const T* object, MemberSignature member, + typename ConstRef::type p1) + : Callback1(), object_(object), member_(member), p1_(p1) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback1"); @@ -2572,9 +2765,9 @@ class _ConstMemberResultCallback_1_1*member_)(p1_,a1); + (object_->*member_)(p1_, a1); } else { - (object_->*member_)(p1_,a1); + (object_->*member_)(p1_, a1); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -2584,43 +2777,43 @@ class _ConstMemberResultCallback_1_1 -inline typename _ConstMemberResultCallback_1_1::base* -NewCallback(const T1* obj, R (T2::*member)(P1,A1) const, typename ConstRef::type p1) { - return new _ConstMemberResultCallback_1_1(obj, member, p1); +inline typename _ConstMemberResultCallback_1_1::base* +NewCallback(const T1* obj, R (T2::*member)(P1, A1) const, + typename ConstRef::type p1) { + return new _ConstMemberResultCallback_1_1(obj, member, + p1); } #endif #ifndef SWIG template -inline typename _ConstMemberResultCallback_1_1::base* -NewPermanentCallback(const T1* obj, R (T2::*member)(P1,A1) const, typename ConstRef::type p1) { - return new _ConstMemberResultCallback_1_1(obj, member, p1); +inline typename _ConstMemberResultCallback_1_1::base* +NewPermanentCallback(const T1* obj, R (T2::*member)(P1, A1) const, + typename ConstRef::type p1) { + return new _ConstMemberResultCallback_1_1(obj, member, + p1); } #endif -template ::value - >::type> -class _MemberResultCallback_1_1 : public ResultCallback1 { +template < + bool del, class R, class T, class P1, class A1, + class OnlyIf = typename c_enable_if::value>::type> +class _MemberResultCallback_1_1 : public ResultCallback1 { public: - typedef ResultCallback1 base; - typedef R (T::*MemberSignature)(P1,A1) ; + typedef ResultCallback1 base; + typedef R (T::*MemberSignature)(P1, A1); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; public: - inline _MemberResultCallback_1_1( T* object, MemberSignature member, typename ConstRef::type p1) - : ResultCallback1(), - object_(object), - member_(member), p1_(p1) { } + inline _MemberResultCallback_1_1(T* object, MemberSignature member, + typename ConstRef::type p1) + : ResultCallback1(), object_(object), member_(member), p1_(p1) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback1"); @@ -2628,10 +2821,10 @@ class _MemberResultCallback_1_1 : public ResultCallback1 { virtual R Run(A1 a1) { if (!del) { - R result = (object_->*member_)(p1_,a1); + R result = (object_->*member_)(p1_, a1); return result; } else { - R result = (object_->*member_)(p1_,a1); + R result = (object_->*member_)(p1_, a1); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -2642,28 +2835,23 @@ class _MemberResultCallback_1_1 : public ResultCallback1 { template class _MemberResultCallback_1_1::value - >::type> - : public Callback1 { + typename c_enable_if::value>::type> : public Callback1 { public: typedef Callback1 base; - typedef void (T::*MemberSignature)(P1,A1) ; + typedef void (T::*MemberSignature)(P1, A1); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; public: - inline _MemberResultCallback_1_1( T* object, MemberSignature member, typename ConstRef::type p1) - : Callback1(), - object_(object), - member_(member), p1_(p1) { } + inline _MemberResultCallback_1_1(T* object, MemberSignature member, + typename ConstRef::type p1) + : Callback1(), object_(object), member_(member), p1_(p1) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback1"); @@ -2671,9 +2859,9 @@ class _MemberResultCallback_1_1*member_)(p1_,a1); + (object_->*member_)(p1_, a1); } else { - (object_->*member_)(p1_,a1); + (object_->*member_)(p1_, a1); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -2683,38 +2871,37 @@ class _MemberResultCallback_1_1 -inline typename _MemberResultCallback_1_1::base* -NewCallback( T1* obj, R (T2::*member)(P1,A1) , typename ConstRef::type p1) { - return new _MemberResultCallback_1_1(obj, member, p1); +inline typename _MemberResultCallback_1_1::base* +NewCallback(T1* obj, R (T2::*member)(P1, A1), typename ConstRef::type p1) { + return new _MemberResultCallback_1_1(obj, member, p1); } #endif #ifndef SWIG template -inline typename _MemberResultCallback_1_1::base* -NewPermanentCallback( T1* obj, R (T2::*member)(P1,A1) , typename ConstRef::type p1) { - return new _MemberResultCallback_1_1(obj, member, p1); +inline typename _MemberResultCallback_1_1::base* +NewPermanentCallback(T1* obj, R (T2::*member)(P1, A1), + typename ConstRef::type p1) { + return new _MemberResultCallback_1_1(obj, member, p1); } #endif template -class _FunctionResultCallback_1_1 : public ResultCallback1 { +class _FunctionResultCallback_1_1 : public ResultCallback1 { public: - typedef ResultCallback1 base; - typedef R (*FunctionSignature)(P1,A1); + typedef ResultCallback1 base; + typedef R (*FunctionSignature)(P1, A1); private: FunctionSignature function_; typename remove_reference::type p1_; public: - inline _FunctionResultCallback_1_1(FunctionSignature function, typename ConstRef::type p1) - : ResultCallback1(), - function_(function), p1_(p1) { } + inline _FunctionResultCallback_1_1(FunctionSignature function, + typename ConstRef::type p1) + : ResultCallback1(), function_(function), p1_(p1) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback1"); @@ -2722,10 +2909,10 @@ class _FunctionResultCallback_1_1 : public ResultCallback1 { virtual R Run(A1 a1) { if (!del) { - R result = (*function_)(p1_,a1); + R result = (*function_)(p1_, a1); return result; } else { - R result = (*function_)(p1_,a1); + R result = (*function_)(p1_, a1); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -2738,20 +2925,18 @@ template class _FunctionResultCallback_1_1 : public Callback1 { public: typedef Callback1 base; - typedef void (*FunctionSignature)(P1,A1); + typedef void (*FunctionSignature)(P1, A1); private: FunctionSignature function_; typename remove_reference::type p1_; public: - inline _FunctionResultCallback_1_1(FunctionSignature function, typename ConstRef::type p1) - : Callback1(), - function_(function), p1_(p1) { } + inline _FunctionResultCallback_1_1(FunctionSignature function, + typename ConstRef::type p1) + : Callback1(), function_(function), p1_(p1) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback1"); @@ -2759,9 +2944,9 @@ class _FunctionResultCallback_1_1 : public Callback1 { virtual void Run(A1 a1) { if (!del) { - (*function_)(p1_,a1); + (*function_)(p1_, a1); } else { - (*function_)(p1_,a1); + (*function_)(p1_, a1); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -2770,25 +2955,24 @@ class _FunctionResultCallback_1_1 : public Callback1 { }; template -inline typename _FunctionResultCallback_1_1::base* -NewCallback(R (*function)(P1,A1), typename ConstRef::type p1) { - return new _FunctionResultCallback_1_1(function, p1); +inline typename _FunctionResultCallback_1_1::base* NewCallback( + R (*function)(P1, A1), typename ConstRef::type p1) { + return new _FunctionResultCallback_1_1(function, p1); } template -inline typename _FunctionResultCallback_1_1::base* -NewPermanentCallback(R (*function)(P1,A1), typename ConstRef::type p1) { - return new _FunctionResultCallback_1_1(function, p1); +inline typename _FunctionResultCallback_1_1::base* +NewPermanentCallback(R (*function)(P1, A1), typename ConstRef::type p1) { + return new _FunctionResultCallback_1_1(function, p1); } -template ::value - >::type> -class _ConstMemberResultCallback_2_1 : public ResultCallback1 { +template < + bool del, class R, class T, class P1, class P2, class A1, + class OnlyIf = typename c_enable_if::value>::type> +class _ConstMemberResultCallback_2_1 : public ResultCallback1 { public: - typedef ResultCallback1 base; - typedef R (T::*MemberSignature)(P1,P2,A1) const; + typedef ResultCallback1 base; + typedef R (T::*MemberSignature)(P1, P2, A1) const; private: const T* object_; @@ -2797,14 +2981,16 @@ class _ConstMemberResultCallback_2_1 : public ResultCallback1 { typename remove_reference::type p2_; public: - inline _ConstMemberResultCallback_2_1(const T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2) - : ResultCallback1(), - object_(object), - member_(member), p1_(p1), p2_(p2) { } + inline _ConstMemberResultCallback_2_1(const T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2) + : ResultCallback1(), + object_(object), + member_(member), + p1_(p1), + p2_(p2) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback1"); @@ -2812,10 +2998,10 @@ class _ConstMemberResultCallback_2_1 : public ResultCallback1 { virtual R Run(A1 a1) { if (!del) { - R result = (object_->*member_)(p1_,p2_,a1); + R result = (object_->*member_)(p1_, p2_, a1); return result; } else { - R result = (object_->*member_)(p1_,p2_,a1); + R result = (object_->*member_)(p1_, p2_, a1); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -2825,14 +3011,12 @@ class _ConstMemberResultCallback_2_1 : public ResultCallback1 { }; template -class _ConstMemberResultCallback_2_1::value - >::type> - : public Callback1 { +class _ConstMemberResultCallback_2_1< + del, void, T, P1, P2, A1, typename c_enable_if::value>::type> : public Callback1 { public: typedef Callback1 base; - typedef void (T::*MemberSignature)(P1,P2,A1) const; + typedef void (T::*MemberSignature)(P1, P2, A1) const; private: const T* object_; @@ -2841,14 +3025,12 @@ class _ConstMemberResultCallback_2_1::type p2_; public: - inline _ConstMemberResultCallback_2_1(const T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2) - : Callback1(), - object_(object), - member_(member), p1_(p1), p2_(p2) { } + inline _ConstMemberResultCallback_2_1(const T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2) + : Callback1(), object_(object), member_(member), p1_(p1), p2_(p2) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback1"); @@ -2856,9 +3038,9 @@ class _ConstMemberResultCallback_2_1*member_)(p1_,p2_,a1); + (object_->*member_)(p1_, p2_, a1); } else { - (object_->*member_)(p1_,p2_,a1); + (object_->*member_)(p1_, p2_, a1); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -2868,44 +3050,50 @@ class _ConstMemberResultCallback_2_1 -inline typename _ConstMemberResultCallback_2_1::base* -NewCallback(const T1* obj, R (T2::*member)(P1,P2,A1) const, typename ConstRef::type p1, typename ConstRef::type p2) { - return new _ConstMemberResultCallback_2_1(obj, member, p1, p2); +inline typename _ConstMemberResultCallback_2_1::base* +NewCallback(const T1* obj, R (T2::*member)(P1, P2, A1) const, + typename ConstRef::type p1, typename ConstRef::type p2) { + return new _ConstMemberResultCallback_2_1( + obj, member, p1, p2); } #endif #ifndef SWIG template -inline typename _ConstMemberResultCallback_2_1::base* -NewPermanentCallback(const T1* obj, R (T2::*member)(P1,P2,A1) const, typename ConstRef::type p1, typename ConstRef::type p2) { - return new _ConstMemberResultCallback_2_1(obj, member, p1, p2); +inline typename _ConstMemberResultCallback_2_1::base* +NewPermanentCallback(const T1* obj, R (T2::*member)(P1, P2, A1) const, + typename ConstRef::type p1, + typename ConstRef::type p2) { + return new _ConstMemberResultCallback_2_1( + obj, member, p1, p2); } #endif -template ::value - >::type> -class _MemberResultCallback_2_1 : public ResultCallback1 { +template < + bool del, class R, class T, class P1, class P2, class A1, + class OnlyIf = typename c_enable_if::value>::type> +class _MemberResultCallback_2_1 : public ResultCallback1 { public: - typedef ResultCallback1 base; - typedef R (T::*MemberSignature)(P1,P2,A1) ; + typedef ResultCallback1 base; + typedef R (T::*MemberSignature)(P1, P2, A1); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; typename remove_reference::type p2_; public: - inline _MemberResultCallback_2_1( T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2) - : ResultCallback1(), - object_(object), - member_(member), p1_(p1), p2_(p2) { } + inline _MemberResultCallback_2_1(T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2) + : ResultCallback1(), + object_(object), + member_(member), + p1_(p1), + p2_(p2) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback1"); @@ -2913,10 +3101,10 @@ class _MemberResultCallback_2_1 : public ResultCallback1 { virtual R Run(A1 a1) { if (!del) { - R result = (object_->*member_)(p1_,p2_,a1); + R result = (object_->*member_)(p1_, p2_, a1); return result; } else { - R result = (object_->*member_)(p1_,p2_,a1); + R result = (object_->*member_)(p1_, p2_, a1); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -2927,29 +3115,25 @@ class _MemberResultCallback_2_1 : public ResultCallback1 { template class _MemberResultCallback_2_1::value - >::type> - : public Callback1 { + typename c_enable_if::value>::type> : public Callback1 { public: typedef Callback1 base; - typedef void (T::*MemberSignature)(P1,P2,A1) ; + typedef void (T::*MemberSignature)(P1, P2, A1); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; typename remove_reference::type p2_; public: - inline _MemberResultCallback_2_1( T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2) - : Callback1(), - object_(object), - member_(member), p1_(p1), p2_(p2) { } + inline _MemberResultCallback_2_1(T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2) + : Callback1(), object_(object), member_(member), p1_(p1), p2_(p2) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback1"); @@ -2957,9 +3141,9 @@ class _MemberResultCallback_2_1*member_)(p1_,p2_,a1); + (object_->*member_)(p1_, p2_, a1); } else { - (object_->*member_)(p1_,p2_,a1); + (object_->*member_)(p1_, p2_, a1); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -2969,25 +3153,30 @@ class _MemberResultCallback_2_1 -inline typename _MemberResultCallback_2_1::base* -NewCallback( T1* obj, R (T2::*member)(P1,P2,A1) , typename ConstRef::type p1, typename ConstRef::type p2) { - return new _MemberResultCallback_2_1(obj, member, p1, p2); +inline typename _MemberResultCallback_2_1::base* +NewCallback(T1* obj, R (T2::*member)(P1, P2, A1), + typename ConstRef::type p1, typename ConstRef::type p2) { + return new _MemberResultCallback_2_1(obj, member, p1, + p2); } #endif #ifndef SWIG template -inline typename _MemberResultCallback_2_1::base* -NewPermanentCallback( T1* obj, R (T2::*member)(P1,P2,A1) , typename ConstRef::type p1, typename ConstRef::type p2) { - return new _MemberResultCallback_2_1(obj, member, p1, p2); +inline typename _MemberResultCallback_2_1::base* +NewPermanentCallback(T1* obj, R (T2::*member)(P1, P2, A1), + typename ConstRef::type p1, + typename ConstRef::type p2) { + return new _MemberResultCallback_2_1(obj, member, + p1, p2); } #endif template -class _FunctionResultCallback_2_1 : public ResultCallback1 { +class _FunctionResultCallback_2_1 : public ResultCallback1 { public: - typedef ResultCallback1 base; - typedef R (*FunctionSignature)(P1,P2,A1); + typedef ResultCallback1 base; + typedef R (*FunctionSignature)(P1, P2, A1); private: FunctionSignature function_; @@ -2995,13 +3184,12 @@ class _FunctionResultCallback_2_1 : public ResultCallback1 { typename remove_reference::type p2_; public: - inline _FunctionResultCallback_2_1(FunctionSignature function, typename ConstRef::type p1, typename ConstRef::type p2) - : ResultCallback1(), - function_(function), p1_(p1), p2_(p2) { } + inline _FunctionResultCallback_2_1(FunctionSignature function, + typename ConstRef::type p1, + typename ConstRef::type p2) + : ResultCallback1(), function_(function), p1_(p1), p2_(p2) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback1"); @@ -3009,10 +3197,10 @@ class _FunctionResultCallback_2_1 : public ResultCallback1 { virtual R Run(A1 a1) { if (!del) { - R result = (*function_)(p1_,p2_,a1); + R result = (*function_)(p1_, p2_, a1); return result; } else { - R result = (*function_)(p1_,p2_,a1); + R result = (*function_)(p1_, p2_, a1); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -3022,10 +3210,11 @@ class _FunctionResultCallback_2_1 : public ResultCallback1 { }; template -class _FunctionResultCallback_2_1 : public Callback1 { +class _FunctionResultCallback_2_1 : public Callback1 { public: typedef Callback1 base; - typedef void (*FunctionSignature)(P1,P2,A1); + typedef void (*FunctionSignature)(P1, P2, A1); private: FunctionSignature function_; @@ -3033,13 +3222,12 @@ class _FunctionResultCallback_2_1 : public Callback1 typename remove_reference::type p2_; public: - inline _FunctionResultCallback_2_1(FunctionSignature function, typename ConstRef::type p1, typename ConstRef::type p2) - : Callback1(), - function_(function), p1_(p1), p2_(p2) { } + inline _FunctionResultCallback_2_1(FunctionSignature function, + typename ConstRef::type p1, + typename ConstRef::type p2) + : Callback1(), function_(function), p1_(p1), p2_(p2) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback1"); @@ -3047,9 +3235,9 @@ class _FunctionResultCallback_2_1 : public Callback1 virtual void Run(A1 a1) { if (!del) { - (*function_)(p1_,p2_,a1); + (*function_)(p1_, p2_, a1); } else { - (*function_)(p1_,p2_,a1); + (*function_)(p1_, p2_, a1); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -3058,25 +3246,27 @@ class _FunctionResultCallback_2_1 : public Callback1 }; template -inline typename _FunctionResultCallback_2_1::base* -NewCallback(R (*function)(P1,P2,A1), typename ConstRef::type p1, typename ConstRef::type p2) { - return new _FunctionResultCallback_2_1(function, p1, p2); +inline typename _FunctionResultCallback_2_1::base* +NewCallback(R (*function)(P1, P2, A1), typename ConstRef::type p1, + typename ConstRef::type p2) { + return new _FunctionResultCallback_2_1(function, p1, p2); } template -inline typename _FunctionResultCallback_2_1::base* -NewPermanentCallback(R (*function)(P1,P2,A1), typename ConstRef::type p1, typename ConstRef::type p2) { - return new _FunctionResultCallback_2_1(function, p1, p2); +inline typename _FunctionResultCallback_2_1::base* +NewPermanentCallback(R (*function)(P1, P2, A1), typename ConstRef::type p1, + typename ConstRef::type p2) { + return new _FunctionResultCallback_2_1(function, p1, + p2); } -template ::value - >::type> -class _ConstMemberResultCallback_3_1 : public ResultCallback1 { +template < + bool del, class R, class T, class P1, class P2, class P3, class A1, + class OnlyIf = typename c_enable_if::value>::type> +class _ConstMemberResultCallback_3_1 : public ResultCallback1 { public: - typedef ResultCallback1 base; - typedef R (T::*MemberSignature)(P1,P2,P3,A1) const; + typedef ResultCallback1 base; + typedef R (T::*MemberSignature)(P1, P2, P3, A1) const; private: const T* object_; @@ -3086,14 +3276,18 @@ class _ConstMemberResultCallback_3_1 : public ResultCallback1 { typename remove_reference::type p3_; public: - inline _ConstMemberResultCallback_3_1(const T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) - : ResultCallback1(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3) { } + inline _ConstMemberResultCallback_3_1(const T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3) + : ResultCallback1(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback1"); @@ -3101,10 +3295,10 @@ class _ConstMemberResultCallback_3_1 : public ResultCallback1 { virtual R Run(A1 a1) { if (!del) { - R result = (object_->*member_)(p1_,p2_,p3_,a1); + R result = (object_->*member_)(p1_, p2_, p3_, a1); return result; } else { - R result = (object_->*member_)(p1_,p2_,p3_,a1); + R result = (object_->*member_)(p1_, p2_, p3_, a1); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -3114,14 +3308,12 @@ class _ConstMemberResultCallback_3_1 : public ResultCallback1 { }; template -class _ConstMemberResultCallback_3_1::value - >::type> - : public Callback1 { +class _ConstMemberResultCallback_3_1< + del, void, T, P1, P2, P3, A1, typename c_enable_if::value>::type> : public Callback1 { public: typedef Callback1 base; - typedef void (T::*MemberSignature)(P1,P2,P3,A1) const; + typedef void (T::*MemberSignature)(P1, P2, P3, A1) const; private: const T* object_; @@ -3131,14 +3323,18 @@ class _ConstMemberResultCallback_3_1::type p3_; public: - inline _ConstMemberResultCallback_3_1(const T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) - : Callback1(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3) { } + inline _ConstMemberResultCallback_3_1(const T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3) + : Callback1(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback1"); @@ -3146,9 +3342,9 @@ class _ConstMemberResultCallback_3_1*member_)(p1_,p2_,p3_,a1); + (object_->*member_)(p1_, p2_, p3_, a1); } else { - (object_->*member_)(p1_,p2_,p3_,a1); + (object_->*member_)(p1_, p2_, p3_, a1); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -3158,45 +3354,57 @@ class _ConstMemberResultCallback_3_1 -inline typename _ConstMemberResultCallback_3_1::base* -NewCallback(const T1* obj, R (T2::*member)(P1,P2,P3,A1) const, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) { - return new _ConstMemberResultCallback_3_1(obj, member, p1, p2, p3); +inline typename _ConstMemberResultCallback_3_1::base* +NewCallback(const T1* obj, R (T2::*member)(P1, P2, P3, A1) const, + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3) { + return new _ConstMemberResultCallback_3_1( + obj, member, p1, p2, p3); } #endif #ifndef SWIG template -inline typename _ConstMemberResultCallback_3_1::base* -NewPermanentCallback(const T1* obj, R (T2::*member)(P1,P2,P3,A1) const, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) { - return new _ConstMemberResultCallback_3_1(obj, member, p1, p2, p3); +inline typename _ConstMemberResultCallback_3_1::base* +NewPermanentCallback(const T1* obj, R (T2::*member)(P1, P2, P3, A1) const, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3) { + return new _ConstMemberResultCallback_3_1( + obj, member, p1, p2, p3); } #endif -template ::value - >::type> -class _MemberResultCallback_3_1 : public ResultCallback1 { +template < + bool del, class R, class T, class P1, class P2, class P3, class A1, + class OnlyIf = typename c_enable_if::value>::type> +class _MemberResultCallback_3_1 : public ResultCallback1 { public: - typedef ResultCallback1 base; - typedef R (T::*MemberSignature)(P1,P2,P3,A1) ; + typedef ResultCallback1 base; + typedef R (T::*MemberSignature)(P1, P2, P3, A1); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; typename remove_reference::type p2_; typename remove_reference::type p3_; public: - inline _MemberResultCallback_3_1( T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) - : ResultCallback1(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3) { } + inline _MemberResultCallback_3_1(T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3) + : ResultCallback1(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback1"); @@ -3204,10 +3412,10 @@ class _MemberResultCallback_3_1 : public ResultCallback1 { virtual R Run(A1 a1) { if (!del) { - R result = (object_->*member_)(p1_,p2_,p3_,a1); + R result = (object_->*member_)(p1_, p2_, p3_, a1); return result; } else { - R result = (object_->*member_)(p1_,p2_,p3_,a1); + R result = (object_->*member_)(p1_, p2_, p3_, a1); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -3218,30 +3426,32 @@ class _MemberResultCallback_3_1 : public ResultCallback1 { template class _MemberResultCallback_3_1::value - >::type> - : public Callback1 { + typename c_enable_if::value>::type> : public Callback1 { public: typedef Callback1 base; - typedef void (T::*MemberSignature)(P1,P2,P3,A1) ; + typedef void (T::*MemberSignature)(P1, P2, P3, A1); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; typename remove_reference::type p2_; typename remove_reference::type p3_; public: - inline _MemberResultCallback_3_1( T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) - : Callback1(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3) { } + inline _MemberResultCallback_3_1(T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3) + : Callback1(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback1"); @@ -3249,9 +3459,9 @@ class _MemberResultCallback_3_1*member_)(p1_,p2_,p3_,a1); + (object_->*member_)(p1_, p2_, p3_, a1); } else { - (object_->*member_)(p1_,p2_,p3_,a1); + (object_->*member_)(p1_, p2_, p3_, a1); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -3261,25 +3471,32 @@ class _MemberResultCallback_3_1 -inline typename _MemberResultCallback_3_1::base* -NewCallback( T1* obj, R (T2::*member)(P1,P2,P3,A1) , typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) { - return new _MemberResultCallback_3_1(obj, member, p1, p2, p3); +inline typename _MemberResultCallback_3_1::base* +NewCallback(T1* obj, R (T2::*member)(P1, P2, P3, A1), + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3) { + return new _MemberResultCallback_3_1(obj, member, + p1, p2, p3); } #endif #ifndef SWIG template -inline typename _MemberResultCallback_3_1::base* -NewPermanentCallback( T1* obj, R (T2::*member)(P1,P2,P3,A1) , typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) { - return new _MemberResultCallback_3_1(obj, member, p1, p2, p3); +inline typename _MemberResultCallback_3_1::base* +NewPermanentCallback(T1* obj, R (T2::*member)(P1, P2, P3, A1), + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3) { + return new _MemberResultCallback_3_1( + obj, member, p1, p2, p3); } #endif template -class _FunctionResultCallback_3_1 : public ResultCallback1 { +class _FunctionResultCallback_3_1 : public ResultCallback1 { public: - typedef ResultCallback1 base; - typedef R (*FunctionSignature)(P1,P2,P3,A1); + typedef ResultCallback1 base; + typedef R (*FunctionSignature)(P1, P2, P3, A1); private: FunctionSignature function_; @@ -3288,13 +3505,17 @@ class _FunctionResultCallback_3_1 : public ResultCallback1 { typename remove_reference::type p3_; public: - inline _FunctionResultCallback_3_1(FunctionSignature function, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) - : ResultCallback1(), - function_(function), p1_(p1), p2_(p2), p3_(p3) { } + inline _FunctionResultCallback_3_1(FunctionSignature function, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3) + : ResultCallback1(), + function_(function), + p1_(p1), + p2_(p2), + p3_(p3) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback1"); @@ -3302,10 +3523,10 @@ class _FunctionResultCallback_3_1 : public ResultCallback1 { virtual R Run(A1 a1) { if (!del) { - R result = (*function_)(p1_,p2_,p3_,a1); + R result = (*function_)(p1_, p2_, p3_, a1); return result; } else { - R result = (*function_)(p1_,p2_,p3_,a1); + R result = (*function_)(p1_, p2_, p3_, a1); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -3315,10 +3536,11 @@ class _FunctionResultCallback_3_1 : public ResultCallback1 { }; template -class _FunctionResultCallback_3_1 : public Callback1 { +class _FunctionResultCallback_3_1 : public Callback1 { public: typedef Callback1 base; - typedef void (*FunctionSignature)(P1,P2,P3,A1); + typedef void (*FunctionSignature)(P1, P2, P3, A1); private: FunctionSignature function_; @@ -3327,13 +3549,13 @@ class _FunctionResultCallback_3_1 : public Callback1< typename remove_reference::type p3_; public: - inline _FunctionResultCallback_3_1(FunctionSignature function, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) - : Callback1(), - function_(function), p1_(p1), p2_(p2), p3_(p3) { } + inline _FunctionResultCallback_3_1(FunctionSignature function, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3) + : Callback1(), function_(function), p1_(p1), p2_(p2), p3_(p3) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback1"); @@ -3341,9 +3563,9 @@ class _FunctionResultCallback_3_1 : public Callback1< virtual void Run(A1 a1) { if (!del) { - (*function_)(p1_,p2_,p3_,a1); + (*function_)(p1_, p2_, p3_, a1); } else { - (*function_)(p1_,p2_,p3_,a1); + (*function_)(p1_, p2_, p3_, a1); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -3352,25 +3574,30 @@ class _FunctionResultCallback_3_1 : public Callback1< }; template -inline typename _FunctionResultCallback_3_1::base* -NewCallback(R (*function)(P1,P2,P3,A1), typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) { - return new _FunctionResultCallback_3_1(function, p1, p2, p3); +inline typename _FunctionResultCallback_3_1::base* +NewCallback(R (*function)(P1, P2, P3, A1), typename ConstRef::type p1, + typename ConstRef::type p2, typename ConstRef::type p3) { + return new _FunctionResultCallback_3_1(function, p1, + p2, p3); } template -inline typename _FunctionResultCallback_3_1::base* -NewPermanentCallback(R (*function)(P1,P2,P3,A1), typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) { - return new _FunctionResultCallback_3_1(function, p1, p2, p3); +inline typename _FunctionResultCallback_3_1::base* +NewPermanentCallback(R (*function)(P1, P2, P3, A1), + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3) { + return new _FunctionResultCallback_3_1(function, p1, + p2, p3); } -template ::value - >::type> -class _ConstMemberResultCallback_4_1 : public ResultCallback1 { +template ::value>::type> +class _ConstMemberResultCallback_4_1 : public ResultCallback1 { public: - typedef ResultCallback1 base; - typedef R (T::*MemberSignature)(P1,P2,P3,P4,A1) const; + typedef ResultCallback1 base; + typedef R (T::*MemberSignature)(P1, P2, P3, P4, A1) const; private: const T* object_; @@ -3381,14 +3608,20 @@ class _ConstMemberResultCallback_4_1 : public ResultCallback1 { typename remove_reference::type p4_; public: - inline _ConstMemberResultCallback_4_1(const T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) - : ResultCallback1(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4) { } + inline _ConstMemberResultCallback_4_1(const T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4) + : ResultCallback1(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback1"); @@ -3396,10 +3629,10 @@ class _ConstMemberResultCallback_4_1 : public ResultCallback1 { virtual R Run(A1 a1) { if (!del) { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,a1); + R result = (object_->*member_)(p1_, p2_, p3_, p4_, a1); return result; } else { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,a1); + R result = (object_->*member_)(p1_, p2_, p3_, p4_, a1); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -3409,14 +3642,13 @@ class _ConstMemberResultCallback_4_1 : public ResultCallback1 { }; template -class _ConstMemberResultCallback_4_1::value - >::type> - : public Callback1 { +class _ConstMemberResultCallback_4_1< + del, void, T, P1, P2, P3, P4, A1, + typename c_enable_if< + is_class_or_union::value>::type> : public Callback1 { public: typedef Callback1 base; - typedef void (T::*MemberSignature)(P1,P2,P3,P4,A1) const; + typedef void (T::*MemberSignature)(P1, P2, P3, P4, A1) const; private: const T* object_; @@ -3427,14 +3659,20 @@ class _ConstMemberResultCallback_4_1::type p4_; public: - inline _ConstMemberResultCallback_4_1(const T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) - : Callback1(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4) { } + inline _ConstMemberResultCallback_4_1(const T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4) + : Callback1(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback1"); @@ -3442,9 +3680,9 @@ class _ConstMemberResultCallback_4_1*member_)(p1_,p2_,p3_,p4_,a1); + (object_->*member_)(p1_, p2_, p3_, p4_, a1); } else { - (object_->*member_)(p1_,p2_,p3_,p4_,a1); + (object_->*member_)(p1_, p2_, p3_, p4_, a1); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -3453,32 +3691,43 @@ class _ConstMemberResultCallback_4_1 -inline typename _ConstMemberResultCallback_4_1::base* -NewCallback(const T1* obj, R (T2::*member)(P1,P2,P3,P4,A1) const, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) { - return new _ConstMemberResultCallback_4_1(obj, member, p1, p2, p3, p4); +template +inline typename _ConstMemberResultCallback_4_1::base* +NewCallback(const T1* obj, R (T2::*member)(P1, P2, P3, P4, A1) const, + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3, typename ConstRef::type p4) { + return new _ConstMemberResultCallback_4_1( + obj, member, p1, p2, p3, p4); } #endif #ifndef SWIG -template -inline typename _ConstMemberResultCallback_4_1::base* -NewPermanentCallback(const T1* obj, R (T2::*member)(P1,P2,P3,P4,A1) const, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) { - return new _ConstMemberResultCallback_4_1(obj, member, p1, p2, p3, p4); +template +inline typename _ConstMemberResultCallback_4_1::base* +NewPermanentCallback(const T1* obj, R (T2::*member)(P1, P2, P3, P4, A1) const, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4) { + return new _ConstMemberResultCallback_4_1( + obj, member, p1, p2, p3, p4); } #endif -template ::value - >::type> -class _MemberResultCallback_4_1 : public ResultCallback1 { +template ::value>::type> +class _MemberResultCallback_4_1 : public ResultCallback1 { public: - typedef ResultCallback1 base; - typedef R (T::*MemberSignature)(P1,P2,P3,P4,A1) ; + typedef ResultCallback1 base; + typedef R (T::*MemberSignature)(P1, P2, P3, P4, A1); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; typename remove_reference::type p2_; @@ -3486,14 +3735,20 @@ class _MemberResultCallback_4_1 : public ResultCallback1 { typename remove_reference::type p4_; public: - inline _MemberResultCallback_4_1( T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) - : ResultCallback1(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4) { } + inline _MemberResultCallback_4_1(T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4) + : ResultCallback1(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback1"); @@ -3501,10 +3756,10 @@ class _MemberResultCallback_4_1 : public ResultCallback1 { virtual R Run(A1 a1) { if (!del) { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,a1); + R result = (object_->*member_)(p1_, p2_, p3_, p4_, a1); return result; } else { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,a1); + R result = (object_->*member_)(p1_, p2_, p3_, p4_, a1); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -3515,16 +3770,14 @@ class _MemberResultCallback_4_1 : public ResultCallback1 { template class _MemberResultCallback_4_1::value - >::type> - : public Callback1 { + typename c_enable_if::value>::type> : public Callback1 { public: typedef Callback1 base; - typedef void (T::*MemberSignature)(P1,P2,P3,P4,A1) ; + typedef void (T::*MemberSignature)(P1, P2, P3, P4, A1); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; typename remove_reference::type p2_; @@ -3532,14 +3785,20 @@ class _MemberResultCallback_4_1::type p4_; public: - inline _MemberResultCallback_4_1( T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) - : Callback1(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4) { } + inline _MemberResultCallback_4_1(T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4) + : Callback1(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback1"); @@ -3547,9 +3806,9 @@ class _MemberResultCallback_4_1*member_)(p1_,p2_,p3_,p4_,a1); + (object_->*member_)(p1_, p2_, p3_, p4_, a1); } else { - (object_->*member_)(p1_,p2_,p3_,p4_,a1); + (object_->*member_)(p1_, p2_, p3_, p4_, a1); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -3558,26 +3817,38 @@ class _MemberResultCallback_4_1 -inline typename _MemberResultCallback_4_1::base* -NewCallback( T1* obj, R (T2::*member)(P1,P2,P3,P4,A1) , typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) { - return new _MemberResultCallback_4_1(obj, member, p1, p2, p3, p4); +template +inline typename _MemberResultCallback_4_1::base* +NewCallback(T1* obj, R (T2::*member)(P1, P2, P3, P4, A1), + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3, typename ConstRef::type p4) { + return new _MemberResultCallback_4_1( + obj, member, p1, p2, p3, p4); } #endif #ifndef SWIG -template -inline typename _MemberResultCallback_4_1::base* -NewPermanentCallback( T1* obj, R (T2::*member)(P1,P2,P3,P4,A1) , typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) { - return new _MemberResultCallback_4_1(obj, member, p1, p2, p3, p4); +template +inline typename _MemberResultCallback_4_1::base* +NewPermanentCallback(T1* obj, R (T2::*member)(P1, P2, P3, P4, A1), + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4) { + return new _MemberResultCallback_4_1( + obj, member, p1, p2, p3, p4); } #endif template -class _FunctionResultCallback_4_1 : public ResultCallback1 { +class _FunctionResultCallback_4_1 : public ResultCallback1 { public: - typedef ResultCallback1 base; - typedef R (*FunctionSignature)(P1,P2,P3,P4,A1); + typedef ResultCallback1 base; + typedef R (*FunctionSignature)(P1, P2, P3, P4, A1); private: FunctionSignature function_; @@ -3587,13 +3858,19 @@ class _FunctionResultCallback_4_1 : public ResultCallback1 { typename remove_reference::type p4_; public: - inline _FunctionResultCallback_4_1(FunctionSignature function, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) - : ResultCallback1(), - function_(function), p1_(p1), p2_(p2), p3_(p3), p4_(p4) { } + inline _FunctionResultCallback_4_1(FunctionSignature function, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4) + : ResultCallback1(), + function_(function), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback1"); @@ -3601,10 +3878,10 @@ class _FunctionResultCallback_4_1 : public ResultCallback1 { virtual R Run(A1 a1) { if (!del) { - R result = (*function_)(p1_,p2_,p3_,p4_,a1); + R result = (*function_)(p1_, p2_, p3_, p4_, a1); return result; } else { - R result = (*function_)(p1_,p2_,p3_,p4_,a1); + R result = (*function_)(p1_, p2_, p3_, p4_, a1); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -3614,10 +3891,11 @@ class _FunctionResultCallback_4_1 : public ResultCallback1 { }; template -class _FunctionResultCallback_4_1 : public Callback1 { +class _FunctionResultCallback_4_1 : public Callback1 { public: typedef Callback1 base; - typedef void (*FunctionSignature)(P1,P2,P3,P4,A1); + typedef void (*FunctionSignature)(P1, P2, P3, P4, A1); private: FunctionSignature function_; @@ -3627,13 +3905,19 @@ class _FunctionResultCallback_4_1 : public Callba typename remove_reference::type p4_; public: - inline _FunctionResultCallback_4_1(FunctionSignature function, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) - : Callback1(), - function_(function), p1_(p1), p2_(p2), p3_(p3), p4_(p4) { } + inline _FunctionResultCallback_4_1(FunctionSignature function, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4) + : Callback1(), + function_(function), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback1"); @@ -3641,9 +3925,9 @@ class _FunctionResultCallback_4_1 : public Callba virtual void Run(A1 a1) { if (!del) { - (*function_)(p1_,p2_,p3_,p4_,a1); + (*function_)(p1_, p2_, p3_, p4_, a1); } else { - (*function_)(p1_,p2_,p3_,p4_,a1); + (*function_)(p1_, p2_, p3_, p4_, a1); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -3652,25 +3936,32 @@ class _FunctionResultCallback_4_1 : public Callba }; template -inline typename _FunctionResultCallback_4_1::base* -NewCallback(R (*function)(P1,P2,P3,P4,A1), typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) { - return new _FunctionResultCallback_4_1(function, p1, p2, p3, p4); +inline typename _FunctionResultCallback_4_1::base* +NewCallback(R (*function)(P1, P2, P3, P4, A1), typename ConstRef::type p1, + typename ConstRef::type p2, typename ConstRef::type p3, + typename ConstRef::type p4) { + return new _FunctionResultCallback_4_1( + function, p1, p2, p3, p4); } template -inline typename _FunctionResultCallback_4_1::base* -NewPermanentCallback(R (*function)(P1,P2,P3,P4,A1), typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) { - return new _FunctionResultCallback_4_1(function, p1, p2, p3, p4); +inline typename _FunctionResultCallback_4_1::base* +NewPermanentCallback(R (*function)(P1, P2, P3, P4, A1), + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4) { + return new _FunctionResultCallback_4_1( + function, p1, p2, p3, p4); } -template ::value - >::type> -class _ConstMemberResultCallback_5_1 : public ResultCallback1 { +template ::value>::type> +class _ConstMemberResultCallback_5_1 : public ResultCallback1 { public: - typedef ResultCallback1 base; - typedef R (T::*MemberSignature)(P1,P2,P3,P4,P5,A1) const; + typedef ResultCallback1 base; + typedef R (T::*MemberSignature)(P1, P2, P3, P4, P5, A1) const; private: const T* object_; @@ -3682,14 +3973,22 @@ class _ConstMemberResultCallback_5_1 : public ResultCallback1 { typename remove_reference::type p5_; public: - inline _ConstMemberResultCallback_5_1(const T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) - : ResultCallback1(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5) { } + inline _ConstMemberResultCallback_5_1(const T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5) + : ResultCallback1(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback1"); @@ -3697,10 +3996,10 @@ class _ConstMemberResultCallback_5_1 : public ResultCallback1 { virtual R Run(A1 a1) { if (!del) { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,p5_,a1); + R result = (object_->*member_)(p1_, p2_, p3_, p4_, p5_, a1); return result; } else { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,p5_,a1); + R result = (object_->*member_)(p1_, p2_, p3_, p4_, p5_, a1); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -3709,15 +4008,15 @@ class _ConstMemberResultCallback_5_1 : public ResultCallback1 { } }; -template -class _ConstMemberResultCallback_5_1::value - >::type> - : public Callback1 { +template +class _ConstMemberResultCallback_5_1< + del, void, T, P1, P2, P3, P4, P5, A1, + typename c_enable_if< + is_class_or_union::value>::type> : public Callback1 { public: typedef Callback1 base; - typedef void (T::*MemberSignature)(P1,P2,P3,P4,P5,A1) const; + typedef void (T::*MemberSignature)(P1, P2, P3, P4, P5, A1) const; private: const T* object_; @@ -3729,14 +4028,22 @@ class _ConstMemberResultCallback_5_1::type p5_; public: - inline _ConstMemberResultCallback_5_1(const T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) - : Callback1(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5) { } + inline _ConstMemberResultCallback_5_1(const T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5) + : Callback1(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback1"); @@ -3744,9 +4051,9 @@ class _ConstMemberResultCallback_5_1*member_)(p1_,p2_,p3_,p4_,p5_,a1); + (object_->*member_)(p1_, p2_, p3_, p4_, p5_, a1); } else { - (object_->*member_)(p1_,p2_,p3_,p4_,p5_,a1); + (object_->*member_)(p1_, p2_, p3_, p4_, p5_, a1); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -3755,32 +4062,46 @@ class _ConstMemberResultCallback_5_1 -inline typename _ConstMemberResultCallback_5_1::base* -NewCallback(const T1* obj, R (T2::*member)(P1,P2,P3,P4,P5,A1) const, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) { - return new _ConstMemberResultCallback_5_1(obj, member, p1, p2, p3, p4, p5); +template +inline typename _ConstMemberResultCallback_5_1::base* +NewCallback(const T1* obj, R (T2::*member)(P1, P2, P3, P4, P5, A1) const, + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3, typename ConstRef::type p4, + typename ConstRef::type p5) { + return new _ConstMemberResultCallback_5_1< + true, R, T1, P1, P2, P3, P4, P5, A1>(obj, member, p1, p2, p3, p4, p5); } #endif #ifndef SWIG -template -inline typename _ConstMemberResultCallback_5_1::base* -NewPermanentCallback(const T1* obj, R (T2::*member)(P1,P2,P3,P4,P5,A1) const, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) { - return new _ConstMemberResultCallback_5_1(obj, member, p1, p2, p3, p4, p5); +template +inline typename _ConstMemberResultCallback_5_1::base* +NewPermanentCallback(const T1* obj, + R (T2::*member)(P1, P2, P3, P4, P5, A1) const, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5) { + return new _ConstMemberResultCallback_5_1< + false, R, T1, P1, P2, P3, P4, P5, A1>(obj, member, p1, p2, p3, p4, p5); } #endif -template ::value - >::type> -class _MemberResultCallback_5_1 : public ResultCallback1 { +template ::value>::type> +class _MemberResultCallback_5_1 : public ResultCallback1 { public: - typedef ResultCallback1 base; - typedef R (T::*MemberSignature)(P1,P2,P3,P4,P5,A1) ; + typedef ResultCallback1 base; + typedef R (T::*MemberSignature)(P1, P2, P3, P4, P5, A1); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; typename remove_reference::type p2_; @@ -3789,14 +4110,22 @@ class _MemberResultCallback_5_1 : public ResultCallback1 { typename remove_reference::type p5_; public: - inline _MemberResultCallback_5_1( T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) - : ResultCallback1(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5) { } + inline _MemberResultCallback_5_1(T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5) + : ResultCallback1(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback1"); @@ -3804,10 +4133,10 @@ class _MemberResultCallback_5_1 : public ResultCallback1 { virtual R Run(A1 a1) { if (!del) { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,p5_,a1); + R result = (object_->*member_)(p1_, p2_, p3_, p4_, p5_, a1); return result; } else { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,p5_,a1); + R result = (object_->*member_)(p1_, p2_, p3_, p4_, p5_, a1); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -3816,18 +4145,17 @@ class _MemberResultCallback_5_1 : public ResultCallback1 { } }; -template +template class _MemberResultCallback_5_1::value - >::type> - : public Callback1 { + typename c_enable_if::value>::type> : public Callback1 { public: typedef Callback1 base; - typedef void (T::*MemberSignature)(P1,P2,P3,P4,P5,A1) ; + typedef void (T::*MemberSignature)(P1, P2, P3, P4, P5, A1); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; typename remove_reference::type p2_; @@ -3836,14 +4164,22 @@ class _MemberResultCallback_5_1::type p5_; public: - inline _MemberResultCallback_5_1( T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) - : Callback1(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5) { } + inline _MemberResultCallback_5_1(T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5) + : Callback1(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback1"); @@ -3851,9 +4187,9 @@ class _MemberResultCallback_5_1*member_)(p1_,p2_,p3_,p4_,p5_,a1); + (object_->*member_)(p1_, p2_, p3_, p4_, p5_, a1); } else { - (object_->*member_)(p1_,p2_,p3_,p4_,p5_,a1); + (object_->*member_)(p1_, p2_, p3_, p4_, p5_, a1); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -3862,26 +4198,41 @@ class _MemberResultCallback_5_1 -inline typename _MemberResultCallback_5_1::base* -NewCallback( T1* obj, R (T2::*member)(P1,P2,P3,P4,P5,A1) , typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) { - return new _MemberResultCallback_5_1(obj, member, p1, p2, p3, p4, p5); +template +inline typename _MemberResultCallback_5_1::base* +NewCallback(T1* obj, R (T2::*member)(P1, P2, P3, P4, P5, A1), + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3, typename ConstRef::type p4, + typename ConstRef::type p5) { + return new _MemberResultCallback_5_1( + obj, member, p1, p2, p3, p4, p5); } #endif #ifndef SWIG -template -inline typename _MemberResultCallback_5_1::base* -NewPermanentCallback( T1* obj, R (T2::*member)(P1,P2,P3,P4,P5,A1) , typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) { - return new _MemberResultCallback_5_1(obj, member, p1, p2, p3, p4, p5); +template +inline typename _MemberResultCallback_5_1::base* +NewPermanentCallback(T1* obj, R (T2::*member)(P1, P2, P3, P4, P5, A1), + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5) { + return new _MemberResultCallback_5_1( + obj, member, p1, p2, p3, p4, p5); } #endif -template -class _FunctionResultCallback_5_1 : public ResultCallback1 { +template +class _FunctionResultCallback_5_1 : public ResultCallback1 { public: - typedef ResultCallback1 base; - typedef R (*FunctionSignature)(P1,P2,P3,P4,P5,A1); + typedef ResultCallback1 base; + typedef R (*FunctionSignature)(P1, P2, P3, P4, P5, A1); private: FunctionSignature function_; @@ -3892,13 +4243,21 @@ class _FunctionResultCallback_5_1 : public ResultCallback1 { typename remove_reference::type p5_; public: - inline _FunctionResultCallback_5_1(FunctionSignature function, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) - : ResultCallback1(), - function_(function), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5) { } + inline _FunctionResultCallback_5_1(FunctionSignature function, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5) + : ResultCallback1(), + function_(function), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback1"); @@ -3906,10 +4265,10 @@ class _FunctionResultCallback_5_1 : public ResultCallback1 { virtual R Run(A1 a1) { if (!del) { - R result = (*function_)(p1_,p2_,p3_,p4_,p5_,a1); + R result = (*function_)(p1_, p2_, p3_, p4_, p5_, a1); return result; } else { - R result = (*function_)(p1_,p2_,p3_,p4_,p5_,a1); + R result = (*function_)(p1_, p2_, p3_, p4_, p5_, a1); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -3919,10 +4278,11 @@ class _FunctionResultCallback_5_1 : public ResultCallback1 { }; template -class _FunctionResultCallback_5_1 : public Callback1 { +class _FunctionResultCallback_5_1 : public Callback1 { public: typedef Callback1 base; - typedef void (*FunctionSignature)(P1,P2,P3,P4,P5,A1); + typedef void (*FunctionSignature)(P1, P2, P3, P4, P5, A1); private: FunctionSignature function_; @@ -3933,13 +4293,21 @@ class _FunctionResultCallback_5_1 : public Ca typename remove_reference::type p5_; public: - inline _FunctionResultCallback_5_1(FunctionSignature function, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) - : Callback1(), - function_(function), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5) { } + inline _FunctionResultCallback_5_1(FunctionSignature function, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5) + : Callback1(), + function_(function), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback1"); @@ -3947,9 +4315,9 @@ class _FunctionResultCallback_5_1 : public Ca virtual void Run(A1 a1) { if (!del) { - (*function_)(p1_,p2_,p3_,p4_,p5_,a1); + (*function_)(p1_, p2_, p3_, p4_, p5_, a1); } else { - (*function_)(p1_,p2_,p3_,p4_,p5_,a1); + (*function_)(p1_, p2_, p3_, p4_, p5_, a1); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -3958,25 +4326,36 @@ class _FunctionResultCallback_5_1 : public Ca }; template -inline typename _FunctionResultCallback_5_1::base* -NewCallback(R (*function)(P1,P2,P3,P4,P5,A1), typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) { - return new _FunctionResultCallback_5_1(function, p1, p2, p3, p4, p5); +inline typename _FunctionResultCallback_5_1::base* +NewCallback(R (*function)(P1, P2, P3, P4, P5, A1), + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3, typename ConstRef::type p4, + typename ConstRef::type p5) { + return new _FunctionResultCallback_5_1( + function, p1, p2, p3, p4, p5); } template -inline typename _FunctionResultCallback_5_1::base* -NewPermanentCallback(R (*function)(P1,P2,P3,P4,P5,A1), typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) { - return new _FunctionResultCallback_5_1(function, p1, p2, p3, p4, p5); +inline typename _FunctionResultCallback_5_1::base* +NewPermanentCallback(R (*function)(P1, P2, P3, P4, P5, A1), + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5) { + return new _FunctionResultCallback_5_1( + function, p1, p2, p3, p4, p5); } -template ::value - >::type> -class _ConstMemberResultCallback_6_1 : public ResultCallback1 { +template ::value>::type> +class _ConstMemberResultCallback_6_1 : public ResultCallback1 { public: - typedef ResultCallback1 base; - typedef R (T::*MemberSignature)(P1,P2,P3,P4,P5,P6,A1) const; + typedef ResultCallback1 base; + typedef R (T::*MemberSignature)(P1, P2, P3, P4, P5, P6, A1) const; private: const T* object_; @@ -3989,14 +4368,24 @@ class _ConstMemberResultCallback_6_1 : public ResultCallback1 { typename remove_reference::type p6_; public: - inline _ConstMemberResultCallback_6_1(const T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) - : ResultCallback1(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5), p6_(p6) { } + inline _ConstMemberResultCallback_6_1(const T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5, + typename ConstRef::type p6) + : ResultCallback1(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5), + p6_(p6) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback1"); @@ -4004,10 +4393,10 @@ class _ConstMemberResultCallback_6_1 : public ResultCallback1 { virtual R Run(A1 a1) { if (!del) { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,p5_,p6_,a1); + R result = (object_->*member_)(p1_, p2_, p3_, p4_, p5_, p6_, a1); return result; } else { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,p5_,p6_,a1); + R result = (object_->*member_)(p1_, p2_, p3_, p4_, p5_, p6_, a1); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -4016,15 +4405,15 @@ class _ConstMemberResultCallback_6_1 : public ResultCallback1 { } }; -template -class _ConstMemberResultCallback_6_1::value - >::type> - : public Callback1 { +template +class _ConstMemberResultCallback_6_1< + del, void, T, P1, P2, P3, P4, P5, P6, A1, + typename c_enable_if< + is_class_or_union::value>::type> : public Callback1 { public: typedef Callback1 base; - typedef void (T::*MemberSignature)(P1,P2,P3,P4,P5,P6,A1) const; + typedef void (T::*MemberSignature)(P1, P2, P3, P4, P5, P6, A1) const; private: const T* object_; @@ -4037,14 +4426,24 @@ class _ConstMemberResultCallback_6_1::type p6_; public: - inline _ConstMemberResultCallback_6_1(const T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) - : Callback1(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5), p6_(p6) { } + inline _ConstMemberResultCallback_6_1(const T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5, + typename ConstRef::type p6) + : Callback1(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5), + p6_(p6) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback1"); @@ -4052,9 +4451,9 @@ class _ConstMemberResultCallback_6_1*member_)(p1_,p2_,p3_,p4_,p5_,p6_,a1); + (object_->*member_)(p1_, p2_, p3_, p4_, p5_, p6_, a1); } else { - (object_->*member_)(p1_,p2_,p3_,p4_,p5_,p6_,a1); + (object_->*member_)(p1_, p2_, p3_, p4_, p5_, p6_, a1); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -4063,32 +4462,46 @@ class _ConstMemberResultCallback_6_1 -inline typename _ConstMemberResultCallback_6_1::base* -NewCallback(const T1* obj, R (T2::*member)(P1,P2,P3,P4,P5,P6,A1) const, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) { - return new _ConstMemberResultCallback_6_1(obj, member, p1, p2, p3, p4, p5, p6); +template +inline typename _ConstMemberResultCallback_6_1::base* +NewCallback(const T1* obj, R (T2::*member)(P1, P2, P3, P4, P5, P6, A1) const, + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3, typename ConstRef::type p4, + typename ConstRef::type p5, typename ConstRef::type p6) { + return new _ConstMemberResultCallback_6_1(obj, member, p1, p2, p3, p4, p5, + p6); } #endif #ifndef SWIG -template -inline typename _ConstMemberResultCallback_6_1::base* -NewPermanentCallback(const T1* obj, R (T2::*member)(P1,P2,P3,P4,P5,P6,A1) const, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) { - return new _ConstMemberResultCallback_6_1(obj, member, p1, p2, p3, p4, p5, p6); +template +inline typename _ConstMemberResultCallback_6_1::base* +NewPermanentCallback( + const T1* obj, R (T2::*member)(P1, P2, P3, P4, P5, P6, A1) const, + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3, typename ConstRef::type p4, + typename ConstRef::type p5, typename ConstRef::type p6) { + return new _ConstMemberResultCallback_6_1< + false, R, T1, P1, P2, P3, P4, P5, P6, A1>(obj, member, p1, p2, p3, p4, p5, + p6); } #endif -template ::value - >::type> -class _MemberResultCallback_6_1 : public ResultCallback1 { +template ::value>::type> +class _MemberResultCallback_6_1 : public ResultCallback1 { public: - typedef ResultCallback1 base; - typedef R (T::*MemberSignature)(P1,P2,P3,P4,P5,P6,A1) ; + typedef ResultCallback1 base; + typedef R (T::*MemberSignature)(P1, P2, P3, P4, P5, P6, A1); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; typename remove_reference::type p2_; @@ -4098,14 +4511,24 @@ class _MemberResultCallback_6_1 : public ResultCallback1 { typename remove_reference::type p6_; public: - inline _MemberResultCallback_6_1( T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) - : ResultCallback1(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5), p6_(p6) { } + inline _MemberResultCallback_6_1(T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5, + typename ConstRef::type p6) + : ResultCallback1(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5), + p6_(p6) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback1"); @@ -4113,10 +4536,10 @@ class _MemberResultCallback_6_1 : public ResultCallback1 { virtual R Run(A1 a1) { if (!del) { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,p5_,p6_,a1); + R result = (object_->*member_)(p1_, p2_, p3_, p4_, p5_, p6_, a1); return result; } else { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,p5_,p6_,a1); + R result = (object_->*member_)(p1_, p2_, p3_, p4_, p5_, p6_, a1); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -4125,18 +4548,17 @@ class _MemberResultCallback_6_1 : public ResultCallback1 { } }; -template +template class _MemberResultCallback_6_1::value - >::type> - : public Callback1 { + typename c_enable_if::value>::type> : public Callback1 { public: typedef Callback1 base; - typedef void (T::*MemberSignature)(P1,P2,P3,P4,P5,P6,A1) ; + typedef void (T::*MemberSignature)(P1, P2, P3, P4, P5, P6, A1); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; typename remove_reference::type p2_; @@ -4146,14 +4568,24 @@ class _MemberResultCallback_6_1::type p6_; public: - inline _MemberResultCallback_6_1( T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) - : Callback1(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5), p6_(p6) { } + inline _MemberResultCallback_6_1(T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5, + typename ConstRef::type p6) + : Callback1(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5), + p6_(p6) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback1"); @@ -4161,9 +4593,9 @@ class _MemberResultCallback_6_1*member_)(p1_,p2_,p3_,p4_,p5_,p6_,a1); + (object_->*member_)(p1_, p2_, p3_, p4_, p5_, p6_, a1); } else { - (object_->*member_)(p1_,p2_,p3_,p4_,p5_,p6_,a1); + (object_->*member_)(p1_, p2_, p3_, p4_, p5_, p6_, a1); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -4172,26 +4604,42 @@ class _MemberResultCallback_6_1 -inline typename _MemberResultCallback_6_1::base* -NewCallback( T1* obj, R (T2::*member)(P1,P2,P3,P4,P5,P6,A1) , typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) { - return new _MemberResultCallback_6_1(obj, member, p1, p2, p3, p4, p5, p6); +template +inline typename _MemberResultCallback_6_1::base* +NewCallback(T1* obj, R (T2::*member)(P1, P2, P3, P4, P5, P6, A1), + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3, typename ConstRef::type p4, + typename ConstRef::type p5, typename ConstRef::type p6) { + return new _MemberResultCallback_6_1( + obj, member, p1, p2, p3, p4, p5, p6); } #endif #ifndef SWIG -template -inline typename _MemberResultCallback_6_1::base* -NewPermanentCallback( T1* obj, R (T2::*member)(P1,P2,P3,P4,P5,P6,A1) , typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) { - return new _MemberResultCallback_6_1(obj, member, p1, p2, p3, p4, p5, p6); +template +inline typename _MemberResultCallback_6_1::base* +NewPermanentCallback(T1* obj, R (T2::*member)(P1, P2, P3, P4, P5, P6, A1), + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5, + typename ConstRef::type p6) { + return new _MemberResultCallback_6_1(obj, member, p1, p2, p3, p4, p5, p6); } #endif -template -class _FunctionResultCallback_6_1 : public ResultCallback1 { +template +class _FunctionResultCallback_6_1 : public ResultCallback1 { public: - typedef ResultCallback1 base; - typedef R (*FunctionSignature)(P1,P2,P3,P4,P5,P6,A1); + typedef ResultCallback1 base; + typedef R (*FunctionSignature)(P1, P2, P3, P4, P5, P6, A1); private: FunctionSignature function_; @@ -4203,13 +4651,23 @@ class _FunctionResultCallback_6_1 : public ResultCallback1 { typename remove_reference::type p6_; public: - inline _FunctionResultCallback_6_1(FunctionSignature function, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) - : ResultCallback1(), - function_(function), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5), p6_(p6) { } + inline _FunctionResultCallback_6_1(FunctionSignature function, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5, + typename ConstRef::type p6) + : ResultCallback1(), + function_(function), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5), + p6_(p6) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback1"); @@ -4217,10 +4675,10 @@ class _FunctionResultCallback_6_1 : public ResultCallback1 { virtual R Run(A1 a1) { if (!del) { - R result = (*function_)(p1_,p2_,p3_,p4_,p5_,p6_,a1); + R result = (*function_)(p1_, p2_, p3_, p4_, p5_, p6_, a1); return result; } else { - R result = (*function_)(p1_,p2_,p3_,p4_,p5_,p6_,a1); + R result = (*function_)(p1_, p2_, p3_, p4_, p5_, p6_, a1); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -4229,11 +4687,13 @@ class _FunctionResultCallback_6_1 : public ResultCallback1 { } }; -template -class _FunctionResultCallback_6_1 : public Callback1 { +template +class _FunctionResultCallback_6_1 : public Callback1 { public: typedef Callback1 base; - typedef void (*FunctionSignature)(P1,P2,P3,P4,P5,P6,A1); + typedef void (*FunctionSignature)(P1, P2, P3, P4, P5, P6, A1); private: FunctionSignature function_; @@ -4245,13 +4705,23 @@ class _FunctionResultCallback_6_1 : publi typename remove_reference::type p6_; public: - inline _FunctionResultCallback_6_1(FunctionSignature function, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) - : Callback1(), - function_(function), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5), p6_(p6) { } + inline _FunctionResultCallback_6_1(FunctionSignature function, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5, + typename ConstRef::type p6) + : Callback1(), + function_(function), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5), + p6_(p6) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback1"); @@ -4259,9 +4729,9 @@ class _FunctionResultCallback_6_1 : publi virtual void Run(A1 a1) { if (!del) { - (*function_)(p1_,p2_,p3_,p4_,p5_,p6_,a1); + (*function_)(p1_, p2_, p3_, p4_, p5_, p6_, a1); } else { - (*function_)(p1_,p2_,p3_,p4_,p5_,p6_,a1); + (*function_)(p1_, p2_, p3_, p4_, p5_, p6_, a1); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -4269,26 +4739,40 @@ class _FunctionResultCallback_6_1 : publi } }; -template -inline typename _FunctionResultCallback_6_1::base* -NewCallback(R (*function)(P1,P2,P3,P4,P5,P6,A1), typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) { - return new _FunctionResultCallback_6_1(function, p1, p2, p3, p4, p5, p6); +template +inline typename _FunctionResultCallback_6_1::base* +NewCallback(R (*function)(P1, P2, P3, P4, P5, P6, A1), + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3, typename ConstRef::type p4, + typename ConstRef::type p5, typename ConstRef::type p6) { + return new _FunctionResultCallback_6_1( + function, p1, p2, p3, p4, p5, p6); } -template -inline typename _FunctionResultCallback_6_1::base* -NewPermanentCallback(R (*function)(P1,P2,P3,P4,P5,P6,A1), typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) { - return new _FunctionResultCallback_6_1(function, p1, p2, p3, p4, p5, p6); +template +inline typename _FunctionResultCallback_6_1::base* +NewPermanentCallback(R (*function)(P1, P2, P3, P4, P5, P6, A1), + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5, + typename ConstRef::type p6) { + return new _FunctionResultCallback_6_1( + function, p1, p2, p3, p4, p5, p6); } -template ::value - >::type> -class _ConstMemberResultCallback_0_2 : public ResultCallback2 { +template < + bool del, class R, class T, class A1, class A2, + class OnlyIf = typename c_enable_if::value>::type> +class _ConstMemberResultCallback_0_2 : public ResultCallback2 { public: - typedef ResultCallback2 base; - typedef R (T::*MemberSignature)(A1,A2) const; + typedef ResultCallback2 base; + typedef R (T::*MemberSignature)(A1, A2) const; private: const T* object_; @@ -4296,24 +4780,20 @@ class _ConstMemberResultCallback_0_2 : public ResultCallback2 { public: inline _ConstMemberResultCallback_0_2(const T* object, MemberSignature member) - : ResultCallback2(), - object_(object), - member_(member) { } + : ResultCallback2(), object_(object), member_(member) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback2"); } - virtual R Run(A1 a1,A2 a2) { + virtual R Run(A1 a1, A2 a2) { if (!del) { - R result = (object_->*member_)(a1,a2); + R result = (object_->*member_)(a1, a2); return result; } else { - R result = (object_->*member_)(a1,a2); + R result = (object_->*member_)(a1, a2); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -4323,14 +4803,12 @@ class _ConstMemberResultCallback_0_2 : public ResultCallback2 { }; template -class _ConstMemberResultCallback_0_2::value - >::type> - : public Callback2 { +class _ConstMemberResultCallback_0_2< + del, void, T, A1, A2, typename c_enable_if::value>::type> : public Callback2 { public: - typedef Callback2 base; - typedef void (T::*MemberSignature)(A1,A2) const; + typedef Callback2 base; + typedef void (T::*MemberSignature)(A1, A2) const; private: const T* object_; @@ -4338,23 +4816,19 @@ class _ConstMemberResultCallback_0_2(), - object_(object), - member_(member) { } + : Callback2(), object_(object), member_(member) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback2"); } - virtual void Run(A1 a1,A2 a2) { + virtual void Run(A1 a1, A2 a2) { if (!del) { - (object_->*member_)(a1,a2); + (object_->*member_)(a1, a2); } else { - (object_->*member_)(a1,a2); + (object_->*member_)(a1, a2); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -4364,53 +4838,48 @@ class _ConstMemberResultCallback_0_2 -inline typename _ConstMemberResultCallback_0_2::base* -NewCallback(const T1* obj, R (T2::*member)(A1,A2) const) { - return new _ConstMemberResultCallback_0_2(obj, member); +inline typename _ConstMemberResultCallback_0_2::base* +NewCallback(const T1* obj, R (T2::*member)(A1, A2) const) { + return new _ConstMemberResultCallback_0_2(obj, member); } #endif #ifndef SWIG template -inline typename _ConstMemberResultCallback_0_2::base* -NewPermanentCallback(const T1* obj, R (T2::*member)(A1,A2) const) { - return new _ConstMemberResultCallback_0_2(obj, member); +inline typename _ConstMemberResultCallback_0_2::base* +NewPermanentCallback(const T1* obj, R (T2::*member)(A1, A2) const) { + return new _ConstMemberResultCallback_0_2(obj, member); } #endif -template ::value - >::type> -class _MemberResultCallback_0_2 : public ResultCallback2 { +template < + bool del, class R, class T, class A1, class A2, + class OnlyIf = typename c_enable_if::value>::type> +class _MemberResultCallback_0_2 : public ResultCallback2 { public: - typedef ResultCallback2 base; - typedef R (T::*MemberSignature)(A1,A2) ; + typedef ResultCallback2 base; + typedef R (T::*MemberSignature)(A1, A2); private: - T* object_; + T* object_; MemberSignature member_; public: - inline _MemberResultCallback_0_2( T* object, MemberSignature member) - : ResultCallback2(), - object_(object), - member_(member) { } + inline _MemberResultCallback_0_2(T* object, MemberSignature member) + : ResultCallback2(), object_(object), member_(member) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback2"); } - virtual R Run(A1 a1,A2 a2) { + virtual R Run(A1 a1, A2 a2) { if (!del) { - R result = (object_->*member_)(a1,a2); + R result = (object_->*member_)(a1, a2); return result; } else { - R result = (object_->*member_)(a1,a2); + R result = (object_->*member_)(a1, a2); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -4420,38 +4889,32 @@ class _MemberResultCallback_0_2 : public ResultCallback2 { }; template -class _MemberResultCallback_0_2::value - >::type> - : public Callback2 { +class _MemberResultCallback_0_2< + del, void, T, A1, A2, typename c_enable_if::value>::type> : public Callback2 { public: - typedef Callback2 base; - typedef void (T::*MemberSignature)(A1,A2) ; + typedef Callback2 base; + typedef void (T::*MemberSignature)(A1, A2); private: - T* object_; + T* object_; MemberSignature member_; public: - inline _MemberResultCallback_0_2( T* object, MemberSignature member) - : Callback2(), - object_(object), - member_(member) { } + inline _MemberResultCallback_0_2(T* object, MemberSignature member) + : Callback2(), object_(object), member_(member) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback2"); } - virtual void Run(A1 a1,A2 a2) { + virtual void Run(A1 a1, A2 a2) { if (!del) { - (object_->*member_)(a1,a2); + (object_->*member_)(a1, a2); } else { - (object_->*member_)(a1,a2); + (object_->*member_)(a1, a2); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -4461,48 +4924,45 @@ class _MemberResultCallback_0_2 -inline typename _MemberResultCallback_0_2::base* -NewCallback( T1* obj, R (T2::*member)(A1,A2) ) { - return new _MemberResultCallback_0_2(obj, member); +inline typename _MemberResultCallback_0_2::base* +NewCallback(T1* obj, R (T2::*member)(A1, A2)) { + return new _MemberResultCallback_0_2(obj, member); } #endif #ifndef SWIG template -inline typename _MemberResultCallback_0_2::base* -NewPermanentCallback( T1* obj, R (T2::*member)(A1,A2) ) { - return new _MemberResultCallback_0_2(obj, member); +inline typename _MemberResultCallback_0_2::base* +NewPermanentCallback(T1* obj, R (T2::*member)(A1, A2)) { + return new _MemberResultCallback_0_2(obj, member); } #endif template -class _FunctionResultCallback_0_2 : public ResultCallback2 { +class _FunctionResultCallback_0_2 : public ResultCallback2 { public: - typedef ResultCallback2 base; - typedef R (*FunctionSignature)(A1,A2); + typedef ResultCallback2 base; + typedef R (*FunctionSignature)(A1, A2); private: FunctionSignature function_; public: inline _FunctionResultCallback_0_2(FunctionSignature function) - : ResultCallback2(), - function_(function) { } + : ResultCallback2(), function_(function) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback2"); } - virtual R Run(A1 a1,A2 a2) { + virtual R Run(A1 a1, A2 a2) { if (!del) { - R result = (*function_)(a1,a2); + R result = (*function_)(a1, a2); return result; } else { - R result = (*function_)(a1,a2); + R result = (*function_)(a1, a2); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -4512,32 +4972,30 @@ class _FunctionResultCallback_0_2 : public ResultCallback2 { }; template -class _FunctionResultCallback_0_2 : public Callback2 { +class _FunctionResultCallback_0_2 : public Callback2 { public: - typedef Callback2 base; - typedef void (*FunctionSignature)(A1,A2); + typedef Callback2 base; + typedef void (*FunctionSignature)(A1, A2); private: FunctionSignature function_; public: inline _FunctionResultCallback_0_2(FunctionSignature function) - : Callback2(), - function_(function) { } + : Callback2(), function_(function) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback2"); } - virtual void Run(A1 a1,A2 a2) { + virtual void Run(A1 a1, A2 a2) { if (!del) { - (*function_)(a1,a2); + (*function_)(a1, a2); } else { - (*function_)(a1,a2); + (*function_)(a1, a2); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -4546,25 +5004,24 @@ class _FunctionResultCallback_0_2 : public Callback2 { }; template -inline typename _FunctionResultCallback_0_2::base* -NewCallback(R (*function)(A1,A2)) { - return new _FunctionResultCallback_0_2(function); +inline typename _FunctionResultCallback_0_2::base* NewCallback( + R (*function)(A1, A2)) { + return new _FunctionResultCallback_0_2(function); } template -inline typename _FunctionResultCallback_0_2::base* -NewPermanentCallback(R (*function)(A1,A2)) { - return new _FunctionResultCallback_0_2(function); +inline typename _FunctionResultCallback_0_2::base* +NewPermanentCallback(R (*function)(A1, A2)) { + return new _FunctionResultCallback_0_2(function); } -template ::value - >::type> -class _ConstMemberResultCallback_1_2 : public ResultCallback2 { +template < + bool del, class R, class T, class P1, class A1, class A2, + class OnlyIf = typename c_enable_if::value>::type> +class _ConstMemberResultCallback_1_2 : public ResultCallback2 { public: - typedef ResultCallback2 base; - typedef R (T::*MemberSignature)(P1,A1,A2) const; + typedef ResultCallback2 base; + typedef R (T::*MemberSignature)(P1, A1, A2) const; private: const T* object_; @@ -4572,25 +5029,25 @@ class _ConstMemberResultCallback_1_2 : public ResultCallback2 { typename remove_reference::type p1_; public: - inline _ConstMemberResultCallback_1_2(const T* object, MemberSignature member, typename ConstRef::type p1) - : ResultCallback2(), - object_(object), - member_(member), p1_(p1) { } + inline _ConstMemberResultCallback_1_2(const T* object, MemberSignature member, + typename ConstRef::type p1) + : ResultCallback2(), + object_(object), + member_(member), + p1_(p1) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback2"); } - virtual R Run(A1 a1,A2 a2) { + virtual R Run(A1 a1, A2 a2) { if (!del) { - R result = (object_->*member_)(p1_,a1,a2); + R result = (object_->*member_)(p1_, a1, a2); return result; } else { - R result = (object_->*member_)(p1_,a1,a2); + R result = (object_->*member_)(p1_, a1, a2); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -4600,14 +5057,12 @@ class _ConstMemberResultCallback_1_2 : public ResultCallback2 { }; template -class _ConstMemberResultCallback_1_2::value - >::type> - : public Callback2 { +class _ConstMemberResultCallback_1_2< + del, void, T, P1, A1, A2, typename c_enable_if::value>::type> : public Callback2 { public: - typedef Callback2 base; - typedef void (T::*MemberSignature)(P1,A1,A2) const; + typedef Callback2 base; + typedef void (T::*MemberSignature)(P1, A1, A2) const; private: const T* object_; @@ -4615,24 +5070,21 @@ class _ConstMemberResultCallback_1_2::type p1_; public: - inline _ConstMemberResultCallback_1_2(const T* object, MemberSignature member, typename ConstRef::type p1) - : Callback2(), - object_(object), - member_(member), p1_(p1) { } + inline _ConstMemberResultCallback_1_2(const T* object, MemberSignature member, + typename ConstRef::type p1) + : Callback2(), object_(object), member_(member), p1_(p1) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback2"); } - virtual void Run(A1 a1,A2 a2) { + virtual void Run(A1 a1, A2 a2) { if (!del) { - (object_->*member_)(p1_,a1,a2); + (object_->*member_)(p1_, a1, a2); } else { - (object_->*member_)(p1_,a1,a2); + (object_->*member_)(p1_, a1, a2); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -4642,54 +5094,57 @@ class _ConstMemberResultCallback_1_2 -inline typename _ConstMemberResultCallback_1_2::base* -NewCallback(const T1* obj, R (T2::*member)(P1,A1,A2) const, typename ConstRef::type p1) { - return new _ConstMemberResultCallback_1_2(obj, member, p1); +inline typename _ConstMemberResultCallback_1_2::base* +NewCallback(const T1* obj, R (T2::*member)(P1, A1, A2) const, + typename ConstRef::type p1) { + return new _ConstMemberResultCallback_1_2( + obj, member, p1); } #endif #ifndef SWIG template -inline typename _ConstMemberResultCallback_1_2::base* -NewPermanentCallback(const T1* obj, R (T2::*member)(P1,A1,A2) const, typename ConstRef::type p1) { - return new _ConstMemberResultCallback_1_2(obj, member, p1); +inline typename _ConstMemberResultCallback_1_2::base* +NewPermanentCallback(const T1* obj, R (T2::*member)(P1, A1, A2) const, + typename ConstRef::type p1) { + return new _ConstMemberResultCallback_1_2( + obj, member, p1); } #endif -template ::value - >::type> -class _MemberResultCallback_1_2 : public ResultCallback2 { +template < + bool del, class R, class T, class P1, class A1, class A2, + class OnlyIf = typename c_enable_if::value>::type> +class _MemberResultCallback_1_2 : public ResultCallback2 { public: - typedef ResultCallback2 base; - typedef R (T::*MemberSignature)(P1,A1,A2) ; + typedef ResultCallback2 base; + typedef R (T::*MemberSignature)(P1, A1, A2); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; public: - inline _MemberResultCallback_1_2( T* object, MemberSignature member, typename ConstRef::type p1) - : ResultCallback2(), - object_(object), - member_(member), p1_(p1) { } + inline _MemberResultCallback_1_2(T* object, MemberSignature member, + typename ConstRef::type p1) + : ResultCallback2(), + object_(object), + member_(member), + p1_(p1) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback2"); } - virtual R Run(A1 a1,A2 a2) { + virtual R Run(A1 a1, A2 a2) { if (!del) { - R result = (object_->*member_)(p1_,a1,a2); + R result = (object_->*member_)(p1_, a1, a2); return result; } else { - R result = (object_->*member_)(p1_,a1,a2); + R result = (object_->*member_)(p1_, a1, a2); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -4699,39 +5154,34 @@ class _MemberResultCallback_1_2 : public ResultCallback2 { }; template -class _MemberResultCallback_1_2::value - >::type> - : public Callback2 { +class _MemberResultCallback_1_2< + del, void, T, P1, A1, A2, typename c_enable_if::value>::type> : public Callback2 { public: - typedef Callback2 base; - typedef void (T::*MemberSignature)(P1,A1,A2) ; + typedef Callback2 base; + typedef void (T::*MemberSignature)(P1, A1, A2); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; public: - inline _MemberResultCallback_1_2( T* object, MemberSignature member, typename ConstRef::type p1) - : Callback2(), - object_(object), - member_(member), p1_(p1) { } + inline _MemberResultCallback_1_2(T* object, MemberSignature member, + typename ConstRef::type p1) + : Callback2(), object_(object), member_(member), p1_(p1) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback2"); } - virtual void Run(A1 a1,A2 a2) { + virtual void Run(A1 a1, A2 a2) { if (!del) { - (object_->*member_)(p1_,a1,a2); + (object_->*member_)(p1_, a1, a2); } else { - (object_->*member_)(p1_,a1,a2); + (object_->*member_)(p1_, a1, a2); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -4741,49 +5191,51 @@ class _MemberResultCallback_1_2 -inline typename _MemberResultCallback_1_2::base* -NewCallback( T1* obj, R (T2::*member)(P1,A1,A2) , typename ConstRef::type p1) { - return new _MemberResultCallback_1_2(obj, member, p1); +inline typename _MemberResultCallback_1_2::base* +NewCallback(T1* obj, R (T2::*member)(P1, A1, A2), + typename ConstRef::type p1) { + return new _MemberResultCallback_1_2(obj, member, + p1); } #endif #ifndef SWIG template -inline typename _MemberResultCallback_1_2::base* -NewPermanentCallback( T1* obj, R (T2::*member)(P1,A1,A2) , typename ConstRef::type p1) { - return new _MemberResultCallback_1_2(obj, member, p1); +inline typename _MemberResultCallback_1_2::base* +NewPermanentCallback(T1* obj, R (T2::*member)(P1, A1, A2), + typename ConstRef::type p1) { + return new _MemberResultCallback_1_2(obj, member, + p1); } #endif template -class _FunctionResultCallback_1_2 : public ResultCallback2 { +class _FunctionResultCallback_1_2 : public ResultCallback2 { public: - typedef ResultCallback2 base; - typedef R (*FunctionSignature)(P1,A1,A2); + typedef ResultCallback2 base; + typedef R (*FunctionSignature)(P1, A1, A2); private: FunctionSignature function_; typename remove_reference::type p1_; public: - inline _FunctionResultCallback_1_2(FunctionSignature function, typename ConstRef::type p1) - : ResultCallback2(), - function_(function), p1_(p1) { } + inline _FunctionResultCallback_1_2(FunctionSignature function, + typename ConstRef::type p1) + : ResultCallback2(), function_(function), p1_(p1) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback2"); } - virtual R Run(A1 a1,A2 a2) { + virtual R Run(A1 a1, A2 a2) { if (!del) { - R result = (*function_)(p1_,a1,a2); + R result = (*function_)(p1_, a1, a2); return result; } else { - R result = (*function_)(p1_,a1,a2); + R result = (*function_)(p1_, a1, a2); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -4793,33 +5245,32 @@ class _FunctionResultCallback_1_2 : public ResultCallback2 { }; template -class _FunctionResultCallback_1_2 : public Callback2 { +class _FunctionResultCallback_1_2 : public Callback2< + A1, A2> { public: - typedef Callback2 base; - typedef void (*FunctionSignature)(P1,A1,A2); + typedef Callback2 base; + typedef void (*FunctionSignature)(P1, A1, A2); private: FunctionSignature function_; typename remove_reference::type p1_; public: - inline _FunctionResultCallback_1_2(FunctionSignature function, typename ConstRef::type p1) - : Callback2(), - function_(function), p1_(p1) { } + inline _FunctionResultCallback_1_2(FunctionSignature function, + typename ConstRef::type p1) + : Callback2(), function_(function), p1_(p1) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback2"); } - virtual void Run(A1 a1,A2 a2) { + virtual void Run(A1 a1, A2 a2) { if (!del) { - (*function_)(p1_,a1,a2); + (*function_)(p1_, a1, a2); } else { - (*function_)(p1_,a1,a2); + (*function_)(p1_, a1, a2); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -4828,25 +5279,25 @@ class _FunctionResultCallback_1_2 : public Callback2 -inline typename _FunctionResultCallback_1_2::base* -NewCallback(R (*function)(P1,A1,A2), typename ConstRef::type p1) { - return new _FunctionResultCallback_1_2(function, p1); +inline typename _FunctionResultCallback_1_2::base* +NewCallback(R (*function)(P1, A1, A2), typename ConstRef::type p1) { + return new _FunctionResultCallback_1_2(function, p1); } template -inline typename _FunctionResultCallback_1_2::base* -NewPermanentCallback(R (*function)(P1,A1,A2), typename ConstRef::type p1) { - return new _FunctionResultCallback_1_2(function, p1); +inline typename _FunctionResultCallback_1_2::base* +NewPermanentCallback(R (*function)(P1, A1, A2), + typename ConstRef::type p1) { + return new _FunctionResultCallback_1_2(function, p1); } -template ::value - >::type> -class _ConstMemberResultCallback_2_2 : public ResultCallback2 { +template < + bool del, class R, class T, class P1, class P2, class A1, class A2, + class OnlyIf = typename c_enable_if::value>::type> +class _ConstMemberResultCallback_2_2 : public ResultCallback2 { public: - typedef ResultCallback2 base; - typedef R (T::*MemberSignature)(P1,P2,A1,A2) const; + typedef ResultCallback2 base; + typedef R (T::*MemberSignature)(P1, P2, A1, A2) const; private: const T* object_; @@ -4855,25 +5306,27 @@ class _ConstMemberResultCallback_2_2 : public ResultCallback2 { typename remove_reference::type p2_; public: - inline _ConstMemberResultCallback_2_2(const T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2) - : ResultCallback2(), - object_(object), - member_(member), p1_(p1), p2_(p2) { } + inline _ConstMemberResultCallback_2_2(const T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2) + : ResultCallback2(), + object_(object), + member_(member), + p1_(p1), + p2_(p2) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback2"); } - virtual R Run(A1 a1,A2 a2) { + virtual R Run(A1 a1, A2 a2) { if (!del) { - R result = (object_->*member_)(p1_,p2_,a1,a2); + R result = (object_->*member_)(p1_, p2_, a1, a2); return result; } else { - R result = (object_->*member_)(p1_,p2_,a1,a2); + R result = (object_->*member_)(p1_, p2_, a1, a2); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -4883,14 +5336,13 @@ class _ConstMemberResultCallback_2_2 : public ResultCallback2 { }; template -class _ConstMemberResultCallback_2_2::value - >::type> - : public Callback2 { +class _ConstMemberResultCallback_2_2< + del, void, T, P1, P2, A1, A2, + typename c_enable_if< + is_class_or_union::value>::type> : public Callback2 { public: - typedef Callback2 base; - typedef void (T::*MemberSignature)(P1,P2,A1,A2) const; + typedef Callback2 base; + typedef void (T::*MemberSignature)(P1, P2, A1, A2) const; private: const T* object_; @@ -4899,24 +5351,26 @@ class _ConstMemberResultCallback_2_2::type p2_; public: - inline _ConstMemberResultCallback_2_2(const T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2) - : Callback2(), - object_(object), - member_(member), p1_(p1), p2_(p2) { } + inline _ConstMemberResultCallback_2_2(const T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2) + : Callback2(), + object_(object), + member_(member), + p1_(p1), + p2_(p2) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback2"); } - virtual void Run(A1 a1,A2 a2) { + virtual void Run(A1 a1, A2 a2) { if (!del) { - (object_->*member_)(p1_,p2_,a1,a2); + (object_->*member_)(p1_, p2_, a1, a2); } else { - (object_->*member_)(p1_,p2_,a1,a2); + (object_->*member_)(p1_, p2_, a1, a2); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -4926,55 +5380,63 @@ class _ConstMemberResultCallback_2_2 -inline typename _ConstMemberResultCallback_2_2::base* -NewCallback(const T1* obj, R (T2::*member)(P1,P2,A1,A2) const, typename ConstRef::type p1, typename ConstRef::type p2) { - return new _ConstMemberResultCallback_2_2(obj, member, p1, p2); +inline typename _ConstMemberResultCallback_2_2::base* +NewCallback(const T1* obj, R (T2::*member)(P1, P2, A1, A2) const, + typename ConstRef::type p1, typename ConstRef::type p2) { + return new _ConstMemberResultCallback_2_2( + obj, member, p1, p2); } #endif #ifndef SWIG template -inline typename _ConstMemberResultCallback_2_2::base* -NewPermanentCallback(const T1* obj, R (T2::*member)(P1,P2,A1,A2) const, typename ConstRef::type p1, typename ConstRef::type p2) { - return new _ConstMemberResultCallback_2_2(obj, member, p1, p2); +inline typename _ConstMemberResultCallback_2_2::base* +NewPermanentCallback(const T1* obj, R (T2::*member)(P1, P2, A1, A2) const, + typename ConstRef::type p1, + typename ConstRef::type p2) { + return new _ConstMemberResultCallback_2_2( + obj, member, p1, p2); } #endif -template ::value - >::type> -class _MemberResultCallback_2_2 : public ResultCallback2 { +template < + bool del, class R, class T, class P1, class P2, class A1, class A2, + class OnlyIf = typename c_enable_if::value>::type> +class _MemberResultCallback_2_2 : public ResultCallback2 { public: - typedef ResultCallback2 base; - typedef R (T::*MemberSignature)(P1,P2,A1,A2) ; + typedef ResultCallback2 base; + typedef R (T::*MemberSignature)(P1, P2, A1, A2); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; typename remove_reference::type p2_; public: - inline _MemberResultCallback_2_2( T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2) - : ResultCallback2(), - object_(object), - member_(member), p1_(p1), p2_(p2) { } + inline _MemberResultCallback_2_2(T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2) + : ResultCallback2(), + object_(object), + member_(member), + p1_(p1), + p2_(p2) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback2"); } - virtual R Run(A1 a1,A2 a2) { + virtual R Run(A1 a1, A2 a2) { if (!del) { - R result = (object_->*member_)(p1_,p2_,a1,a2); + R result = (object_->*member_)(p1_, p2_, a1, a2); return result; } else { - R result = (object_->*member_)(p1_,p2_,a1,a2); + R result = (object_->*member_)(p1_, p2_, a1, a2); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -4984,40 +5446,41 @@ class _MemberResultCallback_2_2 : public ResultCallback2 { }; template -class _MemberResultCallback_2_2::value - >::type> - : public Callback2 { +class _MemberResultCallback_2_2< + del, void, T, P1, P2, A1, A2, + typename c_enable_if< + is_class_or_union::value>::type> : public Callback2 { public: - typedef Callback2 base; - typedef void (T::*MemberSignature)(P1,P2,A1,A2) ; + typedef Callback2 base; + typedef void (T::*MemberSignature)(P1, P2, A1, A2); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; typename remove_reference::type p2_; public: - inline _MemberResultCallback_2_2( T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2) - : Callback2(), - object_(object), - member_(member), p1_(p1), p2_(p2) { } + inline _MemberResultCallback_2_2(T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2) + : Callback2(), + object_(object), + member_(member), + p1_(p1), + p2_(p2) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback2"); } - virtual void Run(A1 a1,A2 a2) { + virtual void Run(A1 a1, A2 a2) { if (!del) { - (object_->*member_)(p1_,p2_,a1,a2); + (object_->*member_)(p1_, p2_, a1, a2); } else { - (object_->*member_)(p1_,p2_,a1,a2); + (object_->*member_)(p1_, p2_, a1, a2); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -5027,25 +5490,30 @@ class _MemberResultCallback_2_2 -inline typename _MemberResultCallback_2_2::base* -NewCallback( T1* obj, R (T2::*member)(P1,P2,A1,A2) , typename ConstRef::type p1, typename ConstRef::type p2) { - return new _MemberResultCallback_2_2(obj, member, p1, p2); +inline typename _MemberResultCallback_2_2::base* +NewCallback(T1* obj, R (T2::*member)(P1, P2, A1, A2), + typename ConstRef::type p1, typename ConstRef::type p2) { + return new _MemberResultCallback_2_2(obj, member, + p1, p2); } #endif #ifndef SWIG template -inline typename _MemberResultCallback_2_2::base* -NewPermanentCallback( T1* obj, R (T2::*member)(P1,P2,A1,A2) , typename ConstRef::type p1, typename ConstRef::type p2) { - return new _MemberResultCallback_2_2(obj, member, p1, p2); +inline typename _MemberResultCallback_2_2::base* +NewPermanentCallback(T1* obj, R (T2::*member)(P1, P2, A1, A2), + typename ConstRef::type p1, + typename ConstRef::type p2) { + return new _MemberResultCallback_2_2( + obj, member, p1, p2); } #endif template -class _FunctionResultCallback_2_2 : public ResultCallback2 { +class _FunctionResultCallback_2_2 : public ResultCallback2 { public: - typedef ResultCallback2 base; - typedef R (*FunctionSignature)(P1,P2,A1,A2); + typedef ResultCallback2 base; + typedef R (*FunctionSignature)(P1, P2, A1, A2); private: FunctionSignature function_; @@ -5053,24 +5521,23 @@ class _FunctionResultCallback_2_2 : public ResultCallback2 { typename remove_reference::type p2_; public: - inline _FunctionResultCallback_2_2(FunctionSignature function, typename ConstRef::type p1, typename ConstRef::type p2) - : ResultCallback2(), - function_(function), p1_(p1), p2_(p2) { } + inline _FunctionResultCallback_2_2(FunctionSignature function, + typename ConstRef::type p1, + typename ConstRef::type p2) + : ResultCallback2(), function_(function), p1_(p1), p2_(p2) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback2"); } - virtual R Run(A1 a1,A2 a2) { + virtual R Run(A1 a1, A2 a2) { if (!del) { - R result = (*function_)(p1_,p2_,a1,a2); + R result = (*function_)(p1_, p2_, a1, a2); return result; } else { - R result = (*function_)(p1_,p2_,a1,a2); + R result = (*function_)(p1_, p2_, a1, a2); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -5080,10 +5547,11 @@ class _FunctionResultCallback_2_2 : public ResultCallback2 { }; template -class _FunctionResultCallback_2_2 : public Callback2 { +class _FunctionResultCallback_2_2 : public Callback2< + A1, A2> { public: - typedef Callback2 base; - typedef void (*FunctionSignature)(P1,P2,A1,A2); + typedef Callback2 base; + typedef void (*FunctionSignature)(P1, P2, A1, A2); private: FunctionSignature function_; @@ -5091,23 +5559,22 @@ class _FunctionResultCallback_2_2 : public Callback2< typename remove_reference::type p2_; public: - inline _FunctionResultCallback_2_2(FunctionSignature function, typename ConstRef::type p1, typename ConstRef::type p2) - : Callback2(), - function_(function), p1_(p1), p2_(p2) { } + inline _FunctionResultCallback_2_2(FunctionSignature function, + typename ConstRef::type p1, + typename ConstRef::type p2) + : Callback2(), function_(function), p1_(p1), p2_(p2) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback2"); } - virtual void Run(A1 a1,A2 a2) { + virtual void Run(A1 a1, A2 a2) { if (!del) { - (*function_)(p1_,p2_,a1,a2); + (*function_)(p1_, p2_, a1, a2); } else { - (*function_)(p1_,p2_,a1,a2); + (*function_)(p1_, p2_, a1, a2); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -5116,25 +5583,29 @@ class _FunctionResultCallback_2_2 : public Callback2< }; template -inline typename _FunctionResultCallback_2_2::base* -NewCallback(R (*function)(P1,P2,A1,A2), typename ConstRef::type p1, typename ConstRef::type p2) { - return new _FunctionResultCallback_2_2(function, p1, p2); +inline typename _FunctionResultCallback_2_2::base* +NewCallback(R (*function)(P1, P2, A1, A2), typename ConstRef::type p1, + typename ConstRef::type p2) { + return new _FunctionResultCallback_2_2(function, p1, + p2); } template -inline typename _FunctionResultCallback_2_2::base* -NewPermanentCallback(R (*function)(P1,P2,A1,A2), typename ConstRef::type p1, typename ConstRef::type p2) { - return new _FunctionResultCallback_2_2(function, p1, p2); +inline typename _FunctionResultCallback_2_2::base* +NewPermanentCallback(R (*function)(P1, P2, A1, A2), + typename ConstRef::type p1, + typename ConstRef::type p2) { + return new _FunctionResultCallback_2_2(function, p1, + p2); } -template ::value - >::type> -class _ConstMemberResultCallback_3_2 : public ResultCallback2 { +template ::value>::type> +class _ConstMemberResultCallback_3_2 : public ResultCallback2 { public: - typedef ResultCallback2 base; - typedef R (T::*MemberSignature)(P1,P2,P3,A1,A2) const; + typedef ResultCallback2 base; + typedef R (T::*MemberSignature)(P1, P2, P3, A1, A2) const; private: const T* object_; @@ -5144,25 +5615,29 @@ class _ConstMemberResultCallback_3_2 : public ResultCallback2 { typename remove_reference::type p3_; public: - inline _ConstMemberResultCallback_3_2(const T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) - : ResultCallback2(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3) { } + inline _ConstMemberResultCallback_3_2(const T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3) + : ResultCallback2(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback2"); } - virtual R Run(A1 a1,A2 a2) { + virtual R Run(A1 a1, A2 a2) { if (!del) { - R result = (object_->*member_)(p1_,p2_,p3_,a1,a2); + R result = (object_->*member_)(p1_, p2_, p3_, a1, a2); return result; } else { - R result = (object_->*member_)(p1_,p2_,p3_,a1,a2); + R result = (object_->*member_)(p1_, p2_, p3_, a1, a2); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -5172,14 +5647,13 @@ class _ConstMemberResultCallback_3_2 : public ResultCallback2 { }; template -class _ConstMemberResultCallback_3_2::value - >::type> - : public Callback2 { +class _ConstMemberResultCallback_3_2< + del, void, T, P1, P2, P3, A1, A2, + typename c_enable_if< + is_class_or_union::value>::type> : public Callback2 { public: - typedef Callback2 base; - typedef void (T::*MemberSignature)(P1,P2,P3,A1,A2) const; + typedef Callback2 base; + typedef void (T::*MemberSignature)(P1, P2, P3, A1, A2) const; private: const T* object_; @@ -5189,24 +5663,28 @@ class _ConstMemberResultCallback_3_2::type p3_; public: - inline _ConstMemberResultCallback_3_2(const T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) - : Callback2(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3) { } + inline _ConstMemberResultCallback_3_2(const T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3) + : Callback2(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback2"); } - virtual void Run(A1 a1,A2 a2) { + virtual void Run(A1 a1, A2 a2) { if (!del) { - (object_->*member_)(p1_,p2_,p3_,a1,a2); + (object_->*member_)(p1_, p2_, p3_, a1, a2); } else { - (object_->*member_)(p1_,p2_,p3_,a1,a2); + (object_->*member_)(p1_, p2_, p3_, a1, a2); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -5215,57 +5693,71 @@ class _ConstMemberResultCallback_3_2 -inline typename _ConstMemberResultCallback_3_2::base* -NewCallback(const T1* obj, R (T2::*member)(P1,P2,P3,A1,A2) const, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) { - return new _ConstMemberResultCallback_3_2(obj, member, p1, p2, p3); +template +inline typename _ConstMemberResultCallback_3_2::base* +NewCallback(const T1* obj, R (T2::*member)(P1, P2, P3, A1, A2) const, + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3) { + return new _ConstMemberResultCallback_3_2( + obj, member, p1, p2, p3); } #endif #ifndef SWIG -template -inline typename _ConstMemberResultCallback_3_2::base* -NewPermanentCallback(const T1* obj, R (T2::*member)(P1,P2,P3,A1,A2) const, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) { - return new _ConstMemberResultCallback_3_2(obj, member, p1, p2, p3); +template +inline typename _ConstMemberResultCallback_3_2::base* +NewPermanentCallback(const T1* obj, R (T2::*member)(P1, P2, P3, A1, A2) const, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3) { + return new _ConstMemberResultCallback_3_2( + obj, member, p1, p2, p3); } #endif -template ::value - >::type> -class _MemberResultCallback_3_2 : public ResultCallback2 { +template ::value>::type> +class _MemberResultCallback_3_2 : public ResultCallback2 { public: - typedef ResultCallback2 base; - typedef R (T::*MemberSignature)(P1,P2,P3,A1,A2) ; + typedef ResultCallback2 base; + typedef R (T::*MemberSignature)(P1, P2, P3, A1, A2); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; typename remove_reference::type p2_; typename remove_reference::type p3_; public: - inline _MemberResultCallback_3_2( T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) - : ResultCallback2(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3) { } + inline _MemberResultCallback_3_2(T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3) + : ResultCallback2(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback2"); } - virtual R Run(A1 a1,A2 a2) { + virtual R Run(A1 a1, A2 a2) { if (!del) { - R result = (object_->*member_)(p1_,p2_,p3_,a1,a2); + R result = (object_->*member_)(p1_, p2_, p3_, a1, a2); return result; } else { - R result = (object_->*member_)(p1_,p2_,p3_,a1,a2); + R result = (object_->*member_)(p1_, p2_, p3_, a1, a2); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -5275,41 +5767,44 @@ class _MemberResultCallback_3_2 : public ResultCallback2 { }; template -class _MemberResultCallback_3_2::value - >::type> - : public Callback2 { +class _MemberResultCallback_3_2< + del, void, T, P1, P2, P3, A1, A2, + typename c_enable_if< + is_class_or_union::value>::type> : public Callback2 { public: - typedef Callback2 base; - typedef void (T::*MemberSignature)(P1,P2,P3,A1,A2) ; + typedef Callback2 base; + typedef void (T::*MemberSignature)(P1, P2, P3, A1, A2); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; typename remove_reference::type p2_; typename remove_reference::type p3_; public: - inline _MemberResultCallback_3_2( T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) - : Callback2(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3) { } + inline _MemberResultCallback_3_2(T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3) + : Callback2(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback2"); } - virtual void Run(A1 a1,A2 a2) { + virtual void Run(A1 a1, A2 a2) { if (!del) { - (object_->*member_)(p1_,p2_,p3_,a1,a2); + (object_->*member_)(p1_, p2_, p3_, a1, a2); } else { - (object_->*member_)(p1_,p2_,p3_,a1,a2); + (object_->*member_)(p1_, p2_, p3_, a1, a2); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -5318,26 +5813,37 @@ class _MemberResultCallback_3_2 -inline typename _MemberResultCallback_3_2::base* -NewCallback( T1* obj, R (T2::*member)(P1,P2,P3,A1,A2) , typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) { - return new _MemberResultCallback_3_2(obj, member, p1, p2, p3); +template +inline typename _MemberResultCallback_3_2::base* +NewCallback(T1* obj, R (T2::*member)(P1, P2, P3, A1, A2), + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3) { + return new _MemberResultCallback_3_2( + obj, member, p1, p2, p3); } #endif #ifndef SWIG -template -inline typename _MemberResultCallback_3_2::base* -NewPermanentCallback( T1* obj, R (T2::*member)(P1,P2,P3,A1,A2) , typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) { - return new _MemberResultCallback_3_2(obj, member, p1, p2, p3); +template +inline typename _MemberResultCallback_3_2::base* +NewPermanentCallback(T1* obj, R (T2::*member)(P1, P2, P3, A1, A2), + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3) { + return new _MemberResultCallback_3_2( + obj, member, p1, p2, p3); } #endif template -class _FunctionResultCallback_3_2 : public ResultCallback2 { +class _FunctionResultCallback_3_2 : public ResultCallback2 { public: - typedef ResultCallback2 base; - typedef R (*FunctionSignature)(P1,P2,P3,A1,A2); + typedef ResultCallback2 base; + typedef R (*FunctionSignature)(P1, P2, P3, A1, A2); private: FunctionSignature function_; @@ -5346,24 +5852,28 @@ class _FunctionResultCallback_3_2 : public ResultCallback2 { typename remove_reference::type p3_; public: - inline _FunctionResultCallback_3_2(FunctionSignature function, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) - : ResultCallback2(), - function_(function), p1_(p1), p2_(p2), p3_(p3) { } + inline _FunctionResultCallback_3_2(FunctionSignature function, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3) + : ResultCallback2(), + function_(function), + p1_(p1), + p2_(p2), + p3_(p3) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback2"); } - virtual R Run(A1 a1,A2 a2) { + virtual R Run(A1 a1, A2 a2) { if (!del) { - R result = (*function_)(p1_,p2_,p3_,a1,a2); + R result = (*function_)(p1_, p2_, p3_, a1, a2); return result; } else { - R result = (*function_)(p1_,p2_,p3_,a1,a2); + R result = (*function_)(p1_, p2_, p3_, a1, a2); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -5373,10 +5883,11 @@ class _FunctionResultCallback_3_2 : public ResultCallback2 { }; template -class _FunctionResultCallback_3_2 : public Callback2 { +class _FunctionResultCallback_3_2 : public Callback2 { public: - typedef Callback2 base; - typedef void (*FunctionSignature)(P1,P2,P3,A1,A2); + typedef Callback2 base; + typedef void (*FunctionSignature)(P1, P2, P3, A1, A2); private: FunctionSignature function_; @@ -5385,23 +5896,23 @@ class _FunctionResultCallback_3_2 : public Callba typename remove_reference::type p3_; public: - inline _FunctionResultCallback_3_2(FunctionSignature function, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) - : Callback2(), - function_(function), p1_(p1), p2_(p2), p3_(p3) { } + inline _FunctionResultCallback_3_2(FunctionSignature function, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3) + : Callback2(), function_(function), p1_(p1), p2_(p2), p3_(p3) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback2"); } - virtual void Run(A1 a1,A2 a2) { + virtual void Run(A1 a1, A2 a2) { if (!del) { - (*function_)(p1_,p2_,p3_,a1,a2); + (*function_)(p1_, p2_, p3_, a1, a2); } else { - (*function_)(p1_,p2_,p3_,a1,a2); + (*function_)(p1_, p2_, p3_, a1, a2); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -5410,25 +5921,30 @@ class _FunctionResultCallback_3_2 : public Callba }; template -inline typename _FunctionResultCallback_3_2::base* -NewCallback(R (*function)(P1,P2,P3,A1,A2), typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) { - return new _FunctionResultCallback_3_2(function, p1, p2, p3); +inline typename _FunctionResultCallback_3_2::base* +NewCallback(R (*function)(P1, P2, P3, A1, A2), typename ConstRef::type p1, + typename ConstRef::type p2, typename ConstRef::type p3) { + return new _FunctionResultCallback_3_2( + function, p1, p2, p3); } template -inline typename _FunctionResultCallback_3_2::base* -NewPermanentCallback(R (*function)(P1,P2,P3,A1,A2), typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) { - return new _FunctionResultCallback_3_2(function, p1, p2, p3); +inline typename _FunctionResultCallback_3_2::base* +NewPermanentCallback(R (*function)(P1, P2, P3, A1, A2), + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3) { + return new _FunctionResultCallback_3_2( + function, p1, p2, p3); } -template ::value - >::type> -class _ConstMemberResultCallback_4_2 : public ResultCallback2 { +template ::value>::type> +class _ConstMemberResultCallback_4_2 : public ResultCallback2 { public: - typedef ResultCallback2 base; - typedef R (T::*MemberSignature)(P1,P2,P3,P4,A1,A2) const; + typedef ResultCallback2 base; + typedef R (T::*MemberSignature)(P1, P2, P3, P4, A1, A2) const; private: const T* object_; @@ -5439,25 +5955,31 @@ class _ConstMemberResultCallback_4_2 : public ResultCallback2 { typename remove_reference::type p4_; public: - inline _ConstMemberResultCallback_4_2(const T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) - : ResultCallback2(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4) { } + inline _ConstMemberResultCallback_4_2(const T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4) + : ResultCallback2(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback2"); } - virtual R Run(A1 a1,A2 a2) { + virtual R Run(A1 a1, A2 a2) { if (!del) { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,a1,a2); + R result = (object_->*member_)(p1_, p2_, p3_, p4_, a1, a2); return result; } else { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,a1,a2); + R result = (object_->*member_)(p1_, p2_, p3_, p4_, a1, a2); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -5466,15 +5988,15 @@ class _ConstMemberResultCallback_4_2 : public ResultCallback2 { } }; -template -class _ConstMemberResultCallback_4_2::value - >::type> - : public Callback2 { +template +class _ConstMemberResultCallback_4_2< + del, void, T, P1, P2, P3, P4, A1, A2, + typename c_enable_if< + is_class_or_union::value>::type> : public Callback2 { public: - typedef Callback2 base; - typedef void (T::*MemberSignature)(P1,P2,P3,P4,A1,A2) const; + typedef Callback2 base; + typedef void (T::*MemberSignature)(P1, P2, P3, P4, A1, A2) const; private: const T* object_; @@ -5485,24 +6007,30 @@ class _ConstMemberResultCallback_4_2::type p4_; public: - inline _ConstMemberResultCallback_4_2(const T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) - : Callback2(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4) { } + inline _ConstMemberResultCallback_4_2(const T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4) + : Callback2(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback2"); } - virtual void Run(A1 a1,A2 a2) { + virtual void Run(A1 a1, A2 a2) { if (!del) { - (object_->*member_)(p1_,p2_,p3_,p4_,a1,a2); + (object_->*member_)(p1_, p2_, p3_, p4_, a1, a2); } else { - (object_->*member_)(p1_,p2_,p3_,p4_,a1,a2); + (object_->*member_)(p1_, p2_, p3_, p4_, a1, a2); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -5511,32 +6039,44 @@ class _ConstMemberResultCallback_4_2 -inline typename _ConstMemberResultCallback_4_2::base* -NewCallback(const T1* obj, R (T2::*member)(P1,P2,P3,P4,A1,A2) const, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) { - return new _ConstMemberResultCallback_4_2(obj, member, p1, p2, p3, p4); +template +inline typename _ConstMemberResultCallback_4_2::base* +NewCallback(const T1* obj, R (T2::*member)(P1, P2, P3, P4, A1, A2) const, + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3, typename ConstRef::type p4) { + return new _ConstMemberResultCallback_4_2(obj, member, p1, p2, p3, p4); } #endif #ifndef SWIG -template -inline typename _ConstMemberResultCallback_4_2::base* -NewPermanentCallback(const T1* obj, R (T2::*member)(P1,P2,P3,P4,A1,A2) const, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) { - return new _ConstMemberResultCallback_4_2(obj, member, p1, p2, p3, p4); +template +inline typename _ConstMemberResultCallback_4_2::base* +NewPermanentCallback(const T1* obj, + R (T2::*member)(P1, P2, P3, P4, A1, A2) const, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4) { + return new _ConstMemberResultCallback_4_2(obj, member, p1, p2, p3, p4); } #endif -template ::value - >::type> -class _MemberResultCallback_4_2 : public ResultCallback2 { +template ::value>::type> +class _MemberResultCallback_4_2 : public ResultCallback2 { public: - typedef ResultCallback2 base; - typedef R (T::*MemberSignature)(P1,P2,P3,P4,A1,A2) ; + typedef ResultCallback2 base; + typedef R (T::*MemberSignature)(P1, P2, P3, P4, A1, A2); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; typename remove_reference::type p2_; @@ -5544,25 +6084,31 @@ class _MemberResultCallback_4_2 : public ResultCallback2 { typename remove_reference::type p4_; public: - inline _MemberResultCallback_4_2( T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) - : ResultCallback2(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4) { } + inline _MemberResultCallback_4_2(T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4) + : ResultCallback2(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback2"); } - virtual R Run(A1 a1,A2 a2) { + virtual R Run(A1 a1, A2 a2) { if (!del) { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,a1,a2); + R result = (object_->*member_)(p1_, p2_, p3_, p4_, a1, a2); return result; } else { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,a1,a2); + R result = (object_->*member_)(p1_, p2_, p3_, p4_, a1, a2); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -5571,18 +6117,18 @@ class _MemberResultCallback_4_2 : public ResultCallback2 { } }; -template -class _MemberResultCallback_4_2::value - >::type> - : public Callback2 { +template +class _MemberResultCallback_4_2< + del, void, T, P1, P2, P3, P4, A1, A2, + typename c_enable_if< + is_class_or_union::value>::type> : public Callback2 { public: - typedef Callback2 base; - typedef void (T::*MemberSignature)(P1,P2,P3,P4,A1,A2) ; + typedef Callback2 base; + typedef void (T::*MemberSignature)(P1, P2, P3, P4, A1, A2); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; typename remove_reference::type p2_; @@ -5590,24 +6136,30 @@ class _MemberResultCallback_4_2::type p4_; public: - inline _MemberResultCallback_4_2( T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) - : Callback2(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4) { } + inline _MemberResultCallback_4_2(T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4) + : Callback2(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback2"); } - virtual void Run(A1 a1,A2 a2) { + virtual void Run(A1 a1, A2 a2) { if (!del) { - (object_->*member_)(p1_,p2_,p3_,p4_,a1,a2); + (object_->*member_)(p1_, p2_, p3_, p4_, a1, a2); } else { - (object_->*member_)(p1_,p2_,p3_,p4_,a1,a2); + (object_->*member_)(p1_, p2_, p3_, p4_, a1, a2); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -5616,26 +6168,39 @@ class _MemberResultCallback_4_2 -inline typename _MemberResultCallback_4_2::base* -NewCallback( T1* obj, R (T2::*member)(P1,P2,P3,P4,A1,A2) , typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) { - return new _MemberResultCallback_4_2(obj, member, p1, p2, p3, p4); +template +inline typename _MemberResultCallback_4_2::base* +NewCallback(T1* obj, R (T2::*member)(P1, P2, P3, P4, A1, A2), + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3, typename ConstRef::type p4) { + return new _MemberResultCallback_4_2( + obj, member, p1, p2, p3, p4); } #endif #ifndef SWIG -template -inline typename _MemberResultCallback_4_2::base* -NewPermanentCallback( T1* obj, R (T2::*member)(P1,P2,P3,P4,A1,A2) , typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) { - return new _MemberResultCallback_4_2(obj, member, p1, p2, p3, p4); +template +inline typename _MemberResultCallback_4_2::base* +NewPermanentCallback(T1* obj, R (T2::*member)(P1, P2, P3, P4, A1, A2), + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4) { + return new _MemberResultCallback_4_2( + obj, member, p1, p2, p3, p4); } #endif -template -class _FunctionResultCallback_4_2 : public ResultCallback2 { +template +class _FunctionResultCallback_4_2 : public ResultCallback2 { public: - typedef ResultCallback2 base; - typedef R (*FunctionSignature)(P1,P2,P3,P4,A1,A2); + typedef ResultCallback2 base; + typedef R (*FunctionSignature)(P1, P2, P3, P4, A1, A2); private: FunctionSignature function_; @@ -5645,24 +6210,30 @@ class _FunctionResultCallback_4_2 : public ResultCallback2 { typename remove_reference::type p4_; public: - inline _FunctionResultCallback_4_2(FunctionSignature function, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) - : ResultCallback2(), - function_(function), p1_(p1), p2_(p2), p3_(p3), p4_(p4) { } + inline _FunctionResultCallback_4_2(FunctionSignature function, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4) + : ResultCallback2(), + function_(function), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback2"); } - virtual R Run(A1 a1,A2 a2) { + virtual R Run(A1 a1, A2 a2) { if (!del) { - R result = (*function_)(p1_,p2_,p3_,p4_,a1,a2); + R result = (*function_)(p1_, p2_, p3_, p4_, a1, a2); return result; } else { - R result = (*function_)(p1_,p2_,p3_,p4_,a1,a2); + R result = (*function_)(p1_, p2_, p3_, p4_, a1, a2); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -5672,10 +6243,11 @@ class _FunctionResultCallback_4_2 : public ResultCallback2 { }; template -class _FunctionResultCallback_4_2 : public Callback2 { +class _FunctionResultCallback_4_2 : public Callback2 { public: - typedef Callback2 base; - typedef void (*FunctionSignature)(P1,P2,P3,P4,A1,A2); + typedef Callback2 base; + typedef void (*FunctionSignature)(P1, P2, P3, P4, A1, A2); private: FunctionSignature function_; @@ -5685,23 +6257,29 @@ class _FunctionResultCallback_4_2 : public Ca typename remove_reference::type p4_; public: - inline _FunctionResultCallback_4_2(FunctionSignature function, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) - : Callback2(), - function_(function), p1_(p1), p2_(p2), p3_(p3), p4_(p4) { } + inline _FunctionResultCallback_4_2(FunctionSignature function, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4) + : Callback2(), + function_(function), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback2"); } - virtual void Run(A1 a1,A2 a2) { + virtual void Run(A1 a1, A2 a2) { if (!del) { - (*function_)(p1_,p2_,p3_,p4_,a1,a2); + (*function_)(p1_, p2_, p3_, p4_, a1, a2); } else { - (*function_)(p1_,p2_,p3_,p4_,a1,a2); + (*function_)(p1_, p2_, p3_, p4_, a1, a2); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -5710,25 +6288,34 @@ class _FunctionResultCallback_4_2 : public Ca }; template -inline typename _FunctionResultCallback_4_2::base* -NewCallback(R (*function)(P1,P2,P3,P4,A1,A2), typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) { - return new _FunctionResultCallback_4_2(function, p1, p2, p3, p4); +inline typename _FunctionResultCallback_4_2::base* +NewCallback(R (*function)(P1, P2, P3, P4, A1, A2), + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3, typename ConstRef::type p4) { + return new _FunctionResultCallback_4_2( + function, p1, p2, p3, p4); } template -inline typename _FunctionResultCallback_4_2::base* -NewPermanentCallback(R (*function)(P1,P2,P3,P4,A1,A2), typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) { - return new _FunctionResultCallback_4_2(function, p1, p2, p3, p4); +inline typename _FunctionResultCallback_4_2::base* +NewPermanentCallback(R (*function)(P1, P2, P3, P4, A1, A2), + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4) { + return new _FunctionResultCallback_4_2( + function, p1, p2, p3, p4); } -template ::value - >::type> -class _ConstMemberResultCallback_5_2 : public ResultCallback2 { +template ::value>::type> +class _ConstMemberResultCallback_5_2 : public ResultCallback2 { public: - typedef ResultCallback2 base; - typedef R (T::*MemberSignature)(P1,P2,P3,P4,P5,A1,A2) const; + typedef ResultCallback2 base; + typedef R (T::*MemberSignature)(P1, P2, P3, P4, P5, A1, A2) const; private: const T* object_; @@ -5740,25 +6327,33 @@ class _ConstMemberResultCallback_5_2 : public ResultCallback2 { typename remove_reference::type p5_; public: - inline _ConstMemberResultCallback_5_2(const T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) - : ResultCallback2(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5) { } + inline _ConstMemberResultCallback_5_2(const T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5) + : ResultCallback2(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback2"); } - virtual R Run(A1 a1,A2 a2) { + virtual R Run(A1 a1, A2 a2) { if (!del) { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,p5_,a1,a2); + R result = (object_->*member_)(p1_, p2_, p3_, p4_, p5_, a1, a2); return result; } else { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,p5_,a1,a2); + R result = (object_->*member_)(p1_, p2_, p3_, p4_, p5_, a1, a2); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -5767,15 +6362,15 @@ class _ConstMemberResultCallback_5_2 : public ResultCallback2 { } }; -template -class _ConstMemberResultCallback_5_2::value - >::type> - : public Callback2 { +template +class _ConstMemberResultCallback_5_2< + del, void, T, P1, P2, P3, P4, P5, A1, A2, + typename c_enable_if< + is_class_or_union::value>::type> : public Callback2 { public: - typedef Callback2 base; - typedef void (T::*MemberSignature)(P1,P2,P3,P4,P5,A1,A2) const; + typedef Callback2 base; + typedef void (T::*MemberSignature)(P1, P2, P3, P4, P5, A1, A2) const; private: const T* object_; @@ -5787,24 +6382,32 @@ class _ConstMemberResultCallback_5_2::type p5_; public: - inline _ConstMemberResultCallback_5_2(const T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) - : Callback2(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5) { } + inline _ConstMemberResultCallback_5_2(const T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5) + : Callback2(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback2"); } - virtual void Run(A1 a1,A2 a2) { + virtual void Run(A1 a1, A2 a2) { if (!del) { - (object_->*member_)(p1_,p2_,p3_,p4_,p5_,a1,a2); + (object_->*member_)(p1_, p2_, p3_, p4_, p5_, a1, a2); } else { - (object_->*member_)(p1_,p2_,p3_,p4_,p5_,a1,a2); + (object_->*member_)(p1_, p2_, p3_, p4_, p5_, a1, a2); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -5813,32 +6416,47 @@ class _ConstMemberResultCallback_5_2 -inline typename _ConstMemberResultCallback_5_2::base* -NewCallback(const T1* obj, R (T2::*member)(P1,P2,P3,P4,P5,A1,A2) const, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) { - return new _ConstMemberResultCallback_5_2(obj, member, p1, p2, p3, p4, p5); +template +inline typename _ConstMemberResultCallback_5_2::base* +NewCallback(const T1* obj, R (T2::*member)(P1, P2, P3, P4, P5, A1, A2) const, + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3, typename ConstRef::type p4, + typename ConstRef::type p5) { + return new _ConstMemberResultCallback_5_2< + true, R, T1, P1, P2, P3, P4, P5, A1, A2>(obj, member, p1, p2, p3, p4, p5); } #endif #ifndef SWIG -template -inline typename _ConstMemberResultCallback_5_2::base* -NewPermanentCallback(const T1* obj, R (T2::*member)(P1,P2,P3,P4,P5,A1,A2) const, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) { - return new _ConstMemberResultCallback_5_2(obj, member, p1, p2, p3, p4, p5); +template +inline typename _ConstMemberResultCallback_5_2::base* +NewPermanentCallback(const T1* obj, + R (T2::*member)(P1, P2, P3, P4, P5, A1, A2) const, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5) { + return new _ConstMemberResultCallback_5_2(obj, member, p1, p2, p3, p4, + p5); } #endif -template ::value - >::type> -class _MemberResultCallback_5_2 : public ResultCallback2 { +template ::value>::type> +class _MemberResultCallback_5_2 : public ResultCallback2 { public: - typedef ResultCallback2 base; - typedef R (T::*MemberSignature)(P1,P2,P3,P4,P5,A1,A2) ; + typedef ResultCallback2 base; + typedef R (T::*MemberSignature)(P1, P2, P3, P4, P5, A1, A2); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; typename remove_reference::type p2_; @@ -5847,25 +6465,33 @@ class _MemberResultCallback_5_2 : public ResultCallback2 { typename remove_reference::type p5_; public: - inline _MemberResultCallback_5_2( T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) - : ResultCallback2(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5) { } + inline _MemberResultCallback_5_2(T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5) + : ResultCallback2(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback2"); } - virtual R Run(A1 a1,A2 a2) { + virtual R Run(A1 a1, A2 a2) { if (!del) { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,p5_,a1,a2); + R result = (object_->*member_)(p1_, p2_, p3_, p4_, p5_, a1, a2); return result; } else { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,p5_,a1,a2); + R result = (object_->*member_)(p1_, p2_, p3_, p4_, p5_, a1, a2); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -5874,18 +6500,18 @@ class _MemberResultCallback_5_2 : public ResultCallback2 { } }; -template -class _MemberResultCallback_5_2::value - >::type> - : public Callback2 { +template +class _MemberResultCallback_5_2< + del, void, T, P1, P2, P3, P4, P5, A1, A2, + typename c_enable_if< + is_class_or_union::value>::type> : public Callback2 { public: - typedef Callback2 base; - typedef void (T::*MemberSignature)(P1,P2,P3,P4,P5,A1,A2) ; + typedef Callback2 base; + typedef void (T::*MemberSignature)(P1, P2, P3, P4, P5, A1, A2); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; typename remove_reference::type p2_; @@ -5894,24 +6520,32 @@ class _MemberResultCallback_5_2::type p5_; public: - inline _MemberResultCallback_5_2( T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) - : Callback2(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5) { } + inline _MemberResultCallback_5_2(T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5) + : Callback2(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback2"); } - virtual void Run(A1 a1,A2 a2) { + virtual void Run(A1 a1, A2 a2) { if (!del) { - (object_->*member_)(p1_,p2_,p3_,p4_,p5_,a1,a2); + (object_->*member_)(p1_, p2_, p3_, p4_, p5_, a1, a2); } else { - (object_->*member_)(p1_,p2_,p3_,p4_,p5_,a1,a2); + (object_->*member_)(p1_, p2_, p3_, p4_, p5_, a1, a2); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -5920,26 +6554,41 @@ class _MemberResultCallback_5_2 -inline typename _MemberResultCallback_5_2::base* -NewCallback( T1* obj, R (T2::*member)(P1,P2,P3,P4,P5,A1,A2) , typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) { - return new _MemberResultCallback_5_2(obj, member, p1, p2, p3, p4, p5); +template +inline typename _MemberResultCallback_5_2::base* +NewCallback(T1* obj, R (T2::*member)(P1, P2, P3, P4, P5, A1, A2), + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3, typename ConstRef::type p4, + typename ConstRef::type p5) { + return new _MemberResultCallback_5_2( + obj, member, p1, p2, p3, p4, p5); } #endif #ifndef SWIG -template -inline typename _MemberResultCallback_5_2::base* -NewPermanentCallback( T1* obj, R (T2::*member)(P1,P2,P3,P4,P5,A1,A2) , typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) { - return new _MemberResultCallback_5_2(obj, member, p1, p2, p3, p4, p5); +template +inline typename _MemberResultCallback_5_2::base* +NewPermanentCallback(T1* obj, R (T2::*member)(P1, P2, P3, P4, P5, A1, A2), + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5) { + return new _MemberResultCallback_5_2(obj, member, p1, p2, p3, p4, p5); } #endif -template -class _FunctionResultCallback_5_2 : public ResultCallback2 { +template +class _FunctionResultCallback_5_2 : public ResultCallback2 { public: - typedef ResultCallback2 base; - typedef R (*FunctionSignature)(P1,P2,P3,P4,P5,A1,A2); + typedef ResultCallback2 base; + typedef R (*FunctionSignature)(P1, P2, P3, P4, P5, A1, A2); private: FunctionSignature function_; @@ -5950,24 +6599,32 @@ class _FunctionResultCallback_5_2 : public ResultCallback2 { typename remove_reference::type p5_; public: - inline _FunctionResultCallback_5_2(FunctionSignature function, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) - : ResultCallback2(), - function_(function), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5) { } + inline _FunctionResultCallback_5_2(FunctionSignature function, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5) + : ResultCallback2(), + function_(function), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback2"); } - virtual R Run(A1 a1,A2 a2) { + virtual R Run(A1 a1, A2 a2) { if (!del) { - R result = (*function_)(p1_,p2_,p3_,p4_,p5_,a1,a2); + R result = (*function_)(p1_, p2_, p3_, p4_, p5_, a1, a2); return result; } else { - R result = (*function_)(p1_,p2_,p3_,p4_,p5_,a1,a2); + R result = (*function_)(p1_, p2_, p3_, p4_, p5_, a1, a2); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -5976,11 +6633,13 @@ class _FunctionResultCallback_5_2 : public ResultCallback2 { } }; -template -class _FunctionResultCallback_5_2 : public Callback2 { +template +class _FunctionResultCallback_5_2 : public Callback2 { public: - typedef Callback2 base; - typedef void (*FunctionSignature)(P1,P2,P3,P4,P5,A1,A2); + typedef Callback2 base; + typedef void (*FunctionSignature)(P1, P2, P3, P4, P5, A1, A2); private: FunctionSignature function_; @@ -5991,23 +6650,31 @@ class _FunctionResultCallback_5_2 : publi typename remove_reference::type p5_; public: - inline _FunctionResultCallback_5_2(FunctionSignature function, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) - : Callback2(), - function_(function), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5) { } + inline _FunctionResultCallback_5_2(FunctionSignature function, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5) + : Callback2(), + function_(function), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback2"); } - virtual void Run(A1 a1,A2 a2) { + virtual void Run(A1 a1, A2 a2) { if (!del) { - (*function_)(p1_,p2_,p3_,p4_,p5_,a1,a2); + (*function_)(p1_, p2_, p3_, p4_, p5_, a1, a2); } else { - (*function_)(p1_,p2_,p3_,p4_,p5_,a1,a2); + (*function_)(p1_, p2_, p3_, p4_, p5_, a1, a2); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -6015,26 +6682,40 @@ class _FunctionResultCallback_5_2 : publi } }; -template -inline typename _FunctionResultCallback_5_2::base* -NewCallback(R (*function)(P1,P2,P3,P4,P5,A1,A2), typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) { - return new _FunctionResultCallback_5_2(function, p1, p2, p3, p4, p5); +template +inline typename _FunctionResultCallback_5_2::base* +NewCallback(R (*function)(P1, P2, P3, P4, P5, A1, A2), + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3, typename ConstRef::type p4, + typename ConstRef::type p5) { + return new _FunctionResultCallback_5_2( + function, p1, p2, p3, p4, p5); } -template -inline typename _FunctionResultCallback_5_2::base* -NewPermanentCallback(R (*function)(P1,P2,P3,P4,P5,A1,A2), typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) { - return new _FunctionResultCallback_5_2(function, p1, p2, p3, p4, p5); +template +inline typename _FunctionResultCallback_5_2::base* +NewPermanentCallback(R (*function)(P1, P2, P3, P4, P5, A1, A2), + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5) { + return new _FunctionResultCallback_5_2( + function, p1, p2, p3, p4, p5); } -template ::value - >::type> -class _ConstMemberResultCallback_6_2 : public ResultCallback2 { +template < + bool del, class R, class T, class P1, class P2, class P3, class P4, + class P5, class P6, class A1, class A2, + class OnlyIf = typename c_enable_if::value>::type> +class _ConstMemberResultCallback_6_2 : public ResultCallback2 { public: - typedef ResultCallback2 base; - typedef R (T::*MemberSignature)(P1,P2,P3,P4,P5,P6,A1,A2) const; + typedef ResultCallback2 base; + typedef R (T::*MemberSignature)(P1, P2, P3, P4, P5, P6, A1, A2) const; private: const T* object_; @@ -6047,25 +6728,35 @@ class _ConstMemberResultCallback_6_2 : public ResultCallback2 { typename remove_reference::type p6_; public: - inline _ConstMemberResultCallback_6_2(const T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) - : ResultCallback2(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5), p6_(p6) { } + inline _ConstMemberResultCallback_6_2(const T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5, + typename ConstRef::type p6) + : ResultCallback2(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5), + p6_(p6) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback2"); } - virtual R Run(A1 a1,A2 a2) { + virtual R Run(A1 a1, A2 a2) { if (!del) { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,p5_,p6_,a1,a2); + R result = (object_->*member_)(p1_, p2_, p3_, p4_, p5_, p6_, a1, a2); return result; } else { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,p5_,p6_,a1,a2); + R result = (object_->*member_)(p1_, p2_, p3_, p4_, p5_, p6_, a1, a2); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -6074,15 +6765,15 @@ class _ConstMemberResultCallback_6_2 : public ResultCallback2 { } }; -template -class _ConstMemberResultCallback_6_2::value - >::type> - : public Callback2 { +template +class _ConstMemberResultCallback_6_2< + del, void, T, P1, P2, P3, P4, P5, P6, A1, A2, + typename c_enable_if< + is_class_or_union::value>::type> : public Callback2 { public: - typedef Callback2 base; - typedef void (T::*MemberSignature)(P1,P2,P3,P4,P5,P6,A1,A2) const; + typedef Callback2 base; + typedef void (T::*MemberSignature)(P1, P2, P3, P4, P5, P6, A1, A2) const; private: const T* object_; @@ -6095,24 +6786,34 @@ class _ConstMemberResultCallback_6_2::type p6_; public: - inline _ConstMemberResultCallback_6_2(const T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) - : Callback2(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5), p6_(p6) { } + inline _ConstMemberResultCallback_6_2(const T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5, + typename ConstRef::type p6) + : Callback2(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5), + p6_(p6) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback2"); } - virtual void Run(A1 a1,A2 a2) { + virtual void Run(A1 a1, A2 a2) { if (!del) { - (object_->*member_)(p1_,p2_,p3_,p4_,p5_,p6_,a1,a2); + (object_->*member_)(p1_, p2_, p3_, p4_, p5_, p6_, a1, a2); } else { - (object_->*member_)(p1_,p2_,p3_,p4_,p5_,p6_,a1,a2); + (object_->*member_)(p1_, p2_, p3_, p4_, p5_, p6_, a1, a2); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -6121,32 +6822,48 @@ class _ConstMemberResultCallback_6_2 -inline typename _ConstMemberResultCallback_6_2::base* -NewCallback(const T1* obj, R (T2::*member)(P1,P2,P3,P4,P5,P6,A1,A2) const, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) { - return new _ConstMemberResultCallback_6_2(obj, member, p1, p2, p3, p4, p5, p6); +template +inline typename _ConstMemberResultCallback_6_2::base* +NewCallback(const T1* obj, + R (T2::*member)(P1, P2, P3, P4, P5, P6, A1, A2) const, + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3, typename ConstRef::type p4, + typename ConstRef::type p5, typename ConstRef::type p6) { + return new _ConstMemberResultCallback_6_2(obj, member, p1, p2, p3, p4, + p5, p6); } #endif #ifndef SWIG -template -inline typename _ConstMemberResultCallback_6_2::base* -NewPermanentCallback(const T1* obj, R (T2::*member)(P1,P2,P3,P4,P5,P6,A1,A2) const, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) { - return new _ConstMemberResultCallback_6_2(obj, member, p1, p2, p3, p4, p5, p6); +template +inline typename _ConstMemberResultCallback_6_2::base* +NewPermanentCallback( + const T1* obj, R (T2::*member)(P1, P2, P3, P4, P5, P6, A1, A2) const, + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3, typename ConstRef::type p4, + typename ConstRef::type p5, typename ConstRef::type p6) { + return new _ConstMemberResultCallback_6_2< + false, R, T1, P1, P2, P3, P4, P5, P6, A1, A2>(obj, member, p1, p2, p3, p4, + p5, p6); } #endif -template ::value - >::type> -class _MemberResultCallback_6_2 : public ResultCallback2 { +template < + bool del, class R, class T, class P1, class P2, class P3, class P4, + class P5, class P6, class A1, class A2, + class OnlyIf = typename c_enable_if::value>::type> +class _MemberResultCallback_6_2 : public ResultCallback2 { public: - typedef ResultCallback2 base; - typedef R (T::*MemberSignature)(P1,P2,P3,P4,P5,P6,A1,A2) ; + typedef ResultCallback2 base; + typedef R (T::*MemberSignature)(P1, P2, P3, P4, P5, P6, A1, A2); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; typename remove_reference::type p2_; @@ -6156,25 +6873,35 @@ class _MemberResultCallback_6_2 : public ResultCallback2 { typename remove_reference::type p6_; public: - inline _MemberResultCallback_6_2( T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) - : ResultCallback2(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5), p6_(p6) { } + inline _MemberResultCallback_6_2(T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5, + typename ConstRef::type p6) + : ResultCallback2(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5), + p6_(p6) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback2"); } - virtual R Run(A1 a1,A2 a2) { + virtual R Run(A1 a1, A2 a2) { if (!del) { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,p5_,p6_,a1,a2); + R result = (object_->*member_)(p1_, p2_, p3_, p4_, p5_, p6_, a1, a2); return result; } else { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,p5_,p6_,a1,a2); + R result = (object_->*member_)(p1_, p2_, p3_, p4_, p5_, p6_, a1, a2); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -6183,18 +6910,18 @@ class _MemberResultCallback_6_2 : public ResultCallback2 { } }; -template -class _MemberResultCallback_6_2::value - >::type> - : public Callback2 { +template +class _MemberResultCallback_6_2< + del, void, T, P1, P2, P3, P4, P5, P6, A1, A2, + typename c_enable_if< + is_class_or_union::value>::type> : public Callback2 { public: - typedef Callback2 base; - typedef void (T::*MemberSignature)(P1,P2,P3,P4,P5,P6,A1,A2) ; + typedef Callback2 base; + typedef void (T::*MemberSignature)(P1, P2, P3, P4, P5, P6, A1, A2); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; typename remove_reference::type p2_; @@ -6204,24 +6931,34 @@ class _MemberResultCallback_6_2::type p6_; public: - inline _MemberResultCallback_6_2( T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) - : Callback2(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5), p6_(p6) { } + inline _MemberResultCallback_6_2(T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5, + typename ConstRef::type p6) + : Callback2(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5), + p6_(p6) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback2"); } - virtual void Run(A1 a1,A2 a2) { + virtual void Run(A1 a1, A2 a2) { if (!del) { - (object_->*member_)(p1_,p2_,p3_,p4_,p5_,p6_,a1,a2); + (object_->*member_)(p1_, p2_, p3_, p4_, p5_, p6_, a1, a2); } else { - (object_->*member_)(p1_,p2_,p3_,p4_,p5_,p6_,a1,a2); + (object_->*member_)(p1_, p2_, p3_, p4_, p5_, p6_, a1, a2); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -6230,26 +6967,42 @@ class _MemberResultCallback_6_2 -inline typename _MemberResultCallback_6_2::base* -NewCallback( T1* obj, R (T2::*member)(P1,P2,P3,P4,P5,P6,A1,A2) , typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) { - return new _MemberResultCallback_6_2(obj, member, p1, p2, p3, p4, p5, p6); +template +inline typename _MemberResultCallback_6_2::base* +NewCallback(T1* obj, R (T2::*member)(P1, P2, P3, P4, P5, P6, A1, A2), + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3, typename ConstRef::type p4, + typename ConstRef::type p5, typename ConstRef::type p6) { + return new _MemberResultCallback_6_2(obj, member, p1, p2, p3, p4, p5, p6); } #endif #ifndef SWIG -template -inline typename _MemberResultCallback_6_2::base* -NewPermanentCallback( T1* obj, R (T2::*member)(P1,P2,P3,P4,P5,P6,A1,A2) , typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) { - return new _MemberResultCallback_6_2(obj, member, p1, p2, p3, p4, p5, p6); +template +inline typename _MemberResultCallback_6_2::base* +NewPermanentCallback(T1* obj, R (T2::*member)(P1, P2, P3, P4, P5, P6, A1, A2), + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5, + typename ConstRef::type p6) { + return new _MemberResultCallback_6_2(obj, member, p1, p2, p3, p4, p5, p6); } #endif -template -class _FunctionResultCallback_6_2 : public ResultCallback2 { +template +class _FunctionResultCallback_6_2 : public ResultCallback2 { public: - typedef ResultCallback2 base; - typedef R (*FunctionSignature)(P1,P2,P3,P4,P5,P6,A1,A2); + typedef ResultCallback2 base; + typedef R (*FunctionSignature)(P1, P2, P3, P4, P5, P6, A1, A2); private: FunctionSignature function_; @@ -6261,24 +7014,34 @@ class _FunctionResultCallback_6_2 : public ResultCallback2 { typename remove_reference::type p6_; public: - inline _FunctionResultCallback_6_2(FunctionSignature function, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) - : ResultCallback2(), - function_(function), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5), p6_(p6) { } + inline _FunctionResultCallback_6_2(FunctionSignature function, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5, + typename ConstRef::type p6) + : ResultCallback2(), + function_(function), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5), + p6_(p6) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback2"); } - virtual R Run(A1 a1,A2 a2) { + virtual R Run(A1 a1, A2 a2) { if (!del) { - R result = (*function_)(p1_,p2_,p3_,p4_,p5_,p6_,a1,a2); + R result = (*function_)(p1_, p2_, p3_, p4_, p5_, p6_, a1, a2); return result; } else { - R result = (*function_)(p1_,p2_,p3_,p4_,p5_,p6_,a1,a2); + R result = (*function_)(p1_, p2_, p3_, p4_, p5_, p6_, a1, a2); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -6287,11 +7050,13 @@ class _FunctionResultCallback_6_2 : public ResultCallback2 { } }; -template -class _FunctionResultCallback_6_2 : public Callback2 { +template +class _FunctionResultCallback_6_2 : public Callback2 { public: - typedef Callback2 base; - typedef void (*FunctionSignature)(P1,P2,P3,P4,P5,P6,A1,A2); + typedef Callback2 base; + typedef void (*FunctionSignature)(P1, P2, P3, P4, P5, P6, A1, A2); private: FunctionSignature function_; @@ -6303,23 +7068,33 @@ class _FunctionResultCallback_6_2 : p typename remove_reference::type p6_; public: - inline _FunctionResultCallback_6_2(FunctionSignature function, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) - : Callback2(), - function_(function), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5), p6_(p6) { } + inline _FunctionResultCallback_6_2(FunctionSignature function, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5, + typename ConstRef::type p6) + : Callback2(), + function_(function), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5), + p6_(p6) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback2"); } - virtual void Run(A1 a1,A2 a2) { + virtual void Run(A1 a1, A2 a2) { if (!del) { - (*function_)(p1_,p2_,p3_,p4_,p5_,p6_,a1,a2); + (*function_)(p1_, p2_, p3_, p4_, p5_, p6_, a1, a2); } else { - (*function_)(p1_,p2_,p3_,p4_,p5_,p6_,a1,a2); + (*function_)(p1_, p2_, p3_, p4_, p5_, p6_, a1, a2); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -6327,26 +7102,40 @@ class _FunctionResultCallback_6_2 : p } }; -template -inline typename _FunctionResultCallback_6_2::base* -NewCallback(R (*function)(P1,P2,P3,P4,P5,P6,A1,A2), typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) { - return new _FunctionResultCallback_6_2(function, p1, p2, p3, p4, p5, p6); +template +inline typename _FunctionResultCallback_6_2::base* +NewCallback(R (*function)(P1, P2, P3, P4, P5, P6, A1, A2), + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3, typename ConstRef::type p4, + typename ConstRef::type p5, typename ConstRef::type p6) { + return new _FunctionResultCallback_6_2(function, p1, p2, p3, p4, p5, p6); } -template -inline typename _FunctionResultCallback_6_2::base* -NewPermanentCallback(R (*function)(P1,P2,P3,P4,P5,P6,A1,A2), typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) { - return new _FunctionResultCallback_6_2(function, p1, p2, p3, p4, p5, p6); +template +inline typename _FunctionResultCallback_6_2::base* +NewPermanentCallback(R (*function)(P1, P2, P3, P4, P5, P6, A1, A2), + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5, + typename ConstRef::type p6) { + return new _FunctionResultCallback_6_2(function, p1, p2, p3, p4, p5, p6); } -template ::value - >::type> -class _ConstMemberResultCallback_0_3 : public ResultCallback3 { +template < + bool del, class R, class T, class A1, class A2, class A3, + class OnlyIf = typename c_enable_if::value>::type> +class _ConstMemberResultCallback_0_3 : public ResultCallback3 { public: - typedef ResultCallback3 base; - typedef R (T::*MemberSignature)(A1,A2,A3) const; + typedef ResultCallback3 base; + typedef R (T::*MemberSignature)(A1, A2, A3) const; private: const T* object_; @@ -6354,24 +7143,20 @@ class _ConstMemberResultCallback_0_3 : public ResultCallback3 { public: inline _ConstMemberResultCallback_0_3(const T* object, MemberSignature member) - : ResultCallback3(), - object_(object), - member_(member) { } + : ResultCallback3(), object_(object), member_(member) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback3"); } - virtual R Run(A1 a1,A2 a2,A3 a3) { + virtual R Run(A1 a1, A2 a2, A3 a3) { if (!del) { - R result = (object_->*member_)(a1,a2,a3); + R result = (object_->*member_)(a1, a2, a3); return result; } else { - R result = (object_->*member_)(a1,a2,a3); + R result = (object_->*member_)(a1, a2, a3); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -6381,14 +7166,13 @@ class _ConstMemberResultCallback_0_3 : public ResultCallback3 { }; template -class _ConstMemberResultCallback_0_3::value - >::type> - : public Callback3 { +class _ConstMemberResultCallback_0_3< + del, void, T, A1, A2, A3, + typename c_enable_if< + is_class_or_union::value>::type> : public Callback3 { public: - typedef Callback3 base; - typedef void (T::*MemberSignature)(A1,A2,A3) const; + typedef Callback3 base; + typedef void (T::*MemberSignature)(A1, A2, A3) const; private: const T* object_; @@ -6396,23 +7180,19 @@ class _ConstMemberResultCallback_0_3(), - object_(object), - member_(member) { } + : Callback3(), object_(object), member_(member) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback3"); } - virtual void Run(A1 a1,A2 a2,A3 a3) { + virtual void Run(A1 a1, A2 a2, A3 a3) { if (!del) { - (object_->*member_)(a1,a2,a3); + (object_->*member_)(a1, a2, a3); } else { - (object_->*member_)(a1,a2,a3); + (object_->*member_)(a1, a2, a3); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -6422,53 +7202,50 @@ class _ConstMemberResultCallback_0_3 -inline typename _ConstMemberResultCallback_0_3::base* -NewCallback(const T1* obj, R (T2::*member)(A1,A2,A3) const) { - return new _ConstMemberResultCallback_0_3(obj, member); +inline typename _ConstMemberResultCallback_0_3::base* +NewCallback(const T1* obj, R (T2::*member)(A1, A2, A3) const) { + return new _ConstMemberResultCallback_0_3(obj, + member); } #endif #ifndef SWIG template -inline typename _ConstMemberResultCallback_0_3::base* -NewPermanentCallback(const T1* obj, R (T2::*member)(A1,A2,A3) const) { - return new _ConstMemberResultCallback_0_3(obj, member); +inline typename _ConstMemberResultCallback_0_3::base* +NewPermanentCallback(const T1* obj, R (T2::*member)(A1, A2, A3) const) { + return new _ConstMemberResultCallback_0_3(obj, + member); } #endif -template ::value - >::type> -class _MemberResultCallback_0_3 : public ResultCallback3 { +template < + bool del, class R, class T, class A1, class A2, class A3, + class OnlyIf = typename c_enable_if::value>::type> +class _MemberResultCallback_0_3 : public ResultCallback3 { public: - typedef ResultCallback3 base; - typedef R (T::*MemberSignature)(A1,A2,A3) ; + typedef ResultCallback3 base; + typedef R (T::*MemberSignature)(A1, A2, A3); private: - T* object_; + T* object_; MemberSignature member_; public: - inline _MemberResultCallback_0_3( T* object, MemberSignature member) - : ResultCallback3(), - object_(object), - member_(member) { } + inline _MemberResultCallback_0_3(T* object, MemberSignature member) + : ResultCallback3(), object_(object), member_(member) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback3"); } - virtual R Run(A1 a1,A2 a2,A3 a3) { + virtual R Run(A1 a1, A2 a2, A3 a3) { if (!del) { - R result = (object_->*member_)(a1,a2,a3); + R result = (object_->*member_)(a1, a2, a3); return result; } else { - R result = (object_->*member_)(a1,a2,a3); + R result = (object_->*member_)(a1, a2, a3); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -6478,38 +7255,33 @@ class _MemberResultCallback_0_3 : public ResultCallback3 { }; template -class _MemberResultCallback_0_3::value - >::type> - : public Callback3 { +class _MemberResultCallback_0_3< + del, void, T, A1, A2, A3, + typename c_enable_if< + is_class_or_union::value>::type> : public Callback3 { public: - typedef Callback3 base; - typedef void (T::*MemberSignature)(A1,A2,A3) ; + typedef Callback3 base; + typedef void (T::*MemberSignature)(A1, A2, A3); private: - T* object_; + T* object_; MemberSignature member_; public: - inline _MemberResultCallback_0_3( T* object, MemberSignature member) - : Callback3(), - object_(object), - member_(member) { } + inline _MemberResultCallback_0_3(T* object, MemberSignature member) + : Callback3(), object_(object), member_(member) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback3"); } - virtual void Run(A1 a1,A2 a2,A3 a3) { + virtual void Run(A1 a1, A2 a2, A3 a3) { if (!del) { - (object_->*member_)(a1,a2,a3); + (object_->*member_)(a1, a2, a3); } else { - (object_->*member_)(a1,a2,a3); + (object_->*member_)(a1, a2, a3); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -6519,48 +7291,45 @@ class _MemberResultCallback_0_3 -inline typename _MemberResultCallback_0_3::base* -NewCallback( T1* obj, R (T2::*member)(A1,A2,A3) ) { - return new _MemberResultCallback_0_3(obj, member); +inline typename _MemberResultCallback_0_3::base* +NewCallback(T1* obj, R (T2::*member)(A1, A2, A3)) { + return new _MemberResultCallback_0_3(obj, member); } #endif #ifndef SWIG template -inline typename _MemberResultCallback_0_3::base* -NewPermanentCallback( T1* obj, R (T2::*member)(A1,A2,A3) ) { - return new _MemberResultCallback_0_3(obj, member); +inline typename _MemberResultCallback_0_3::base* +NewPermanentCallback(T1* obj, R (T2::*member)(A1, A2, A3)) { + return new _MemberResultCallback_0_3(obj, member); } #endif template -class _FunctionResultCallback_0_3 : public ResultCallback3 { +class _FunctionResultCallback_0_3 : public ResultCallback3 { public: - typedef ResultCallback3 base; - typedef R (*FunctionSignature)(A1,A2,A3); + typedef ResultCallback3 base; + typedef R (*FunctionSignature)(A1, A2, A3); private: FunctionSignature function_; public: inline _FunctionResultCallback_0_3(FunctionSignature function) - : ResultCallback3(), - function_(function) { } + : ResultCallback3(), function_(function) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback3"); } - virtual R Run(A1 a1,A2 a2,A3 a3) { + virtual R Run(A1 a1, A2 a2, A3 a3) { if (!del) { - R result = (*function_)(a1,a2,a3); + R result = (*function_)(a1, a2, a3); return result; } else { - R result = (*function_)(a1,a2,a3); + R result = (*function_)(a1, a2, a3); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -6570,32 +7339,30 @@ class _FunctionResultCallback_0_3 : public ResultCallback3 { }; template -class _FunctionResultCallback_0_3 : public Callback3 { +class _FunctionResultCallback_0_3 : public Callback3< + A1, A2, A3> { public: - typedef Callback3 base; - typedef void (*FunctionSignature)(A1,A2,A3); + typedef Callback3 base; + typedef void (*FunctionSignature)(A1, A2, A3); private: FunctionSignature function_; public: inline _FunctionResultCallback_0_3(FunctionSignature function) - : Callback3(), - function_(function) { } + : Callback3(), function_(function) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback3"); } - virtual void Run(A1 a1,A2 a2,A3 a3) { + virtual void Run(A1 a1, A2 a2, A3 a3) { if (!del) { - (*function_)(a1,a2,a3); + (*function_)(a1, a2, a3); } else { - (*function_)(a1,a2,a3); + (*function_)(a1, a2, a3); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -6604,25 +7371,24 @@ class _FunctionResultCallback_0_3 : public Callback3 -inline typename _FunctionResultCallback_0_3::base* -NewCallback(R (*function)(A1,A2,A3)) { - return new _FunctionResultCallback_0_3(function); +inline typename _FunctionResultCallback_0_3::base* +NewCallback(R (*function)(A1, A2, A3)) { + return new _FunctionResultCallback_0_3(function); } template -inline typename _FunctionResultCallback_0_3::base* -NewPermanentCallback(R (*function)(A1,A2,A3)) { - return new _FunctionResultCallback_0_3(function); +inline typename _FunctionResultCallback_0_3::base* +NewPermanentCallback(R (*function)(A1, A2, A3)) { + return new _FunctionResultCallback_0_3(function); } -template ::value - >::type> -class _ConstMemberResultCallback_1_3 : public ResultCallback3 { +template < + bool del, class R, class T, class P1, class A1, class A2, class A3, + class OnlyIf = typename c_enable_if::value>::type> +class _ConstMemberResultCallback_1_3 : public ResultCallback3 { public: - typedef ResultCallback3 base; - typedef R (T::*MemberSignature)(P1,A1,A2,A3) const; + typedef ResultCallback3 base; + typedef R (T::*MemberSignature)(P1, A1, A2, A3) const; private: const T* object_; @@ -6630,25 +7396,25 @@ class _ConstMemberResultCallback_1_3 : public ResultCallback3 { typename remove_reference::type p1_; public: - inline _ConstMemberResultCallback_1_3(const T* object, MemberSignature member, typename ConstRef::type p1) - : ResultCallback3(), - object_(object), - member_(member), p1_(p1) { } + inline _ConstMemberResultCallback_1_3(const T* object, MemberSignature member, + typename ConstRef::type p1) + : ResultCallback3(), + object_(object), + member_(member), + p1_(p1) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback3"); } - virtual R Run(A1 a1,A2 a2,A3 a3) { + virtual R Run(A1 a1, A2 a2, A3 a3) { if (!del) { - R result = (object_->*member_)(p1_,a1,a2,a3); + R result = (object_->*member_)(p1_, a1, a2, a3); return result; } else { - R result = (object_->*member_)(p1_,a1,a2,a3); + R result = (object_->*member_)(p1_, a1, a2, a3); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -6658,14 +7424,13 @@ class _ConstMemberResultCallback_1_3 : public ResultCallback3 { }; template -class _ConstMemberResultCallback_1_3::value - >::type> - : public Callback3 { +class _ConstMemberResultCallback_1_3< + del, void, T, P1, A1, A2, A3, + typename c_enable_if< + is_class_or_union::value>::type> : public Callback3 { public: - typedef Callback3 base; - typedef void (T::*MemberSignature)(P1,A1,A2,A3) const; + typedef Callback3 base; + typedef void (T::*MemberSignature)(P1, A1, A2, A3) const; private: const T* object_; @@ -6673,24 +7438,21 @@ class _ConstMemberResultCallback_1_3::type p1_; public: - inline _ConstMemberResultCallback_1_3(const T* object, MemberSignature member, typename ConstRef::type p1) - : Callback3(), - object_(object), - member_(member), p1_(p1) { } + inline _ConstMemberResultCallback_1_3(const T* object, MemberSignature member, + typename ConstRef::type p1) + : Callback3(), object_(object), member_(member), p1_(p1) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback3"); } - virtual void Run(A1 a1,A2 a2,A3 a3) { + virtual void Run(A1 a1, A2 a2, A3 a3) { if (!del) { - (object_->*member_)(p1_,a1,a2,a3); + (object_->*member_)(p1_, a1, a2, a3); } else { - (object_->*member_)(p1_,a1,a2,a3); + (object_->*member_)(p1_, a1, a2, a3); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -6700,54 +7462,59 @@ class _ConstMemberResultCallback_1_3 -inline typename _ConstMemberResultCallback_1_3::base* -NewCallback(const T1* obj, R (T2::*member)(P1,A1,A2,A3) const, typename ConstRef::type p1) { - return new _ConstMemberResultCallback_1_3(obj, member, p1); +inline typename _ConstMemberResultCallback_1_3::base* +NewCallback(const T1* obj, R (T2::*member)(P1, A1, A2, A3) const, + typename ConstRef::type p1) { + return new _ConstMemberResultCallback_1_3( + obj, member, p1); } #endif #ifndef SWIG template -inline typename _ConstMemberResultCallback_1_3::base* -NewPermanentCallback(const T1* obj, R (T2::*member)(P1,A1,A2,A3) const, typename ConstRef::type p1) { - return new _ConstMemberResultCallback_1_3(obj, member, p1); +inline typename _ConstMemberResultCallback_1_3::base* +NewPermanentCallback(const T1* obj, R (T2::*member)(P1, A1, A2, A3) const, + typename ConstRef::type p1) { + return new _ConstMemberResultCallback_1_3( + obj, member, p1); } #endif -template ::value - >::type> -class _MemberResultCallback_1_3 : public ResultCallback3 { +template < + bool del, class R, class T, class P1, class A1, class A2, class A3, + class OnlyIf = typename c_enable_if::value>::type> +class _MemberResultCallback_1_3 : public ResultCallback3 { public: - typedef ResultCallback3 base; - typedef R (T::*MemberSignature)(P1,A1,A2,A3) ; + typedef ResultCallback3 base; + typedef R (T::*MemberSignature)(P1, A1, A2, A3); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; public: - inline _MemberResultCallback_1_3( T* object, MemberSignature member, typename ConstRef::type p1) - : ResultCallback3(), - object_(object), - member_(member), p1_(p1) { } + inline _MemberResultCallback_1_3(T* object, MemberSignature member, + typename ConstRef::type p1) + : ResultCallback3(), + object_(object), + member_(member), + p1_(p1) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback3"); } - virtual R Run(A1 a1,A2 a2,A3 a3) { + virtual R Run(A1 a1, A2 a2, A3 a3) { if (!del) { - R result = (object_->*member_)(p1_,a1,a2,a3); + R result = (object_->*member_)(p1_, a1, a2, a3); return result; } else { - R result = (object_->*member_)(p1_,a1,a2,a3); + R result = (object_->*member_)(p1_, a1, a2, a3); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -6757,39 +7524,35 @@ class _MemberResultCallback_1_3 : public ResultCallback3 { }; template -class _MemberResultCallback_1_3::value - >::type> - : public Callback3 { +class _MemberResultCallback_1_3< + del, void, T, P1, A1, A2, A3, + typename c_enable_if< + is_class_or_union::value>::type> : public Callback3 { public: - typedef Callback3 base; - typedef void (T::*MemberSignature)(P1,A1,A2,A3) ; + typedef Callback3 base; + typedef void (T::*MemberSignature)(P1, A1, A2, A3); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; public: - inline _MemberResultCallback_1_3( T* object, MemberSignature member, typename ConstRef::type p1) - : Callback3(), - object_(object), - member_(member), p1_(p1) { } + inline _MemberResultCallback_1_3(T* object, MemberSignature member, + typename ConstRef::type p1) + : Callback3(), object_(object), member_(member), p1_(p1) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback3"); } - virtual void Run(A1 a1,A2 a2,A3 a3) { + virtual void Run(A1 a1, A2 a2, A3 a3) { if (!del) { - (object_->*member_)(p1_,a1,a2,a3); + (object_->*member_)(p1_, a1, a2, a3); } else { - (object_->*member_)(p1_,a1,a2,a3); + (object_->*member_)(p1_, a1, a2, a3); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -6799,49 +7562,51 @@ class _MemberResultCallback_1_3 -inline typename _MemberResultCallback_1_3::base* -NewCallback( T1* obj, R (T2::*member)(P1,A1,A2,A3) , typename ConstRef::type p1) { - return new _MemberResultCallback_1_3(obj, member, p1); +inline typename _MemberResultCallback_1_3::base* +NewCallback(T1* obj, R (T2::*member)(P1, A1, A2, A3), + typename ConstRef::type p1) { + return new _MemberResultCallback_1_3(obj, member, + p1); } #endif #ifndef SWIG template -inline typename _MemberResultCallback_1_3::base* -NewPermanentCallback( T1* obj, R (T2::*member)(P1,A1,A2,A3) , typename ConstRef::type p1) { - return new _MemberResultCallback_1_3(obj, member, p1); +inline typename _MemberResultCallback_1_3::base* +NewPermanentCallback(T1* obj, R (T2::*member)(P1, A1, A2, A3), + typename ConstRef::type p1) { + return new _MemberResultCallback_1_3( + obj, member, p1); } #endif template -class _FunctionResultCallback_1_3 : public ResultCallback3 { +class _FunctionResultCallback_1_3 : public ResultCallback3 { public: - typedef ResultCallback3 base; - typedef R (*FunctionSignature)(P1,A1,A2,A3); + typedef ResultCallback3 base; + typedef R (*FunctionSignature)(P1, A1, A2, A3); private: FunctionSignature function_; typename remove_reference::type p1_; public: - inline _FunctionResultCallback_1_3(FunctionSignature function, typename ConstRef::type p1) - : ResultCallback3(), - function_(function), p1_(p1) { } + inline _FunctionResultCallback_1_3(FunctionSignature function, + typename ConstRef::type p1) + : ResultCallback3(), function_(function), p1_(p1) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback3"); } - virtual R Run(A1 a1,A2 a2,A3 a3) { + virtual R Run(A1 a1, A2 a2, A3 a3) { if (!del) { - R result = (*function_)(p1_,a1,a2,a3); + R result = (*function_)(p1_, a1, a2, a3); return result; } else { - R result = (*function_)(p1_,a1,a2,a3); + R result = (*function_)(p1_, a1, a2, a3); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -6851,33 +7616,32 @@ class _FunctionResultCallback_1_3 : public ResultCallback3 { }; template -class _FunctionResultCallback_1_3 : public Callback3 { +class _FunctionResultCallback_1_3 : public Callback3< + A1, A2, A3> { public: - typedef Callback3 base; - typedef void (*FunctionSignature)(P1,A1,A2,A3); + typedef Callback3 base; + typedef void (*FunctionSignature)(P1, A1, A2, A3); private: FunctionSignature function_; typename remove_reference::type p1_; public: - inline _FunctionResultCallback_1_3(FunctionSignature function, typename ConstRef::type p1) - : Callback3(), - function_(function), p1_(p1) { } + inline _FunctionResultCallback_1_3(FunctionSignature function, + typename ConstRef::type p1) + : Callback3(), function_(function), p1_(p1) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback3"); } - virtual void Run(A1 a1,A2 a2,A3 a3) { + virtual void Run(A1 a1, A2 a2, A3 a3) { if (!del) { - (*function_)(p1_,a1,a2,a3); + (*function_)(p1_, a1, a2, a3); } else { - (*function_)(p1_,a1,a2,a3); + (*function_)(p1_, a1, a2, a3); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -6886,25 +7650,26 @@ class _FunctionResultCallback_1_3 : public Callback3< }; template -inline typename _FunctionResultCallback_1_3::base* -NewCallback(R (*function)(P1,A1,A2,A3), typename ConstRef::type p1) { - return new _FunctionResultCallback_1_3(function, p1); +inline typename _FunctionResultCallback_1_3::base* +NewCallback(R (*function)(P1, A1, A2, A3), typename ConstRef::type p1) { + return new _FunctionResultCallback_1_3(function, p1); } template -inline typename _FunctionResultCallback_1_3::base* -NewPermanentCallback(R (*function)(P1,A1,A2,A3), typename ConstRef::type p1) { - return new _FunctionResultCallback_1_3(function, p1); +inline typename _FunctionResultCallback_1_3::base* +NewPermanentCallback(R (*function)(P1, A1, A2, A3), + typename ConstRef::type p1) { + return new _FunctionResultCallback_1_3(function, + p1); } -template ::value - >::type> -class _ConstMemberResultCallback_2_3 : public ResultCallback3 { +template ::value>::type> +class _ConstMemberResultCallback_2_3 : public ResultCallback3 { public: - typedef ResultCallback3 base; - typedef R (T::*MemberSignature)(P1,P2,A1,A2,A3) const; + typedef ResultCallback3 base; + typedef R (T::*MemberSignature)(P1, P2, A1, A2, A3) const; private: const T* object_; @@ -6913,25 +7678,27 @@ class _ConstMemberResultCallback_2_3 : public ResultCallback3 { typename remove_reference::type p2_; public: - inline _ConstMemberResultCallback_2_3(const T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2) - : ResultCallback3(), - object_(object), - member_(member), p1_(p1), p2_(p2) { } + inline _ConstMemberResultCallback_2_3(const T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2) + : ResultCallback3(), + object_(object), + member_(member), + p1_(p1), + p2_(p2) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback3"); } - virtual R Run(A1 a1,A2 a2,A3 a3) { + virtual R Run(A1 a1, A2 a2, A3 a3) { if (!del) { - R result = (object_->*member_)(p1_,p2_,a1,a2,a3); + R result = (object_->*member_)(p1_, p2_, a1, a2, a3); return result; } else { - R result = (object_->*member_)(p1_,p2_,a1,a2,a3); + R result = (object_->*member_)(p1_, p2_, a1, a2, a3); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -6941,14 +7708,13 @@ class _ConstMemberResultCallback_2_3 : public ResultCallback3 { }; template -class _ConstMemberResultCallback_2_3::value - >::type> - : public Callback3 { +class _ConstMemberResultCallback_2_3< + del, void, T, P1, P2, A1, A2, A3, + typename c_enable_if< + is_class_or_union::value>::type> : public Callback3 { public: - typedef Callback3 base; - typedef void (T::*MemberSignature)(P1,P2,A1,A2,A3) const; + typedef Callback3 base; + typedef void (T::*MemberSignature)(P1, P2, A1, A2, A3) const; private: const T* object_; @@ -6957,24 +7723,26 @@ class _ConstMemberResultCallback_2_3::type p2_; public: - inline _ConstMemberResultCallback_2_3(const T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2) - : Callback3(), - object_(object), - member_(member), p1_(p1), p2_(p2) { } + inline _ConstMemberResultCallback_2_3(const T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2) + : Callback3(), + object_(object), + member_(member), + p1_(p1), + p2_(p2) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback3"); } - virtual void Run(A1 a1,A2 a2,A3 a3) { + virtual void Run(A1 a1, A2 a2, A3 a3) { if (!del) { - (object_->*member_)(p1_,p2_,a1,a2,a3); + (object_->*member_)(p1_, p2_, a1, a2, a3); } else { - (object_->*member_)(p1_,p2_,a1,a2,a3); + (object_->*member_)(p1_, p2_, a1, a2, a3); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -6983,56 +7751,66 @@ class _ConstMemberResultCallback_2_3 -inline typename _ConstMemberResultCallback_2_3::base* -NewCallback(const T1* obj, R (T2::*member)(P1,P2,A1,A2,A3) const, typename ConstRef::type p1, typename ConstRef::type p2) { - return new _ConstMemberResultCallback_2_3(obj, member, p1, p2); +template +inline typename _ConstMemberResultCallback_2_3::base* +NewCallback(const T1* obj, R (T2::*member)(P1, P2, A1, A2, A3) const, + typename ConstRef::type p1, typename ConstRef::type p2) { + return new _ConstMemberResultCallback_2_3( + obj, member, p1, p2); } #endif #ifndef SWIG -template -inline typename _ConstMemberResultCallback_2_3::base* -NewPermanentCallback(const T1* obj, R (T2::*member)(P1,P2,A1,A2,A3) const, typename ConstRef::type p1, typename ConstRef::type p2) { - return new _ConstMemberResultCallback_2_3(obj, member, p1, p2); +template +inline typename _ConstMemberResultCallback_2_3::base* +NewPermanentCallback(const T1* obj, R (T2::*member)(P1, P2, A1, A2, A3) const, + typename ConstRef::type p1, + typename ConstRef::type p2) { + return new _ConstMemberResultCallback_2_3( + obj, member, p1, p2); } #endif -template ::value - >::type> -class _MemberResultCallback_2_3 : public ResultCallback3 { +template ::value>::type> +class _MemberResultCallback_2_3 : public ResultCallback3 { public: - typedef ResultCallback3 base; - typedef R (T::*MemberSignature)(P1,P2,A1,A2,A3) ; + typedef ResultCallback3 base; + typedef R (T::*MemberSignature)(P1, P2, A1, A2, A3); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; typename remove_reference::type p2_; public: - inline _MemberResultCallback_2_3( T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2) - : ResultCallback3(), - object_(object), - member_(member), p1_(p1), p2_(p2) { } + inline _MemberResultCallback_2_3(T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2) + : ResultCallback3(), + object_(object), + member_(member), + p1_(p1), + p2_(p2) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback3"); } - virtual R Run(A1 a1,A2 a2,A3 a3) { + virtual R Run(A1 a1, A2 a2, A3 a3) { if (!del) { - R result = (object_->*member_)(p1_,p2_,a1,a2,a3); + R result = (object_->*member_)(p1_, p2_, a1, a2, a3); return result; } else { - R result = (object_->*member_)(p1_,p2_,a1,a2,a3); + R result = (object_->*member_)(p1_, p2_, a1, a2, a3); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -7042,40 +7820,41 @@ class _MemberResultCallback_2_3 : public ResultCallback3 { }; template -class _MemberResultCallback_2_3::value - >::type> - : public Callback3 { +class _MemberResultCallback_2_3< + del, void, T, P1, P2, A1, A2, A3, + typename c_enable_if< + is_class_or_union::value>::type> : public Callback3 { public: - typedef Callback3 base; - typedef void (T::*MemberSignature)(P1,P2,A1,A2,A3) ; + typedef Callback3 base; + typedef void (T::*MemberSignature)(P1, P2, A1, A2, A3); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; typename remove_reference::type p2_; public: - inline _MemberResultCallback_2_3( T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2) - : Callback3(), - object_(object), - member_(member), p1_(p1), p2_(p2) { } + inline _MemberResultCallback_2_3(T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2) + : Callback3(), + object_(object), + member_(member), + p1_(p1), + p2_(p2) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback3"); } - virtual void Run(A1 a1,A2 a2,A3 a3) { + virtual void Run(A1 a1, A2 a2, A3 a3) { if (!del) { - (object_->*member_)(p1_,p2_,a1,a2,a3); + (object_->*member_)(p1_, p2_, a1, a2, a3); } else { - (object_->*member_)(p1_,p2_,a1,a2,a3); + (object_->*member_)(p1_, p2_, a1, a2, a3); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -7084,26 +7863,35 @@ class _MemberResultCallback_2_3 -inline typename _MemberResultCallback_2_3::base* -NewCallback( T1* obj, R (T2::*member)(P1,P2,A1,A2,A3) , typename ConstRef::type p1, typename ConstRef::type p2) { - return new _MemberResultCallback_2_3(obj, member, p1, p2); +template +inline typename _MemberResultCallback_2_3::base* +NewCallback(T1* obj, R (T2::*member)(P1, P2, A1, A2, A3), + typename ConstRef::type p1, typename ConstRef::type p2) { + return new _MemberResultCallback_2_3( + obj, member, p1, p2); } #endif #ifndef SWIG -template -inline typename _MemberResultCallback_2_3::base* -NewPermanentCallback( T1* obj, R (T2::*member)(P1,P2,A1,A2,A3) , typename ConstRef::type p1, typename ConstRef::type p2) { - return new _MemberResultCallback_2_3(obj, member, p1, p2); +template +inline typename _MemberResultCallback_2_3::base* +NewPermanentCallback(T1* obj, R (T2::*member)(P1, P2, A1, A2, A3), + typename ConstRef::type p1, + typename ConstRef::type p2) { + return new _MemberResultCallback_2_3( + obj, member, p1, p2); } #endif template -class _FunctionResultCallback_2_3 : public ResultCallback3 { +class _FunctionResultCallback_2_3 : public ResultCallback3 { public: - typedef ResultCallback3 base; - typedef R (*FunctionSignature)(P1,P2,A1,A2,A3); + typedef ResultCallback3 base; + typedef R (*FunctionSignature)(P1, P2, A1, A2, A3); private: FunctionSignature function_; @@ -7111,24 +7899,26 @@ class _FunctionResultCallback_2_3 : public ResultCallback3 { typename remove_reference::type p2_; public: - inline _FunctionResultCallback_2_3(FunctionSignature function, typename ConstRef::type p1, typename ConstRef::type p2) - : ResultCallback3(), - function_(function), p1_(p1), p2_(p2) { } + inline _FunctionResultCallback_2_3(FunctionSignature function, + typename ConstRef::type p1, + typename ConstRef::type p2) + : ResultCallback3(), + function_(function), + p1_(p1), + p2_(p2) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback3"); } - virtual R Run(A1 a1,A2 a2,A3 a3) { + virtual R Run(A1 a1, A2 a2, A3 a3) { if (!del) { - R result = (*function_)(p1_,p2_,a1,a2,a3); + R result = (*function_)(p1_, p2_, a1, a2, a3); return result; } else { - R result = (*function_)(p1_,p2_,a1,a2,a3); + R result = (*function_)(p1_, p2_, a1, a2, a3); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -7138,10 +7928,11 @@ class _FunctionResultCallback_2_3 : public ResultCallback3 { }; template -class _FunctionResultCallback_2_3 : public Callback3 { +class _FunctionResultCallback_2_3 : public Callback3 { public: - typedef Callback3 base; - typedef void (*FunctionSignature)(P1,P2,A1,A2,A3); + typedef Callback3 base; + typedef void (*FunctionSignature)(P1, P2, A1, A2, A3); private: FunctionSignature function_; @@ -7149,23 +7940,22 @@ class _FunctionResultCallback_2_3 : public Callba typename remove_reference::type p2_; public: - inline _FunctionResultCallback_2_3(FunctionSignature function, typename ConstRef::type p1, typename ConstRef::type p2) - : Callback3(), - function_(function), p1_(p1), p2_(p2) { } + inline _FunctionResultCallback_2_3(FunctionSignature function, + typename ConstRef::type p1, + typename ConstRef::type p2) + : Callback3(), function_(function), p1_(p1), p2_(p2) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback3"); } - virtual void Run(A1 a1,A2 a2,A3 a3) { + virtual void Run(A1 a1, A2 a2, A3 a3) { if (!del) { - (*function_)(p1_,p2_,a1,a2,a3); + (*function_)(p1_, p2_, a1, a2, a3); } else { - (*function_)(p1_,p2_,a1,a2,a3); + (*function_)(p1_, p2_, a1, a2, a3); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -7174,25 +7964,29 @@ class _FunctionResultCallback_2_3 : public Callba }; template -inline typename _FunctionResultCallback_2_3::base* -NewCallback(R (*function)(P1,P2,A1,A2,A3), typename ConstRef::type p1, typename ConstRef::type p2) { - return new _FunctionResultCallback_2_3(function, p1, p2); +inline typename _FunctionResultCallback_2_3::base* +NewCallback(R (*function)(P1, P2, A1, A2, A3), typename ConstRef::type p1, + typename ConstRef::type p2) { + return new _FunctionResultCallback_2_3(function, + p1, p2); } template -inline typename _FunctionResultCallback_2_3::base* -NewPermanentCallback(R (*function)(P1,P2,A1,A2,A3), typename ConstRef::type p1, typename ConstRef::type p2) { - return new _FunctionResultCallback_2_3(function, p1, p2); +inline typename _FunctionResultCallback_2_3::base* +NewPermanentCallback(R (*function)(P1, P2, A1, A2, A3), + typename ConstRef::type p1, + typename ConstRef::type p2) { + return new _FunctionResultCallback_2_3(function, + p1, p2); } -template ::value - >::type> -class _ConstMemberResultCallback_3_3 : public ResultCallback3 { +template ::value>::type> +class _ConstMemberResultCallback_3_3 : public ResultCallback3 { public: - typedef ResultCallback3 base; - typedef R (T::*MemberSignature)(P1,P2,P3,A1,A2,A3) const; + typedef ResultCallback3 base; + typedef R (T::*MemberSignature)(P1, P2, P3, A1, A2, A3) const; private: const T* object_; @@ -7202,25 +7996,29 @@ class _ConstMemberResultCallback_3_3 : public ResultCallback3 { typename remove_reference::type p3_; public: - inline _ConstMemberResultCallback_3_3(const T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) - : ResultCallback3(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3) { } + inline _ConstMemberResultCallback_3_3(const T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3) + : ResultCallback3(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback3"); } - virtual R Run(A1 a1,A2 a2,A3 a3) { + virtual R Run(A1 a1, A2 a2, A3 a3) { if (!del) { - R result = (object_->*member_)(p1_,p2_,p3_,a1,a2,a3); + R result = (object_->*member_)(p1_, p2_, p3_, a1, a2, a3); return result; } else { - R result = (object_->*member_)(p1_,p2_,p3_,a1,a2,a3); + R result = (object_->*member_)(p1_, p2_, p3_, a1, a2, a3); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -7229,15 +8027,15 @@ class _ConstMemberResultCallback_3_3 : public ResultCallback3 { } }; -template -class _ConstMemberResultCallback_3_3::value - >::type> - : public Callback3 { +template +class _ConstMemberResultCallback_3_3< + del, void, T, P1, P2, P3, A1, A2, A3, + typename c_enable_if< + is_class_or_union::value>::type> : public Callback3 { public: - typedef Callback3 base; - typedef void (T::*MemberSignature)(P1,P2,P3,A1,A2,A3) const; + typedef Callback3 base; + typedef void (T::*MemberSignature)(P1, P2, P3, A1, A2, A3) const; private: const T* object_; @@ -7247,24 +8045,28 @@ class _ConstMemberResultCallback_3_3::type p3_; public: - inline _ConstMemberResultCallback_3_3(const T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) - : Callback3(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3) { } + inline _ConstMemberResultCallback_3_3(const T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3) + : Callback3(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback3"); } - virtual void Run(A1 a1,A2 a2,A3 a3) { + virtual void Run(A1 a1, A2 a2, A3 a3) { if (!del) { - (object_->*member_)(p1_,p2_,p3_,a1,a2,a3); + (object_->*member_)(p1_, p2_, p3_, a1, a2, a3); } else { - (object_->*member_)(p1_,p2_,p3_,a1,a2,a3); + (object_->*member_)(p1_, p2_, p3_, a1, a2, a3); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -7273,57 +8075,72 @@ class _ConstMemberResultCallback_3_3 -inline typename _ConstMemberResultCallback_3_3::base* -NewCallback(const T1* obj, R (T2::*member)(P1,P2,P3,A1,A2,A3) const, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) { - return new _ConstMemberResultCallback_3_3(obj, member, p1, p2, p3); +template +inline typename _ConstMemberResultCallback_3_3::base* +NewCallback(const T1* obj, R (T2::*member)(P1, P2, P3, A1, A2, A3) const, + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3) { + return new _ConstMemberResultCallback_3_3(obj, member, p1, p2, p3); } #endif #ifndef SWIG -template -inline typename _ConstMemberResultCallback_3_3::base* -NewPermanentCallback(const T1* obj, R (T2::*member)(P1,P2,P3,A1,A2,A3) const, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) { - return new _ConstMemberResultCallback_3_3(obj, member, p1, p2, p3); +template +inline typename _ConstMemberResultCallback_3_3::base* +NewPermanentCallback(const T1* obj, + R (T2::*member)(P1, P2, P3, A1, A2, A3) const, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3) { + return new _ConstMemberResultCallback_3_3(obj, member, p1, p2, p3); } #endif -template ::value - >::type> -class _MemberResultCallback_3_3 : public ResultCallback3 { +template ::value>::type> +class _MemberResultCallback_3_3 : public ResultCallback3 { public: - typedef ResultCallback3 base; - typedef R (T::*MemberSignature)(P1,P2,P3,A1,A2,A3) ; + typedef ResultCallback3 base; + typedef R (T::*MemberSignature)(P1, P2, P3, A1, A2, A3); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; typename remove_reference::type p2_; typename remove_reference::type p3_; public: - inline _MemberResultCallback_3_3( T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) - : ResultCallback3(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3) { } + inline _MemberResultCallback_3_3(T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3) + : ResultCallback3(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback3"); } - virtual R Run(A1 a1,A2 a2,A3 a3) { + virtual R Run(A1 a1, A2 a2, A3 a3) { if (!del) { - R result = (object_->*member_)(p1_,p2_,p3_,a1,a2,a3); + R result = (object_->*member_)(p1_, p2_, p3_, a1, a2, a3); return result; } else { - R result = (object_->*member_)(p1_,p2_,p3_,a1,a2,a3); + R result = (object_->*member_)(p1_, p2_, p3_, a1, a2, a3); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -7332,42 +8149,46 @@ class _MemberResultCallback_3_3 : public ResultCallback3 { } }; -template -class _MemberResultCallback_3_3::value - >::type> - : public Callback3 { +template +class _MemberResultCallback_3_3< + del, void, T, P1, P2, P3, A1, A2, A3, + typename c_enable_if< + is_class_or_union::value>::type> : public Callback3 { public: - typedef Callback3 base; - typedef void (T::*MemberSignature)(P1,P2,P3,A1,A2,A3) ; + typedef Callback3 base; + typedef void (T::*MemberSignature)(P1, P2, P3, A1, A2, A3); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; typename remove_reference::type p2_; typename remove_reference::type p3_; public: - inline _MemberResultCallback_3_3( T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) - : Callback3(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3) { } + inline _MemberResultCallback_3_3(T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3) + : Callback3(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback3"); } - virtual void Run(A1 a1,A2 a2,A3 a3) { + virtual void Run(A1 a1, A2 a2, A3 a3) { if (!del) { - (object_->*member_)(p1_,p2_,p3_,a1,a2,a3); + (object_->*member_)(p1_, p2_, p3_, a1, a2, a3); } else { - (object_->*member_)(p1_,p2_,p3_,a1,a2,a3); + (object_->*member_)(p1_, p2_, p3_, a1, a2, a3); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -7376,26 +8197,38 @@ class _MemberResultCallback_3_3 -inline typename _MemberResultCallback_3_3::base* -NewCallback( T1* obj, R (T2::*member)(P1,P2,P3,A1,A2,A3) , typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) { - return new _MemberResultCallback_3_3(obj, member, p1, p2, p3); +template +inline typename _MemberResultCallback_3_3::base* +NewCallback(T1* obj, R (T2::*member)(P1, P2, P3, A1, A2, A3), + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3) { + return new _MemberResultCallback_3_3( + obj, member, p1, p2, p3); } #endif #ifndef SWIG -template -inline typename _MemberResultCallback_3_3::base* -NewPermanentCallback( T1* obj, R (T2::*member)(P1,P2,P3,A1,A2,A3) , typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) { - return new _MemberResultCallback_3_3(obj, member, p1, p2, p3); +template +inline typename _MemberResultCallback_3_3::base* +NewPermanentCallback(T1* obj, R (T2::*member)(P1, P2, P3, A1, A2, A3), + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3) { + return new _MemberResultCallback_3_3( + obj, member, p1, p2, p3); } #endif -template -class _FunctionResultCallback_3_3 : public ResultCallback3 { +template +class _FunctionResultCallback_3_3 : public ResultCallback3 { public: - typedef ResultCallback3 base; - typedef R (*FunctionSignature)(P1,P2,P3,A1,A2,A3); + typedef ResultCallback3 base; + typedef R (*FunctionSignature)(P1, P2, P3, A1, A2, A3); private: FunctionSignature function_; @@ -7404,24 +8237,28 @@ class _FunctionResultCallback_3_3 : public ResultCallback3 { typename remove_reference::type p3_; public: - inline _FunctionResultCallback_3_3(FunctionSignature function, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) - : ResultCallback3(), - function_(function), p1_(p1), p2_(p2), p3_(p3) { } + inline _FunctionResultCallback_3_3(FunctionSignature function, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3) + : ResultCallback3(), + function_(function), + p1_(p1), + p2_(p2), + p3_(p3) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback3"); } - virtual R Run(A1 a1,A2 a2,A3 a3) { + virtual R Run(A1 a1, A2 a2, A3 a3) { if (!del) { - R result = (*function_)(p1_,p2_,p3_,a1,a2,a3); + R result = (*function_)(p1_, p2_, p3_, a1, a2, a3); return result; } else { - R result = (*function_)(p1_,p2_,p3_,a1,a2,a3); + R result = (*function_)(p1_, p2_, p3_, a1, a2, a3); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -7431,10 +8268,11 @@ class _FunctionResultCallback_3_3 : public ResultCallback3 { }; template -class _FunctionResultCallback_3_3 : public Callback3 { +class _FunctionResultCallback_3_3 : public Callback3 { public: - typedef Callback3 base; - typedef void (*FunctionSignature)(P1,P2,P3,A1,A2,A3); + typedef Callback3 base; + typedef void (*FunctionSignature)(P1, P2, P3, A1, A2, A3); private: FunctionSignature function_; @@ -7443,23 +8281,27 @@ class _FunctionResultCallback_3_3 : public Ca typename remove_reference::type p3_; public: - inline _FunctionResultCallback_3_3(FunctionSignature function, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) - : Callback3(), - function_(function), p1_(p1), p2_(p2), p3_(p3) { } + inline _FunctionResultCallback_3_3(FunctionSignature function, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3) + : Callback3(), + function_(function), + p1_(p1), + p2_(p2), + p3_(p3) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback3"); } - virtual void Run(A1 a1,A2 a2,A3 a3) { + virtual void Run(A1 a1, A2 a2, A3 a3) { if (!del) { - (*function_)(p1_,p2_,p3_,a1,a2,a3); + (*function_)(p1_, p2_, p3_, a1, a2, a3); } else { - (*function_)(p1_,p2_,p3_,a1,a2,a3); + (*function_)(p1_, p2_, p3_, a1, a2, a3); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -7468,25 +8310,33 @@ class _FunctionResultCallback_3_3 : public Ca }; template -inline typename _FunctionResultCallback_3_3::base* -NewCallback(R (*function)(P1,P2,P3,A1,A2,A3), typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) { - return new _FunctionResultCallback_3_3(function, p1, p2, p3); +inline typename _FunctionResultCallback_3_3::base* +NewCallback(R (*function)(P1, P2, P3, A1, A2, A3), + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3) { + return new _FunctionResultCallback_3_3( + function, p1, p2, p3); } template -inline typename _FunctionResultCallback_3_3::base* -NewPermanentCallback(R (*function)(P1,P2,P3,A1,A2,A3), typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) { - return new _FunctionResultCallback_3_3(function, p1, p2, p3); +inline typename _FunctionResultCallback_3_3::base* +NewPermanentCallback(R (*function)(P1, P2, P3, A1, A2, A3), + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3) { + return new _FunctionResultCallback_3_3( + function, p1, p2, p3); } -template ::value - >::type> -class _ConstMemberResultCallback_4_3 : public ResultCallback3 { +template ::value>::type> +class _ConstMemberResultCallback_4_3 : public ResultCallback3 { public: - typedef ResultCallback3 base; - typedef R (T::*MemberSignature)(P1,P2,P3,P4,A1,A2,A3) const; + typedef ResultCallback3 base; + typedef R (T::*MemberSignature)(P1, P2, P3, P4, A1, A2, A3) const; private: const T* object_; @@ -7497,25 +8347,31 @@ class _ConstMemberResultCallback_4_3 : public ResultCallback3 { typename remove_reference::type p4_; public: - inline _ConstMemberResultCallback_4_3(const T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) - : ResultCallback3(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4) { } + inline _ConstMemberResultCallback_4_3(const T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4) + : ResultCallback3(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback3"); } - virtual R Run(A1 a1,A2 a2,A3 a3) { + virtual R Run(A1 a1, A2 a2, A3 a3) { if (!del) { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,a1,a2,a3); + R result = (object_->*member_)(p1_, p2_, p3_, p4_, a1, a2, a3); return result; } else { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,a1,a2,a3); + R result = (object_->*member_)(p1_, p2_, p3_, p4_, a1, a2, a3); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -7524,15 +8380,15 @@ class _ConstMemberResultCallback_4_3 : public ResultCallback3 { } }; -template -class _ConstMemberResultCallback_4_3::value - >::type> - : public Callback3 { +template +class _ConstMemberResultCallback_4_3< + del, void, T, P1, P2, P3, P4, A1, A2, A3, + typename c_enable_if< + is_class_or_union::value>::type> : public Callback3 { public: - typedef Callback3 base; - typedef void (T::*MemberSignature)(P1,P2,P3,P4,A1,A2,A3) const; + typedef Callback3 base; + typedef void (T::*MemberSignature)(P1, P2, P3, P4, A1, A2, A3) const; private: const T* object_; @@ -7543,24 +8399,30 @@ class _ConstMemberResultCallback_4_3::type p4_; public: - inline _ConstMemberResultCallback_4_3(const T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) - : Callback3(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4) { } + inline _ConstMemberResultCallback_4_3(const T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4) + : Callback3(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback3"); } - virtual void Run(A1 a1,A2 a2,A3 a3) { + virtual void Run(A1 a1, A2 a2, A3 a3) { if (!del) { - (object_->*member_)(p1_,p2_,p3_,p4_,a1,a2,a3); + (object_->*member_)(p1_, p2_, p3_, p4_, a1, a2, a3); } else { - (object_->*member_)(p1_,p2_,p3_,p4_,a1,a2,a3); + (object_->*member_)(p1_, p2_, p3_, p4_, a1, a2, a3); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -7569,32 +8431,44 @@ class _ConstMemberResultCallback_4_3 -inline typename _ConstMemberResultCallback_4_3::base* -NewCallback(const T1* obj, R (T2::*member)(P1,P2,P3,P4,A1,A2,A3) const, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) { - return new _ConstMemberResultCallback_4_3(obj, member, p1, p2, p3, p4); +template +inline typename _ConstMemberResultCallback_4_3::base* +NewCallback(const T1* obj, R (T2::*member)(P1, P2, P3, P4, A1, A2, A3) const, + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3, typename ConstRef::type p4) { + return new _ConstMemberResultCallback_4_3(obj, member, p1, p2, p3, p4); } #endif #ifndef SWIG -template -inline typename _ConstMemberResultCallback_4_3::base* -NewPermanentCallback(const T1* obj, R (T2::*member)(P1,P2,P3,P4,A1,A2,A3) const, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) { - return new _ConstMemberResultCallback_4_3(obj, member, p1, p2, p3, p4); +template +inline typename _ConstMemberResultCallback_4_3::base* +NewPermanentCallback(const T1* obj, + R (T2::*member)(P1, P2, P3, P4, A1, A2, A3) const, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4) { + return new _ConstMemberResultCallback_4_3< + false, R, T1, P1, P2, P3, P4, A1, A2, A3>(obj, member, p1, p2, p3, p4); } #endif -template ::value - >::type> -class _MemberResultCallback_4_3 : public ResultCallback3 { +template ::value>::type> +class _MemberResultCallback_4_3 : public ResultCallback3 { public: - typedef ResultCallback3 base; - typedef R (T::*MemberSignature)(P1,P2,P3,P4,A1,A2,A3) ; + typedef ResultCallback3 base; + typedef R (T::*MemberSignature)(P1, P2, P3, P4, A1, A2, A3); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; typename remove_reference::type p2_; @@ -7602,25 +8476,31 @@ class _MemberResultCallback_4_3 : public ResultCallback3 { typename remove_reference::type p4_; public: - inline _MemberResultCallback_4_3( T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) - : ResultCallback3(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4) { } + inline _MemberResultCallback_4_3(T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4) + : ResultCallback3(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback3"); } - virtual R Run(A1 a1,A2 a2,A3 a3) { + virtual R Run(A1 a1, A2 a2, A3 a3) { if (!del) { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,a1,a2,a3); + R result = (object_->*member_)(p1_, p2_, p3_, p4_, a1, a2, a3); return result; } else { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,a1,a2,a3); + R result = (object_->*member_)(p1_, p2_, p3_, p4_, a1, a2, a3); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -7629,18 +8509,18 @@ class _MemberResultCallback_4_3 : public ResultCallback3 { } }; -template -class _MemberResultCallback_4_3::value - >::type> - : public Callback3 { +template +class _MemberResultCallback_4_3< + del, void, T, P1, P2, P3, P4, A1, A2, A3, + typename c_enable_if< + is_class_or_union::value>::type> : public Callback3 { public: - typedef Callback3 base; - typedef void (T::*MemberSignature)(P1,P2,P3,P4,A1,A2,A3) ; + typedef Callback3 base; + typedef void (T::*MemberSignature)(P1, P2, P3, P4, A1, A2, A3); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; typename remove_reference::type p2_; @@ -7648,24 +8528,30 @@ class _MemberResultCallback_4_3::type p4_; public: - inline _MemberResultCallback_4_3( T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) - : Callback3(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4) { } + inline _MemberResultCallback_4_3(T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4) + : Callback3(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback3"); } - virtual void Run(A1 a1,A2 a2,A3 a3) { + virtual void Run(A1 a1, A2 a2, A3 a3) { if (!del) { - (object_->*member_)(p1_,p2_,p3_,p4_,a1,a2,a3); + (object_->*member_)(p1_, p2_, p3_, p4_, a1, a2, a3); } else { - (object_->*member_)(p1_,p2_,p3_,p4_,a1,a2,a3); + (object_->*member_)(p1_, p2_, p3_, p4_, a1, a2, a3); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -7674,26 +8560,39 @@ class _MemberResultCallback_4_3 -inline typename _MemberResultCallback_4_3::base* -NewCallback( T1* obj, R (T2::*member)(P1,P2,P3,P4,A1,A2,A3) , typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) { - return new _MemberResultCallback_4_3(obj, member, p1, p2, p3, p4); +template +inline typename _MemberResultCallback_4_3::base* +NewCallback(T1* obj, R (T2::*member)(P1, P2, P3, P4, A1, A2, A3), + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3, typename ConstRef::type p4) { + return new _MemberResultCallback_4_3( + obj, member, p1, p2, p3, p4); } #endif #ifndef SWIG -template -inline typename _MemberResultCallback_4_3::base* -NewPermanentCallback( T1* obj, R (T2::*member)(P1,P2,P3,P4,A1,A2,A3) , typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) { - return new _MemberResultCallback_4_3(obj, member, p1, p2, p3, p4); +template +inline typename _MemberResultCallback_4_3::base* +NewPermanentCallback(T1* obj, R (T2::*member)(P1, P2, P3, P4, A1, A2, A3), + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4) { + return new _MemberResultCallback_4_3(obj, member, p1, p2, p3, p4); } #endif -template -class _FunctionResultCallback_4_3 : public ResultCallback3 { +template +class _FunctionResultCallback_4_3 : public ResultCallback3 { public: - typedef ResultCallback3 base; - typedef R (*FunctionSignature)(P1,P2,P3,P4,A1,A2,A3); + typedef ResultCallback3 base; + typedef R (*FunctionSignature)(P1, P2, P3, P4, A1, A2, A3); private: FunctionSignature function_; @@ -7703,24 +8602,30 @@ class _FunctionResultCallback_4_3 : public ResultCallback3 { typename remove_reference::type p4_; public: - inline _FunctionResultCallback_4_3(FunctionSignature function, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) - : ResultCallback3(), - function_(function), p1_(p1), p2_(p2), p3_(p3), p4_(p4) { } + inline _FunctionResultCallback_4_3(FunctionSignature function, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4) + : ResultCallback3(), + function_(function), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback3"); } - virtual R Run(A1 a1,A2 a2,A3 a3) { + virtual R Run(A1 a1, A2 a2, A3 a3) { if (!del) { - R result = (*function_)(p1_,p2_,p3_,p4_,a1,a2,a3); + R result = (*function_)(p1_, p2_, p3_, p4_, a1, a2, a3); return result; } else { - R result = (*function_)(p1_,p2_,p3_,p4_,a1,a2,a3); + R result = (*function_)(p1_, p2_, p3_, p4_, a1, a2, a3); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -7729,11 +8634,13 @@ class _FunctionResultCallback_4_3 : public ResultCallback3 { } }; -template -class _FunctionResultCallback_4_3 : public Callback3 { +template +class _FunctionResultCallback_4_3 : public Callback3 { public: - typedef Callback3 base; - typedef void (*FunctionSignature)(P1,P2,P3,P4,A1,A2,A3); + typedef Callback3 base; + typedef void (*FunctionSignature)(P1, P2, P3, P4, A1, A2, A3); private: FunctionSignature function_; @@ -7743,23 +8650,29 @@ class _FunctionResultCallback_4_3 : publi typename remove_reference::type p4_; public: - inline _FunctionResultCallback_4_3(FunctionSignature function, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) - : Callback3(), - function_(function), p1_(p1), p2_(p2), p3_(p3), p4_(p4) { } + inline _FunctionResultCallback_4_3(FunctionSignature function, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4) + : Callback3(), + function_(function), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback3"); } - virtual void Run(A1 a1,A2 a2,A3 a3) { + virtual void Run(A1 a1, A2 a2, A3 a3) { if (!del) { - (*function_)(p1_,p2_,p3_,p4_,a1,a2,a3); + (*function_)(p1_, p2_, p3_, p4_, a1, a2, a3); } else { - (*function_)(p1_,p2_,p3_,p4_,a1,a2,a3); + (*function_)(p1_, p2_, p3_, p4_, a1, a2, a3); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -7767,26 +8680,38 @@ class _FunctionResultCallback_4_3 : publi } }; -template -inline typename _FunctionResultCallback_4_3::base* -NewCallback(R (*function)(P1,P2,P3,P4,A1,A2,A3), typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) { - return new _FunctionResultCallback_4_3(function, p1, p2, p3, p4); +template +inline typename _FunctionResultCallback_4_3::base* +NewCallback(R (*function)(P1, P2, P3, P4, A1, A2, A3), + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3, typename ConstRef::type p4) { + return new _FunctionResultCallback_4_3( + function, p1, p2, p3, p4); } -template -inline typename _FunctionResultCallback_4_3::base* -NewPermanentCallback(R (*function)(P1,P2,P3,P4,A1,A2,A3), typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) { - return new _FunctionResultCallback_4_3(function, p1, p2, p3, p4); +template +inline typename _FunctionResultCallback_4_3::base* +NewPermanentCallback(R (*function)(P1, P2, P3, P4, A1, A2, A3), + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4) { + return new _FunctionResultCallback_4_3( + function, p1, p2, p3, p4); } -template ::value - >::type> -class _ConstMemberResultCallback_5_3 : public ResultCallback3 { +template < + bool del, class R, class T, class P1, class P2, class P3, class P4, + class P5, class A1, class A2, class A3, + class OnlyIf = typename c_enable_if::value>::type> +class _ConstMemberResultCallback_5_3 : public ResultCallback3 { public: - typedef ResultCallback3 base; - typedef R (T::*MemberSignature)(P1,P2,P3,P4,P5,A1,A2,A3) const; + typedef ResultCallback3 base; + typedef R (T::*MemberSignature)(P1, P2, P3, P4, P5, A1, A2, A3) const; private: const T* object_; @@ -7798,25 +8723,33 @@ class _ConstMemberResultCallback_5_3 : public ResultCallback3 { typename remove_reference::type p5_; public: - inline _ConstMemberResultCallback_5_3(const T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) - : ResultCallback3(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5) { } + inline _ConstMemberResultCallback_5_3(const T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5) + : ResultCallback3(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback3"); } - virtual R Run(A1 a1,A2 a2,A3 a3) { + virtual R Run(A1 a1, A2 a2, A3 a3) { if (!del) { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,p5_,a1,a2,a3); + R result = (object_->*member_)(p1_, p2_, p3_, p4_, p5_, a1, a2, a3); return result; } else { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,p5_,a1,a2,a3); + R result = (object_->*member_)(p1_, p2_, p3_, p4_, p5_, a1, a2, a3); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -7825,15 +8758,15 @@ class _ConstMemberResultCallback_5_3 : public ResultCallback3 { } }; -template -class _ConstMemberResultCallback_5_3::value - >::type> - : public Callback3 { +template +class _ConstMemberResultCallback_5_3< + del, void, T, P1, P2, P3, P4, P5, A1, A2, A3, + typename c_enable_if< + is_class_or_union::value>::type> : public Callback3 { public: - typedef Callback3 base; - typedef void (T::*MemberSignature)(P1,P2,P3,P4,P5,A1,A2,A3) const; + typedef Callback3 base; + typedef void (T::*MemberSignature)(P1, P2, P3, P4, P5, A1, A2, A3) const; private: const T* object_; @@ -7845,24 +8778,32 @@ class _ConstMemberResultCallback_5_3::type p5_; public: - inline _ConstMemberResultCallback_5_3(const T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) - : Callback3(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5) { } + inline _ConstMemberResultCallback_5_3(const T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5) + : Callback3(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback3"); } - virtual void Run(A1 a1,A2 a2,A3 a3) { + virtual void Run(A1 a1, A2 a2, A3 a3) { if (!del) { - (object_->*member_)(p1_,p2_,p3_,p4_,p5_,a1,a2,a3); + (object_->*member_)(p1_, p2_, p3_, p4_, p5_, a1, a2, a3); } else { - (object_->*member_)(p1_,p2_,p3_,p4_,p5_,a1,a2,a3); + (object_->*member_)(p1_, p2_, p3_, p4_, p5_, a1, a2, a3); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -7871,32 +8812,50 @@ class _ConstMemberResultCallback_5_3 -inline typename _ConstMemberResultCallback_5_3::base* -NewCallback(const T1* obj, R (T2::*member)(P1,P2,P3,P4,P5,A1,A2,A3) const, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) { - return new _ConstMemberResultCallback_5_3(obj, member, p1, p2, p3, p4, p5); +template +inline typename _ConstMemberResultCallback_5_3::base* +NewCallback(const T1* obj, + R (T2::*member)(P1, P2, P3, P4, P5, A1, A2, A3) const, + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3, typename ConstRef::type p4, + typename ConstRef::type p5) { + return new _ConstMemberResultCallback_5_3(obj, member, p1, p2, p3, p4, + p5); } #endif #ifndef SWIG -template -inline typename _ConstMemberResultCallback_5_3::base* -NewPermanentCallback(const T1* obj, R (T2::*member)(P1,P2,P3,P4,P5,A1,A2,A3) const, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) { - return new _ConstMemberResultCallback_5_3(obj, member, p1, p2, p3, p4, p5); +template +inline typename _ConstMemberResultCallback_5_3::base* +NewPermanentCallback(const T1* obj, + R (T2::*member)(P1, P2, P3, P4, P5, A1, A2, A3) const, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5) { + return new _ConstMemberResultCallback_5_3< + false, R, T1, P1, P2, P3, P4, P5, A1, A2, A3>(obj, member, p1, p2, p3, p4, + p5); } #endif -template ::value - >::type> -class _MemberResultCallback_5_3 : public ResultCallback3 { +template < + bool del, class R, class T, class P1, class P2, class P3, class P4, + class P5, class A1, class A2, class A3, + class OnlyIf = typename c_enable_if::value>::type> +class _MemberResultCallback_5_3 : public ResultCallback3 { public: - typedef ResultCallback3 base; - typedef R (T::*MemberSignature)(P1,P2,P3,P4,P5,A1,A2,A3) ; + typedef ResultCallback3 base; + typedef R (T::*MemberSignature)(P1, P2, P3, P4, P5, A1, A2, A3); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; typename remove_reference::type p2_; @@ -7905,25 +8864,33 @@ class _MemberResultCallback_5_3 : public ResultCallback3 { typename remove_reference::type p5_; public: - inline _MemberResultCallback_5_3( T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) - : ResultCallback3(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5) { } + inline _MemberResultCallback_5_3(T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5) + : ResultCallback3(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback3"); } - virtual R Run(A1 a1,A2 a2,A3 a3) { + virtual R Run(A1 a1, A2 a2, A3 a3) { if (!del) { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,p5_,a1,a2,a3); + R result = (object_->*member_)(p1_, p2_, p3_, p4_, p5_, a1, a2, a3); return result; } else { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,p5_,a1,a2,a3); + R result = (object_->*member_)(p1_, p2_, p3_, p4_, p5_, a1, a2, a3); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -7932,18 +8899,18 @@ class _MemberResultCallback_5_3 : public ResultCallback3 { } }; -template -class _MemberResultCallback_5_3::value - >::type> - : public Callback3 { +template +class _MemberResultCallback_5_3< + del, void, T, P1, P2, P3, P4, P5, A1, A2, A3, + typename c_enable_if< + is_class_or_union::value>::type> : public Callback3 { public: - typedef Callback3 base; - typedef void (T::*MemberSignature)(P1,P2,P3,P4,P5,A1,A2,A3) ; + typedef Callback3 base; + typedef void (T::*MemberSignature)(P1, P2, P3, P4, P5, A1, A2, A3); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; typename remove_reference::type p2_; @@ -7952,24 +8919,32 @@ class _MemberResultCallback_5_3::type p5_; public: - inline _MemberResultCallback_5_3( T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) - : Callback3(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5) { } + inline _MemberResultCallback_5_3(T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5) + : Callback3(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback3"); } - virtual void Run(A1 a1,A2 a2,A3 a3) { + virtual void Run(A1 a1, A2 a2, A3 a3) { if (!del) { - (object_->*member_)(p1_,p2_,p3_,p4_,p5_,a1,a2,a3); + (object_->*member_)(p1_, p2_, p3_, p4_, p5_, a1, a2, a3); } else { - (object_->*member_)(p1_,p2_,p3_,p4_,p5_,a1,a2,a3); + (object_->*member_)(p1_, p2_, p3_, p4_, p5_, a1, a2, a3); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -7978,26 +8953,41 @@ class _MemberResultCallback_5_3 -inline typename _MemberResultCallback_5_3::base* -NewCallback( T1* obj, R (T2::*member)(P1,P2,P3,P4,P5,A1,A2,A3) , typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) { - return new _MemberResultCallback_5_3(obj, member, p1, p2, p3, p4, p5); +template +inline typename _MemberResultCallback_5_3::base* +NewCallback(T1* obj, R (T2::*member)(P1, P2, P3, P4, P5, A1, A2, A3), + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3, typename ConstRef::type p4, + typename ConstRef::type p5) { + return new _MemberResultCallback_5_3(obj, member, p1, p2, p3, p4, p5); } #endif #ifndef SWIG -template -inline typename _MemberResultCallback_5_3::base* -NewPermanentCallback( T1* obj, R (T2::*member)(P1,P2,P3,P4,P5,A1,A2,A3) , typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) { - return new _MemberResultCallback_5_3(obj, member, p1, p2, p3, p4, p5); +template +inline typename _MemberResultCallback_5_3::base* +NewPermanentCallback(T1* obj, R (T2::*member)(P1, P2, P3, P4, P5, A1, A2, A3), + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5) { + return new _MemberResultCallback_5_3(obj, member, p1, p2, p3, p4, p5); } #endif -template -class _FunctionResultCallback_5_3 : public ResultCallback3 { +template +class _FunctionResultCallback_5_3 : public ResultCallback3 { public: - typedef ResultCallback3 base; - typedef R (*FunctionSignature)(P1,P2,P3,P4,P5,A1,A2,A3); + typedef ResultCallback3 base; + typedef R (*FunctionSignature)(P1, P2, P3, P4, P5, A1, A2, A3); private: FunctionSignature function_; @@ -8008,24 +8998,32 @@ class _FunctionResultCallback_5_3 : public ResultCallback3 { typename remove_reference::type p5_; public: - inline _FunctionResultCallback_5_3(FunctionSignature function, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) - : ResultCallback3(), - function_(function), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5) { } + inline _FunctionResultCallback_5_3(FunctionSignature function, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5) + : ResultCallback3(), + function_(function), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback3"); } - virtual R Run(A1 a1,A2 a2,A3 a3) { + virtual R Run(A1 a1, A2 a2, A3 a3) { if (!del) { - R result = (*function_)(p1_,p2_,p3_,p4_,p5_,a1,a2,a3); + R result = (*function_)(p1_, p2_, p3_, p4_, p5_, a1, a2, a3); return result; } else { - R result = (*function_)(p1_,p2_,p3_,p4_,p5_,a1,a2,a3); + R result = (*function_)(p1_, p2_, p3_, p4_, p5_, a1, a2, a3); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -8034,11 +9032,13 @@ class _FunctionResultCallback_5_3 : public ResultCallback3 { } }; -template -class _FunctionResultCallback_5_3 : public Callback3 { +template +class _FunctionResultCallback_5_3 : public Callback3 { public: - typedef Callback3 base; - typedef void (*FunctionSignature)(P1,P2,P3,P4,P5,A1,A2,A3); + typedef Callback3 base; + typedef void (*FunctionSignature)(P1, P2, P3, P4, P5, A1, A2, A3); private: FunctionSignature function_; @@ -8049,23 +9049,31 @@ class _FunctionResultCallback_5_3 : p typename remove_reference::type p5_; public: - inline _FunctionResultCallback_5_3(FunctionSignature function, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) - : Callback3(), - function_(function), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5) { } + inline _FunctionResultCallback_5_3(FunctionSignature function, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5) + : Callback3(), + function_(function), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback3"); } - virtual void Run(A1 a1,A2 a2,A3 a3) { + virtual void Run(A1 a1, A2 a2, A3 a3) { if (!del) { - (*function_)(p1_,p2_,p3_,p4_,p5_,a1,a2,a3); + (*function_)(p1_, p2_, p3_, p4_, p5_, a1, a2, a3); } else { - (*function_)(p1_,p2_,p3_,p4_,p5_,a1,a2,a3); + (*function_)(p1_, p2_, p3_, p4_, p5_, a1, a2, a3); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -8073,26 +9081,40 @@ class _FunctionResultCallback_5_3 : p } }; -template -inline typename _FunctionResultCallback_5_3::base* -NewCallback(R (*function)(P1,P2,P3,P4,P5,A1,A2,A3), typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) { - return new _FunctionResultCallback_5_3(function, p1, p2, p3, p4, p5); +template +inline typename _FunctionResultCallback_5_3::base* +NewCallback(R (*function)(P1, P2, P3, P4, P5, A1, A2, A3), + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3, typename ConstRef::type p4, + typename ConstRef::type p5) { + return new _FunctionResultCallback_5_3(function, p1, p2, p3, p4, p5); } -template -inline typename _FunctionResultCallback_5_3::base* -NewPermanentCallback(R (*function)(P1,P2,P3,P4,P5,A1,A2,A3), typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) { - return new _FunctionResultCallback_5_3(function, p1, p2, p3, p4, p5); +template +inline typename _FunctionResultCallback_5_3::base* +NewPermanentCallback(R (*function)(P1, P2, P3, P4, P5, A1, A2, A3), + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5) { + return new _FunctionResultCallback_5_3(function, p1, p2, p3, p4, p5); } -template ::value - >::type> -class _ConstMemberResultCallback_6_3 : public ResultCallback3 { +template < + bool del, class R, class T, class P1, class P2, class P3, class P4, + class P5, class P6, class A1, class A2, class A3, + class OnlyIf = typename c_enable_if::value>::type> +class _ConstMemberResultCallback_6_3 : public ResultCallback3 { public: - typedef ResultCallback3 base; - typedef R (T::*MemberSignature)(P1,P2,P3,P4,P5,P6,A1,A2,A3) const; + typedef ResultCallback3 base; + typedef R (T::*MemberSignature)(P1, P2, P3, P4, P5, P6, A1, A2, A3) const; private: const T* object_; @@ -8105,25 +9127,35 @@ class _ConstMemberResultCallback_6_3 : public ResultCallback3 { typename remove_reference::type p6_; public: - inline _ConstMemberResultCallback_6_3(const T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) - : ResultCallback3(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5), p6_(p6) { } + inline _ConstMemberResultCallback_6_3(const T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5, + typename ConstRef::type p6) + : ResultCallback3(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5), + p6_(p6) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback3"); } - virtual R Run(A1 a1,A2 a2,A3 a3) { + virtual R Run(A1 a1, A2 a2, A3 a3) { if (!del) { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,p5_,p6_,a1,a2,a3); + R result = (object_->*member_)(p1_, p2_, p3_, p4_, p5_, p6_, a1, a2, a3); return result; } else { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,p5_,p6_,a1,a2,a3); + R result = (object_->*member_)(p1_, p2_, p3_, p4_, p5_, p6_, a1, a2, a3); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -8132,15 +9164,15 @@ class _ConstMemberResultCallback_6_3 : public ResultCallback3 { } }; -template -class _ConstMemberResultCallback_6_3::value - >::type> - : public Callback3 { +template +class _ConstMemberResultCallback_6_3< + del, void, T, P1, P2, P3, P4, P5, P6, A1, A2, A3, + typename c_enable_if< + is_class_or_union::value>::type> : public Callback3 { public: - typedef Callback3 base; - typedef void (T::*MemberSignature)(P1,P2,P3,P4,P5,P6,A1,A2,A3) const; + typedef Callback3 base; + typedef void (T::*MemberSignature)(P1, P2, P3, P4, P5, P6, A1, A2, A3) const; private: const T* object_; @@ -8153,24 +9185,34 @@ class _ConstMemberResultCallback_6_3::type p6_; public: - inline _ConstMemberResultCallback_6_3(const T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) - : Callback3(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5), p6_(p6) { } + inline _ConstMemberResultCallback_6_3(const T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5, + typename ConstRef::type p6) + : Callback3(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5), + p6_(p6) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback3"); } - virtual void Run(A1 a1,A2 a2,A3 a3) { + virtual void Run(A1 a1, A2 a2, A3 a3) { if (!del) { - (object_->*member_)(p1_,p2_,p3_,p4_,p5_,p6_,a1,a2,a3); + (object_->*member_)(p1_, p2_, p3_, p4_, p5_, p6_, a1, a2, a3); } else { - (object_->*member_)(p1_,p2_,p3_,p4_,p5_,p6_,a1,a2,a3); + (object_->*member_)(p1_, p2_, p3_, p4_, p5_, p6_, a1, a2, a3); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -8179,32 +9221,48 @@ class _ConstMemberResultCallback_6_3 -inline typename _ConstMemberResultCallback_6_3::base* -NewCallback(const T1* obj, R (T2::*member)(P1,P2,P3,P4,P5,P6,A1,A2,A3) const, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) { - return new _ConstMemberResultCallback_6_3(obj, member, p1, p2, p3, p4, p5, p6); +template +inline typename _ConstMemberResultCallback_6_3::base* +NewCallback(const T1* obj, + R (T2::*member)(P1, P2, P3, P4, P5, P6, A1, A2, A3) const, + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3, typename ConstRef::type p4, + typename ConstRef::type p5, typename ConstRef::type p6) { + return new _ConstMemberResultCallback_6_3(obj, member, p1, p2, p3, + p4, p5, p6); } #endif #ifndef SWIG -template -inline typename _ConstMemberResultCallback_6_3::base* -NewPermanentCallback(const T1* obj, R (T2::*member)(P1,P2,P3,P4,P5,P6,A1,A2,A3) const, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) { - return new _ConstMemberResultCallback_6_3(obj, member, p1, p2, p3, p4, p5, p6); +template +inline typename _ConstMemberResultCallback_6_3::base* +NewPermanentCallback( + const T1* obj, R (T2::*member)(P1, P2, P3, P4, P5, P6, A1, A2, A3) const, + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3, typename ConstRef::type p4, + typename ConstRef::type p5, typename ConstRef::type p6) { + return new _ConstMemberResultCallback_6_3< + false, R, T1, P1, P2, P3, P4, P5, P6, A1, A2, A3>(obj, member, p1, p2, p3, + p4, p5, p6); } #endif -template ::value - >::type> -class _MemberResultCallback_6_3 : public ResultCallback3 { +template < + bool del, class R, class T, class P1, class P2, class P3, class P4, + class P5, class P6, class A1, class A2, class A3, + class OnlyIf = typename c_enable_if::value>::type> +class _MemberResultCallback_6_3 : public ResultCallback3 { public: - typedef ResultCallback3 base; - typedef R (T::*MemberSignature)(P1,P2,P3,P4,P5,P6,A1,A2,A3) ; + typedef ResultCallback3 base; + typedef R (T::*MemberSignature)(P1, P2, P3, P4, P5, P6, A1, A2, A3); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; typename remove_reference::type p2_; @@ -8214,25 +9272,35 @@ class _MemberResultCallback_6_3 : public ResultCallback3 { typename remove_reference::type p6_; public: - inline _MemberResultCallback_6_3( T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) - : ResultCallback3(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5), p6_(p6) { } + inline _MemberResultCallback_6_3(T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5, + typename ConstRef::type p6) + : ResultCallback3(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5), + p6_(p6) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback3"); } - virtual R Run(A1 a1,A2 a2,A3 a3) { + virtual R Run(A1 a1, A2 a2, A3 a3) { if (!del) { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,p5_,p6_,a1,a2,a3); + R result = (object_->*member_)(p1_, p2_, p3_, p4_, p5_, p6_, a1, a2, a3); return result; } else { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,p5_,p6_,a1,a2,a3); + R result = (object_->*member_)(p1_, p2_, p3_, p4_, p5_, p6_, a1, a2, a3); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -8241,18 +9309,18 @@ class _MemberResultCallback_6_3 : public ResultCallback3 { } }; -template -class _MemberResultCallback_6_3::value - >::type> - : public Callback3 { +template +class _MemberResultCallback_6_3< + del, void, T, P1, P2, P3, P4, P5, P6, A1, A2, A3, + typename c_enable_if< + is_class_or_union::value>::type> : public Callback3 { public: - typedef Callback3 base; - typedef void (T::*MemberSignature)(P1,P2,P3,P4,P5,P6,A1,A2,A3) ; + typedef Callback3 base; + typedef void (T::*MemberSignature)(P1, P2, P3, P4, P5, P6, A1, A2, A3); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; typename remove_reference::type p2_; @@ -8262,24 +9330,34 @@ class _MemberResultCallback_6_3::type p6_; public: - inline _MemberResultCallback_6_3( T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) - : Callback3(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5), p6_(p6) { } + inline _MemberResultCallback_6_3(T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5, + typename ConstRef::type p6) + : Callback3(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5), + p6_(p6) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback3"); } - virtual void Run(A1 a1,A2 a2,A3 a3) { + virtual void Run(A1 a1, A2 a2, A3 a3) { if (!del) { - (object_->*member_)(p1_,p2_,p3_,p4_,p5_,p6_,a1,a2,a3); + (object_->*member_)(p1_, p2_, p3_, p4_, p5_, p6_, a1, a2, a3); } else { - (object_->*member_)(p1_,p2_,p3_,p4_,p5_,p6_,a1,a2,a3); + (object_->*member_)(p1_, p2_, p3_, p4_, p5_, p6_, a1, a2, a3); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -8288,26 +9366,42 @@ class _MemberResultCallback_6_3 -inline typename _MemberResultCallback_6_3::base* -NewCallback( T1* obj, R (T2::*member)(P1,P2,P3,P4,P5,P6,A1,A2,A3) , typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) { - return new _MemberResultCallback_6_3(obj, member, p1, p2, p3, p4, p5, p6); +template +inline typename _MemberResultCallback_6_3::base* +NewCallback(T1* obj, R (T2::*member)(P1, P2, P3, P4, P5, P6, A1, A2, A3), + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3, typename ConstRef::type p4, + typename ConstRef::type p5, typename ConstRef::type p6) { + return new _MemberResultCallback_6_3(obj, member, p1, p2, p3, p4, p5, + p6); } #endif #ifndef SWIG -template -inline typename _MemberResultCallback_6_3::base* -NewPermanentCallback( T1* obj, R (T2::*member)(P1,P2,P3,P4,P5,P6,A1,A2,A3) , typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) { - return new _MemberResultCallback_6_3(obj, member, p1, p2, p3, p4, p5, p6); +template +inline typename _MemberResultCallback_6_3::base* +NewPermanentCallback( + T1* obj, R (T2::*member)(P1, P2, P3, P4, P5, P6, A1, A2, A3), + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3, typename ConstRef::type p4, + typename ConstRef::type p5, typename ConstRef::type p6) { + return new _MemberResultCallback_6_3(obj, member, p1, p2, p3, p4, p5, + p6); } #endif -template -class _FunctionResultCallback_6_3 : public ResultCallback3 { +template +class _FunctionResultCallback_6_3 : public ResultCallback3 { public: - typedef ResultCallback3 base; - typedef R (*FunctionSignature)(P1,P2,P3,P4,P5,P6,A1,A2,A3); + typedef ResultCallback3 base; + typedef R (*FunctionSignature)(P1, P2, P3, P4, P5, P6, A1, A2, A3); private: FunctionSignature function_; @@ -8319,24 +9413,34 @@ class _FunctionResultCallback_6_3 : public ResultCallback3 { typename remove_reference::type p6_; public: - inline _FunctionResultCallback_6_3(FunctionSignature function, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) - : ResultCallback3(), - function_(function), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5), p6_(p6) { } + inline _FunctionResultCallback_6_3(FunctionSignature function, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5, + typename ConstRef::type p6) + : ResultCallback3(), + function_(function), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5), + p6_(p6) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback3"); } - virtual R Run(A1 a1,A2 a2,A3 a3) { + virtual R Run(A1 a1, A2 a2, A3 a3) { if (!del) { - R result = (*function_)(p1_,p2_,p3_,p4_,p5_,p6_,a1,a2,a3); + R result = (*function_)(p1_, p2_, p3_, p4_, p5_, p6_, a1, a2, a3); return result; } else { - R result = (*function_)(p1_,p2_,p3_,p4_,p5_,p6_,a1,a2,a3); + R result = (*function_)(p1_, p2_, p3_, p4_, p5_, p6_, a1, a2, a3); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -8345,11 +9449,13 @@ class _FunctionResultCallback_6_3 : public ResultCallback3 { } }; -template -class _FunctionResultCallback_6_3 : public Callback3 { +template +class _FunctionResultCallback_6_3 : public Callback3 { public: - typedef Callback3 base; - typedef void (*FunctionSignature)(P1,P2,P3,P4,P5,P6,A1,A2,A3); + typedef Callback3 base; + typedef void (*FunctionSignature)(P1, P2, P3, P4, P5, P6, A1, A2, A3); private: FunctionSignature function_; @@ -8361,23 +9467,33 @@ class _FunctionResultCallback_6_3 typename remove_reference::type p6_; public: - inline _FunctionResultCallback_6_3(FunctionSignature function, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) - : Callback3(), - function_(function), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5), p6_(p6) { } + inline _FunctionResultCallback_6_3(FunctionSignature function, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5, + typename ConstRef::type p6) + : Callback3(), + function_(function), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5), + p6_(p6) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback3"); } - virtual void Run(A1 a1,A2 a2,A3 a3) { + virtual void Run(A1 a1, A2 a2, A3 a3) { if (!del) { - (*function_)(p1_,p2_,p3_,p4_,p5_,p6_,a1,a2,a3); + (*function_)(p1_, p2_, p3_, p4_, p5_, p6_, a1, a2, a3); } else { - (*function_)(p1_,p2_,p3_,p4_,p5_,p6_,a1,a2,a3); + (*function_)(p1_, p2_, p3_, p4_, p5_, p6_, a1, a2, a3); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -8385,26 +9501,43 @@ class _FunctionResultCallback_6_3 } }; -template -inline typename _FunctionResultCallback_6_3::base* -NewCallback(R (*function)(P1,P2,P3,P4,P5,P6,A1,A2,A3), typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) { - return new _FunctionResultCallback_6_3(function, p1, p2, p3, p4, p5, p6); +template +inline typename _FunctionResultCallback_6_3::base* +NewCallback(R (*function)(P1, P2, P3, P4, P5, P6, A1, A2, A3), + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3, typename ConstRef::type p4, + typename ConstRef::type p5, typename ConstRef::type p6) { + return new _FunctionResultCallback_6_3(function, p1, p2, p3, p4, p5, + p6); } -template -inline typename _FunctionResultCallback_6_3::base* -NewPermanentCallback(R (*function)(P1,P2,P3,P4,P5,P6,A1,A2,A3), typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) { - return new _FunctionResultCallback_6_3(function, p1, p2, p3, p4, p5, p6); +template +inline typename _FunctionResultCallback_6_3::base* +NewPermanentCallback(R (*function)(P1, P2, P3, P4, P5, P6, A1, A2, A3), + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5, + typename ConstRef::type p6) { + return new _FunctionResultCallback_6_3(function, p1, p2, p3, p4, p5, + p6); } -template ::value - >::type> -class _ConstMemberResultCallback_0_4 : public ResultCallback4 { +template < + bool del, class R, class T, class A1, class A2, class A3, class A4, + class OnlyIf = typename c_enable_if::value>::type> +class _ConstMemberResultCallback_0_4 + : public ResultCallback4 { public: - typedef ResultCallback4 base; - typedef R (T::*MemberSignature)(A1,A2,A3,A4) const; + typedef ResultCallback4 base; + typedef R (T::*MemberSignature)(A1, A2, A3, A4) const; private: const T* object_; @@ -8412,24 +9545,22 @@ class _ConstMemberResultCallback_0_4 : public ResultCallback4 { public: inline _ConstMemberResultCallback_0_4(const T* object, MemberSignature member) - : ResultCallback4(), - object_(object), - member_(member) { } + : ResultCallback4(), + object_(object), + member_(member) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback4"); } - virtual R Run(A1 a1,A2 a2,A3 a3,A4 a4) { + virtual R Run(A1 a1, A2 a2, A3 a3, A4 a4) { if (!del) { - R result = (object_->*member_)(a1,a2,a3,a4); + R result = (object_->*member_)(a1, a2, a3, a4); return result; } else { - R result = (object_->*member_)(a1,a2,a3,a4); + R result = (object_->*member_)(a1, a2, a3, a4); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -8439,14 +9570,13 @@ class _ConstMemberResultCallback_0_4 : public ResultCallback4 { }; template -class _ConstMemberResultCallback_0_4::value - >::type> - : public Callback4 { +class _ConstMemberResultCallback_0_4< + del, void, T, A1, A2, A3, A4, + typename c_enable_if< + is_class_or_union::value>::type> : public Callback4 { public: - typedef Callback4 base; - typedef void (T::*MemberSignature)(A1,A2,A3,A4) const; + typedef Callback4 base; + typedef void (T::*MemberSignature)(A1, A2, A3, A4) const; private: const T* object_; @@ -8454,23 +9584,19 @@ class _ConstMemberResultCallback_0_4(), - object_(object), - member_(member) { } + : Callback4(), object_(object), member_(member) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback4"); } - virtual void Run(A1 a1,A2 a2,A3 a3,A4 a4) { + virtual void Run(A1 a1, A2 a2, A3 a3, A4 a4) { if (!del) { - (object_->*member_)(a1,a2,a3,a4); + (object_->*member_)(a1, a2, a3, a4); } else { - (object_->*member_)(a1,a2,a3,a4); + (object_->*member_)(a1, a2, a3, a4); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -8480,53 +9606,54 @@ class _ConstMemberResultCallback_0_4 -inline typename _ConstMemberResultCallback_0_4::base* -NewCallback(const T1* obj, R (T2::*member)(A1,A2,A3,A4) const) { - return new _ConstMemberResultCallback_0_4(obj, member); +inline typename _ConstMemberResultCallback_0_4::base* +NewCallback(const T1* obj, R (T2::*member)(A1, A2, A3, A4) const) { + return new _ConstMemberResultCallback_0_4( + obj, member); } #endif #ifndef SWIG template -inline typename _ConstMemberResultCallback_0_4::base* -NewPermanentCallback(const T1* obj, R (T2::*member)(A1,A2,A3,A4) const) { - return new _ConstMemberResultCallback_0_4(obj, member); +inline typename _ConstMemberResultCallback_0_4::base* +NewPermanentCallback(const T1* obj, R (T2::*member)(A1, A2, A3, A4) const) { + return new _ConstMemberResultCallback_0_4( + obj, member); } #endif -template ::value - >::type> -class _MemberResultCallback_0_4 : public ResultCallback4 { +template < + bool del, class R, class T, class A1, class A2, class A3, class A4, + class OnlyIf = typename c_enable_if::value>::type> +class _MemberResultCallback_0_4 : public ResultCallback4 { public: - typedef ResultCallback4 base; - typedef R (T::*MemberSignature)(A1,A2,A3,A4) ; + typedef ResultCallback4 base; + typedef R (T::*MemberSignature)(A1, A2, A3, A4); private: - T* object_; + T* object_; MemberSignature member_; public: - inline _MemberResultCallback_0_4( T* object, MemberSignature member) - : ResultCallback4(), - object_(object), - member_(member) { } + inline _MemberResultCallback_0_4(T* object, MemberSignature member) + : ResultCallback4(), + object_(object), + member_(member) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback4"); } - virtual R Run(A1 a1,A2 a2,A3 a3,A4 a4) { + virtual R Run(A1 a1, A2 a2, A3 a3, A4 a4) { if (!del) { - R result = (object_->*member_)(a1,a2,a3,a4); + R result = (object_->*member_)(a1, a2, a3, a4); return result; } else { - R result = (object_->*member_)(a1,a2,a3,a4); + R result = (object_->*member_)(a1, a2, a3, a4); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -8536,38 +9663,33 @@ class _MemberResultCallback_0_4 : public ResultCallback4 { }; template -class _MemberResultCallback_0_4::value - >::type> - : public Callback4 { +class _MemberResultCallback_0_4< + del, void, T, A1, A2, A3, A4, + typename c_enable_if< + is_class_or_union::value>::type> : public Callback4 { public: - typedef Callback4 base; - typedef void (T::*MemberSignature)(A1,A2,A3,A4) ; + typedef Callback4 base; + typedef void (T::*MemberSignature)(A1, A2, A3, A4); private: - T* object_; + T* object_; MemberSignature member_; public: - inline _MemberResultCallback_0_4( T* object, MemberSignature member) - : Callback4(), - object_(object), - member_(member) { } + inline _MemberResultCallback_0_4(T* object, MemberSignature member) + : Callback4(), object_(object), member_(member) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback4"); } - virtual void Run(A1 a1,A2 a2,A3 a3,A4 a4) { + virtual void Run(A1 a1, A2 a2, A3 a3, A4 a4) { if (!del) { - (object_->*member_)(a1,a2,a3,a4); + (object_->*member_)(a1, a2, a3, a4); } else { - (object_->*member_)(a1,a2,a3,a4); + (object_->*member_)(a1, a2, a3, a4); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -8577,48 +9699,47 @@ class _MemberResultCallback_0_4 -inline typename _MemberResultCallback_0_4::base* -NewCallback( T1* obj, R (T2::*member)(A1,A2,A3,A4) ) { - return new _MemberResultCallback_0_4(obj, member); +inline typename _MemberResultCallback_0_4::base* +NewCallback(T1* obj, R (T2::*member)(A1, A2, A3, A4)) { + return new _MemberResultCallback_0_4(obj, + member); } #endif #ifndef SWIG template -inline typename _MemberResultCallback_0_4::base* -NewPermanentCallback( T1* obj, R (T2::*member)(A1,A2,A3,A4) ) { - return new _MemberResultCallback_0_4(obj, member); +inline typename _MemberResultCallback_0_4::base* +NewPermanentCallback(T1* obj, R (T2::*member)(A1, A2, A3, A4)) { + return new _MemberResultCallback_0_4(obj, + member); } #endif template -class _FunctionResultCallback_0_4 : public ResultCallback4 { +class _FunctionResultCallback_0_4 : public ResultCallback4 { public: - typedef ResultCallback4 base; - typedef R (*FunctionSignature)(A1,A2,A3,A4); + typedef ResultCallback4 base; + typedef R (*FunctionSignature)(A1, A2, A3, A4); private: FunctionSignature function_; public: inline _FunctionResultCallback_0_4(FunctionSignature function) - : ResultCallback4(), - function_(function) { } + : ResultCallback4(), function_(function) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback4"); } - virtual R Run(A1 a1,A2 a2,A3 a3,A4 a4) { + virtual R Run(A1 a1, A2 a2, A3 a3, A4 a4) { if (!del) { - R result = (*function_)(a1,a2,a3,a4); + R result = (*function_)(a1, a2, a3, a4); return result; } else { - R result = (*function_)(a1,a2,a3,a4); + R result = (*function_)(a1, a2, a3, a4); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -8628,32 +9749,30 @@ class _FunctionResultCallback_0_4 : public ResultCallback4 { }; template -class _FunctionResultCallback_0_4 : public Callback4 { +class _FunctionResultCallback_0_4 : public Callback4 { public: - typedef Callback4 base; - typedef void (*FunctionSignature)(A1,A2,A3,A4); + typedef Callback4 base; + typedef void (*FunctionSignature)(A1, A2, A3, A4); private: FunctionSignature function_; public: inline _FunctionResultCallback_0_4(FunctionSignature function) - : Callback4(), - function_(function) { } + : Callback4(), function_(function) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback4"); } - virtual void Run(A1 a1,A2 a2,A3 a3,A4 a4) { + virtual void Run(A1 a1, A2 a2, A3 a3, A4 a4) { if (!del) { - (*function_)(a1,a2,a3,a4); + (*function_)(a1, a2, a3, a4); } else { - (*function_)(a1,a2,a3,a4); + (*function_)(a1, a2, a3, a4); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -8662,25 +9781,25 @@ class _FunctionResultCallback_0_4 : public Callback4< }; template -inline typename _FunctionResultCallback_0_4::base* -NewCallback(R (*function)(A1,A2,A3,A4)) { - return new _FunctionResultCallback_0_4(function); +inline typename _FunctionResultCallback_0_4::base* +NewCallback(R (*function)(A1, A2, A3, A4)) { + return new _FunctionResultCallback_0_4(function); } template -inline typename _FunctionResultCallback_0_4::base* -NewPermanentCallback(R (*function)(A1,A2,A3,A4)) { - return new _FunctionResultCallback_0_4(function); +inline typename _FunctionResultCallback_0_4::base* +NewPermanentCallback(R (*function)(A1, A2, A3, A4)) { + return new _FunctionResultCallback_0_4(function); } -template ::value - >::type> -class _ConstMemberResultCallback_1_4 : public ResultCallback4 { +template ::value>::type> +class _ConstMemberResultCallback_1_4 + : public ResultCallback4 { public: - typedef ResultCallback4 base; - typedef R (T::*MemberSignature)(P1,A1,A2,A3,A4) const; + typedef ResultCallback4 base; + typedef R (T::*MemberSignature)(P1, A1, A2, A3, A4) const; private: const T* object_; @@ -8688,25 +9807,25 @@ class _ConstMemberResultCallback_1_4 : public ResultCallback4 { typename remove_reference::type p1_; public: - inline _ConstMemberResultCallback_1_4(const T* object, MemberSignature member, typename ConstRef::type p1) - : ResultCallback4(), - object_(object), - member_(member), p1_(p1) { } + inline _ConstMemberResultCallback_1_4(const T* object, MemberSignature member, + typename ConstRef::type p1) + : ResultCallback4(), + object_(object), + member_(member), + p1_(p1) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback4"); } - virtual R Run(A1 a1,A2 a2,A3 a3,A4 a4) { + virtual R Run(A1 a1, A2 a2, A3 a3, A4 a4) { if (!del) { - R result = (object_->*member_)(p1_,a1,a2,a3,a4); + R result = (object_->*member_)(p1_, a1, a2, a3, a4); return result; } else { - R result = (object_->*member_)(p1_,a1,a2,a3,a4); + R result = (object_->*member_)(p1_, a1, a2, a3, a4); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -8716,14 +9835,13 @@ class _ConstMemberResultCallback_1_4 : public ResultCallback4 { }; template -class _ConstMemberResultCallback_1_4::value - >::type> - : public Callback4 { +class _ConstMemberResultCallback_1_4< + del, void, T, P1, A1, A2, A3, A4, + typename c_enable_if< + is_class_or_union::value>::type> : public Callback4 { public: - typedef Callback4 base; - typedef void (T::*MemberSignature)(P1,A1,A2,A3,A4) const; + typedef Callback4 base; + typedef void (T::*MemberSignature)(P1, A1, A2, A3, A4) const; private: const T* object_; @@ -8731,24 +9849,24 @@ class _ConstMemberResultCallback_1_4::type p1_; public: - inline _ConstMemberResultCallback_1_4(const T* object, MemberSignature member, typename ConstRef::type p1) - : Callback4(), - object_(object), - member_(member), p1_(p1) { } + inline _ConstMemberResultCallback_1_4(const T* object, MemberSignature member, + typename ConstRef::type p1) + : Callback4(), + object_(object), + member_(member), + p1_(p1) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback4"); } - virtual void Run(A1 a1,A2 a2,A3 a3,A4 a4) { + virtual void Run(A1 a1, A2 a2, A3 a3, A4 a4) { if (!del) { - (object_->*member_)(p1_,a1,a2,a3,a4); + (object_->*member_)(p1_, a1, a2, a3, a4); } else { - (object_->*member_)(p1_,a1,a2,a3,a4); + (object_->*member_)(p1_, a1, a2, a3, a4); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -8757,55 +9875,62 @@ class _ConstMemberResultCallback_1_4 -inline typename _ConstMemberResultCallback_1_4::base* -NewCallback(const T1* obj, R (T2::*member)(P1,A1,A2,A3,A4) const, typename ConstRef::type p1) { - return new _ConstMemberResultCallback_1_4(obj, member, p1); +template +inline typename _ConstMemberResultCallback_1_4::base* +NewCallback(const T1* obj, R (T2::*member)(P1, A1, A2, A3, A4) const, + typename ConstRef::type p1) { + return new _ConstMemberResultCallback_1_4( + obj, member, p1); } #endif #ifndef SWIG -template -inline typename _ConstMemberResultCallback_1_4::base* -NewPermanentCallback(const T1* obj, R (T2::*member)(P1,A1,A2,A3,A4) const, typename ConstRef::type p1) { - return new _ConstMemberResultCallback_1_4(obj, member, p1); +template +inline typename _ConstMemberResultCallback_1_4::base* +NewPermanentCallback(const T1* obj, R (T2::*member)(P1, A1, A2, A3, A4) const, + typename ConstRef::type p1) { + return new _ConstMemberResultCallback_1_4( + obj, member, p1); } #endif -template ::value - >::type> -class _MemberResultCallback_1_4 : public ResultCallback4 { +template ::value>::type> +class _MemberResultCallback_1_4 : public ResultCallback4 { public: - typedef ResultCallback4 base; - typedef R (T::*MemberSignature)(P1,A1,A2,A3,A4) ; + typedef ResultCallback4 base; + typedef R (T::*MemberSignature)(P1, A1, A2, A3, A4); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; public: - inline _MemberResultCallback_1_4( T* object, MemberSignature member, typename ConstRef::type p1) - : ResultCallback4(), - object_(object), - member_(member), p1_(p1) { } + inline _MemberResultCallback_1_4(T* object, MemberSignature member, + typename ConstRef::type p1) + : ResultCallback4(), + object_(object), + member_(member), + p1_(p1) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback4"); } - virtual R Run(A1 a1,A2 a2,A3 a3,A4 a4) { + virtual R Run(A1 a1, A2 a2, A3 a3, A4 a4) { if (!del) { - R result = (object_->*member_)(p1_,a1,a2,a3,a4); + R result = (object_->*member_)(p1_, a1, a2, a3, a4); return result; } else { - R result = (object_->*member_)(p1_,a1,a2,a3,a4); + R result = (object_->*member_)(p1_, a1, a2, a3, a4); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -8815,39 +9940,38 @@ class _MemberResultCallback_1_4 : public ResultCallback4 { }; template -class _MemberResultCallback_1_4::value - >::type> - : public Callback4 { +class _MemberResultCallback_1_4< + del, void, T, P1, A1, A2, A3, A4, + typename c_enable_if< + is_class_or_union::value>::type> : public Callback4 { public: - typedef Callback4 base; - typedef void (T::*MemberSignature)(P1,A1,A2,A3,A4) ; + typedef Callback4 base; + typedef void (T::*MemberSignature)(P1, A1, A2, A3, A4); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; public: - inline _MemberResultCallback_1_4( T* object, MemberSignature member, typename ConstRef::type p1) - : Callback4(), - object_(object), - member_(member), p1_(p1) { } + inline _MemberResultCallback_1_4(T* object, MemberSignature member, + typename ConstRef::type p1) + : Callback4(), + object_(object), + member_(member), + p1_(p1) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback4"); } - virtual void Run(A1 a1,A2 a2,A3 a3,A4 a4) { + virtual void Run(A1 a1, A2 a2, A3 a3, A4 a4) { if (!del) { - (object_->*member_)(p1_,a1,a2,a3,a4); + (object_->*member_)(p1_, a1, a2, a3, a4); } else { - (object_->*member_)(p1_,a1,a2,a3,a4); + (object_->*member_)(p1_, a1, a2, a3, a4); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -8856,50 +9980,56 @@ class _MemberResultCallback_1_4 -inline typename _MemberResultCallback_1_4::base* -NewCallback( T1* obj, R (T2::*member)(P1,A1,A2,A3,A4) , typename ConstRef::type p1) { - return new _MemberResultCallback_1_4(obj, member, p1); +template +inline typename _MemberResultCallback_1_4::base* +NewCallback(T1* obj, R (T2::*member)(P1, A1, A2, A3, A4), + typename ConstRef::type p1) { + return new _MemberResultCallback_1_4( + obj, member, p1); } #endif #ifndef SWIG -template -inline typename _MemberResultCallback_1_4::base* -NewPermanentCallback( T1* obj, R (T2::*member)(P1,A1,A2,A3,A4) , typename ConstRef::type p1) { - return new _MemberResultCallback_1_4(obj, member, p1); +template +inline typename _MemberResultCallback_1_4::base* +NewPermanentCallback(T1* obj, R (T2::*member)(P1, A1, A2, A3, A4), + typename ConstRef::type p1) { + return new _MemberResultCallback_1_4( + obj, member, p1); } #endif template -class _FunctionResultCallback_1_4 : public ResultCallback4 { +class _FunctionResultCallback_1_4 : public ResultCallback4 { public: - typedef ResultCallback4 base; - typedef R (*FunctionSignature)(P1,A1,A2,A3,A4); + typedef ResultCallback4 base; + typedef R (*FunctionSignature)(P1, A1, A2, A3, A4); private: FunctionSignature function_; typename remove_reference::type p1_; public: - inline _FunctionResultCallback_1_4(FunctionSignature function, typename ConstRef::type p1) - : ResultCallback4(), - function_(function), p1_(p1) { } + inline _FunctionResultCallback_1_4(FunctionSignature function, + typename ConstRef::type p1) + : ResultCallback4(), function_(function), p1_(p1) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback4"); } - virtual R Run(A1 a1,A2 a2,A3 a3,A4 a4) { + virtual R Run(A1 a1, A2 a2, A3 a3, A4 a4) { if (!del) { - R result = (*function_)(p1_,a1,a2,a3,a4); + R result = (*function_)(p1_, a1, a2, a3, a4); return result; } else { - R result = (*function_)(p1_,a1,a2,a3,a4); + R result = (*function_)(p1_, a1, a2, a3, a4); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -8909,33 +10039,32 @@ class _FunctionResultCallback_1_4 : public ResultCallback4 { }; template -class _FunctionResultCallback_1_4 : public Callback4 { +class _FunctionResultCallback_1_4 : public Callback4 { public: - typedef Callback4 base; - typedef void (*FunctionSignature)(P1,A1,A2,A3,A4); + typedef Callback4 base; + typedef void (*FunctionSignature)(P1, A1, A2, A3, A4); private: FunctionSignature function_; typename remove_reference::type p1_; public: - inline _FunctionResultCallback_1_4(FunctionSignature function, typename ConstRef::type p1) - : Callback4(), - function_(function), p1_(p1) { } + inline _FunctionResultCallback_1_4(FunctionSignature function, + typename ConstRef::type p1) + : Callback4(), function_(function), p1_(p1) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback4"); } - virtual void Run(A1 a1,A2 a2,A3 a3,A4 a4) { + virtual void Run(A1 a1, A2 a2, A3 a3, A4 a4) { if (!del) { - (*function_)(p1_,a1,a2,a3,a4); + (*function_)(p1_, a1, a2, a3, a4); } else { - (*function_)(p1_,a1,a2,a3,a4); + (*function_)(p1_, a1, a2, a3, a4); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -8944,25 +10073,28 @@ class _FunctionResultCallback_1_4 : public Callba }; template -inline typename _FunctionResultCallback_1_4::base* -NewCallback(R (*function)(P1,A1,A2,A3,A4), typename ConstRef::type p1) { - return new _FunctionResultCallback_1_4(function, p1); +inline typename _FunctionResultCallback_1_4::base* +NewCallback(R (*function)(P1, A1, A2, A3, A4), typename ConstRef::type p1) { + return new _FunctionResultCallback_1_4(function, + p1); } template -inline typename _FunctionResultCallback_1_4::base* -NewPermanentCallback(R (*function)(P1,A1,A2,A3,A4), typename ConstRef::type p1) { - return new _FunctionResultCallback_1_4(function, p1); +inline typename _FunctionResultCallback_1_4::base* +NewPermanentCallback(R (*function)(P1, A1, A2, A3, A4), + typename ConstRef::type p1) { + return new _FunctionResultCallback_1_4(function, + p1); } -template ::value - >::type> -class _ConstMemberResultCallback_2_4 : public ResultCallback4 { +template ::value>::type> +class _ConstMemberResultCallback_2_4 + : public ResultCallback4 { public: - typedef ResultCallback4 base; - typedef R (T::*MemberSignature)(P1,P2,A1,A2,A3,A4) const; + typedef ResultCallback4 base; + typedef R (T::*MemberSignature)(P1, P2, A1, A2, A3, A4) const; private: const T* object_; @@ -8971,25 +10103,27 @@ class _ConstMemberResultCallback_2_4 : public ResultCallback4 { typename remove_reference::type p2_; public: - inline _ConstMemberResultCallback_2_4(const T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2) - : ResultCallback4(), - object_(object), - member_(member), p1_(p1), p2_(p2) { } + inline _ConstMemberResultCallback_2_4(const T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2) + : ResultCallback4(), + object_(object), + member_(member), + p1_(p1), + p2_(p2) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback4"); } - virtual R Run(A1 a1,A2 a2,A3 a3,A4 a4) { + virtual R Run(A1 a1, A2 a2, A3 a3, A4 a4) { if (!del) { - R result = (object_->*member_)(p1_,p2_,a1,a2,a3,a4); + R result = (object_->*member_)(p1_, p2_, a1, a2, a3, a4); return result; } else { - R result = (object_->*member_)(p1_,p2_,a1,a2,a3,a4); + R result = (object_->*member_)(p1_, p2_, a1, a2, a3, a4); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -8998,15 +10132,15 @@ class _ConstMemberResultCallback_2_4 : public ResultCallback4 { } }; -template -class _ConstMemberResultCallback_2_4::value - >::type> - : public Callback4 { +template +class _ConstMemberResultCallback_2_4< + del, void, T, P1, P2, A1, A2, A3, A4, + typename c_enable_if< + is_class_or_union::value>::type> : public Callback4 { public: - typedef Callback4 base; - typedef void (T::*MemberSignature)(P1,P2,A1,A2,A3,A4) const; + typedef Callback4 base; + typedef void (T::*MemberSignature)(P1, P2, A1, A2, A3, A4) const; private: const T* object_; @@ -9015,24 +10149,26 @@ class _ConstMemberResultCallback_2_4::type p2_; public: - inline _ConstMemberResultCallback_2_4(const T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2) - : Callback4(), - object_(object), - member_(member), p1_(p1), p2_(p2) { } + inline _ConstMemberResultCallback_2_4(const T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2) + : Callback4(), + object_(object), + member_(member), + p1_(p1), + p2_(p2) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback4"); } - virtual void Run(A1 a1,A2 a2,A3 a3,A4 a4) { + virtual void Run(A1 a1, A2 a2, A3 a3, A4 a4) { if (!del) { - (object_->*member_)(p1_,p2_,a1,a2,a3,a4); + (object_->*member_)(p1_, p2_, a1, a2, a3, a4); } else { - (object_->*member_)(p1_,p2_,a1,a2,a3,a4); + (object_->*member_)(p1_, p2_, a1, a2, a3, a4); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -9041,56 +10177,67 @@ class _ConstMemberResultCallback_2_4 -inline typename _ConstMemberResultCallback_2_4::base* -NewCallback(const T1* obj, R (T2::*member)(P1,P2,A1,A2,A3,A4) const, typename ConstRef::type p1, typename ConstRef::type p2) { - return new _ConstMemberResultCallback_2_4(obj, member, p1, p2); +template +inline typename _ConstMemberResultCallback_2_4::base* +NewCallback(const T1* obj, R (T2::*member)(P1, P2, A1, A2, A3, A4) const, + typename ConstRef::type p1, typename ConstRef::type p2) { + return new _ConstMemberResultCallback_2_4(obj, member, p1, p2); } #endif #ifndef SWIG -template -inline typename _ConstMemberResultCallback_2_4::base* -NewPermanentCallback(const T1* obj, R (T2::*member)(P1,P2,A1,A2,A3,A4) const, typename ConstRef::type p1, typename ConstRef::type p2) { - return new _ConstMemberResultCallback_2_4(obj, member, p1, p2); +template +inline typename _ConstMemberResultCallback_2_4::base* +NewPermanentCallback(const T1* obj, + R (T2::*member)(P1, P2, A1, A2, A3, A4) const, + typename ConstRef::type p1, + typename ConstRef::type p2) { + return new _ConstMemberResultCallback_2_4(obj, member, p1, p2); } #endif -template ::value - >::type> -class _MemberResultCallback_2_4 : public ResultCallback4 { +template ::value>::type> +class _MemberResultCallback_2_4 : public ResultCallback4 { public: - typedef ResultCallback4 base; - typedef R (T::*MemberSignature)(P1,P2,A1,A2,A3,A4) ; + typedef ResultCallback4 base; + typedef R (T::*MemberSignature)(P1, P2, A1, A2, A3, A4); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; typename remove_reference::type p2_; public: - inline _MemberResultCallback_2_4( T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2) - : ResultCallback4(), - object_(object), - member_(member), p1_(p1), p2_(p2) { } + inline _MemberResultCallback_2_4(T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2) + : ResultCallback4(), + object_(object), + member_(member), + p1_(p1), + p2_(p2) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback4"); } - virtual R Run(A1 a1,A2 a2,A3 a3,A4 a4) { + virtual R Run(A1 a1, A2 a2, A3 a3, A4 a4) { if (!del) { - R result = (object_->*member_)(p1_,p2_,a1,a2,a3,a4); + R result = (object_->*member_)(p1_, p2_, a1, a2, a3, a4); return result; } else { - R result = (object_->*member_)(p1_,p2_,a1,a2,a3,a4); + R result = (object_->*member_)(p1_, p2_, a1, a2, a3, a4); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -9099,41 +10246,43 @@ class _MemberResultCallback_2_4 : public ResultCallback4 { } }; -template -class _MemberResultCallback_2_4::value - >::type> - : public Callback4 { +template +class _MemberResultCallback_2_4< + del, void, T, P1, P2, A1, A2, A3, A4, + typename c_enable_if< + is_class_or_union::value>::type> : public Callback4 { public: - typedef Callback4 base; - typedef void (T::*MemberSignature)(P1,P2,A1,A2,A3,A4) ; + typedef Callback4 base; + typedef void (T::*MemberSignature)(P1, P2, A1, A2, A3, A4); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; typename remove_reference::type p2_; public: - inline _MemberResultCallback_2_4( T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2) - : Callback4(), - object_(object), - member_(member), p1_(p1), p2_(p2) { } + inline _MemberResultCallback_2_4(T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2) + : Callback4(), + object_(object), + member_(member), + p1_(p1), + p2_(p2) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback4"); } - virtual void Run(A1 a1,A2 a2,A3 a3,A4 a4) { + virtual void Run(A1 a1, A2 a2, A3 a3, A4 a4) { if (!del) { - (object_->*member_)(p1_,p2_,a1,a2,a3,a4); + (object_->*member_)(p1_, p2_, a1, a2, a3, a4); } else { - (object_->*member_)(p1_,p2_,a1,a2,a3,a4); + (object_->*member_)(p1_, p2_, a1, a2, a3, a4); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -9142,26 +10291,36 @@ class _MemberResultCallback_2_4 -inline typename _MemberResultCallback_2_4::base* -NewCallback( T1* obj, R (T2::*member)(P1,P2,A1,A2,A3,A4) , typename ConstRef::type p1, typename ConstRef::type p2) { - return new _MemberResultCallback_2_4(obj, member, p1, p2); +template +inline typename _MemberResultCallback_2_4::base* +NewCallback(T1* obj, R (T2::*member)(P1, P2, A1, A2, A3, A4), + typename ConstRef::type p1, typename ConstRef::type p2) { + return new _MemberResultCallback_2_4( + obj, member, p1, p2); } #endif #ifndef SWIG -template -inline typename _MemberResultCallback_2_4::base* -NewPermanentCallback( T1* obj, R (T2::*member)(P1,P2,A1,A2,A3,A4) , typename ConstRef::type p1, typename ConstRef::type p2) { - return new _MemberResultCallback_2_4(obj, member, p1, p2); +template +inline typename _MemberResultCallback_2_4::base* +NewPermanentCallback(T1* obj, R (T2::*member)(P1, P2, A1, A2, A3, A4), + typename ConstRef::type p1, + typename ConstRef::type p2) { + return new _MemberResultCallback_2_4( + obj, member, p1, p2); } #endif -template -class _FunctionResultCallback_2_4 : public ResultCallback4 { +template +class _FunctionResultCallback_2_4 : public ResultCallback4 { public: - typedef ResultCallback4 base; - typedef R (*FunctionSignature)(P1,P2,A1,A2,A3,A4); + typedef ResultCallback4 base; + typedef R (*FunctionSignature)(P1, P2, A1, A2, A3, A4); private: FunctionSignature function_; @@ -9169,24 +10328,26 @@ class _FunctionResultCallback_2_4 : public ResultCallback4 { typename remove_reference::type p2_; public: - inline _FunctionResultCallback_2_4(FunctionSignature function, typename ConstRef::type p1, typename ConstRef::type p2) - : ResultCallback4(), - function_(function), p1_(p1), p2_(p2) { } + inline _FunctionResultCallback_2_4(FunctionSignature function, + typename ConstRef::type p1, + typename ConstRef::type p2) + : ResultCallback4(), + function_(function), + p1_(p1), + p2_(p2) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback4"); } - virtual R Run(A1 a1,A2 a2,A3 a3,A4 a4) { + virtual R Run(A1 a1, A2 a2, A3 a3, A4 a4) { if (!del) { - R result = (*function_)(p1_,p2_,a1,a2,a3,a4); + R result = (*function_)(p1_, p2_, a1, a2, a3, a4); return result; } else { - R result = (*function_)(p1_,p2_,a1,a2,a3,a4); + R result = (*function_)(p1_, p2_, a1, a2, a3, a4); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -9196,10 +10357,11 @@ class _FunctionResultCallback_2_4 : public ResultCallback4 { }; template -class _FunctionResultCallback_2_4 : public Callback4 { +class _FunctionResultCallback_2_4 : public Callback4 { public: - typedef Callback4 base; - typedef void (*FunctionSignature)(P1,P2,A1,A2,A3,A4); + typedef Callback4 base; + typedef void (*FunctionSignature)(P1, P2, A1, A2, A3, A4); private: FunctionSignature function_; @@ -9207,23 +10369,22 @@ class _FunctionResultCallback_2_4 : public Ca typename remove_reference::type p2_; public: - inline _FunctionResultCallback_2_4(FunctionSignature function, typename ConstRef::type p1, typename ConstRef::type p2) - : Callback4(), - function_(function), p1_(p1), p2_(p2) { } + inline _FunctionResultCallback_2_4(FunctionSignature function, + typename ConstRef::type p1, + typename ConstRef::type p2) + : Callback4(), function_(function), p1_(p1), p2_(p2) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback4"); } - virtual void Run(A1 a1,A2 a2,A3 a3,A4 a4) { + virtual void Run(A1 a1, A2 a2, A3 a3, A4 a4) { if (!del) { - (*function_)(p1_,p2_,a1,a2,a3,a4); + (*function_)(p1_, p2_, a1, a2, a3, a4); } else { - (*function_)(p1_,p2_,a1,a2,a3,a4); + (*function_)(p1_, p2_, a1, a2, a3, a4); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -9232,25 +10393,32 @@ class _FunctionResultCallback_2_4 : public Ca }; template -inline typename _FunctionResultCallback_2_4::base* -NewCallback(R (*function)(P1,P2,A1,A2,A3,A4), typename ConstRef::type p1, typename ConstRef::type p2) { - return new _FunctionResultCallback_2_4(function, p1, p2); +inline typename _FunctionResultCallback_2_4::base* +NewCallback(R (*function)(P1, P2, A1, A2, A3, A4), + typename ConstRef::type p1, typename ConstRef::type p2) { + return new _FunctionResultCallback_2_4( + function, p1, p2); } template -inline typename _FunctionResultCallback_2_4::base* -NewPermanentCallback(R (*function)(P1,P2,A1,A2,A3,A4), typename ConstRef::type p1, typename ConstRef::type p2) { - return new _FunctionResultCallback_2_4(function, p1, p2); +inline typename _FunctionResultCallback_2_4::base* +NewPermanentCallback(R (*function)(P1, P2, A1, A2, A3, A4), + typename ConstRef::type p1, + typename ConstRef::type p2) { + return new _FunctionResultCallback_2_4( + function, p1, p2); } -template ::value - >::type> -class _ConstMemberResultCallback_3_4 : public ResultCallback4 { +template ::value>::type> +class _ConstMemberResultCallback_3_4 + : public ResultCallback4 { public: - typedef ResultCallback4 base; - typedef R (T::*MemberSignature)(P1,P2,P3,A1,A2,A3,A4) const; + typedef ResultCallback4 base; + typedef R (T::*MemberSignature)(P1, P2, P3, A1, A2, A3, A4) const; private: const T* object_; @@ -9260,25 +10428,29 @@ class _ConstMemberResultCallback_3_4 : public ResultCallback4 { typename remove_reference::type p3_; public: - inline _ConstMemberResultCallback_3_4(const T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) - : ResultCallback4(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3) { } + inline _ConstMemberResultCallback_3_4(const T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3) + : ResultCallback4(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback4"); } - virtual R Run(A1 a1,A2 a2,A3 a3,A4 a4) { + virtual R Run(A1 a1, A2 a2, A3 a3, A4 a4) { if (!del) { - R result = (object_->*member_)(p1_,p2_,p3_,a1,a2,a3,a4); + R result = (object_->*member_)(p1_, p2_, p3_, a1, a2, a3, a4); return result; } else { - R result = (object_->*member_)(p1_,p2_,p3_,a1,a2,a3,a4); + R result = (object_->*member_)(p1_, p2_, p3_, a1, a2, a3, a4); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -9287,15 +10459,15 @@ class _ConstMemberResultCallback_3_4 : public ResultCallback4 { } }; -template -class _ConstMemberResultCallback_3_4::value - >::type> - : public Callback4 { +template +class _ConstMemberResultCallback_3_4< + del, void, T, P1, P2, P3, A1, A2, A3, A4, + typename c_enable_if< + is_class_or_union::value>::type> : public Callback4 { public: - typedef Callback4 base; - typedef void (T::*MemberSignature)(P1,P2,P3,A1,A2,A3,A4) const; + typedef Callback4 base; + typedef void (T::*MemberSignature)(P1, P2, P3, A1, A2, A3, A4) const; private: const T* object_; @@ -9305,24 +10477,28 @@ class _ConstMemberResultCallback_3_4::type p3_; public: - inline _ConstMemberResultCallback_3_4(const T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) - : Callback4(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3) { } + inline _ConstMemberResultCallback_3_4(const T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3) + : Callback4(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback4"); } - virtual void Run(A1 a1,A2 a2,A3 a3,A4 a4) { + virtual void Run(A1 a1, A2 a2, A3 a3, A4 a4) { if (!del) { - (object_->*member_)(p1_,p2_,p3_,a1,a2,a3,a4); + (object_->*member_)(p1_, p2_, p3_, a1, a2, a3, a4); } else { - (object_->*member_)(p1_,p2_,p3_,a1,a2,a3,a4); + (object_->*member_)(p1_, p2_, p3_, a1, a2, a3, a4); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -9331,57 +10507,72 @@ class _ConstMemberResultCallback_3_4 -inline typename _ConstMemberResultCallback_3_4::base* -NewCallback(const T1* obj, R (T2::*member)(P1,P2,P3,A1,A2,A3,A4) const, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) { - return new _ConstMemberResultCallback_3_4(obj, member, p1, p2, p3); +template +inline typename _ConstMemberResultCallback_3_4::base* +NewCallback(const T1* obj, R (T2::*member)(P1, P2, P3, A1, A2, A3, A4) const, + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3) { + return new _ConstMemberResultCallback_3_4(obj, member, p1, p2, p3); } #endif #ifndef SWIG -template -inline typename _ConstMemberResultCallback_3_4::base* -NewPermanentCallback(const T1* obj, R (T2::*member)(P1,P2,P3,A1,A2,A3,A4) const, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) { - return new _ConstMemberResultCallback_3_4(obj, member, p1, p2, p3); +template +inline typename _ConstMemberResultCallback_3_4::base* +NewPermanentCallback(const T1* obj, + R (T2::*member)(P1, P2, P3, A1, A2, A3, A4) const, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3) { + return new _ConstMemberResultCallback_3_4(obj, member, p1, p2, p3); } #endif -template ::value - >::type> -class _MemberResultCallback_3_4 : public ResultCallback4 { +template ::value>::type> +class _MemberResultCallback_3_4 : public ResultCallback4 { public: - typedef ResultCallback4 base; - typedef R (T::*MemberSignature)(P1,P2,P3,A1,A2,A3,A4) ; + typedef ResultCallback4 base; + typedef R (T::*MemberSignature)(P1, P2, P3, A1, A2, A3, A4); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; typename remove_reference::type p2_; typename remove_reference::type p3_; public: - inline _MemberResultCallback_3_4( T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) - : ResultCallback4(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3) { } + inline _MemberResultCallback_3_4(T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3) + : ResultCallback4(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback4"); } - virtual R Run(A1 a1,A2 a2,A3 a3,A4 a4) { + virtual R Run(A1 a1, A2 a2, A3 a3, A4 a4) { if (!del) { - R result = (object_->*member_)(p1_,p2_,p3_,a1,a2,a3,a4); + R result = (object_->*member_)(p1_, p2_, p3_, a1, a2, a3, a4); return result; } else { - R result = (object_->*member_)(p1_,p2_,p3_,a1,a2,a3,a4); + R result = (object_->*member_)(p1_, p2_, p3_, a1, a2, a3, a4); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -9390,42 +10581,46 @@ class _MemberResultCallback_3_4 : public ResultCallback4 { } }; -template -class _MemberResultCallback_3_4::value - >::type> - : public Callback4 { +template +class _MemberResultCallback_3_4< + del, void, T, P1, P2, P3, A1, A2, A3, A4, + typename c_enable_if< + is_class_or_union::value>::type> : public Callback4 { public: - typedef Callback4 base; - typedef void (T::*MemberSignature)(P1,P2,P3,A1,A2,A3,A4) ; + typedef Callback4 base; + typedef void (T::*MemberSignature)(P1, P2, P3, A1, A2, A3, A4); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; typename remove_reference::type p2_; typename remove_reference::type p3_; public: - inline _MemberResultCallback_3_4( T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) - : Callback4(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3) { } + inline _MemberResultCallback_3_4(T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3) + : Callback4(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback4"); } - virtual void Run(A1 a1,A2 a2,A3 a3,A4 a4) { + virtual void Run(A1 a1, A2 a2, A3 a3, A4 a4) { if (!del) { - (object_->*member_)(p1_,p2_,p3_,a1,a2,a3,a4); + (object_->*member_)(p1_, p2_, p3_, a1, a2, a3, a4); } else { - (object_->*member_)(p1_,p2_,p3_,a1,a2,a3,a4); + (object_->*member_)(p1_, p2_, p3_, a1, a2, a3, a4); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -9434,26 +10629,38 @@ class _MemberResultCallback_3_4 -inline typename _MemberResultCallback_3_4::base* -NewCallback( T1* obj, R (T2::*member)(P1,P2,P3,A1,A2,A3,A4) , typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) { - return new _MemberResultCallback_3_4(obj, member, p1, p2, p3); +template +inline typename _MemberResultCallback_3_4::base* +NewCallback(T1* obj, R (T2::*member)(P1, P2, P3, A1, A2, A3, A4), + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3) { + return new _MemberResultCallback_3_4( + obj, member, p1, p2, p3); } #endif #ifndef SWIG -template -inline typename _MemberResultCallback_3_4::base* -NewPermanentCallback( T1* obj, R (T2::*member)(P1,P2,P3,A1,A2,A3,A4) , typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) { - return new _MemberResultCallback_3_4(obj, member, p1, p2, p3); +template +inline typename _MemberResultCallback_3_4::base* +NewPermanentCallback(T1* obj, R (T2::*member)(P1, P2, P3, A1, A2, A3, A4), + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3) { + return new _MemberResultCallback_3_4(obj, member, p1, p2, p3); } #endif -template -class _FunctionResultCallback_3_4 : public ResultCallback4 { +template +class _FunctionResultCallback_3_4 : public ResultCallback4 { public: - typedef ResultCallback4 base; - typedef R (*FunctionSignature)(P1,P2,P3,A1,A2,A3,A4); + typedef ResultCallback4 base; + typedef R (*FunctionSignature)(P1, P2, P3, A1, A2, A3, A4); private: FunctionSignature function_; @@ -9462,24 +10669,28 @@ class _FunctionResultCallback_3_4 : public ResultCallback4 { typename remove_reference::type p3_; public: - inline _FunctionResultCallback_3_4(FunctionSignature function, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) - : ResultCallback4(), - function_(function), p1_(p1), p2_(p2), p3_(p3) { } + inline _FunctionResultCallback_3_4(FunctionSignature function, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3) + : ResultCallback4(), + function_(function), + p1_(p1), + p2_(p2), + p3_(p3) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback4"); } - virtual R Run(A1 a1,A2 a2,A3 a3,A4 a4) { + virtual R Run(A1 a1, A2 a2, A3 a3, A4 a4) { if (!del) { - R result = (*function_)(p1_,p2_,p3_,a1,a2,a3,a4); + R result = (*function_)(p1_, p2_, p3_, a1, a2, a3, a4); return result; } else { - R result = (*function_)(p1_,p2_,p3_,a1,a2,a3,a4); + R result = (*function_)(p1_, p2_, p3_, a1, a2, a3, a4); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -9488,11 +10699,13 @@ class _FunctionResultCallback_3_4 : public ResultCallback4 { } }; -template -class _FunctionResultCallback_3_4 : public Callback4 { +template +class _FunctionResultCallback_3_4 : public Callback4 { public: - typedef Callback4 base; - typedef void (*FunctionSignature)(P1,P2,P3,A1,A2,A3,A4); + typedef Callback4 base; + typedef void (*FunctionSignature)(P1, P2, P3, A1, A2, A3, A4); private: FunctionSignature function_; @@ -9501,23 +10714,27 @@ class _FunctionResultCallback_3_4 : publi typename remove_reference::type p3_; public: - inline _FunctionResultCallback_3_4(FunctionSignature function, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) - : Callback4(), - function_(function), p1_(p1), p2_(p2), p3_(p3) { } + inline _FunctionResultCallback_3_4(FunctionSignature function, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3) + : Callback4(), + function_(function), + p1_(p1), + p2_(p2), + p3_(p3) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback4"); } - virtual void Run(A1 a1,A2 a2,A3 a3,A4 a4) { + virtual void Run(A1 a1, A2 a2, A3 a3, A4 a4) { if (!del) { - (*function_)(p1_,p2_,p3_,a1,a2,a3,a4); + (*function_)(p1_, p2_, p3_, a1, a2, a3, a4); } else { - (*function_)(p1_,p2_,p3_,a1,a2,a3,a4); + (*function_)(p1_, p2_, p3_, a1, a2, a3, a4); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -9525,26 +10742,38 @@ class _FunctionResultCallback_3_4 : publi } }; -template -inline typename _FunctionResultCallback_3_4::base* -NewCallback(R (*function)(P1,P2,P3,A1,A2,A3,A4), typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) { - return new _FunctionResultCallback_3_4(function, p1, p2, p3); +template +inline typename _FunctionResultCallback_3_4::base* +NewCallback(R (*function)(P1, P2, P3, A1, A2, A3, A4), + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3) { + return new _FunctionResultCallback_3_4( + function, p1, p2, p3); } -template -inline typename _FunctionResultCallback_3_4::base* -NewPermanentCallback(R (*function)(P1,P2,P3,A1,A2,A3,A4), typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) { - return new _FunctionResultCallback_3_4(function, p1, p2, p3); +template +inline typename _FunctionResultCallback_3_4::base* +NewPermanentCallback(R (*function)(P1, P2, P3, A1, A2, A3, A4), + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3) { + return new _FunctionResultCallback_3_4( + function, p1, p2, p3); } -template ::value - >::type> -class _ConstMemberResultCallback_4_4 : public ResultCallback4 { +template < + bool del, class R, class T, class P1, class P2, class P3, class P4, + class A1, class A2, class A3, class A4, + class OnlyIf = typename c_enable_if::value>::type> +class _ConstMemberResultCallback_4_4 + : public ResultCallback4 { public: - typedef ResultCallback4 base; - typedef R (T::*MemberSignature)(P1,P2,P3,P4,A1,A2,A3,A4) const; + typedef ResultCallback4 base; + typedef R (T::*MemberSignature)(P1, P2, P3, P4, A1, A2, A3, A4) const; private: const T* object_; @@ -9555,25 +10784,31 @@ class _ConstMemberResultCallback_4_4 : public ResultCallback4 { typename remove_reference::type p4_; public: - inline _ConstMemberResultCallback_4_4(const T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) - : ResultCallback4(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4) { } + inline _ConstMemberResultCallback_4_4(const T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4) + : ResultCallback4(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback4"); } - virtual R Run(A1 a1,A2 a2,A3 a3,A4 a4) { + virtual R Run(A1 a1, A2 a2, A3 a3, A4 a4) { if (!del) { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,a1,a2,a3,a4); + R result = (object_->*member_)(p1_, p2_, p3_, p4_, a1, a2, a3, a4); return result; } else { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,a1,a2,a3,a4); + R result = (object_->*member_)(p1_, p2_, p3_, p4_, a1, a2, a3, a4); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -9582,15 +10817,15 @@ class _ConstMemberResultCallback_4_4 : public ResultCallback4 { } }; -template -class _ConstMemberResultCallback_4_4::value - >::type> - : public Callback4 { +template +class _ConstMemberResultCallback_4_4< + del, void, T, P1, P2, P3, P4, A1, A2, A3, A4, + typename c_enable_if< + is_class_or_union::value>::type> : public Callback4 { public: - typedef Callback4 base; - typedef void (T::*MemberSignature)(P1,P2,P3,P4,A1,A2,A3,A4) const; + typedef Callback4 base; + typedef void (T::*MemberSignature)(P1, P2, P3, P4, A1, A2, A3, A4) const; private: const T* object_; @@ -9601,24 +10836,30 @@ class _ConstMemberResultCallback_4_4::type p4_; public: - inline _ConstMemberResultCallback_4_4(const T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) - : Callback4(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4) { } + inline _ConstMemberResultCallback_4_4(const T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4) + : Callback4(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback4"); } - virtual void Run(A1 a1,A2 a2,A3 a3,A4 a4) { + virtual void Run(A1 a1, A2 a2, A3 a3, A4 a4) { if (!del) { - (object_->*member_)(p1_,p2_,p3_,p4_,a1,a2,a3,a4); + (object_->*member_)(p1_, p2_, p3_, p4_, a1, a2, a3, a4); } else { - (object_->*member_)(p1_,p2_,p3_,p4_,a1,a2,a3,a4); + (object_->*member_)(p1_, p2_, p3_, p4_, a1, a2, a3, a4); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -9627,32 +10868,47 @@ class _ConstMemberResultCallback_4_4 -inline typename _ConstMemberResultCallback_4_4::base* -NewCallback(const T1* obj, R (T2::*member)(P1,P2,P3,P4,A1,A2,A3,A4) const, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) { - return new _ConstMemberResultCallback_4_4(obj, member, p1, p2, p3, p4); +template +inline typename _ConstMemberResultCallback_4_4::base* +NewCallback(const T1* obj, + R (T2::*member)(P1, P2, P3, P4, A1, A2, A3, A4) const, + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3, typename ConstRef::type p4) { + return new _ConstMemberResultCallback_4_4< + true, R, T1, P1, P2, P3, P4, A1, A2, A3, A4>(obj, member, p1, p2, p3, p4); } #endif #ifndef SWIG -template -inline typename _ConstMemberResultCallback_4_4::base* -NewPermanentCallback(const T1* obj, R (T2::*member)(P1,P2,P3,P4,A1,A2,A3,A4) const, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) { - return new _ConstMemberResultCallback_4_4(obj, member, p1, p2, p3, p4); +template +inline typename _ConstMemberResultCallback_4_4::base* +NewPermanentCallback(const T1* obj, + R (T2::*member)(P1, P2, P3, P4, A1, A2, A3, A4) const, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4) { + return new _ConstMemberResultCallback_4_4(obj, member, p1, p2, p3, + p4); } #endif -template ::value - >::type> -class _MemberResultCallback_4_4 : public ResultCallback4 { +template < + bool del, class R, class T, class P1, class P2, class P3, class P4, + class A1, class A2, class A3, class A4, + class OnlyIf = typename c_enable_if::value>::type> +class _MemberResultCallback_4_4 : public ResultCallback4 { public: - typedef ResultCallback4 base; - typedef R (T::*MemberSignature)(P1,P2,P3,P4,A1,A2,A3,A4) ; + typedef ResultCallback4 base; + typedef R (T::*MemberSignature)(P1, P2, P3, P4, A1, A2, A3, A4); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; typename remove_reference::type p2_; @@ -9660,25 +10916,31 @@ class _MemberResultCallback_4_4 : public ResultCallback4 { typename remove_reference::type p4_; public: - inline _MemberResultCallback_4_4( T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) - : ResultCallback4(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4) { } + inline _MemberResultCallback_4_4(T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4) + : ResultCallback4(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback4"); } - virtual R Run(A1 a1,A2 a2,A3 a3,A4 a4) { + virtual R Run(A1 a1, A2 a2, A3 a3, A4 a4) { if (!del) { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,a1,a2,a3,a4); + R result = (object_->*member_)(p1_, p2_, p3_, p4_, a1, a2, a3, a4); return result; } else { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,a1,a2,a3,a4); + R result = (object_->*member_)(p1_, p2_, p3_, p4_, a1, a2, a3, a4); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -9687,18 +10949,18 @@ class _MemberResultCallback_4_4 : public ResultCallback4 { } }; -template -class _MemberResultCallback_4_4::value - >::type> - : public Callback4 { +template +class _MemberResultCallback_4_4< + del, void, T, P1, P2, P3, P4, A1, A2, A3, A4, + typename c_enable_if< + is_class_or_union::value>::type> : public Callback4 { public: - typedef Callback4 base; - typedef void (T::*MemberSignature)(P1,P2,P3,P4,A1,A2,A3,A4) ; + typedef Callback4 base; + typedef void (T::*MemberSignature)(P1, P2, P3, P4, A1, A2, A3, A4); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; typename remove_reference::type p2_; @@ -9706,24 +10968,30 @@ class _MemberResultCallback_4_4::type p4_; public: - inline _MemberResultCallback_4_4( T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) - : Callback4(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4) { } + inline _MemberResultCallback_4_4(T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4) + : Callback4(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback4"); } - virtual void Run(A1 a1,A2 a2,A3 a3,A4 a4) { + virtual void Run(A1 a1, A2 a2, A3 a3, A4 a4) { if (!del) { - (object_->*member_)(p1_,p2_,p3_,p4_,a1,a2,a3,a4); + (object_->*member_)(p1_, p2_, p3_, p4_, a1, a2, a3, a4); } else { - (object_->*member_)(p1_,p2_,p3_,p4_,a1,a2,a3,a4); + (object_->*member_)(p1_, p2_, p3_, p4_, a1, a2, a3, a4); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -9732,26 +11000,39 @@ class _MemberResultCallback_4_4 -inline typename _MemberResultCallback_4_4::base* -NewCallback( T1* obj, R (T2::*member)(P1,P2,P3,P4,A1,A2,A3,A4) , typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) { - return new _MemberResultCallback_4_4(obj, member, p1, p2, p3, p4); +template +inline typename _MemberResultCallback_4_4::base* +NewCallback(T1* obj, R (T2::*member)(P1, P2, P3, P4, A1, A2, A3, A4), + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3, typename ConstRef::type p4) { + return new _MemberResultCallback_4_4(obj, member, p1, p2, p3, p4); } #endif #ifndef SWIG -template -inline typename _MemberResultCallback_4_4::base* -NewPermanentCallback( T1* obj, R (T2::*member)(P1,P2,P3,P4,A1,A2,A3,A4) , typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) { - return new _MemberResultCallback_4_4(obj, member, p1, p2, p3, p4); +template +inline typename _MemberResultCallback_4_4::base* +NewPermanentCallback(T1* obj, R (T2::*member)(P1, P2, P3, P4, A1, A2, A3, A4), + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4) { + return new _MemberResultCallback_4_4(obj, member, p1, p2, p3, p4); } #endif -template -class _FunctionResultCallback_4_4 : public ResultCallback4 { +template +class _FunctionResultCallback_4_4 : public ResultCallback4 { public: - typedef ResultCallback4 base; - typedef R (*FunctionSignature)(P1,P2,P3,P4,A1,A2,A3,A4); + typedef ResultCallback4 base; + typedef R (*FunctionSignature)(P1, P2, P3, P4, A1, A2, A3, A4); private: FunctionSignature function_; @@ -9761,24 +11042,30 @@ class _FunctionResultCallback_4_4 : public ResultCallback4 { typename remove_reference::type p4_; public: - inline _FunctionResultCallback_4_4(FunctionSignature function, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) - : ResultCallback4(), - function_(function), p1_(p1), p2_(p2), p3_(p3), p4_(p4) { } + inline _FunctionResultCallback_4_4(FunctionSignature function, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4) + : ResultCallback4(), + function_(function), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback4"); } - virtual R Run(A1 a1,A2 a2,A3 a3,A4 a4) { + virtual R Run(A1 a1, A2 a2, A3 a3, A4 a4) { if (!del) { - R result = (*function_)(p1_,p2_,p3_,p4_,a1,a2,a3,a4); + R result = (*function_)(p1_, p2_, p3_, p4_, a1, a2, a3, a4); return result; } else { - R result = (*function_)(p1_,p2_,p3_,p4_,a1,a2,a3,a4); + R result = (*function_)(p1_, p2_, p3_, p4_, a1, a2, a3, a4); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -9787,11 +11074,13 @@ class _FunctionResultCallback_4_4 : public ResultCallback4 { } }; -template -class _FunctionResultCallback_4_4 : public Callback4 { +template +class _FunctionResultCallback_4_4 : public Callback4 { public: - typedef Callback4 base; - typedef void (*FunctionSignature)(P1,P2,P3,P4,A1,A2,A3,A4); + typedef Callback4 base; + typedef void (*FunctionSignature)(P1, P2, P3, P4, A1, A2, A3, A4); private: FunctionSignature function_; @@ -9801,23 +11090,29 @@ class _FunctionResultCallback_4_4 : p typename remove_reference::type p4_; public: - inline _FunctionResultCallback_4_4(FunctionSignature function, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) - : Callback4(), - function_(function), p1_(p1), p2_(p2), p3_(p3), p4_(p4) { } + inline _FunctionResultCallback_4_4(FunctionSignature function, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4) + : Callback4(), + function_(function), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback4"); } - virtual void Run(A1 a1,A2 a2,A3 a3,A4 a4) { + virtual void Run(A1 a1, A2 a2, A3 a3, A4 a4) { if (!del) { - (*function_)(p1_,p2_,p3_,p4_,a1,a2,a3,a4); + (*function_)(p1_, p2_, p3_, p4_, a1, a2, a3, a4); } else { - (*function_)(p1_,p2_,p3_,p4_,a1,a2,a3,a4); + (*function_)(p1_, p2_, p3_, p4_, a1, a2, a3, a4); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -9825,26 +11120,39 @@ class _FunctionResultCallback_4_4 : p } }; -template -inline typename _FunctionResultCallback_4_4::base* -NewCallback(R (*function)(P1,P2,P3,P4,A1,A2,A3,A4), typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) { - return new _FunctionResultCallback_4_4(function, p1, p2, p3, p4); +template +inline typename _FunctionResultCallback_4_4::base* +NewCallback(R (*function)(P1, P2, P3, P4, A1, A2, A3, A4), + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3, typename ConstRef::type p4) { + return new _FunctionResultCallback_4_4(function, p1, p2, p3, p4); } -template -inline typename _FunctionResultCallback_4_4::base* -NewPermanentCallback(R (*function)(P1,P2,P3,P4,A1,A2,A3,A4), typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) { - return new _FunctionResultCallback_4_4(function, p1, p2, p3, p4); +template +inline typename _FunctionResultCallback_4_4::base* +NewPermanentCallback(R (*function)(P1, P2, P3, P4, A1, A2, A3, A4), + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4) { + return new _FunctionResultCallback_4_4(function, p1, p2, p3, p4); } -template ::value - >::type> -class _ConstMemberResultCallback_5_4 : public ResultCallback4 { +template < + bool del, class R, class T, class P1, class P2, class P3, class P4, + class P5, class A1, class A2, class A3, class A4, + class OnlyIf = typename c_enable_if::value>::type> +class _ConstMemberResultCallback_5_4 + : public ResultCallback4 { public: - typedef ResultCallback4 base; - typedef R (T::*MemberSignature)(P1,P2,P3,P4,P5,A1,A2,A3,A4) const; + typedef ResultCallback4 base; + typedef R (T::*MemberSignature)(P1, P2, P3, P4, P5, A1, A2, A3, A4) const; private: const T* object_; @@ -9856,25 +11164,33 @@ class _ConstMemberResultCallback_5_4 : public ResultCallback4 { typename remove_reference::type p5_; public: - inline _ConstMemberResultCallback_5_4(const T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) - : ResultCallback4(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5) { } + inline _ConstMemberResultCallback_5_4(const T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5) + : ResultCallback4(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback4"); } - virtual R Run(A1 a1,A2 a2,A3 a3,A4 a4) { + virtual R Run(A1 a1, A2 a2, A3 a3, A4 a4) { if (!del) { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,p5_,a1,a2,a3,a4); + R result = (object_->*member_)(p1_, p2_, p3_, p4_, p5_, a1, a2, a3, a4); return result; } else { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,p5_,a1,a2,a3,a4); + R result = (object_->*member_)(p1_, p2_, p3_, p4_, p5_, a1, a2, a3, a4); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -9883,15 +11199,15 @@ class _ConstMemberResultCallback_5_4 : public ResultCallback4 { } }; -template -class _ConstMemberResultCallback_5_4::value - >::type> - : public Callback4 { +template +class _ConstMemberResultCallback_5_4< + del, void, T, P1, P2, P3, P4, P5, A1, A2, A3, A4, + typename c_enable_if< + is_class_or_union::value>::type> : public Callback4 { public: - typedef Callback4 base; - typedef void (T::*MemberSignature)(P1,P2,P3,P4,P5,A1,A2,A3,A4) const; + typedef Callback4 base; + typedef void (T::*MemberSignature)(P1, P2, P3, P4, P5, A1, A2, A3, A4) const; private: const T* object_; @@ -9903,24 +11219,32 @@ class _ConstMemberResultCallback_5_4::type p5_; public: - inline _ConstMemberResultCallback_5_4(const T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) - : Callback4(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5) { } + inline _ConstMemberResultCallback_5_4(const T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5) + : Callback4(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback4"); } - virtual void Run(A1 a1,A2 a2,A3 a3,A4 a4) { + virtual void Run(A1 a1, A2 a2, A3 a3, A4 a4) { if (!del) { - (object_->*member_)(p1_,p2_,p3_,p4_,p5_,a1,a2,a3,a4); + (object_->*member_)(p1_, p2_, p3_, p4_, p5_, a1, a2, a3, a4); } else { - (object_->*member_)(p1_,p2_,p3_,p4_,p5_,a1,a2,a3,a4); + (object_->*member_)(p1_, p2_, p3_, p4_, p5_, a1, a2, a3, a4); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -9929,32 +11253,50 @@ class _ConstMemberResultCallback_5_4 -inline typename _ConstMemberResultCallback_5_4::base* -NewCallback(const T1* obj, R (T2::*member)(P1,P2,P3,P4,P5,A1,A2,A3,A4) const, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) { - return new _ConstMemberResultCallback_5_4(obj, member, p1, p2, p3, p4, p5); +template +inline typename _ConstMemberResultCallback_5_4::base* +NewCallback(const T1* obj, + R (T2::*member)(P1, P2, P3, P4, P5, A1, A2, A3, A4) const, + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3, typename ConstRef::type p4, + typename ConstRef::type p5) { + return new _ConstMemberResultCallback_5_4(obj, member, p1, p2, p3, + p4, p5); } #endif #ifndef SWIG -template -inline typename _ConstMemberResultCallback_5_4::base* -NewPermanentCallback(const T1* obj, R (T2::*member)(P1,P2,P3,P4,P5,A1,A2,A3,A4) const, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) { - return new _ConstMemberResultCallback_5_4(obj, member, p1, p2, p3, p4, p5); +template +inline typename _ConstMemberResultCallback_5_4::base* +NewPermanentCallback(const T1* obj, + R (T2::*member)(P1, P2, P3, P4, P5, A1, A2, A3, A4) const, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5) { + return new _ConstMemberResultCallback_5_4< + false, R, T1, P1, P2, P3, P4, P5, A1, A2, A3, A4>(obj, member, p1, p2, p3, + p4, p5); } #endif -template ::value - >::type> -class _MemberResultCallback_5_4 : public ResultCallback4 { +template < + bool del, class R, class T, class P1, class P2, class P3, class P4, + class P5, class A1, class A2, class A3, class A4, + class OnlyIf = typename c_enable_if::value>::type> +class _MemberResultCallback_5_4 : public ResultCallback4 { public: - typedef ResultCallback4 base; - typedef R (T::*MemberSignature)(P1,P2,P3,P4,P5,A1,A2,A3,A4) ; + typedef ResultCallback4 base; + typedef R (T::*MemberSignature)(P1, P2, P3, P4, P5, A1, A2, A3, A4); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; typename remove_reference::type p2_; @@ -9963,25 +11305,33 @@ class _MemberResultCallback_5_4 : public ResultCallback4 { typename remove_reference::type p5_; public: - inline _MemberResultCallback_5_4( T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) - : ResultCallback4(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5) { } + inline _MemberResultCallback_5_4(T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5) + : ResultCallback4(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback4"); } - virtual R Run(A1 a1,A2 a2,A3 a3,A4 a4) { + virtual R Run(A1 a1, A2 a2, A3 a3, A4 a4) { if (!del) { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,p5_,a1,a2,a3,a4); + R result = (object_->*member_)(p1_, p2_, p3_, p4_, p5_, a1, a2, a3, a4); return result; } else { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,p5_,a1,a2,a3,a4); + R result = (object_->*member_)(p1_, p2_, p3_, p4_, p5_, a1, a2, a3, a4); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -9990,18 +11340,18 @@ class _MemberResultCallback_5_4 : public ResultCallback4 { } }; -template -class _MemberResultCallback_5_4::value - >::type> - : public Callback4 { +template +class _MemberResultCallback_5_4< + del, void, T, P1, P2, P3, P4, P5, A1, A2, A3, A4, + typename c_enable_if< + is_class_or_union::value>::type> : public Callback4 { public: - typedef Callback4 base; - typedef void (T::*MemberSignature)(P1,P2,P3,P4,P5,A1,A2,A3,A4) ; + typedef Callback4 base; + typedef void (T::*MemberSignature)(P1, P2, P3, P4, P5, A1, A2, A3, A4); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; typename remove_reference::type p2_; @@ -10010,24 +11360,32 @@ class _MemberResultCallback_5_4::type p5_; public: - inline _MemberResultCallback_5_4( T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) - : Callback4(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5) { } + inline _MemberResultCallback_5_4(T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5) + : Callback4(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback4"); } - virtual void Run(A1 a1,A2 a2,A3 a3,A4 a4) { + virtual void Run(A1 a1, A2 a2, A3 a3, A4 a4) { if (!del) { - (object_->*member_)(p1_,p2_,p3_,p4_,p5_,a1,a2,a3,a4); + (object_->*member_)(p1_, p2_, p3_, p4_, p5_, a1, a2, a3, a4); } else { - (object_->*member_)(p1_,p2_,p3_,p4_,p5_,a1,a2,a3,a4); + (object_->*member_)(p1_, p2_, p3_, p4_, p5_, a1, a2, a3, a4); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -10036,26 +11394,42 @@ class _MemberResultCallback_5_4 -inline typename _MemberResultCallback_5_4::base* -NewCallback( T1* obj, R (T2::*member)(P1,P2,P3,P4,P5,A1,A2,A3,A4) , typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) { - return new _MemberResultCallback_5_4(obj, member, p1, p2, p3, p4, p5); +template +inline typename _MemberResultCallback_5_4::base* +NewCallback(T1* obj, R (T2::*member)(P1, P2, P3, P4, P5, A1, A2, A3, A4), + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3, typename ConstRef::type p4, + typename ConstRef::type p5) { + return new _MemberResultCallback_5_4(obj, member, p1, p2, p3, p4, p5); } #endif #ifndef SWIG -template -inline typename _MemberResultCallback_5_4::base* -NewPermanentCallback( T1* obj, R (T2::*member)(P1,P2,P3,P4,P5,A1,A2,A3,A4) , typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) { - return new _MemberResultCallback_5_4(obj, member, p1, p2, p3, p4, p5); +template +inline typename _MemberResultCallback_5_4::base* +NewPermanentCallback(T1* obj, + R (T2::*member)(P1, P2, P3, P4, P5, A1, A2, A3, A4), + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5) { + return new _MemberResultCallback_5_4(obj, member, p1, p2, p3, p4, p5); } #endif -template -class _FunctionResultCallback_5_4 : public ResultCallback4 { +template +class _FunctionResultCallback_5_4 : public ResultCallback4 { public: - typedef ResultCallback4 base; - typedef R (*FunctionSignature)(P1,P2,P3,P4,P5,A1,A2,A3,A4); + typedef ResultCallback4 base; + typedef R (*FunctionSignature)(P1, P2, P3, P4, P5, A1, A2, A3, A4); private: FunctionSignature function_; @@ -10066,24 +11440,32 @@ class _FunctionResultCallback_5_4 : public ResultCallback4 { typename remove_reference::type p5_; public: - inline _FunctionResultCallback_5_4(FunctionSignature function, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) - : ResultCallback4(), - function_(function), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5) { } + inline _FunctionResultCallback_5_4(FunctionSignature function, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5) + : ResultCallback4(), + function_(function), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback4"); } - virtual R Run(A1 a1,A2 a2,A3 a3,A4 a4) { + virtual R Run(A1 a1, A2 a2, A3 a3, A4 a4) { if (!del) { - R result = (*function_)(p1_,p2_,p3_,p4_,p5_,a1,a2,a3,a4); + R result = (*function_)(p1_, p2_, p3_, p4_, p5_, a1, a2, a3, a4); return result; } else { - R result = (*function_)(p1_,p2_,p3_,p4_,p5_,a1,a2,a3,a4); + R result = (*function_)(p1_, p2_, p3_, p4_, p5_, a1, a2, a3, a4); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -10092,11 +11474,13 @@ class _FunctionResultCallback_5_4 : public ResultCallback4 { } }; -template -class _FunctionResultCallback_5_4 : public Callback4 { +template +class _FunctionResultCallback_5_4 : public Callback4 { public: - typedef Callback4 base; - typedef void (*FunctionSignature)(P1,P2,P3,P4,P5,A1,A2,A3,A4); + typedef Callback4 base; + typedef void (*FunctionSignature)(P1, P2, P3, P4, P5, A1, A2, A3, A4); private: FunctionSignature function_; @@ -10107,23 +11491,31 @@ class _FunctionResultCallback_5_4 typename remove_reference::type p5_; public: - inline _FunctionResultCallback_5_4(FunctionSignature function, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) - : Callback4(), - function_(function), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5) { } + inline _FunctionResultCallback_5_4(FunctionSignature function, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5) + : Callback4(), + function_(function), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback4"); } - virtual void Run(A1 a1,A2 a2,A3 a3,A4 a4) { + virtual void Run(A1 a1, A2 a2, A3 a3, A4 a4) { if (!del) { - (*function_)(p1_,p2_,p3_,p4_,p5_,a1,a2,a3,a4); + (*function_)(p1_, p2_, p3_, p4_, p5_, a1, a2, a3, a4); } else { - (*function_)(p1_,p2_,p3_,p4_,p5_,a1,a2,a3,a4); + (*function_)(p1_, p2_, p3_, p4_, p5_, a1, a2, a3, a4); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -10131,26 +11523,41 @@ class _FunctionResultCallback_5_4 } }; -template -inline typename _FunctionResultCallback_5_4::base* -NewCallback(R (*function)(P1,P2,P3,P4,P5,A1,A2,A3,A4), typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) { - return new _FunctionResultCallback_5_4(function, p1, p2, p3, p4, p5); +template +inline typename _FunctionResultCallback_5_4::base* +NewCallback(R (*function)(P1, P2, P3, P4, P5, A1, A2, A3, A4), + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3, typename ConstRef::type p4, + typename ConstRef::type p5) { + return new _FunctionResultCallback_5_4(function, p1, p2, p3, p4, p5); } -template -inline typename _FunctionResultCallback_5_4::base* -NewPermanentCallback(R (*function)(P1,P2,P3,P4,P5,A1,A2,A3,A4), typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) { - return new _FunctionResultCallback_5_4(function, p1, p2, p3, p4, p5); +template +inline typename _FunctionResultCallback_5_4::base* +NewPermanentCallback(R (*function)(P1, P2, P3, P4, P5, A1, A2, A3, A4), + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5) { + return new _FunctionResultCallback_5_4(function, p1, p2, p3, p4, p5); } -template ::value - >::type> -class _ConstMemberResultCallback_6_4 : public ResultCallback4 { +template < + bool del, class R, class T, class P1, class P2, class P3, class P4, + class P5, class P6, class A1, class A2, class A3, class A4, + class OnlyIf = typename c_enable_if::value>::type> +class _ConstMemberResultCallback_6_4 + : public ResultCallback4 { public: - typedef ResultCallback4 base; - typedef R (T::*MemberSignature)(P1,P2,P3,P4,P5,P6,A1,A2,A3,A4) const; + typedef ResultCallback4 base; + typedef R (T::*MemberSignature)(P1, P2, P3, P4, P5, P6, A1, A2, A3, A4) const; private: const T* object_; @@ -10163,25 +11570,37 @@ class _ConstMemberResultCallback_6_4 : public ResultCallback4 { typename remove_reference::type p6_; public: - inline _ConstMemberResultCallback_6_4(const T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) - : ResultCallback4(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5), p6_(p6) { } + inline _ConstMemberResultCallback_6_4(const T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5, + typename ConstRef::type p6) + : ResultCallback4(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5), + p6_(p6) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback4"); } - virtual R Run(A1 a1,A2 a2,A3 a3,A4 a4) { + virtual R Run(A1 a1, A2 a2, A3 a3, A4 a4) { if (!del) { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,p5_,p6_,a1,a2,a3,a4); + R result = + (object_->*member_)(p1_, p2_, p3_, p4_, p5_, p6_, a1, a2, a3, a4); return result; } else { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,p5_,p6_,a1,a2,a3,a4); + R result = + (object_->*member_)(p1_, p2_, p3_, p4_, p5_, p6_, a1, a2, a3, a4); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -10190,15 +11609,16 @@ class _ConstMemberResultCallback_6_4 : public ResultCallback4 { } }; -template -class _ConstMemberResultCallback_6_4::value - >::type> - : public Callback4 { +template +class _ConstMemberResultCallback_6_4< + del, void, T, P1, P2, P3, P4, P5, P6, A1, A2, A3, A4, + typename c_enable_if< + is_class_or_union::value>::type> : public Callback4 { public: - typedef Callback4 base; - typedef void (T::*MemberSignature)(P1,P2,P3,P4,P5,P6,A1,A2,A3,A4) const; + typedef Callback4 base; + typedef void (T::*MemberSignature)(P1, P2, P3, P4, P5, P6, A1, A2, A3, + A4) const; private: const T* object_; @@ -10211,24 +11631,34 @@ class _ConstMemberResultCallback_6_4::type p6_; public: - inline _ConstMemberResultCallback_6_4(const T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) - : Callback4(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5), p6_(p6) { } + inline _ConstMemberResultCallback_6_4(const T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5, + typename ConstRef::type p6) + : Callback4(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5), + p6_(p6) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback4"); } - virtual void Run(A1 a1,A2 a2,A3 a3,A4 a4) { + virtual void Run(A1 a1, A2 a2, A3 a3, A4 a4) { if (!del) { - (object_->*member_)(p1_,p2_,p3_,p4_,p5_,p6_,a1,a2,a3,a4); + (object_->*member_)(p1_, p2_, p3_, p4_, p5_, p6_, a1, a2, a3, a4); } else { - (object_->*member_)(p1_,p2_,p3_,p4_,p5_,p6_,a1,a2,a3,a4); + (object_->*member_)(p1_, p2_, p3_, p4_, p5_, p6_, a1, a2, a3, a4); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -10237,32 +11667,49 @@ class _ConstMemberResultCallback_6_4 -inline typename _ConstMemberResultCallback_6_4::base* -NewCallback(const T1* obj, R (T2::*member)(P1,P2,P3,P4,P5,P6,A1,A2,A3,A4) const, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) { - return new _ConstMemberResultCallback_6_4(obj, member, p1, p2, p3, p4, p5, p6); +template +inline typename _ConstMemberResultCallback_6_4::base* +NewCallback(const T1* obj, + R (T2::*member)(P1, P2, P3, P4, P5, P6, A1, A2, A3, A4) const, + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3, typename ConstRef::type p4, + typename ConstRef::type p5, typename ConstRef::type p6) { + return new _ConstMemberResultCallback_6_4(obj, member, p1, p2, + p3, p4, p5, p6); } #endif #ifndef SWIG -template -inline typename _ConstMemberResultCallback_6_4::base* -NewPermanentCallback(const T1* obj, R (T2::*member)(P1,P2,P3,P4,P5,P6,A1,A2,A3,A4) const, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) { - return new _ConstMemberResultCallback_6_4(obj, member, p1, p2, p3, p4, p5, p6); +template +inline typename _ConstMemberResultCallback_6_4::base* +NewPermanentCallback( + const T1* obj, + R (T2::*member)(P1, P2, P3, P4, P5, P6, A1, A2, A3, A4) const, + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3, typename ConstRef::type p4, + typename ConstRef::type p5, typename ConstRef::type p6) { + return new _ConstMemberResultCallback_6_4< + false, R, T1, P1, P2, P3, P4, P5, P6, A1, A2, A3, A4>(obj, member, p1, p2, + p3, p4, p5, p6); } #endif -template ::value - >::type> -class _MemberResultCallback_6_4 : public ResultCallback4 { +template < + bool del, class R, class T, class P1, class P2, class P3, class P4, + class P5, class P6, class A1, class A2, class A3, class A4, + class OnlyIf = typename c_enable_if::value>::type> +class _MemberResultCallback_6_4 : public ResultCallback4 { public: - typedef ResultCallback4 base; - typedef R (T::*MemberSignature)(P1,P2,P3,P4,P5,P6,A1,A2,A3,A4) ; + typedef ResultCallback4 base; + typedef R (T::*MemberSignature)(P1, P2, P3, P4, P5, P6, A1, A2, A3, A4); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; typename remove_reference::type p2_; @@ -10272,25 +11719,37 @@ class _MemberResultCallback_6_4 : public ResultCallback4 { typename remove_reference::type p6_; public: - inline _MemberResultCallback_6_4( T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) - : ResultCallback4(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5), p6_(p6) { } + inline _MemberResultCallback_6_4(T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5, + typename ConstRef::type p6) + : ResultCallback4(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5), + p6_(p6) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback4"); } - virtual R Run(A1 a1,A2 a2,A3 a3,A4 a4) { + virtual R Run(A1 a1, A2 a2, A3 a3, A4 a4) { if (!del) { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,p5_,p6_,a1,a2,a3,a4); + R result = + (object_->*member_)(p1_, p2_, p3_, p4_, p5_, p6_, a1, a2, a3, a4); return result; } else { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,p5_,p6_,a1,a2,a3,a4); + R result = + (object_->*member_)(p1_, p2_, p3_, p4_, p5_, p6_, a1, a2, a3, a4); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -10299,18 +11758,18 @@ class _MemberResultCallback_6_4 : public ResultCallback4 { } }; -template -class _MemberResultCallback_6_4::value - >::type> - : public Callback4 { +template +class _MemberResultCallback_6_4< + del, void, T, P1, P2, P3, P4, P5, P6, A1, A2, A3, A4, + typename c_enable_if< + is_class_or_union::value>::type> : public Callback4 { public: - typedef Callback4 base; - typedef void (T::*MemberSignature)(P1,P2,P3,P4,P5,P6,A1,A2,A3,A4) ; + typedef Callback4 base; + typedef void (T::*MemberSignature)(P1, P2, P3, P4, P5, P6, A1, A2, A3, A4); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; typename remove_reference::type p2_; @@ -10320,24 +11779,34 @@ class _MemberResultCallback_6_4::type p6_; public: - inline _MemberResultCallback_6_4( T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) - : Callback4(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5), p6_(p6) { } + inline _MemberResultCallback_6_4(T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5, + typename ConstRef::type p6) + : Callback4(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5), + p6_(p6) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback4"); } - virtual void Run(A1 a1,A2 a2,A3 a3,A4 a4) { + virtual void Run(A1 a1, A2 a2, A3 a3, A4 a4) { if (!del) { - (object_->*member_)(p1_,p2_,p3_,p4_,p5_,p6_,a1,a2,a3,a4); + (object_->*member_)(p1_, p2_, p3_, p4_, p5_, p6_, a1, a2, a3, a4); } else { - (object_->*member_)(p1_,p2_,p3_,p4_,p5_,p6_,a1,a2,a3,a4); + (object_->*member_)(p1_, p2_, p3_, p4_, p5_, p6_, a1, a2, a3, a4); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -10346,26 +11815,42 @@ class _MemberResultCallback_6_4 -inline typename _MemberResultCallback_6_4::base* -NewCallback( T1* obj, R (T2::*member)(P1,P2,P3,P4,P5,P6,A1,A2,A3,A4) , typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) { - return new _MemberResultCallback_6_4(obj, member, p1, p2, p3, p4, p5, p6); +template +inline typename _MemberResultCallback_6_4::base* +NewCallback(T1* obj, R (T2::*member)(P1, P2, P3, P4, P5, P6, A1, A2, A3, A4), + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3, typename ConstRef::type p4, + typename ConstRef::type p5, typename ConstRef::type p6) { + return new _MemberResultCallback_6_4(obj, member, p1, p2, p3, p4, + p5, p6); } #endif #ifndef SWIG -template -inline typename _MemberResultCallback_6_4::base* -NewPermanentCallback( T1* obj, R (T2::*member)(P1,P2,P3,P4,P5,P6,A1,A2,A3,A4) , typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) { - return new _MemberResultCallback_6_4(obj, member, p1, p2, p3, p4, p5, p6); +template +inline typename _MemberResultCallback_6_4::base* +NewPermanentCallback( + T1* obj, R (T2::*member)(P1, P2, P3, P4, P5, P6, A1, A2, A3, A4), + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3, typename ConstRef::type p4, + typename ConstRef::type p5, typename ConstRef::type p6) { + return new _MemberResultCallback_6_4(obj, member, p1, p2, p3, p4, + p5, p6); } #endif -template -class _FunctionResultCallback_6_4 : public ResultCallback4 { +template +class _FunctionResultCallback_6_4 : public ResultCallback4 { public: - typedef ResultCallback4 base; - typedef R (*FunctionSignature)(P1,P2,P3,P4,P5,P6,A1,A2,A3,A4); + typedef ResultCallback4 base; + typedef R (*FunctionSignature)(P1, P2, P3, P4, P5, P6, A1, A2, A3, A4); private: FunctionSignature function_; @@ -10377,24 +11862,34 @@ class _FunctionResultCallback_6_4 : public ResultCallback4 { typename remove_reference::type p6_; public: - inline _FunctionResultCallback_6_4(FunctionSignature function, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) - : ResultCallback4(), - function_(function), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5), p6_(p6) { } + inline _FunctionResultCallback_6_4(FunctionSignature function, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5, + typename ConstRef::type p6) + : ResultCallback4(), + function_(function), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5), + p6_(p6) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("ResultCallback4"); } - virtual R Run(A1 a1,A2 a2,A3 a3,A4 a4) { + virtual R Run(A1 a1, A2 a2, A3 a3, A4 a4) { if (!del) { - R result = (*function_)(p1_,p2_,p3_,p4_,p5_,p6_,a1,a2,a3,a4); + R result = (*function_)(p1_, p2_, p3_, p4_, p5_, p6_, a1, a2, a3, a4); return result; } else { - R result = (*function_)(p1_,p2_,p3_,p4_,p5_,p6_,a1,a2,a3,a4); + R result = (*function_)(p1_, p2_, p3_, p4_, p5_, p6_, a1, a2, a3, a4); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -10403,11 +11898,13 @@ class _FunctionResultCallback_6_4 : public ResultCallback4 { } }; -template -class _FunctionResultCallback_6_4 : public Callback4 { +template +class _FunctionResultCallback_6_4 : public Callback4 { public: - typedef Callback4 base; - typedef void (*FunctionSignature)(P1,P2,P3,P4,P5,P6,A1,A2,A3,A4); + typedef Callback4 base; + typedef void (*FunctionSignature)(P1, P2, P3, P4, P5, P6, A1, A2, A3, A4); private: FunctionSignature function_; @@ -10419,23 +11916,33 @@ class _FunctionResultCallback_6_4::type p6_; public: - inline _FunctionResultCallback_6_4(FunctionSignature function, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) - : Callback4(), - function_(function), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5), p6_(p6) { } + inline _FunctionResultCallback_6_4(FunctionSignature function, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5, + typename ConstRef::type p6) + : Callback4(), + function_(function), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5), + p6_(p6) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback4"); } - virtual void Run(A1 a1,A2 a2,A3 a3,A4 a4) { + virtual void Run(A1 a1, A2 a2, A3 a3, A4 a4) { if (!del) { - (*function_)(p1_,p2_,p3_,p4_,p5_,p6_,a1,a2,a3,a4); + (*function_)(p1_, p2_, p3_, p4_, p5_, p6_, a1, a2, a3, a4); } else { - (*function_)(p1_,p2_,p3_,p4_,p5_,p6_,a1,a2,a3,a4); + (*function_)(p1_, p2_, p3_, p4_, p5_, p6_, a1, a2, a3, a4); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -10443,26 +11950,43 @@ class _FunctionResultCallback_6_4 -inline typename _FunctionResultCallback_6_4::base* -NewCallback(R (*function)(P1,P2,P3,P4,P5,P6,A1,A2,A3,A4), typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) { - return new _FunctionResultCallback_6_4(function, p1, p2, p3, p4, p5, p6); +template +inline typename _FunctionResultCallback_6_4::base* +NewCallback(R (*function)(P1, P2, P3, P4, P5, P6, A1, A2, A3, A4), + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3, typename ConstRef::type p4, + typename ConstRef::type p5, typename ConstRef::type p6) { + return new _FunctionResultCallback_6_4(function, p1, p2, p3, p4, + p5, p6); } -template -inline typename _FunctionResultCallback_6_4::base* -NewPermanentCallback(R (*function)(P1,P2,P3,P4,P5,P6,A1,A2,A3,A4), typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) { - return new _FunctionResultCallback_6_4(function, p1, p2, p3, p4, p5, p6); +template +inline typename _FunctionResultCallback_6_4::base* +NewPermanentCallback(R (*function)(P1, P2, P3, P4, P5, P6, A1, A2, A3, A4), + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5, + typename ConstRef::type p6) { + return new _FunctionResultCallback_6_4(function, p1, p2, p3, p4, + p5, p6); } -template ::value - >::type> -class _ConstMemberResultCallback_0_5 : public ResultCallback5 { +template ::value>::type> +class _ConstMemberResultCallback_0_5 + : public ResultCallback5 { public: - typedef ResultCallback5 base; - typedef R (T::*MemberSignature)(A1,A2,A3,A4,A5) const; + typedef ResultCallback5 base; + typedef R (T::*MemberSignature)(A1, A2, A3, A4, A5) const; private: const T* object_; @@ -10470,24 +11994,23 @@ class _ConstMemberResultCallback_0_5 : public ResultCallback5 public: inline _ConstMemberResultCallback_0_5(const T* object, MemberSignature member) - : ResultCallback5(), - object_(object), - member_(member) { } + : ResultCallback5(), + object_(object), + member_(member) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { - if (del) CallbackUtils_::FailIsRepeatable("ResultCallback5"); + if (del) + CallbackUtils_::FailIsRepeatable("ResultCallback5"); } - virtual R Run(A1 a1,A2 a2,A3 a3,A4 a4,A5 a5) { + virtual R Run(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { if (!del) { - R result = (object_->*member_)(a1,a2,a3,a4,a5); + R result = (object_->*member_)(a1, a2, a3, a4, a5); return result; } else { - R result = (object_->*member_)(a1,a2,a3,a4,a5); + R result = (object_->*member_)(a1, a2, a3, a4, a5); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -10497,14 +12020,13 @@ class _ConstMemberResultCallback_0_5 : public ResultCallback5 }; template -class _ConstMemberResultCallback_0_5::value - >::type> - : public Callback5 { +class _ConstMemberResultCallback_0_5< + del, void, T, A1, A2, A3, A4, A5, + typename c_enable_if::value>::type> : public Callback5 { public: - typedef Callback5 base; - typedef void (T::*MemberSignature)(A1,A2,A3,A4,A5) const; + typedef Callback5 base; + typedef void (T::*MemberSignature)(A1, A2, A3, A4, A5) const; private: const T* object_; @@ -10512,23 +12034,19 @@ class _ConstMemberResultCallback_0_5(), - object_(object), - member_(member) { } + : Callback5(), object_(object), member_(member) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback5"); } - virtual void Run(A1 a1,A2 a2,A3 a3,A4 a4,A5 a5) { + virtual void Run(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { if (!del) { - (object_->*member_)(a1,a2,a3,a4,a5); + (object_->*member_)(a1, a2, a3, a4, a5); } else { - (object_->*member_)(a1,a2,a3,a4,a5); + (object_->*member_)(a1, a2, a3, a4, a5); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -10537,54 +12055,59 @@ class _ConstMemberResultCallback_0_5 -inline typename _ConstMemberResultCallback_0_5::base* -NewCallback(const T1* obj, R (T2::*member)(A1,A2,A3,A4,A5) const) { - return new _ConstMemberResultCallback_0_5(obj, member); +template +inline typename _ConstMemberResultCallback_0_5::base* +NewCallback(const T1* obj, R (T2::*member)(A1, A2, A3, A4, A5) const) { + return new _ConstMemberResultCallback_0_5( + obj, member); } #endif #ifndef SWIG -template -inline typename _ConstMemberResultCallback_0_5::base* -NewPermanentCallback(const T1* obj, R (T2::*member)(A1,A2,A3,A4,A5) const) { - return new _ConstMemberResultCallback_0_5(obj, member); +template +inline typename _ConstMemberResultCallback_0_5::base* +NewPermanentCallback(const T1* obj, R (T2::*member)(A1, A2, A3, A4, A5) const) { + return new _ConstMemberResultCallback_0_5( + obj, member); } #endif -template ::value - >::type> -class _MemberResultCallback_0_5 : public ResultCallback5 { +template ::value>::type> +class _MemberResultCallback_0_5 + : public ResultCallback5 { public: - typedef ResultCallback5 base; - typedef R (T::*MemberSignature)(A1,A2,A3,A4,A5) ; + typedef ResultCallback5 base; + typedef R (T::*MemberSignature)(A1, A2, A3, A4, A5); private: - T* object_; + T* object_; MemberSignature member_; public: - inline _MemberResultCallback_0_5( T* object, MemberSignature member) - : ResultCallback5(), - object_(object), - member_(member) { } + inline _MemberResultCallback_0_5(T* object, MemberSignature member) + : ResultCallback5(), + object_(object), + member_(member) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { - if (del) CallbackUtils_::FailIsRepeatable("ResultCallback5"); + if (del) + CallbackUtils_::FailIsRepeatable("ResultCallback5"); } - virtual R Run(A1 a1,A2 a2,A3 a3,A4 a4,A5 a5) { + virtual R Run(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { if (!del) { - R result = (object_->*member_)(a1,a2,a3,a4,a5); + R result = (object_->*member_)(a1, a2, a3, a4, a5); return result; } else { - R result = (object_->*member_)(a1,a2,a3,a4,a5); + R result = (object_->*member_)(a1, a2, a3, a4, a5); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -10594,38 +12117,33 @@ class _MemberResultCallback_0_5 : public ResultCallback5 { }; template -class _MemberResultCallback_0_5::value - >::type> - : public Callback5 { +class _MemberResultCallback_0_5< + del, void, T, A1, A2, A3, A4, A5, + typename c_enable_if::value>::type> : public Callback5 { public: - typedef Callback5 base; - typedef void (T::*MemberSignature)(A1,A2,A3,A4,A5) ; + typedef Callback5 base; + typedef void (T::*MemberSignature)(A1, A2, A3, A4, A5); private: - T* object_; + T* object_; MemberSignature member_; public: - inline _MemberResultCallback_0_5( T* object, MemberSignature member) - : Callback5(), - object_(object), - member_(member) { } + inline _MemberResultCallback_0_5(T* object, MemberSignature member) + : Callback5(), object_(object), member_(member) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback5"); } - virtual void Run(A1 a1,A2 a2,A3 a3,A4 a4,A5 a5) { + virtual void Run(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { if (!del) { - (object_->*member_)(a1,a2,a3,a4,a5); + (object_->*member_)(a1, a2, a3, a4, a5); } else { - (object_->*member_)(a1,a2,a3,a4,a5); + (object_->*member_)(a1, a2, a3, a4, a5); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -10634,49 +12152,54 @@ class _MemberResultCallback_0_5 -inline typename _MemberResultCallback_0_5::base* -NewCallback( T1* obj, R (T2::*member)(A1,A2,A3,A4,A5) ) { - return new _MemberResultCallback_0_5(obj, member); +template +inline typename _MemberResultCallback_0_5::base* +NewCallback(T1* obj, R (T2::*member)(A1, A2, A3, A4, A5)) { + return new _MemberResultCallback_0_5(obj, + member); } #endif #ifndef SWIG -template -inline typename _MemberResultCallback_0_5::base* -NewPermanentCallback( T1* obj, R (T2::*member)(A1,A2,A3,A4,A5) ) { - return new _MemberResultCallback_0_5(obj, member); +template +inline typename _MemberResultCallback_0_5::base* +NewPermanentCallback(T1* obj, R (T2::*member)(A1, A2, A3, A4, A5)) { + return new _MemberResultCallback_0_5( + obj, member); } #endif template -class _FunctionResultCallback_0_5 : public ResultCallback5 { +class _FunctionResultCallback_0_5 + : public ResultCallback5 { public: - typedef ResultCallback5 base; - typedef R (*FunctionSignature)(A1,A2,A3,A4,A5); + typedef ResultCallback5 base; + typedef R (*FunctionSignature)(A1, A2, A3, A4, A5); private: FunctionSignature function_; public: inline _FunctionResultCallback_0_5(FunctionSignature function) - : ResultCallback5(), - function_(function) { } + : ResultCallback5(), function_(function) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { - if (del) CallbackUtils_::FailIsRepeatable("ResultCallback5"); + if (del) + CallbackUtils_::FailIsRepeatable("ResultCallback5"); } - virtual R Run(A1 a1,A2 a2,A3 a3,A4 a4,A5 a5) { + virtual R Run(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { if (!del) { - R result = (*function_)(a1,a2,a3,a4,a5); + R result = (*function_)(a1, a2, a3, a4, a5); return result; } else { - R result = (*function_)(a1,a2,a3,a4,a5); + R result = (*function_)(a1, a2, a3, a4, a5); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -10686,32 +12209,30 @@ class _FunctionResultCallback_0_5 : public ResultCallback5 { }; template -class _FunctionResultCallback_0_5 : public Callback5 { +class _FunctionResultCallback_0_5 : public Callback5 { public: - typedef Callback5 base; - typedef void (*FunctionSignature)(A1,A2,A3,A4,A5); + typedef Callback5 base; + typedef void (*FunctionSignature)(A1, A2, A3, A4, A5); private: FunctionSignature function_; public: inline _FunctionResultCallback_0_5(FunctionSignature function) - : Callback5(), - function_(function) { } + : Callback5(), function_(function) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback5"); } - virtual void Run(A1 a1,A2 a2,A3 a3,A4 a4,A5 a5) { + virtual void Run(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { if (!del) { - (*function_)(a1,a2,a3,a4,a5); + (*function_)(a1, a2, a3, a4, a5); } else { - (*function_)(a1,a2,a3,a4,a5); + (*function_)(a1, a2, a3, a4, a5); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -10720,25 +12241,26 @@ class _FunctionResultCallback_0_5 : public Callba }; template -inline typename _FunctionResultCallback_0_5::base* -NewCallback(R (*function)(A1,A2,A3,A4,A5)) { - return new _FunctionResultCallback_0_5(function); +inline typename _FunctionResultCallback_0_5::base* +NewCallback(R (*function)(A1, A2, A3, A4, A5)) { + return new _FunctionResultCallback_0_5(function); } template -inline typename _FunctionResultCallback_0_5::base* -NewPermanentCallback(R (*function)(A1,A2,A3,A4,A5)) { - return new _FunctionResultCallback_0_5(function); +inline typename _FunctionResultCallback_0_5::base* +NewPermanentCallback(R (*function)(A1, A2, A3, A4, A5)) { + return new _FunctionResultCallback_0_5( + function); } -template ::value - >::type> -class _ConstMemberResultCallback_1_5 : public ResultCallback5 { +template ::value>::type> +class _ConstMemberResultCallback_1_5 + : public ResultCallback5 { public: - typedef ResultCallback5 base; - typedef R (T::*MemberSignature)(P1,A1,A2,A3,A4,A5) const; + typedef ResultCallback5 base; + typedef R (T::*MemberSignature)(P1, A1, A2, A3, A4, A5) const; private: const T* object_; @@ -10746,25 +12268,26 @@ class _ConstMemberResultCallback_1_5 : public ResultCallback5 typename remove_reference::type p1_; public: - inline _ConstMemberResultCallback_1_5(const T* object, MemberSignature member, typename ConstRef::type p1) - : ResultCallback5(), - object_(object), - member_(member), p1_(p1) { } + inline _ConstMemberResultCallback_1_5(const T* object, MemberSignature member, + typename ConstRef::type p1) + : ResultCallback5(), + object_(object), + member_(member), + p1_(p1) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { - if (del) CallbackUtils_::FailIsRepeatable("ResultCallback5"); + if (del) + CallbackUtils_::FailIsRepeatable("ResultCallback5"); } - virtual R Run(A1 a1,A2 a2,A3 a3,A4 a4,A5 a5) { + virtual R Run(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { if (!del) { - R result = (object_->*member_)(p1_,a1,a2,a3,a4,a5); + R result = (object_->*member_)(p1_, a1, a2, a3, a4, a5); return result; } else { - R result = (object_->*member_)(p1_,a1,a2,a3,a4,a5); + R result = (object_->*member_)(p1_, a1, a2, a3, a4, a5); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -10773,15 +12296,15 @@ class _ConstMemberResultCallback_1_5 : public ResultCallback5 } }; -template -class _ConstMemberResultCallback_1_5::value - >::type> - : public Callback5 { +template +class _ConstMemberResultCallback_1_5< + del, void, T, P1, A1, A2, A3, A4, A5, + typename c_enable_if::value>::type> : public Callback5 { public: - typedef Callback5 base; - typedef void (T::*MemberSignature)(P1,A1,A2,A3,A4,A5) const; + typedef Callback5 base; + typedef void (T::*MemberSignature)(P1, A1, A2, A3, A4, A5) const; private: const T* object_; @@ -10789,24 +12312,24 @@ class _ConstMemberResultCallback_1_5::type p1_; public: - inline _ConstMemberResultCallback_1_5(const T* object, MemberSignature member, typename ConstRef::type p1) - : Callback5(), - object_(object), - member_(member), p1_(p1) { } + inline _ConstMemberResultCallback_1_5(const T* object, MemberSignature member, + typename ConstRef::type p1) + : Callback5(), + object_(object), + member_(member), + p1_(p1) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback5"); } - virtual void Run(A1 a1,A2 a2,A3 a3,A4 a4,A5 a5) { + virtual void Run(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { if (!del) { - (object_->*member_)(p1_,a1,a2,a3,a4,a5); + (object_->*member_)(p1_, a1, a2, a3, a4, a5); } else { - (object_->*member_)(p1_,a1,a2,a3,a4,a5); + (object_->*member_)(p1_, a1, a2, a3, a4, a5); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -10815,55 +12338,65 @@ class _ConstMemberResultCallback_1_5 -inline typename _ConstMemberResultCallback_1_5::base* -NewCallback(const T1* obj, R (T2::*member)(P1,A1,A2,A3,A4,A5) const, typename ConstRef::type p1) { - return new _ConstMemberResultCallback_1_5(obj, member, p1); +template +inline typename _ConstMemberResultCallback_1_5::base* +NewCallback(const T1* obj, R (T2::*member)(P1, A1, A2, A3, A4, A5) const, + typename ConstRef::type p1) { + return new _ConstMemberResultCallback_1_5(obj, member, p1); } #endif #ifndef SWIG -template -inline typename _ConstMemberResultCallback_1_5::base* -NewPermanentCallback(const T1* obj, R (T2::*member)(P1,A1,A2,A3,A4,A5) const, typename ConstRef::type p1) { - return new _ConstMemberResultCallback_1_5(obj, member, p1); +template +inline typename _ConstMemberResultCallback_1_5::base* +NewPermanentCallback(const T1* obj, + R (T2::*member)(P1, A1, A2, A3, A4, A5) const, + typename ConstRef::type p1) { + return new _ConstMemberResultCallback_1_5(obj, member, p1); } #endif -template ::value - >::type> -class _MemberResultCallback_1_5 : public ResultCallback5 { +template ::value>::type> +class _MemberResultCallback_1_5 + : public ResultCallback5 { public: - typedef ResultCallback5 base; - typedef R (T::*MemberSignature)(P1,A1,A2,A3,A4,A5) ; + typedef ResultCallback5 base; + typedef R (T::*MemberSignature)(P1, A1, A2, A3, A4, A5); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; public: - inline _MemberResultCallback_1_5( T* object, MemberSignature member, typename ConstRef::type p1) - : ResultCallback5(), - object_(object), - member_(member), p1_(p1) { } + inline _MemberResultCallback_1_5(T* object, MemberSignature member, + typename ConstRef::type p1) + : ResultCallback5(), + object_(object), + member_(member), + p1_(p1) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { - if (del) CallbackUtils_::FailIsRepeatable("ResultCallback5"); + if (del) + CallbackUtils_::FailIsRepeatable("ResultCallback5"); } - virtual R Run(A1 a1,A2 a2,A3 a3,A4 a4,A5 a5) { + virtual R Run(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { if (!del) { - R result = (object_->*member_)(p1_,a1,a2,a3,a4,a5); + R result = (object_->*member_)(p1_, a1, a2, a3, a4, a5); return result; } else { - R result = (object_->*member_)(p1_,a1,a2,a3,a4,a5); + R result = (object_->*member_)(p1_, a1, a2, a3, a4, a5); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -10872,40 +12405,40 @@ class _MemberResultCallback_1_5 : public ResultCallback5 { } }; -template -class _MemberResultCallback_1_5::value - >::type> - : public Callback5 { +template +class _MemberResultCallback_1_5< + del, void, T, P1, A1, A2, A3, A4, A5, + typename c_enable_if::value>::type> : public Callback5 { public: - typedef Callback5 base; - typedef void (T::*MemberSignature)(P1,A1,A2,A3,A4,A5) ; + typedef Callback5 base; + typedef void (T::*MemberSignature)(P1, A1, A2, A3, A4, A5); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; public: - inline _MemberResultCallback_1_5( T* object, MemberSignature member, typename ConstRef::type p1) - : Callback5(), - object_(object), - member_(member), p1_(p1) { } + inline _MemberResultCallback_1_5(T* object, MemberSignature member, + typename ConstRef::type p1) + : Callback5(), + object_(object), + member_(member), + p1_(p1) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback5"); } - virtual void Run(A1 a1,A2 a2,A3 a3,A4 a4,A5 a5) { + virtual void Run(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { if (!del) { - (object_->*member_)(p1_,a1,a2,a3,a4,a5); + (object_->*member_)(p1_, a1, a2, a3, a4, a5); } else { - (object_->*member_)(p1_,a1,a2,a3,a4,a5); + (object_->*member_)(p1_, a1, a2, a3, a4, a5); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -10914,50 +12447,61 @@ class _MemberResultCallback_1_5 -inline typename _MemberResultCallback_1_5::base* -NewCallback( T1* obj, R (T2::*member)(P1,A1,A2,A3,A4,A5) , typename ConstRef::type p1) { - return new _MemberResultCallback_1_5(obj, member, p1); +template +inline typename _MemberResultCallback_1_5::base* +NewCallback(T1* obj, R (T2::*member)(P1, A1, A2, A3, A4, A5), + typename ConstRef::type p1) { + return new _MemberResultCallback_1_5( + obj, member, p1); } #endif #ifndef SWIG -template -inline typename _MemberResultCallback_1_5::base* -NewPermanentCallback( T1* obj, R (T2::*member)(P1,A1,A2,A3,A4,A5) , typename ConstRef::type p1) { - return new _MemberResultCallback_1_5(obj, member, p1); +template +inline typename _MemberResultCallback_1_5::base* +NewPermanentCallback(T1* obj, R (T2::*member)(P1, A1, A2, A3, A4, A5), + typename ConstRef::type p1) { + return new _MemberResultCallback_1_5( + obj, member, p1); } #endif -template -class _FunctionResultCallback_1_5 : public ResultCallback5 { +template +class _FunctionResultCallback_1_5 + : public ResultCallback5 { public: - typedef ResultCallback5 base; - typedef R (*FunctionSignature)(P1,A1,A2,A3,A4,A5); + typedef ResultCallback5 base; + typedef R (*FunctionSignature)(P1, A1, A2, A3, A4, A5); private: FunctionSignature function_; typename remove_reference::type p1_; public: - inline _FunctionResultCallback_1_5(FunctionSignature function, typename ConstRef::type p1) - : ResultCallback5(), - function_(function), p1_(p1) { } + inline _FunctionResultCallback_1_5(FunctionSignature function, + typename ConstRef::type p1) + : ResultCallback5(), + function_(function), + p1_(p1) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { - if (del) CallbackUtils_::FailIsRepeatable("ResultCallback5"); + if (del) + CallbackUtils_::FailIsRepeatable("ResultCallback5"); } - virtual R Run(A1 a1,A2 a2,A3 a3,A4 a4,A5 a5) { + virtual R Run(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { if (!del) { - R result = (*function_)(p1_,a1,a2,a3,a4,a5); + R result = (*function_)(p1_, a1, a2, a3, a4, a5); return result; } else { - R result = (*function_)(p1_,a1,a2,a3,a4,a5); + R result = (*function_)(p1_, a1, a2, a3, a4, a5); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -10967,33 +12511,32 @@ class _FunctionResultCallback_1_5 : public ResultCallback5 { }; template -class _FunctionResultCallback_1_5 : public Callback5 { +class _FunctionResultCallback_1_5 : public Callback5 { public: - typedef Callback5 base; - typedef void (*FunctionSignature)(P1,A1,A2,A3,A4,A5); + typedef Callback5 base; + typedef void (*FunctionSignature)(P1, A1, A2, A3, A4, A5); private: FunctionSignature function_; typename remove_reference::type p1_; public: - inline _FunctionResultCallback_1_5(FunctionSignature function, typename ConstRef::type p1) - : Callback5(), - function_(function), p1_(p1) { } + inline _FunctionResultCallback_1_5(FunctionSignature function, + typename ConstRef::type p1) + : Callback5(), function_(function), p1_(p1) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback5"); } - virtual void Run(A1 a1,A2 a2,A3 a3,A4 a4,A5 a5) { + virtual void Run(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { if (!del) { - (*function_)(p1_,a1,a2,a3,a4,a5); + (*function_)(p1_, a1, a2, a3, a4, a5); } else { - (*function_)(p1_,a1,a2,a3,a4,a5); + (*function_)(p1_, a1, a2, a3, a4, a5); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -11002,25 +12545,31 @@ class _FunctionResultCallback_1_5 : public Ca }; template -inline typename _FunctionResultCallback_1_5::base* -NewCallback(R (*function)(P1,A1,A2,A3,A4,A5), typename ConstRef::type p1) { - return new _FunctionResultCallback_1_5(function, p1); +inline typename _FunctionResultCallback_1_5::base* +NewCallback(R (*function)(P1, A1, A2, A3, A4, A5), + typename ConstRef::type p1) { + return new _FunctionResultCallback_1_5( + function, p1); } template -inline typename _FunctionResultCallback_1_5::base* -NewPermanentCallback(R (*function)(P1,A1,A2,A3,A4,A5), typename ConstRef::type p1) { - return new _FunctionResultCallback_1_5(function, p1); +inline typename _FunctionResultCallback_1_5::base* +NewPermanentCallback(R (*function)(P1, A1, A2, A3, A4, A5), + typename ConstRef::type p1) { + return new _FunctionResultCallback_1_5( + function, p1); } -template ::value - >::type> -class _ConstMemberResultCallback_2_5 : public ResultCallback5 { +template ::value>::type> +class _ConstMemberResultCallback_2_5 + : public ResultCallback5 { public: - typedef ResultCallback5 base; - typedef R (T::*MemberSignature)(P1,P2,A1,A2,A3,A4,A5) const; + typedef ResultCallback5 base; + typedef R (T::*MemberSignature)(P1, P2, A1, A2, A3, A4, A5) const; private: const T* object_; @@ -11029,25 +12578,28 @@ class _ConstMemberResultCallback_2_5 : public ResultCallback5 typename remove_reference::type p2_; public: - inline _ConstMemberResultCallback_2_5(const T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2) - : ResultCallback5(), - object_(object), - member_(member), p1_(p1), p2_(p2) { } + inline _ConstMemberResultCallback_2_5(const T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2) + : ResultCallback5(), + object_(object), + member_(member), + p1_(p1), + p2_(p2) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { - if (del) CallbackUtils_::FailIsRepeatable("ResultCallback5"); + if (del) + CallbackUtils_::FailIsRepeatable("ResultCallback5"); } - virtual R Run(A1 a1,A2 a2,A3 a3,A4 a4,A5 a5) { + virtual R Run(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { if (!del) { - R result = (object_->*member_)(p1_,p2_,a1,a2,a3,a4,a5); + R result = (object_->*member_)(p1_, p2_, a1, a2, a3, a4, a5); return result; } else { - R result = (object_->*member_)(p1_,p2_,a1,a2,a3,a4,a5); + R result = (object_->*member_)(p1_, p2_, a1, a2, a3, a4, a5); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -11056,15 +12608,15 @@ class _ConstMemberResultCallback_2_5 : public ResultCallback5 } }; -template -class _ConstMemberResultCallback_2_5::value - >::type> - : public Callback5 { +template +class _ConstMemberResultCallback_2_5< + del, void, T, P1, P2, A1, A2, A3, A4, A5, + typename c_enable_if::value>::type> : public Callback5 { public: - typedef Callback5 base; - typedef void (T::*MemberSignature)(P1,P2,A1,A2,A3,A4,A5) const; + typedef Callback5 base; + typedef void (T::*MemberSignature)(P1, P2, A1, A2, A3, A4, A5) const; private: const T* object_; @@ -11073,24 +12625,26 @@ class _ConstMemberResultCallback_2_5::type p2_; public: - inline _ConstMemberResultCallback_2_5(const T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2) - : Callback5(), - object_(object), - member_(member), p1_(p1), p2_(p2) { } + inline _ConstMemberResultCallback_2_5(const T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2) + : Callback5(), + object_(object), + member_(member), + p1_(p1), + p2_(p2) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback5"); } - virtual void Run(A1 a1,A2 a2,A3 a3,A4 a4,A5 a5) { + virtual void Run(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { if (!del) { - (object_->*member_)(p1_,p2_,a1,a2,a3,a4,a5); + (object_->*member_)(p1_, p2_, a1, a2, a3, a4, a5); } else { - (object_->*member_)(p1_,p2_,a1,a2,a3,a4,a5); + (object_->*member_)(p1_, p2_, a1, a2, a3, a4, a5); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -11099,56 +12653,69 @@ class _ConstMemberResultCallback_2_5 -inline typename _ConstMemberResultCallback_2_5::base* -NewCallback(const T1* obj, R (T2::*member)(P1,P2,A1,A2,A3,A4,A5) const, typename ConstRef::type p1, typename ConstRef::type p2) { - return new _ConstMemberResultCallback_2_5(obj, member, p1, p2); +template +inline typename _ConstMemberResultCallback_2_5::base* +NewCallback(const T1* obj, R (T2::*member)(P1, P2, A1, A2, A3, A4, A5) const, + typename ConstRef::type p1, typename ConstRef::type p2) { + return new _ConstMemberResultCallback_2_5(obj, member, p1, p2); } #endif #ifndef SWIG -template -inline typename _ConstMemberResultCallback_2_5::base* -NewPermanentCallback(const T1* obj, R (T2::*member)(P1,P2,A1,A2,A3,A4,A5) const, typename ConstRef::type p1, typename ConstRef::type p2) { - return new _ConstMemberResultCallback_2_5(obj, member, p1, p2); +template +inline typename _ConstMemberResultCallback_2_5::base* +NewPermanentCallback(const T1* obj, + R (T2::*member)(P1, P2, A1, A2, A3, A4, A5) const, + typename ConstRef::type p1, + typename ConstRef::type p2) { + return new _ConstMemberResultCallback_2_5(obj, member, p1, p2); } #endif -template ::value - >::type> -class _MemberResultCallback_2_5 : public ResultCallback5 { +template ::value>::type> +class _MemberResultCallback_2_5 + : public ResultCallback5 { public: - typedef ResultCallback5 base; - typedef R (T::*MemberSignature)(P1,P2,A1,A2,A3,A4,A5) ; + typedef ResultCallback5 base; + typedef R (T::*MemberSignature)(P1, P2, A1, A2, A3, A4, A5); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; typename remove_reference::type p2_; public: - inline _MemberResultCallback_2_5( T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2) - : ResultCallback5(), - object_(object), - member_(member), p1_(p1), p2_(p2) { } + inline _MemberResultCallback_2_5(T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2) + : ResultCallback5(), + object_(object), + member_(member), + p1_(p1), + p2_(p2) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { - if (del) CallbackUtils_::FailIsRepeatable("ResultCallback5"); + if (del) + CallbackUtils_::FailIsRepeatable("ResultCallback5"); } - virtual R Run(A1 a1,A2 a2,A3 a3,A4 a4,A5 a5) { + virtual R Run(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { if (!del) { - R result = (object_->*member_)(p1_,p2_,a1,a2,a3,a4,a5); + R result = (object_->*member_)(p1_, p2_, a1, a2, a3, a4, a5); return result; } else { - R result = (object_->*member_)(p1_,p2_,a1,a2,a3,a4,a5); + R result = (object_->*member_)(p1_, p2_, a1, a2, a3, a4, a5); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -11157,41 +12724,43 @@ class _MemberResultCallback_2_5 : public ResultCallback5 { } }; -template -class _MemberResultCallback_2_5::value - >::type> - : public Callback5 { +template +class _MemberResultCallback_2_5< + del, void, T, P1, P2, A1, A2, A3, A4, A5, + typename c_enable_if::value>::type> : public Callback5 { public: - typedef Callback5 base; - typedef void (T::*MemberSignature)(P1,P2,A1,A2,A3,A4,A5) ; + typedef Callback5 base; + typedef void (T::*MemberSignature)(P1, P2, A1, A2, A3, A4, A5); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; typename remove_reference::type p2_; public: - inline _MemberResultCallback_2_5( T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2) - : Callback5(), - object_(object), - member_(member), p1_(p1), p2_(p2) { } + inline _MemberResultCallback_2_5(T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2) + : Callback5(), + object_(object), + member_(member), + p1_(p1), + p2_(p2) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback5"); } - virtual void Run(A1 a1,A2 a2,A3 a3,A4 a4,A5 a5) { + virtual void Run(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { if (!del) { - (object_->*member_)(p1_,p2_,a1,a2,a3,a4,a5); + (object_->*member_)(p1_, p2_, a1, a2, a3, a4, a5); } else { - (object_->*member_)(p1_,p2_,a1,a2,a3,a4,a5); + (object_->*member_)(p1_, p2_, a1, a2, a3, a4, a5); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -11200,26 +12769,37 @@ class _MemberResultCallback_2_5 -inline typename _MemberResultCallback_2_5::base* -NewCallback( T1* obj, R (T2::*member)(P1,P2,A1,A2,A3,A4,A5) , typename ConstRef::type p1, typename ConstRef::type p2) { - return new _MemberResultCallback_2_5(obj, member, p1, p2); +template +inline typename _MemberResultCallback_2_5::base* +NewCallback(T1* obj, R (T2::*member)(P1, P2, A1, A2, A3, A4, A5), + typename ConstRef::type p1, typename ConstRef::type p2) { + return new _MemberResultCallback_2_5( + obj, member, p1, p2); } #endif #ifndef SWIG -template -inline typename _MemberResultCallback_2_5::base* -NewPermanentCallback( T1* obj, R (T2::*member)(P1,P2,A1,A2,A3,A4,A5) , typename ConstRef::type p1, typename ConstRef::type p2) { - return new _MemberResultCallback_2_5(obj, member, p1, p2); +template +inline typename _MemberResultCallback_2_5::base* +NewPermanentCallback(T1* obj, R (T2::*member)(P1, P2, A1, A2, A3, A4, A5), + typename ConstRef::type p1, + typename ConstRef::type p2) { + return new _MemberResultCallback_2_5(obj, member, p1, p2); } #endif -template -class _FunctionResultCallback_2_5 : public ResultCallback5 { +template +class _FunctionResultCallback_2_5 + : public ResultCallback5 { public: - typedef ResultCallback5 base; - typedef R (*FunctionSignature)(P1,P2,A1,A2,A3,A4,A5); + typedef ResultCallback5 base; + typedef R (*FunctionSignature)(P1, P2, A1, A2, A3, A4, A5); private: FunctionSignature function_; @@ -11227,24 +12807,27 @@ class _FunctionResultCallback_2_5 : public ResultCallback5 { typename remove_reference::type p2_; public: - inline _FunctionResultCallback_2_5(FunctionSignature function, typename ConstRef::type p1, typename ConstRef::type p2) - : ResultCallback5(), - function_(function), p1_(p1), p2_(p2) { } + inline _FunctionResultCallback_2_5(FunctionSignature function, + typename ConstRef::type p1, + typename ConstRef::type p2) + : ResultCallback5(), + function_(function), + p1_(p1), + p2_(p2) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { - if (del) CallbackUtils_::FailIsRepeatable("ResultCallback5"); + if (del) + CallbackUtils_::FailIsRepeatable("ResultCallback5"); } - virtual R Run(A1 a1,A2 a2,A3 a3,A4 a4,A5 a5) { + virtual R Run(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { if (!del) { - R result = (*function_)(p1_,p2_,a1,a2,a3,a4,a5); + R result = (*function_)(p1_, p2_, a1, a2, a3, a4, a5); return result; } else { - R result = (*function_)(p1_,p2_,a1,a2,a3,a4,a5); + R result = (*function_)(p1_, p2_, a1, a2, a3, a4, a5); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -11253,11 +12836,13 @@ class _FunctionResultCallback_2_5 : public ResultCallback5 { } }; -template -class _FunctionResultCallback_2_5 : public Callback5 { +template +class _FunctionResultCallback_2_5 : public Callback5 { public: - typedef Callback5 base; - typedef void (*FunctionSignature)(P1,P2,A1,A2,A3,A4,A5); + typedef Callback5 base; + typedef void (*FunctionSignature)(P1, P2, A1, A2, A3, A4, A5); private: FunctionSignature function_; @@ -11265,23 +12850,25 @@ class _FunctionResultCallback_2_5 : publi typename remove_reference::type p2_; public: - inline _FunctionResultCallback_2_5(FunctionSignature function, typename ConstRef::type p1, typename ConstRef::type p2) - : Callback5(), - function_(function), p1_(p1), p2_(p2) { } + inline _FunctionResultCallback_2_5(FunctionSignature function, + typename ConstRef::type p1, + typename ConstRef::type p2) + : Callback5(), + function_(function), + p1_(p1), + p2_(p2) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback5"); } - virtual void Run(A1 a1,A2 a2,A3 a3,A4 a4,A5 a5) { + virtual void Run(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { if (!del) { - (*function_)(p1_,p2_,a1,a2,a3,a4,a5); + (*function_)(p1_, p2_, a1, a2, a3, a4, a5); } else { - (*function_)(p1_,p2_,a1,a2,a3,a4,a5); + (*function_)(p1_, p2_, a1, a2, a3, a4, a5); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -11289,26 +12876,36 @@ class _FunctionResultCallback_2_5 : publi } }; -template -inline typename _FunctionResultCallback_2_5::base* -NewCallback(R (*function)(P1,P2,A1,A2,A3,A4,A5), typename ConstRef::type p1, typename ConstRef::type p2) { - return new _FunctionResultCallback_2_5(function, p1, p2); +template +inline typename _FunctionResultCallback_2_5::base* +NewCallback(R (*function)(P1, P2, A1, A2, A3, A4, A5), + typename ConstRef::type p1, typename ConstRef::type p2) { + return new _FunctionResultCallback_2_5( + function, p1, p2); } -template -inline typename _FunctionResultCallback_2_5::base* -NewPermanentCallback(R (*function)(P1,P2,A1,A2,A3,A4,A5), typename ConstRef::type p1, typename ConstRef::type p2) { - return new _FunctionResultCallback_2_5(function, p1, p2); +template +inline typename _FunctionResultCallback_2_5::base* +NewPermanentCallback(R (*function)(P1, P2, A1, A2, A3, A4, A5), + typename ConstRef::type p1, + typename ConstRef::type p2) { + return new _FunctionResultCallback_2_5( + function, p1, p2); } -template ::value - >::type> -class _ConstMemberResultCallback_3_5 : public ResultCallback5 { +template < + bool del, class R, class T, class P1, class P2, class P3, class A1, + class A2, class A3, class A4, class A5, + class OnlyIf = typename c_enable_if::value>::type> +class _ConstMemberResultCallback_3_5 + : public ResultCallback5 { public: - typedef ResultCallback5 base; - typedef R (T::*MemberSignature)(P1,P2,P3,A1,A2,A3,A4,A5) const; + typedef ResultCallback5 base; + typedef R (T::*MemberSignature)(P1, P2, P3, A1, A2, A3, A4, A5) const; private: const T* object_; @@ -11318,25 +12915,30 @@ class _ConstMemberResultCallback_3_5 : public ResultCallback5 typename remove_reference::type p3_; public: - inline _ConstMemberResultCallback_3_5(const T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) - : ResultCallback5(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3) { } + inline _ConstMemberResultCallback_3_5(const T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3) + : ResultCallback5(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { - if (del) CallbackUtils_::FailIsRepeatable("ResultCallback5"); + if (del) + CallbackUtils_::FailIsRepeatable("ResultCallback5"); } - virtual R Run(A1 a1,A2 a2,A3 a3,A4 a4,A5 a5) { + virtual R Run(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { if (!del) { - R result = (object_->*member_)(p1_,p2_,p3_,a1,a2,a3,a4,a5); + R result = (object_->*member_)(p1_, p2_, p3_, a1, a2, a3, a4, a5); return result; } else { - R result = (object_->*member_)(p1_,p2_,p3_,a1,a2,a3,a4,a5); + R result = (object_->*member_)(p1_, p2_, p3_, a1, a2, a3, a4, a5); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -11345,15 +12947,15 @@ class _ConstMemberResultCallback_3_5 : public ResultCallback5 } }; -template -class _ConstMemberResultCallback_3_5::value - >::type> - : public Callback5 { +template +class _ConstMemberResultCallback_3_5< + del, void, T, P1, P2, P3, A1, A2, A3, A4, A5, + typename c_enable_if::value>::type> : public Callback5 { public: - typedef Callback5 base; - typedef void (T::*MemberSignature)(P1,P2,P3,A1,A2,A3,A4,A5) const; + typedef Callback5 base; + typedef void (T::*MemberSignature)(P1, P2, P3, A1, A2, A3, A4, A5) const; private: const T* object_; @@ -11363,24 +12965,28 @@ class _ConstMemberResultCallback_3_5::type p3_; public: - inline _ConstMemberResultCallback_3_5(const T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) - : Callback5(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3) { } + inline _ConstMemberResultCallback_3_5(const T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3) + : Callback5(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback5"); } - virtual void Run(A1 a1,A2 a2,A3 a3,A4 a4,A5 a5) { + virtual void Run(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { if (!del) { - (object_->*member_)(p1_,p2_,p3_,a1,a2,a3,a4,a5); + (object_->*member_)(p1_, p2_, p3_, a1, a2, a3, a4, a5); } else { - (object_->*member_)(p1_,p2_,p3_,a1,a2,a3,a4,a5); + (object_->*member_)(p1_, p2_, p3_, a1, a2, a3, a4, a5); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -11389,57 +12995,76 @@ class _ConstMemberResultCallback_3_5 -inline typename _ConstMemberResultCallback_3_5::base* -NewCallback(const T1* obj, R (T2::*member)(P1,P2,P3,A1,A2,A3,A4,A5) const, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) { - return new _ConstMemberResultCallback_3_5(obj, member, p1, p2, p3); +template +inline typename _ConstMemberResultCallback_3_5::base* +NewCallback(const T1* obj, + R (T2::*member)(P1, P2, P3, A1, A2, A3, A4, A5) const, + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3) { + return new _ConstMemberResultCallback_3_5(obj, member, p1, p2, p3); } #endif #ifndef SWIG -template -inline typename _ConstMemberResultCallback_3_5::base* -NewPermanentCallback(const T1* obj, R (T2::*member)(P1,P2,P3,A1,A2,A3,A4,A5) const, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) { - return new _ConstMemberResultCallback_3_5(obj, member, p1, p2, p3); +template +inline typename _ConstMemberResultCallback_3_5::base* +NewPermanentCallback(const T1* obj, + R (T2::*member)(P1, P2, P3, A1, A2, A3, A4, A5) const, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3) { + return new _ConstMemberResultCallback_3_5< + false, R, T1, P1, P2, P3, A1, A2, A3, A4, A5>(obj, member, p1, p2, p3); } #endif -template ::value - >::type> -class _MemberResultCallback_3_5 : public ResultCallback5 { +template < + bool del, class R, class T, class P1, class P2, class P3, class A1, + class A2, class A3, class A4, class A5, + class OnlyIf = typename c_enable_if::value>::type> +class _MemberResultCallback_3_5 + : public ResultCallback5 { public: - typedef ResultCallback5 base; - typedef R (T::*MemberSignature)(P1,P2,P3,A1,A2,A3,A4,A5) ; + typedef ResultCallback5 base; + typedef R (T::*MemberSignature)(P1, P2, P3, A1, A2, A3, A4, A5); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; typename remove_reference::type p2_; typename remove_reference::type p3_; public: - inline _MemberResultCallback_3_5( T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) - : ResultCallback5(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3) { } + inline _MemberResultCallback_3_5(T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3) + : ResultCallback5(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { - if (del) CallbackUtils_::FailIsRepeatable("ResultCallback5"); + if (del) + CallbackUtils_::FailIsRepeatable("ResultCallback5"); } - virtual R Run(A1 a1,A2 a2,A3 a3,A4 a4,A5 a5) { + virtual R Run(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { if (!del) { - R result = (object_->*member_)(p1_,p2_,p3_,a1,a2,a3,a4,a5); + R result = (object_->*member_)(p1_, p2_, p3_, a1, a2, a3, a4, a5); return result; } else { - R result = (object_->*member_)(p1_,p2_,p3_,a1,a2,a3,a4,a5); + R result = (object_->*member_)(p1_, p2_, p3_, a1, a2, a3, a4, a5); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -11448,42 +13073,46 @@ class _MemberResultCallback_3_5 : public ResultCallback5 { } }; -template -class _MemberResultCallback_3_5::value - >::type> - : public Callback5 { +template +class _MemberResultCallback_3_5< + del, void, T, P1, P2, P3, A1, A2, A3, A4, A5, + typename c_enable_if::value>::type> : public Callback5 { public: - typedef Callback5 base; - typedef void (T::*MemberSignature)(P1,P2,P3,A1,A2,A3,A4,A5) ; + typedef Callback5 base; + typedef void (T::*MemberSignature)(P1, P2, P3, A1, A2, A3, A4, A5); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; typename remove_reference::type p2_; typename remove_reference::type p3_; public: - inline _MemberResultCallback_3_5( T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) - : Callback5(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3) { } + inline _MemberResultCallback_3_5(T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3) + : Callback5(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback5"); } - virtual void Run(A1 a1,A2 a2,A3 a3,A4 a4,A5 a5) { + virtual void Run(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { if (!del) { - (object_->*member_)(p1_,p2_,p3_,a1,a2,a3,a4,a5); + (object_->*member_)(p1_, p2_, p3_, a1, a2, a3, a4, a5); } else { - (object_->*member_)(p1_,p2_,p3_,a1,a2,a3,a4,a5); + (object_->*member_)(p1_, p2_, p3_, a1, a2, a3, a4, a5); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -11492,26 +13121,39 @@ class _MemberResultCallback_3_5 -inline typename _MemberResultCallback_3_5::base* -NewCallback( T1* obj, R (T2::*member)(P1,P2,P3,A1,A2,A3,A4,A5) , typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) { - return new _MemberResultCallback_3_5(obj, member, p1, p2, p3); +template +inline typename _MemberResultCallback_3_5::base* +NewCallback(T1* obj, R (T2::*member)(P1, P2, P3, A1, A2, A3, A4, A5), + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3) { + return new _MemberResultCallback_3_5(obj, member, p1, p2, p3); } #endif #ifndef SWIG -template -inline typename _MemberResultCallback_3_5::base* -NewPermanentCallback( T1* obj, R (T2::*member)(P1,P2,P3,A1,A2,A3,A4,A5) , typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) { - return new _MemberResultCallback_3_5(obj, member, p1, p2, p3); +template +inline typename _MemberResultCallback_3_5::base* +NewPermanentCallback(T1* obj, R (T2::*member)(P1, P2, P3, A1, A2, A3, A4, A5), + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3) { + return new _MemberResultCallback_3_5(obj, member, p1, p2, p3); } #endif -template -class _FunctionResultCallback_3_5 : public ResultCallback5 { +template +class _FunctionResultCallback_3_5 + : public ResultCallback5 { public: - typedef ResultCallback5 base; - typedef R (*FunctionSignature)(P1,P2,P3,A1,A2,A3,A4,A5); + typedef ResultCallback5 base; + typedef R (*FunctionSignature)(P1, P2, P3, A1, A2, A3, A4, A5); private: FunctionSignature function_; @@ -11520,24 +13162,29 @@ class _FunctionResultCallback_3_5 : public ResultCallback5 { typename remove_reference::type p3_; public: - inline _FunctionResultCallback_3_5(FunctionSignature function, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) - : ResultCallback5(), - function_(function), p1_(p1), p2_(p2), p3_(p3) { } + inline _FunctionResultCallback_3_5(FunctionSignature function, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3) + : ResultCallback5(), + function_(function), + p1_(p1), + p2_(p2), + p3_(p3) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { - if (del) CallbackUtils_::FailIsRepeatable("ResultCallback5"); + if (del) + CallbackUtils_::FailIsRepeatable("ResultCallback5"); } - virtual R Run(A1 a1,A2 a2,A3 a3,A4 a4,A5 a5) { + virtual R Run(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { if (!del) { - R result = (*function_)(p1_,p2_,p3_,a1,a2,a3,a4,a5); + R result = (*function_)(p1_, p2_, p3_, a1, a2, a3, a4, a5); return result; } else { - R result = (*function_)(p1_,p2_,p3_,a1,a2,a3,a4,a5); + R result = (*function_)(p1_, p2_, p3_, a1, a2, a3, a4, a5); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -11546,11 +13193,13 @@ class _FunctionResultCallback_3_5 : public ResultCallback5 { } }; -template -class _FunctionResultCallback_3_5 : public Callback5 { +template +class _FunctionResultCallback_3_5 : public Callback5 { public: - typedef Callback5 base; - typedef void (*FunctionSignature)(P1,P2,P3,A1,A2,A3,A4,A5); + typedef Callback5 base; + typedef void (*FunctionSignature)(P1, P2, P3, A1, A2, A3, A4, A5); private: FunctionSignature function_; @@ -11559,23 +13208,27 @@ class _FunctionResultCallback_3_5 : p typename remove_reference::type p3_; public: - inline _FunctionResultCallback_3_5(FunctionSignature function, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) - : Callback5(), - function_(function), p1_(p1), p2_(p2), p3_(p3) { } + inline _FunctionResultCallback_3_5(FunctionSignature function, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3) + : Callback5(), + function_(function), + p1_(p1), + p2_(p2), + p3_(p3) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback5"); } - virtual void Run(A1 a1,A2 a2,A3 a3,A4 a4,A5 a5) { + virtual void Run(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { if (!del) { - (*function_)(p1_,p2_,p3_,a1,a2,a3,a4,a5); + (*function_)(p1_, p2_, p3_, a1, a2, a3, a4, a5); } else { - (*function_)(p1_,p2_,p3_,a1,a2,a3,a4,a5); + (*function_)(p1_, p2_, p3_, a1, a2, a3, a4, a5); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -11583,26 +13236,38 @@ class _FunctionResultCallback_3_5 : p } }; -template -inline typename _FunctionResultCallback_3_5::base* -NewCallback(R (*function)(P1,P2,P3,A1,A2,A3,A4,A5), typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) { - return new _FunctionResultCallback_3_5(function, p1, p2, p3); +template +inline typename _FunctionResultCallback_3_5::base* +NewCallback(R (*function)(P1, P2, P3, A1, A2, A3, A4, A5), + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3) { + return new _FunctionResultCallback_3_5(function, p1, p2, p3); } -template -inline typename _FunctionResultCallback_3_5::base* -NewPermanentCallback(R (*function)(P1,P2,P3,A1,A2,A3,A4,A5), typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) { - return new _FunctionResultCallback_3_5(function, p1, p2, p3); +template +inline typename _FunctionResultCallback_3_5::base* +NewPermanentCallback(R (*function)(P1, P2, P3, A1, A2, A3, A4, A5), + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3) { + return new _FunctionResultCallback_3_5(function, p1, p2, p3); } -template ::value - >::type> -class _ConstMemberResultCallback_4_5 : public ResultCallback5 { +template < + bool del, class R, class T, class P1, class P2, class P3, class P4, + class A1, class A2, class A3, class A4, class A5, + class OnlyIf = typename c_enable_if::value>::type> +class _ConstMemberResultCallback_4_5 + : public ResultCallback5 { public: - typedef ResultCallback5 base; - typedef R (T::*MemberSignature)(P1,P2,P3,P4,A1,A2,A3,A4,A5) const; + typedef ResultCallback5 base; + typedef R (T::*MemberSignature)(P1, P2, P3, P4, A1, A2, A3, A4, A5) const; private: const T* object_; @@ -11613,25 +13278,32 @@ class _ConstMemberResultCallback_4_5 : public ResultCallback5 typename remove_reference::type p4_; public: - inline _ConstMemberResultCallback_4_5(const T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) - : ResultCallback5(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4) { } + inline _ConstMemberResultCallback_4_5(const T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4) + : ResultCallback5(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { - if (del) CallbackUtils_::FailIsRepeatable("ResultCallback5"); + if (del) + CallbackUtils_::FailIsRepeatable("ResultCallback5"); } - virtual R Run(A1 a1,A2 a2,A3 a3,A4 a4,A5 a5) { + virtual R Run(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { if (!del) { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,a1,a2,a3,a4,a5); + R result = (object_->*member_)(p1_, p2_, p3_, p4_, a1, a2, a3, a4, a5); return result; } else { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,a1,a2,a3,a4,a5); + R result = (object_->*member_)(p1_, p2_, p3_, p4_, a1, a2, a3, a4, a5); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -11640,15 +13312,15 @@ class _ConstMemberResultCallback_4_5 : public ResultCallback5 } }; -template -class _ConstMemberResultCallback_4_5::value - >::type> - : public Callback5 { +template +class _ConstMemberResultCallback_4_5< + del, void, T, P1, P2, P3, P4, A1, A2, A3, A4, A5, + typename c_enable_if::value>::type> : public Callback5 { public: - typedef Callback5 base; - typedef void (T::*MemberSignature)(P1,P2,P3,P4,A1,A2,A3,A4,A5) const; + typedef Callback5 base; + typedef void (T::*MemberSignature)(P1, P2, P3, P4, A1, A2, A3, A4, A5) const; private: const T* object_; @@ -11659,24 +13331,30 @@ class _ConstMemberResultCallback_4_5::type p4_; public: - inline _ConstMemberResultCallback_4_5(const T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) - : Callback5(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4) { } + inline _ConstMemberResultCallback_4_5(const T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4) + : Callback5(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback5"); } - virtual void Run(A1 a1,A2 a2,A3 a3,A4 a4,A5 a5) { + virtual void Run(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { if (!del) { - (object_->*member_)(p1_,p2_,p3_,p4_,a1,a2,a3,a4,a5); + (object_->*member_)(p1_, p2_, p3_, p4_, a1, a2, a3, a4, a5); } else { - (object_->*member_)(p1_,p2_,p3_,p4_,a1,a2,a3,a4,a5); + (object_->*member_)(p1_, p2_, p3_, p4_, a1, a2, a3, a4, a5); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -11685,32 +13363,49 @@ class _ConstMemberResultCallback_4_5 -inline typename _ConstMemberResultCallback_4_5::base* -NewCallback(const T1* obj, R (T2::*member)(P1,P2,P3,P4,A1,A2,A3,A4,A5) const, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) { - return new _ConstMemberResultCallback_4_5(obj, member, p1, p2, p3, p4); +template +inline typename _ConstMemberResultCallback_4_5::base* +NewCallback(const T1* obj, + R (T2::*member)(P1, P2, P3, P4, A1, A2, A3, A4, A5) const, + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3, typename ConstRef::type p4) { + return new _ConstMemberResultCallback_4_5(obj, member, p1, p2, p3, + p4); } #endif #ifndef SWIG -template -inline typename _ConstMemberResultCallback_4_5::base* -NewPermanentCallback(const T1* obj, R (T2::*member)(P1,P2,P3,P4,A1,A2,A3,A4,A5) const, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) { - return new _ConstMemberResultCallback_4_5(obj, member, p1, p2, p3, p4); +template +inline typename _ConstMemberResultCallback_4_5::base* +NewPermanentCallback(const T1* obj, + R (T2::*member)(P1, P2, P3, P4, A1, A2, A3, A4, A5) const, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4) { + return new _ConstMemberResultCallback_4_5< + false, R, T1, P1, P2, P3, P4, A1, A2, A3, A4, A5>(obj, member, p1, p2, p3, + p4); } #endif -template ::value - >::type> -class _MemberResultCallback_4_5 : public ResultCallback5 { +template < + bool del, class R, class T, class P1, class P2, class P3, class P4, + class A1, class A2, class A3, class A4, class A5, + class OnlyIf = typename c_enable_if::value>::type> +class _MemberResultCallback_4_5 + : public ResultCallback5 { public: - typedef ResultCallback5 base; - typedef R (T::*MemberSignature)(P1,P2,P3,P4,A1,A2,A3,A4,A5) ; + typedef ResultCallback5 base; + typedef R (T::*MemberSignature)(P1, P2, P3, P4, A1, A2, A3, A4, A5); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; typename remove_reference::type p2_; @@ -11718,25 +13413,32 @@ class _MemberResultCallback_4_5 : public ResultCallback5 { typename remove_reference::type p4_; public: - inline _MemberResultCallback_4_5( T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) - : ResultCallback5(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4) { } + inline _MemberResultCallback_4_5(T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4) + : ResultCallback5(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { - if (del) CallbackUtils_::FailIsRepeatable("ResultCallback5"); + if (del) + CallbackUtils_::FailIsRepeatable("ResultCallback5"); } - virtual R Run(A1 a1,A2 a2,A3 a3,A4 a4,A5 a5) { + virtual R Run(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { if (!del) { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,a1,a2,a3,a4,a5); + R result = (object_->*member_)(p1_, p2_, p3_, p4_, a1, a2, a3, a4, a5); return result; } else { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,a1,a2,a3,a4,a5); + R result = (object_->*member_)(p1_, p2_, p3_, p4_, a1, a2, a3, a4, a5); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -11745,18 +13447,18 @@ class _MemberResultCallback_4_5 : public ResultCallback5 { } }; -template -class _MemberResultCallback_4_5::value - >::type> - : public Callback5 { +template +class _MemberResultCallback_4_5< + del, void, T, P1, P2, P3, P4, A1, A2, A3, A4, A5, + typename c_enable_if::value>::type> : public Callback5 { public: - typedef Callback5 base; - typedef void (T::*MemberSignature)(P1,P2,P3,P4,A1,A2,A3,A4,A5) ; + typedef Callback5 base; + typedef void (T::*MemberSignature)(P1, P2, P3, P4, A1, A2, A3, A4, A5); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; typename remove_reference::type p2_; @@ -11764,24 +13466,30 @@ class _MemberResultCallback_4_5::type p4_; public: - inline _MemberResultCallback_4_5( T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) - : Callback5(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4) { } + inline _MemberResultCallback_4_5(T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4) + : Callback5(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback5"); } - virtual void Run(A1 a1,A2 a2,A3 a3,A4 a4,A5 a5) { + virtual void Run(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { if (!del) { - (object_->*member_)(p1_,p2_,p3_,p4_,a1,a2,a3,a4,a5); + (object_->*member_)(p1_, p2_, p3_, p4_, a1, a2, a3, a4, a5); } else { - (object_->*member_)(p1_,p2_,p3_,p4_,a1,a2,a3,a4,a5); + (object_->*member_)(p1_, p2_, p3_, p4_, a1, a2, a3, a4, a5); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -11790,26 +13498,41 @@ class _MemberResultCallback_4_5 -inline typename _MemberResultCallback_4_5::base* -NewCallback( T1* obj, R (T2::*member)(P1,P2,P3,P4,A1,A2,A3,A4,A5) , typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) { - return new _MemberResultCallback_4_5(obj, member, p1, p2, p3, p4); +template +inline typename _MemberResultCallback_4_5::base* +NewCallback(T1* obj, R (T2::*member)(P1, P2, P3, P4, A1, A2, A3, A4, A5), + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3, typename ConstRef::type p4) { + return new _MemberResultCallback_4_5(obj, member, p1, p2, p3, p4); } #endif #ifndef SWIG -template -inline typename _MemberResultCallback_4_5::base* -NewPermanentCallback( T1* obj, R (T2::*member)(P1,P2,P3,P4,A1,A2,A3,A4,A5) , typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) { - return new _MemberResultCallback_4_5(obj, member, p1, p2, p3, p4); +template +inline typename _MemberResultCallback_4_5::base* +NewPermanentCallback(T1* obj, + R (T2::*member)(P1, P2, P3, P4, A1, A2, A3, A4, A5), + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4) { + return new _MemberResultCallback_4_5(obj, member, p1, p2, p3, p4); } #endif -template -class _FunctionResultCallback_4_5 : public ResultCallback5 { +template +class _FunctionResultCallback_4_5 + : public ResultCallback5 { public: - typedef ResultCallback5 base; - typedef R (*FunctionSignature)(P1,P2,P3,P4,A1,A2,A3,A4,A5); + typedef ResultCallback5 base; + typedef R (*FunctionSignature)(P1, P2, P3, P4, A1, A2, A3, A4, A5); private: FunctionSignature function_; @@ -11819,24 +13542,31 @@ class _FunctionResultCallback_4_5 : public ResultCallback5 { typename remove_reference::type p4_; public: - inline _FunctionResultCallback_4_5(FunctionSignature function, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) - : ResultCallback5(), - function_(function), p1_(p1), p2_(p2), p3_(p3), p4_(p4) { } + inline _FunctionResultCallback_4_5(FunctionSignature function, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4) + : ResultCallback5(), + function_(function), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { - if (del) CallbackUtils_::FailIsRepeatable("ResultCallback5"); + if (del) + CallbackUtils_::FailIsRepeatable("ResultCallback5"); } - virtual R Run(A1 a1,A2 a2,A3 a3,A4 a4,A5 a5) { + virtual R Run(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { if (!del) { - R result = (*function_)(p1_,p2_,p3_,p4_,a1,a2,a3,a4,a5); + R result = (*function_)(p1_, p2_, p3_, p4_, a1, a2, a3, a4, a5); return result; } else { - R result = (*function_)(p1_,p2_,p3_,p4_,a1,a2,a3,a4,a5); + R result = (*function_)(p1_, p2_, p3_, p4_, a1, a2, a3, a4, a5); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -11845,11 +13575,13 @@ class _FunctionResultCallback_4_5 : public ResultCallback5 { } }; -template -class _FunctionResultCallback_4_5 : public Callback5 { +template +class _FunctionResultCallback_4_5 : public Callback5 { public: - typedef Callback5 base; - typedef void (*FunctionSignature)(P1,P2,P3,P4,A1,A2,A3,A4,A5); + typedef Callback5 base; + typedef void (*FunctionSignature)(P1, P2, P3, P4, A1, A2, A3, A4, A5); private: FunctionSignature function_; @@ -11859,23 +13591,29 @@ class _FunctionResultCallback_4_5 typename remove_reference::type p4_; public: - inline _FunctionResultCallback_4_5(FunctionSignature function, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) - : Callback5(), - function_(function), p1_(p1), p2_(p2), p3_(p3), p4_(p4) { } + inline _FunctionResultCallback_4_5(FunctionSignature function, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4) + : Callback5(), + function_(function), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback5"); } - virtual void Run(A1 a1,A2 a2,A3 a3,A4 a4,A5 a5) { + virtual void Run(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { if (!del) { - (*function_)(p1_,p2_,p3_,p4_,a1,a2,a3,a4,a5); + (*function_)(p1_, p2_, p3_, p4_, a1, a2, a3, a4, a5); } else { - (*function_)(p1_,p2_,p3_,p4_,a1,a2,a3,a4,a5); + (*function_)(p1_, p2_, p3_, p4_, a1, a2, a3, a4, a5); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -11883,26 +13621,39 @@ class _FunctionResultCallback_4_5 } }; -template -inline typename _FunctionResultCallback_4_5::base* -NewCallback(R (*function)(P1,P2,P3,P4,A1,A2,A3,A4,A5), typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) { - return new _FunctionResultCallback_4_5(function, p1, p2, p3, p4); +template +inline typename _FunctionResultCallback_4_5::base* +NewCallback(R (*function)(P1, P2, P3, P4, A1, A2, A3, A4, A5), + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3, typename ConstRef::type p4) { + return new _FunctionResultCallback_4_5(function, p1, p2, p3, p4); } -template -inline typename _FunctionResultCallback_4_5::base* -NewPermanentCallback(R (*function)(P1,P2,P3,P4,A1,A2,A3,A4,A5), typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) { - return new _FunctionResultCallback_4_5(function, p1, p2, p3, p4); +template +inline typename _FunctionResultCallback_4_5::base* +NewPermanentCallback(R (*function)(P1, P2, P3, P4, A1, A2, A3, A4, A5), + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4) { + return new _FunctionResultCallback_4_5(function, p1, p2, p3, p4); } -template ::value - >::type> -class _ConstMemberResultCallback_5_5 : public ResultCallback5 { +template < + bool del, class R, class T, class P1, class P2, class P3, class P4, + class P5, class A1, class A2, class A3, class A4, class A5, + class OnlyIf = typename c_enable_if::value>::type> +class _ConstMemberResultCallback_5_5 + : public ResultCallback5 { public: - typedef ResultCallback5 base; - typedef R (T::*MemberSignature)(P1,P2,P3,P4,P5,A1,A2,A3,A4,A5) const; + typedef ResultCallback5 base; + typedef R (T::*MemberSignature)(P1, P2, P3, P4, P5, A1, A2, A3, A4, A5) const; private: const T* object_; @@ -11914,25 +13665,36 @@ class _ConstMemberResultCallback_5_5 : public ResultCallback5 typename remove_reference::type p5_; public: - inline _ConstMemberResultCallback_5_5(const T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) - : ResultCallback5(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5) { } + inline _ConstMemberResultCallback_5_5(const T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5) + : ResultCallback5(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { - if (del) CallbackUtils_::FailIsRepeatable("ResultCallback5"); + if (del) + CallbackUtils_::FailIsRepeatable("ResultCallback5"); } - virtual R Run(A1 a1,A2 a2,A3 a3,A4 a4,A5 a5) { + virtual R Run(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { if (!del) { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,p5_,a1,a2,a3,a4,a5); + R result = + (object_->*member_)(p1_, p2_, p3_, p4_, p5_, a1, a2, a3, a4, a5); return result; } else { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,p5_,a1,a2,a3,a4,a5); + R result = + (object_->*member_)(p1_, p2_, p3_, p4_, p5_, a1, a2, a3, a4, a5); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -11941,15 +13703,16 @@ class _ConstMemberResultCallback_5_5 : public ResultCallback5 } }; -template -class _ConstMemberResultCallback_5_5::value - >::type> - : public Callback5 { +template +class _ConstMemberResultCallback_5_5< + del, void, T, P1, P2, P3, P4, P5, A1, A2, A3, A4, A5, + typename c_enable_if::value>::type> : public Callback5 { public: - typedef Callback5 base; - typedef void (T::*MemberSignature)(P1,P2,P3,P4,P5,A1,A2,A3,A4,A5) const; + typedef Callback5 base; + typedef void (T::*MemberSignature)(P1, P2, P3, P4, P5, A1, A2, A3, A4, + A5) const; private: const T* object_; @@ -11961,24 +13724,32 @@ class _ConstMemberResultCallback_5_5::type p5_; public: - inline _ConstMemberResultCallback_5_5(const T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) - : Callback5(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5) { } + inline _ConstMemberResultCallback_5_5(const T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5) + : Callback5(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback5"); } - virtual void Run(A1 a1,A2 a2,A3 a3,A4 a4,A5 a5) { + virtual void Run(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { if (!del) { - (object_->*member_)(p1_,p2_,p3_,p4_,p5_,a1,a2,a3,a4,a5); + (object_->*member_)(p1_, p2_, p3_, p4_, p5_, a1, a2, a3, a4, a5); } else { - (object_->*member_)(p1_,p2_,p3_,p4_,p5_,a1,a2,a3,a4,a5); + (object_->*member_)(p1_, p2_, p3_, p4_, p5_, a1, a2, a3, a4, a5); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -11987,32 +13758,51 @@ class _ConstMemberResultCallback_5_5 -inline typename _ConstMemberResultCallback_5_5::base* -NewCallback(const T1* obj, R (T2::*member)(P1,P2,P3,P4,P5,A1,A2,A3,A4,A5) const, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) { - return new _ConstMemberResultCallback_5_5(obj, member, p1, p2, p3, p4, p5); +template +inline typename _ConstMemberResultCallback_5_5::base* +NewCallback(const T1* obj, + R (T2::*member)(P1, P2, P3, P4, P5, A1, A2, A3, A4, A5) const, + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3, typename ConstRef::type p4, + typename ConstRef::type p5) { + return new _ConstMemberResultCallback_5_5(obj, member, p1, p2, + p3, p4, p5); } #endif #ifndef SWIG -template -inline typename _ConstMemberResultCallback_5_5::base* -NewPermanentCallback(const T1* obj, R (T2::*member)(P1,P2,P3,P4,P5,A1,A2,A3,A4,A5) const, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) { - return new _ConstMemberResultCallback_5_5(obj, member, p1, p2, p3, p4, p5); +template +inline typename _ConstMemberResultCallback_5_5::base* +NewPermanentCallback(const T1* obj, R (T2::*member)(P1, P2, P3, P4, P5, A1, A2, + A3, A4, A5) const, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5) { + return new _ConstMemberResultCallback_5_5< + false, R, T1, P1, P2, P3, P4, P5, A1, A2, A3, A4, A5>(obj, member, p1, p2, + p3, p4, p5); } #endif -template ::value - >::type> -class _MemberResultCallback_5_5 : public ResultCallback5 { +template < + bool del, class R, class T, class P1, class P2, class P3, class P4, + class P5, class A1, class A2, class A3, class A4, class A5, + class OnlyIf = typename c_enable_if::value>::type> +class _MemberResultCallback_5_5 + : public ResultCallback5 { public: - typedef ResultCallback5 base; - typedef R (T::*MemberSignature)(P1,P2,P3,P4,P5,A1,A2,A3,A4,A5) ; + typedef ResultCallback5 base; + typedef R (T::*MemberSignature)(P1, P2, P3, P4, P5, A1, A2, A3, A4, A5); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; typename remove_reference::type p2_; @@ -12021,25 +13811,36 @@ class _MemberResultCallback_5_5 : public ResultCallback5 { typename remove_reference::type p5_; public: - inline _MemberResultCallback_5_5( T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) - : ResultCallback5(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5) { } + inline _MemberResultCallback_5_5(T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5) + : ResultCallback5(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { - if (del) CallbackUtils_::FailIsRepeatable("ResultCallback5"); + if (del) + CallbackUtils_::FailIsRepeatable("ResultCallback5"); } - virtual R Run(A1 a1,A2 a2,A3 a3,A4 a4,A5 a5) { + virtual R Run(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { if (!del) { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,p5_,a1,a2,a3,a4,a5); + R result = + (object_->*member_)(p1_, p2_, p3_, p4_, p5_, a1, a2, a3, a4, a5); return result; } else { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,p5_,a1,a2,a3,a4,a5); + R result = + (object_->*member_)(p1_, p2_, p3_, p4_, p5_, a1, a2, a3, a4, a5); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -12048,18 +13849,18 @@ class _MemberResultCallback_5_5 : public ResultCallback5 { } }; -template -class _MemberResultCallback_5_5::value - >::type> - : public Callback5 { +template +class _MemberResultCallback_5_5< + del, void, T, P1, P2, P3, P4, P5, A1, A2, A3, A4, A5, + typename c_enable_if::value>::type> : public Callback5 { public: - typedef Callback5 base; - typedef void (T::*MemberSignature)(P1,P2,P3,P4,P5,A1,A2,A3,A4,A5) ; + typedef Callback5 base; + typedef void (T::*MemberSignature)(P1, P2, P3, P4, P5, A1, A2, A3, A4, A5); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; typename remove_reference::type p2_; @@ -12068,24 +13869,32 @@ class _MemberResultCallback_5_5::type p5_; public: - inline _MemberResultCallback_5_5( T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) - : Callback5(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5) { } + inline _MemberResultCallback_5_5(T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5) + : Callback5(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback5"); } - virtual void Run(A1 a1,A2 a2,A3 a3,A4 a4,A5 a5) { + virtual void Run(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { if (!del) { - (object_->*member_)(p1_,p2_,p3_,p4_,p5_,a1,a2,a3,a4,a5); + (object_->*member_)(p1_, p2_, p3_, p4_, p5_, a1, a2, a3, a4, a5); } else { - (object_->*member_)(p1_,p2_,p3_,p4_,p5_,a1,a2,a3,a4,a5); + (object_->*member_)(p1_, p2_, p3_, p4_, p5_, a1, a2, a3, a4, a5); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -12094,26 +13903,45 @@ class _MemberResultCallback_5_5 -inline typename _MemberResultCallback_5_5::base* -NewCallback( T1* obj, R (T2::*member)(P1,P2,P3,P4,P5,A1,A2,A3,A4,A5) , typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) { - return new _MemberResultCallback_5_5(obj, member, p1, p2, p3, p4, p5); +template +inline typename _MemberResultCallback_5_5::base* +NewCallback(T1* obj, R (T2::*member)(P1, P2, P3, P4, P5, A1, A2, A3, A4, A5), + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3, typename ConstRef::type p4, + typename ConstRef::type p5) { + return new _MemberResultCallback_5_5(obj, member, p1, p2, p3, p4, + p5); } #endif #ifndef SWIG -template -inline typename _MemberResultCallback_5_5::base* -NewPermanentCallback( T1* obj, R (T2::*member)(P1,P2,P3,P4,P5,A1,A2,A3,A4,A5) , typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) { - return new _MemberResultCallback_5_5(obj, member, p1, p2, p3, p4, p5); +template +inline typename _MemberResultCallback_5_5::base* +NewPermanentCallback(T1* obj, + R (T2::*member)(P1, P2, P3, P4, P5, A1, A2, A3, A4, A5), + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5) { + return new _MemberResultCallback_5_5(obj, member, p1, p2, p3, p4, + p5); } #endif -template -class _FunctionResultCallback_5_5 : public ResultCallback5 { +template +class _FunctionResultCallback_5_5 + : public ResultCallback5 { public: - typedef ResultCallback5 base; - typedef R (*FunctionSignature)(P1,P2,P3,P4,P5,A1,A2,A3,A4,A5); + typedef ResultCallback5 base; + typedef R (*FunctionSignature)(P1, P2, P3, P4, P5, A1, A2, A3, A4, A5); private: FunctionSignature function_; @@ -12124,24 +13952,33 @@ class _FunctionResultCallback_5_5 : public ResultCallback5 { typename remove_reference::type p5_; public: - inline _FunctionResultCallback_5_5(FunctionSignature function, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) - : ResultCallback5(), - function_(function), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5) { } + inline _FunctionResultCallback_5_5(FunctionSignature function, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5) + : ResultCallback5(), + function_(function), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { - if (del) CallbackUtils_::FailIsRepeatable("ResultCallback5"); + if (del) + CallbackUtils_::FailIsRepeatable("ResultCallback5"); } - virtual R Run(A1 a1,A2 a2,A3 a3,A4 a4,A5 a5) { + virtual R Run(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { if (!del) { - R result = (*function_)(p1_,p2_,p3_,p4_,p5_,a1,a2,a3,a4,a5); + R result = (*function_)(p1_, p2_, p3_, p4_, p5_, a1, a2, a3, a4, a5); return result; } else { - R result = (*function_)(p1_,p2_,p3_,p4_,p5_,a1,a2,a3,a4,a5); + R result = (*function_)(p1_, p2_, p3_, p4_, p5_, a1, a2, a3, a4, a5); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -12150,11 +13987,13 @@ class _FunctionResultCallback_5_5 : public ResultCallback5 { } }; -template -class _FunctionResultCallback_5_5 : public Callback5 { +template +class _FunctionResultCallback_5_5 : public Callback5 { public: - typedef Callback5 base; - typedef void (*FunctionSignature)(P1,P2,P3,P4,P5,A1,A2,A3,A4,A5); + typedef Callback5 base; + typedef void (*FunctionSignature)(P1, P2, P3, P4, P5, A1, A2, A3, A4, A5); private: FunctionSignature function_; @@ -12165,23 +14004,31 @@ class _FunctionResultCallback_5_5::type p5_; public: - inline _FunctionResultCallback_5_5(FunctionSignature function, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) - : Callback5(), - function_(function), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5) { } + inline _FunctionResultCallback_5_5(FunctionSignature function, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5) + : Callback5(), + function_(function), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback5"); } - virtual void Run(A1 a1,A2 a2,A3 a3,A4 a4,A5 a5) { + virtual void Run(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { if (!del) { - (*function_)(p1_,p2_,p3_,p4_,p5_,a1,a2,a3,a4,a5); + (*function_)(p1_, p2_, p3_, p4_, p5_, a1, a2, a3, a4, a5); } else { - (*function_)(p1_,p2_,p3_,p4_,p5_,a1,a2,a3,a4,a5); + (*function_)(p1_, p2_, p3_, p4_, p5_, a1, a2, a3, a4, a5); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -12189,26 +14036,44 @@ class _FunctionResultCallback_5_5 -inline typename _FunctionResultCallback_5_5::base* -NewCallback(R (*function)(P1,P2,P3,P4,P5,A1,A2,A3,A4,A5), typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) { - return new _FunctionResultCallback_5_5(function, p1, p2, p3, p4, p5); +template +inline typename _FunctionResultCallback_5_5::base* +NewCallback(R (*function)(P1, P2, P3, P4, P5, A1, A2, A3, A4, A5), + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3, typename ConstRef::type p4, + typename ConstRef::type p5) { + return new _FunctionResultCallback_5_5(function, p1, p2, p3, p4, + p5); } -template -inline typename _FunctionResultCallback_5_5::base* -NewPermanentCallback(R (*function)(P1,P2,P3,P4,P5,A1,A2,A3,A4,A5), typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) { - return new _FunctionResultCallback_5_5(function, p1, p2, p3, p4, p5); +template +inline typename _FunctionResultCallback_5_5::base* +NewPermanentCallback(R (*function)(P1, P2, P3, P4, P5, A1, A2, A3, A4, A5), + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5) { + return new _FunctionResultCallback_5_5(function, p1, p2, p3, p4, + p5); } -template ::value - >::type> -class _ConstMemberResultCallback_6_5 : public ResultCallback5 { +template < + bool del, class R, class T, class P1, class P2, class P3, class P4, + class P5, class P6, class A1, class A2, class A3, class A4, class A5, + class OnlyIf = typename c_enable_if::value>::type> +class _ConstMemberResultCallback_6_5 + : public ResultCallback5 { public: - typedef ResultCallback5 base; - typedef R (T::*MemberSignature)(P1,P2,P3,P4,P5,P6,A1,A2,A3,A4,A5) const; + typedef ResultCallback5 base; + typedef R (T::*MemberSignature)(P1, P2, P3, P4, P5, P6, A1, A2, A3, A4, + A5) const; private: const T* object_; @@ -12221,25 +14086,38 @@ class _ConstMemberResultCallback_6_5 : public ResultCallback5 typename remove_reference::type p6_; public: - inline _ConstMemberResultCallback_6_5(const T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) - : ResultCallback5(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5), p6_(p6) { } + inline _ConstMemberResultCallback_6_5(const T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5, + typename ConstRef::type p6) + : ResultCallback5(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5), + p6_(p6) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { - if (del) CallbackUtils_::FailIsRepeatable("ResultCallback5"); + if (del) + CallbackUtils_::FailIsRepeatable("ResultCallback5"); } - virtual R Run(A1 a1,A2 a2,A3 a3,A4 a4,A5 a5) { + virtual R Run(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { if (!del) { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,p5_,p6_,a1,a2,a3,a4,a5); + R result = + (object_->*member_)(p1_, p2_, p3_, p4_, p5_, p6_, a1, a2, a3, a4, a5); return result; } else { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,p5_,p6_,a1,a2,a3,a4,a5); + R result = + (object_->*member_)(p1_, p2_, p3_, p4_, p5_, p6_, a1, a2, a3, a4, a5); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -12248,15 +14126,16 @@ class _ConstMemberResultCallback_6_5 : public ResultCallback5 } }; -template -class _ConstMemberResultCallback_6_5::value - >::type> - : public Callback5 { +template +class _ConstMemberResultCallback_6_5< + del, void, T, P1, P2, P3, P4, P5, P6, A1, A2, A3, A4, A5, + typename c_enable_if::value>::type> : public Callback5 { public: - typedef Callback5 base; - typedef void (T::*MemberSignature)(P1,P2,P3,P4,P5,P6,A1,A2,A3,A4,A5) const; + typedef Callback5 base; + typedef void (T::*MemberSignature)(P1, P2, P3, P4, P5, P6, A1, A2, A3, A4, + A5) const; private: const T* object_; @@ -12269,24 +14148,34 @@ class _ConstMemberResultCallback_6_5::type p6_; public: - inline _ConstMemberResultCallback_6_5(const T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) - : Callback5(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5), p6_(p6) { } + inline _ConstMemberResultCallback_6_5(const T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5, + typename ConstRef::type p6) + : Callback5(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5), + p6_(p6) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback5"); } - virtual void Run(A1 a1,A2 a2,A3 a3,A4 a4,A5 a5) { + virtual void Run(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { if (!del) { - (object_->*member_)(p1_,p2_,p3_,p4_,p5_,p6_,a1,a2,a3,a4,a5); + (object_->*member_)(p1_, p2_, p3_, p4_, p5_, p6_, a1, a2, a3, a4, a5); } else { - (object_->*member_)(p1_,p2_,p3_,p4_,p5_,p6_,a1,a2,a3,a4,a5); + (object_->*member_)(p1_, p2_, p3_, p4_, p5_, p6_, a1, a2, a3, a4, a5); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -12295,32 +14184,50 @@ class _ConstMemberResultCallback_6_5 -inline typename _ConstMemberResultCallback_6_5::base* -NewCallback(const T1* obj, R (T2::*member)(P1,P2,P3,P4,P5,P6,A1,A2,A3,A4,A5) const, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) { - return new _ConstMemberResultCallback_6_5(obj, member, p1, p2, p3, p4, p5, p6); +template +inline typename _ConstMemberResultCallback_6_5::base* +NewCallback(const T1* obj, + R (T2::*member)(P1, P2, P3, P4, P5, P6, A1, A2, A3, A4, A5) const, + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3, typename ConstRef::type p4, + typename ConstRef::type p5, typename ConstRef::type p6) { + return new _ConstMemberResultCallback_6_5( + obj, member, p1, p2, p3, p4, p5, p6); } #endif #ifndef SWIG -template -inline typename _ConstMemberResultCallback_6_5::base* -NewPermanentCallback(const T1* obj, R (T2::*member)(P1,P2,P3,P4,P5,P6,A1,A2,A3,A4,A5) const, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) { - return new _ConstMemberResultCallback_6_5(obj, member, p1, p2, p3, p4, p5, p6); +template +inline typename _ConstMemberResultCallback_6_5::base* +NewPermanentCallback( + const T1* obj, + R (T2::*member)(P1, P2, P3, P4, P5, P6, A1, A2, A3, A4, A5) const, + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3, typename ConstRef::type p4, + typename ConstRef::type p5, typename ConstRef::type p6) { + return new _ConstMemberResultCallback_6_5( + obj, member, p1, p2, p3, p4, p5, p6); } #endif -template ::value - >::type> -class _MemberResultCallback_6_5 : public ResultCallback5 { +template < + bool del, class R, class T, class P1, class P2, class P3, class P4, + class P5, class P6, class A1, class A2, class A3, class A4, class A5, + class OnlyIf = typename c_enable_if::value>::type> +class _MemberResultCallback_6_5 + : public ResultCallback5 { public: - typedef ResultCallback5 base; - typedef R (T::*MemberSignature)(P1,P2,P3,P4,P5,P6,A1,A2,A3,A4,A5) ; + typedef ResultCallback5 base; + typedef R (T::*MemberSignature)(P1, P2, P3, P4, P5, P6, A1, A2, A3, A4, A5); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; typename remove_reference::type p2_; @@ -12330,25 +14237,38 @@ class _MemberResultCallback_6_5 : public ResultCallback5 { typename remove_reference::type p6_; public: - inline _MemberResultCallback_6_5( T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) - : ResultCallback5(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5), p6_(p6) { } + inline _MemberResultCallback_6_5(T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5, + typename ConstRef::type p6) + : ResultCallback5(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5), + p6_(p6) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { - if (del) CallbackUtils_::FailIsRepeatable("ResultCallback5"); + if (del) + CallbackUtils_::FailIsRepeatable("ResultCallback5"); } - virtual R Run(A1 a1,A2 a2,A3 a3,A4 a4,A5 a5) { + virtual R Run(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { if (!del) { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,p5_,p6_,a1,a2,a3,a4,a5); + R result = + (object_->*member_)(p1_, p2_, p3_, p4_, p5_, p6_, a1, a2, a3, a4, a5); return result; } else { - R result = (object_->*member_)(p1_,p2_,p3_,p4_,p5_,p6_,a1,a2,a3,a4,a5); + R result = + (object_->*member_)(p1_, p2_, p3_, p4_, p5_, p6_, a1, a2, a3, a4, a5); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -12357,18 +14277,19 @@ class _MemberResultCallback_6_5 : public ResultCallback5 { } }; -template -class _MemberResultCallback_6_5::value - >::type> - : public Callback5 { +template +class _MemberResultCallback_6_5< + del, void, T, P1, P2, P3, P4, P5, P6, A1, A2, A3, A4, A5, + typename c_enable_if::value>::type> : public Callback5 { public: - typedef Callback5 base; - typedef void (T::*MemberSignature)(P1,P2,P3,P4,P5,P6,A1,A2,A3,A4,A5) ; + typedef Callback5 base; + typedef void (T::*MemberSignature)(P1, P2, P3, P4, P5, P6, A1, A2, A3, A4, + A5); private: - T* object_; + T* object_; MemberSignature member_; typename remove_reference::type p1_; typename remove_reference::type p2_; @@ -12378,24 +14299,34 @@ class _MemberResultCallback_6_5::type p6_; public: - inline _MemberResultCallback_6_5( T* object, MemberSignature member, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) - : Callback5(), - object_(object), - member_(member), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5), p6_(p6) { } + inline _MemberResultCallback_6_5(T* object, MemberSignature member, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5, + typename ConstRef::type p6) + : Callback5(), + object_(object), + member_(member), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5), + p6_(p6) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback5"); } - virtual void Run(A1 a1,A2 a2,A3 a3,A4 a4,A5 a5) { + virtual void Run(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { if (!del) { - (object_->*member_)(p1_,p2_,p3_,p4_,p5_,p6_,a1,a2,a3,a4,a5); + (object_->*member_)(p1_, p2_, p3_, p4_, p5_, p6_, a1, a2, a3, a4, a5); } else { - (object_->*member_)(p1_,p2_,p3_,p4_,p5_,p6_,a1,a2,a3,a4,a5); + (object_->*member_)(p1_, p2_, p3_, p4_, p5_, p6_, a1, a2, a3, a4, a5); // zero out the pointer to ensure segfault if used again member_ = NULL; delete this; @@ -12404,26 +14335,44 @@ class _MemberResultCallback_6_5 -inline typename _MemberResultCallback_6_5::base* -NewCallback( T1* obj, R (T2::*member)(P1,P2,P3,P4,P5,P6,A1,A2,A3,A4,A5) , typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) { - return new _MemberResultCallback_6_5(obj, member, p1, p2, p3, p4, p5, p6); +template +inline typename _MemberResultCallback_6_5::base* +NewCallback(T1* obj, + R (T2::*member)(P1, P2, P3, P4, P5, P6, A1, A2, A3, A4, A5), + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3, typename ConstRef::type p4, + typename ConstRef::type p5, typename ConstRef::type p6) { + return new _MemberResultCallback_6_5(obj, member, p1, p2, p3, + p4, p5, p6); } #endif #ifndef SWIG -template -inline typename _MemberResultCallback_6_5::base* -NewPermanentCallback( T1* obj, R (T2::*member)(P1,P2,P3,P4,P5,P6,A1,A2,A3,A4,A5) , typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) { - return new _MemberResultCallback_6_5(obj, member, p1, p2, p3, p4, p5, p6); +template +inline typename _MemberResultCallback_6_5::base* +NewPermanentCallback( + T1* obj, R (T2::*member)(P1, P2, P3, P4, P5, P6, A1, A2, A3, A4, A5), + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3, typename ConstRef::type p4, + typename ConstRef::type p5, typename ConstRef::type p6) { + return new _MemberResultCallback_6_5(obj, member, p1, p2, p3, + p4, p5, p6); } #endif -template -class _FunctionResultCallback_6_5 : public ResultCallback5 { +template +class _FunctionResultCallback_6_5 + : public ResultCallback5 { public: - typedef ResultCallback5 base; - typedef R (*FunctionSignature)(P1,P2,P3,P4,P5,P6,A1,A2,A3,A4,A5); + typedef ResultCallback5 base; + typedef R (*FunctionSignature)(P1, P2, P3, P4, P5, P6, A1, A2, A3, A4, A5); private: FunctionSignature function_; @@ -12435,24 +14384,35 @@ class _FunctionResultCallback_6_5 : public ResultCallback5 { typename remove_reference::type p6_; public: - inline _FunctionResultCallback_6_5(FunctionSignature function, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) - : ResultCallback5(), - function_(function), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5), p6_(p6) { } + inline _FunctionResultCallback_6_5(FunctionSignature function, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5, + typename ConstRef::type p6) + : ResultCallback5(), + function_(function), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5), + p6_(p6) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { - if (del) CallbackUtils_::FailIsRepeatable("ResultCallback5"); + if (del) + CallbackUtils_::FailIsRepeatable("ResultCallback5"); } - virtual R Run(A1 a1,A2 a2,A3 a3,A4 a4,A5 a5) { + virtual R Run(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { if (!del) { - R result = (*function_)(p1_,p2_,p3_,p4_,p5_,p6_,a1,a2,a3,a4,a5); + R result = (*function_)(p1_, p2_, p3_, p4_, p5_, p6_, a1, a2, a3, a4, a5); return result; } else { - R result = (*function_)(p1_,p2_,p3_,p4_,p5_,p6_,a1,a2,a3,a4,a5); + R result = (*function_)(p1_, p2_, p3_, p4_, p5_, p6_, a1, a2, a3, a4, a5); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -12461,11 +14421,14 @@ class _FunctionResultCallback_6_5 : public ResultCallback5 { } }; -template -class _FunctionResultCallback_6_5 : public Callback5 { +template +class _FunctionResultCallback_6_5 : public Callback5 { public: - typedef Callback5 base; - typedef void (*FunctionSignature)(P1,P2,P3,P4,P5,P6,A1,A2,A3,A4,A5); + typedef Callback5 base; + typedef void (*FunctionSignature)(P1, P2, P3, P4, P5, P6, A1, A2, A3, A4, A5); private: FunctionSignature function_; @@ -12477,23 +14440,33 @@ class _FunctionResultCallback_6_5::type p6_; public: - inline _FunctionResultCallback_6_5(FunctionSignature function, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) - : Callback5(), - function_(function), p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5), p6_(p6) { } + inline _FunctionResultCallback_6_5(FunctionSignature function, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5, + typename ConstRef::type p6) + : Callback5(), + function_(function), + p1_(p1), + p2_(p2), + p3_(p3), + p4_(p4), + p5_(p5), + p6_(p6) {} - virtual bool IsRepeatable() const { - return !del; - } + virtual bool IsRepeatable() const { return !del; } virtual void CheckIsRepeatable() const { if (del) CallbackUtils_::FailIsRepeatable("Callback5"); } - virtual void Run(A1 a1,A2 a2,A3 a3,A4 a4,A5 a5) { + virtual void Run(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { if (!del) { - (*function_)(p1_,p2_,p3_,p4_,p5_,p6_,a1,a2,a3,a4,a5); + (*function_)(p1_, p2_, p3_, p4_, p5_, p6_, a1, a2, a3, a4, a5); } else { - (*function_)(p1_,p2_,p3_,p4_,p5_,p6_,a1,a2,a3,a4,a5); + (*function_)(p1_, p2_, p3_, p4_, p5_, p6_, a1, a2, a3, a4, a5); // zero out the pointer to ensure segfault if used again function_ = NULL; delete this; @@ -12501,16 +14474,33 @@ class _FunctionResultCallback_6_5 -inline typename _FunctionResultCallback_6_5::base* -NewCallback(R (*function)(P1,P2,P3,P4,P5,P6,A1,A2,A3,A4,A5), typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) { - return new _FunctionResultCallback_6_5(function, p1, p2, p3, p4, p5, p6); +template +inline typename _FunctionResultCallback_6_5::base* +NewCallback(R (*function)(P1, P2, P3, P4, P5, P6, A1, A2, A3, A4, A5), + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3, typename ConstRef::type p4, + typename ConstRef::type p5, typename ConstRef::type p6) { + return new _FunctionResultCallback_6_5(function, p1, p2, p3, + p4, p5, p6); } -template -inline typename _FunctionResultCallback_6_5::base* -NewPermanentCallback(R (*function)(P1,P2,P3,P4,P5,P6,A1,A2,A3,A4,A5), typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) { - return new _FunctionResultCallback_6_5(function, p1, p2, p3, p4, p5, p6); +template +inline typename _FunctionResultCallback_6_5::base* +NewPermanentCallback(R (*function)(P1, P2, P3, P4, P5, P6, A1, A2, A3, A4, A5), + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5, + typename ConstRef::type p6) { + return new _FunctionResultCallback_6_5(function, p1, p2, p3, + p4, p5, p6); } #endif // OR_TOOLS_BASE_CALLBACK_H_ diff --git a/src/base/concise_iterator.h b/src/base/concise_iterator.h index 512eacc1bc..bfc13bf8a7 100644 --- a/src/base/concise_iterator.h +++ b/src/base/concise_iterator.h @@ -61,10 +61,10 @@ namespace operations_research { // } // } -template +template class Eraser; -template +template class ConstIter { public: typedef Container container_type; @@ -77,12 +77,12 @@ class ConstIter { container_ = source.container_; iterator_ = source.iterator_; } - ConstIter& operator= (const ConstIter& source) { + ConstIter& operator=(const ConstIter& source) { container_ = source.container_; iterator_ = source.iterator_; return *this; } - bool operator== (const ConstIter& iter) const { + bool operator==(const ConstIter& iter) const { return iterator_ == iter.iterator_; } const value_type* operator->() const { return iterator_.operator->(); } @@ -107,7 +107,7 @@ class ConstIter { // Note: this class is not compatible with sets (operator* returns a non-const // reference). -template +template class MutableIter { public: typedef Container container_type; @@ -116,17 +116,18 @@ class MutableIter { typedef typename Container::const_iterator const_iterator_type; explicit MutableIter(container_type& container) // NOLINT - : container_(&container), iterator_(container.begin()) {} + : container_(&container), + iterator_(container.begin()) {} MutableIter(const MutableIter& source) { container_ = source.container_; iterator_ = source.iterator_; } - MutableIter& operator= (const MutableIter& source) { + MutableIter& operator=(const MutableIter& source) { container_ = source.container_; iterator_ = source.iterator_; return *this; } - bool operator== (const MutableIter& iter) const { + bool operator==(const MutableIter& iter) const { return iterator_ == iter.iterator_; } value_type* operator->() const { return iterator_.operator->(); } @@ -155,7 +156,7 @@ class MutableIter { iterator_type iterator_; }; -template +template class ConstReverseIter { public: typedef Container container_type; @@ -169,19 +170,20 @@ class ConstReverseIter { container_ = source.container_; iterator_ = source.iterator_; } - ConstReverseIter& operator= (const ConstReverseIter& source) { + ConstReverseIter& operator=(const ConstReverseIter& source) { container_ = source.container_; iterator_ = source.iterator_; return *this; } - bool operator== (const ConstReverseIter& iter) const { + bool operator==(const ConstReverseIter& iter) const { return iterator_ == iter.iterator_; } const value_type* operator->() const { return iterator_.operator->(); } const value_type& operator*() const { return iterator_.operator*(); } const container_type* const_container() const { return container_; } const_reverse_iterator_type const_reverse_iterator() const { - return iterator_; } + return iterator_; + } ConstReverseIter& operator++() { ++iterator_; return *this; @@ -198,7 +200,7 @@ class ConstReverseIter { const_reverse_iterator_type iterator_; }; -template +template class MutableReverseIter { public: typedef Container container_type; @@ -208,24 +210,26 @@ class MutableReverseIter { const_reverse_iterator_type; explicit MutableReverseIter(container_type& container) // NOLINT - : container_(&container), iterator_(container.rbegin()) {} + : container_(&container), + iterator_(container.rbegin()) {} MutableReverseIter(const MutableReverseIter& source) { container_ = source.container_; iterator_ = source.iterator_; } - MutableReverseIter& operator= (const MutableReverseIter& source) { + MutableReverseIter& operator=(const MutableReverseIter& source) { container_ = source.container_; iterator_ = source.iterator_; return *this; } - bool operator== (const MutableReverseIter& iter) const { + bool operator==(const MutableReverseIter& iter) const { return iterator_ == iter.iterator_; } value_type* operator->() const { return iterator_.operator->(); } value_type& operator*() const { return iterator_.operator*(); } const container_type* const_container() const { return container_; } const_reverse_iterator_type const_reverse_iterator() const { - return iterator_; } + return iterator_; + } container_type* container() const { return container_; } reverse_iterator_type reverse_iterator() const { return iterator_; } MutableReverseIter& operator++() { @@ -251,7 +255,7 @@ class MutableReverseIter { // This is only valid for set, multiset, map, multimap and list. // Vectors and Deques are special cases that need specialized processing // defined in the specific template classes below. -template +template class Eraser { public: typedef typename Container::iterator iterator_type; @@ -262,22 +266,22 @@ class Eraser { }; // This version of the Eraser works for vectors -template class Eraser > { +template +class Eraser > { public: typedef typename std::vector::iterator iterator_type; - static iterator_type* erase(std::vector* container, - iterator_type* iterator) { + static iterator_type* erase(std::vector* container, iterator_type* iterator) { *iterator = container->erase(*iterator); return iterator; } }; // This version of the Eraser works for deques -template class Eraser > { +template +class Eraser > { public: typedef typename std::deque::iterator iterator_type; - static iterator_type* erase(std::deque* container, - iterator_type* iterator) { + static iterator_type* erase(std::deque* container, iterator_type* iterator) { *iterator = container->erase(*iterator); return iterator; } diff --git a/src/base/file.cc b/src/base/file.cc index 390e9b3c64..8969929260 100644 --- a/src/base/file.cc +++ b/src/base/file.cc @@ -30,16 +30,11 @@ namespace operations_research { -File::File(FILE* const f_des, const std::string& name) - : f_(f_des), name_(name) {} +File::File(FILE* const f_des, const std::string& name) : f_(f_des), name_(name) {} -bool File::Delete(const char* const name) { - return remove(name) == 0; -} +bool File::Delete(const char* const name) { return remove(name) == 0; } -bool File::Exists(const char* const name) { - return access(name, F_OK) == 0; -} +bool File::Exists(const char* const name) { return access(name, F_OK) == 0; } size_t File::Size() { struct stat f_stat; @@ -47,9 +42,7 @@ size_t File::Size() { return f_stat.st_size; } -bool File::Flush() { - return fflush(f_) == 0; -} +bool File::Flush() { return fflush(f_) == 0; } bool File::Close() { if (fclose(f_) == 0) { @@ -130,19 +123,14 @@ bool File::WriteLine(const std::string& line) { return Write("\n", 1) == 1; } -std::string File::filename() const { - return name_; -} +std::string File::filename() const { return name_; } -bool File::Open() const { - return f_ != NULL; -} +bool File::Open() const { return f_ != NULL; } void File::Init() {} namespace file { -Status SetContents(const std::string& filename, const std::string& contents, - int flags) { +Status SetContents(const std::string& filename, const std::string& contents, int flags) { if (flags != Defaults()) { LOG(DFATAL) << "file::SetContents() with unsupported flags=" << flags; return Status(false); @@ -152,8 +140,7 @@ Status SetContents(const std::string& filename, const std::string& contents, return Status(file->WriteString(contents) == contents.size()); } -Status GetContents(const std::string& filename, std::string* output, - int flags) { +Status GetContents(const std::string& filename, std::string* output, int flags) { if (flags != Defaults()) { LOG(DFATAL) << "file::GetContents() with unsupported flags=" << flags; return Status(false); @@ -175,7 +162,7 @@ bool WriteStringToFile(const std::string& data, const std::string& file_name) { namespace { class NoOpErrorCollector : public google::protobuf::io::ErrorCollector { public: - virtual void AddError(int line, int column, const std::string& message) { } + virtual void AddError(int line, int column, const std::string& message) {} }; } // namespace diff --git a/src/base/file.h b/src/base/file.h index 8a2b39b47d..b4ac23d850 100644 --- a/src/base/file.h +++ b/src/base/file.h @@ -43,11 +43,10 @@ class File { // Opens file "name" with flags specified by "flag" // If open failed, program will exit. - static File* OpenOrDie(const char* const name, const char* const flag); + static File* OpenOrDie(const char* const name, const char* const flag); #ifndef SWIG // no overloading - inline static File* OpenOrDie(const std::string& name, - const char* const flag) { + inline static File* OpenOrDie(const std::string& name, const char* const flag) { return OpenOrDie(name.c_str(), flag); } #endif @@ -114,9 +113,10 @@ namespace file { // A trivial wrapper around a boolean, with a ok() accessor. class Status { public: - explicit Status(bool ok) : ok_(ok) { } + explicit Status(bool ok) : ok_(ok) {} bool ok() const { return ok_; } bool CheckSuccess() const { return ok_; } + private: const bool ok_; }; @@ -125,13 +125,11 @@ inline int Defaults() { return 0xBABA; } // A reduced version of the file::SetContents() function, which as of 2013-04 // can only be used with flags = file::Defaults(). -Status SetContents(const std::string& filename, const std::string& contents, - int flags); +Status SetContents(const std::string& filename, const std::string& contents, int flags); // A reduced version of the file::GetContents() function, which as of 2013-09 // can only be used with flags = file::Defaults(). -Status GetContents(const std::string& filename, std::string* output, - int flags); +Status GetContents(const std::string& filename, std::string* output, int flags); bool ReadFileToString(const std::string& file_name, std::string* output); bool WriteStringToFile(const std::string& data, const std::string& file_name); diff --git a/src/base/filelinereader.cc b/src/base/filelinereader.cc index 897974a48f..bf919e5af6 100644 --- a/src/base/filelinereader.cc +++ b/src/base/filelinereader.cc @@ -11,7 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include "base/filelinereader.h" #include diff --git a/src/base/hash.h b/src/base/hash.h index 9b415273a0..e5fe34935f 100644 --- a/src/base/hash.h +++ b/src/base/hash.h @@ -19,7 +19,7 @@ #include #include namespace operations_research { - using namespace __gnu_cxx; // NOLINT +using namespace __gnu_cxx; // NOLINT } // namespace operations_research #else #include @@ -37,124 +37,168 @@ namespace operations_research { namespace operations_research { // 32 bit version. static inline void mix(uint32& a, uint32& b, uint32& c) { // NOLINT - a -= b; a -= c; a ^= (c >> 13); - b -= c; b -= a; b ^= (a << 8); - c -= a; c -= b; c ^= (b >> 13); - a -= b; a -= c; a ^= (c >> 12); - b -= c; b -= a; b ^= (a << 16); - c -= a; c -= b; c ^= (b >> 5); - a -= b; a -= c; a ^= (c >> 3); - b -= c; b -= a; b ^= (a << 10); - c -= a; c -= b; c ^= (b >> 15); + a -= b; + a -= c; + a ^= (c >> 13); + b -= c; + b -= a; + b ^= (a << 8); + c -= a; + c -= b; + c ^= (b >> 13); + a -= b; + a -= c; + a ^= (c >> 12); + b -= c; + b -= a; + b ^= (a << 16); + c -= a; + c -= b; + c ^= (b >> 5); + a -= b; + a -= c; + a ^= (c >> 3); + b -= c; + b -= a; + b ^= (a << 10); + c -= a; + c -= b; + c ^= (b >> 15); } // 64 bit version. static inline void mix(uint64& a, uint64& b, uint64& c) { // NOLINT - a -= b; a -= c; a ^= (c >> 43); - b -= c; b -= a; b ^= (a << 9); - c -= a; c -= b; c ^= (b >> 8); - a -= b; a -= c; a ^= (c >> 38); - b -= c; b -= a; b ^= (a << 23); - c -= a; c -= b; c ^= (b >> 5); - a -= b; a -= c; a ^= (c >> 35); - b -= c; b -= a; b ^= (a << 49); - c -= a; c -= b; c ^= (b >> 11); - a -= b; a -= c; a ^= (c >> 12); - b -= c; b -= a; b ^= (a << 18); - c -= a; c -= b; c ^= (b >> 22); + a -= b; + a -= c; + a ^= (c >> 43); + b -= c; + b -= a; + b ^= (a << 9); + c -= a; + c -= b; + c ^= (b >> 8); + a -= b; + a -= c; + a ^= (c >> 38); + b -= c; + b -= a; + b ^= (a << 23); + c -= a; + c -= b; + c ^= (b >> 5); + a -= b; + a -= c; + a ^= (c >> 35); + b -= c; + b -= a; + b ^= (a << 49); + c -= a; + c -= b; + c ^= (b >> 11); + a -= b; + a -= c; + a ^= (c >> 12); + b -= c; + b -= a; + b ^= (a << 18); + c -= a; + c -= b; + c ^= (b >> 22); } } // namespace operations_research // -------------------------------------------------------------------------- // Microsoft Visual C++ port // -------------------------------------------------------------------------- -# ifdef _MSC_VER +#ifdef _MSC_VER // The following class defines a hash function for std::pair. -class PairInt64Hasher : public stdext::hash_compare > { +class PairInt64Hasher : public stdext::hash_compare > { public: - size_t operator() (const std::pair& a) const { + size_t operator()(const std::pair& a) const { uint64 x = a.first; uint64 y = GG_ULONGLONG(0xe08c1d668b756f82); uint64 z = a.second; operations_research::mix(x, y, z); return z; } - bool operator() (const std::pair& a1, - const std::pair& a2) const { + bool operator()(const std::pair& a1, + const std::pair& a2) const { return a1.first < a2.first || - (a1.first == a2.first && a1.second < a2.second); + (a1.first == a2.first && a1.second < a2.second); } }; -class PairIntHasher : public stdext::hash_compare > { +class PairIntHasher : public stdext::hash_compare > { public: - size_t operator() (const std::pair& a) const { + size_t operator()(const std::pair& a) const { uint32 x = a.first; uint32 y = 0x9e3779b9UL; uint32 z = a.second; operations_research::mix(x, y, z); return z; } - bool operator() (const std::pair& a1, - const std::pair& a2) const { + bool operator()(const std::pair& a1, const std::pair& a2) const { return a1.first < a2.first || - (a1.first == a2.first && a1.second < a2.second); + (a1.first == a2.first && a1.second < a2.second); } }; using std::hash; using stdext::hash_map; using stdext::hash_set; -# endif // _MSC_VER +#endif // _MSC_VER // -------------------------------------------------------------------------- // GNU C++ port, with or without STLport. // -------------------------------------------------------------------------- -# ifdef __GNUC__ +#ifdef __GNUC__ // hash namespace -# if defined(__GNUC__) && defined(STLPORT) -# define HASH_NAMESPACE std -# elif defined(__GNUC__) && !defined(STLPORT) -# define HASH_NAMESPACE __gnu_cxx -# endif +#if defined(__GNUC__) && defined(STLPORT) +#define HASH_NAMESPACE std +#elif defined(__GNUC__) && !defined(STLPORT) +#define HASH_NAMESPACE __gnu_cxx +#endif // Support a few hash<> operators, in the hash namespace. inline uint32 Hash32NumWithSeed(uint32 num, uint32 c) { - uint32 b = 0x9e3779b9UL; // The golden ratio; an arbitrary value. + uint32 b = 0x9e3779b9UL; // The golden ratio; an arbitrary value. operations_research::mix(num, b, c); return c; } inline uint64 Hash64NumWithSeed(uint64 num, uint64 c) { - uint64 b = GG_ULONGLONG(0xe08c1d668b756f82); // More of the golden ratio. + uint64 b = GG_ULONGLONG(0xe08c1d668b756f82); // More of the golden ratio. operations_research::mix(num, b, c); return c; } namespace HASH_NAMESPACE { -template +template struct hash > { size_t operator()(const std::pair& p) const { size_t h1 = hash()(p.first); size_t h2 = hash()(p.second); // The decision below is at compile time return (sizeof(h1) <= sizeof(uint32)) ? // NOLINT - Hash32NumWithSeed(h1, h2) - : Hash64NumWithSeed(h1, h2); + Hash32NumWithSeed(h1, h2) + : Hash64NumWithSeed(h1, h2); } }; -template struct hash { - size_t operator()(T *x) const { return reinterpret_cast(x); } +template +struct hash { + size_t operator()(T* x) const { return reinterpret_cast(x); } }; // hash and hash are already defined with STLport. -# ifndef STLPORT -template<> struct hash { +#ifndef STLPORT +template <> +struct hash { size_t operator()(int64 x) const { return static_cast(x); } }; -template<> struct hash { +template <> +struct hash { size_t operator()(const std::string& x) const { size_t hash = 0; int c; @@ -165,13 +209,13 @@ template<> struct hash { return hash; } }; -# endif // STLPORT +#endif // STLPORT } // namespace HASH_NAMESPACE using HASH_NAMESPACE::hash; using HASH_NAMESPACE::hash_map; using HASH_NAMESPACE::hash_set; -# endif // __GNUC__ +#endif // __GNUC__ #undef HASH_NAMESPACE diff --git a/src/base/int_type.h b/src/base/int_type.h index 045daeff55..f1788501f3 100755 --- a/src/base/int_type.h +++ b/src/base/int_type.h @@ -11,7 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - // IntType is a simple template class mechanism for defining "logical" // integer-like class types that support many of the same functionalities // as native integer types, but which prevent assignment, construction, and @@ -148,18 +147,19 @@ #include #include "base/hash.h" #include -#include // NOLINT +#include // NOLINT #include "base/macros.h" -template class IntType; +template +class IntType; // Defines the IntType using value_type and typedefs it to int_type_name. // The struct int_type_name ## _tag_ trickery is needed to ensure that a new // type is created per int_type_name. -#define DEFINE_INT_TYPE(int_type_name, value_type) \ - struct int_type_name ## _tag_ {}; \ - typedef IntType int_type_name; +#define DEFINE_INT_TYPE(int_type_name, value_type) \ + struct int_type_name##_tag_ {}; \ + typedef IntType int_type_name; // Holds a integral value (of type ValueType) and behaves as a // ValueType by exposing assignment, unary, comparison, and arithmetic @@ -179,9 +179,9 @@ class IntType { public: // Default c'tor initializing value_ to 0. - IntType() : value_(0) { } + IntType() : value_(0) {} // C'tor explicitly initializing from a ValueType. - explicit IntType(ValueType value) : value_(value) { } + explicit IntType(ValueType value) : value_(value) {} // IntType uses the default copy constructor and destructor. // -- ACCESSORS -------------------------------------------------------------- @@ -191,7 +191,9 @@ class IntType { ValueType value() const { return value_; } template - ValType value() const { return static_cast(value_); } + ValType value() const { + return static_cast(value_); + } // -- UNARY OPERATORS -------------------------------------------------------- ThisType& operator++() { // prefix ++ @@ -218,17 +220,17 @@ class IntType { const ThisType operator-() const { return ThisType(-value_); } const ThisType operator~() const { return ThisType(~value_); } - // -- ASSIGNMENT OPERATORS --------------------------------------------------- - // We support the following assignment operators: =, +=, -=, *=, /=, <<=, >>= - // and %= for both ThisType and ValueType. -#define INT_TYPE_ASSIGNMENT_OP(op) \ - ThisType& operator op(const ThisType& arg_value) { \ - value_ op arg_value.value(); \ - return *this; \ - } \ - ThisType& operator op(ValueType arg_value) { \ - value_ op arg_value; \ - return *this; \ +// -- ASSIGNMENT OPERATORS --------------------------------------------------- +// We support the following assignment operators: =, +=, -=, *=, /=, <<=, >>= +// and %= for both ThisType and ValueType. +#define INT_TYPE_ASSIGNMENT_OP(op) \ + ThisType& operator op(const ThisType& arg_value) { \ + value_ op arg_value.value(); \ + return *this; \ + } \ + ThisType& operator op(ValueType arg_value) { \ + value_ op arg_value; \ + return *this; \ } INT_TYPE_ASSIGNMENT_OP(=); INT_TYPE_ASSIGNMENT_OP(+=); @@ -249,8 +251,8 @@ class IntType { // We provide the << operator, primarily for logging purposes. Currently, there // seems to be no need for an >> operator. template -std::ostream& operator <<(std::ostream& os, // NOLINT - IntType arg) { +std::ostream& operator<<(std::ostream& os, // NOLINT + IntType arg) { return os << arg.value(); } @@ -261,28 +263,28 @@ std::ostream& operator <<(std::ostream& os, // NOLINT // // NB: Although it is possible to do IntType * IntType and IntType / IntType, // it is probably non-sensical from a dimensionality analysis perspective. -#define INT_TYPE_ARITHMETIC_OP(op) \ - template \ - static inline IntType \ - operator op(IntType id_1, \ - IntType id_2) { \ - id_1 op ## = id_2.value(); \ - return id_1; \ - } \ - template \ - static inline IntType \ - operator op(IntType id, \ - typename IntType::ValueType arg_val) { \ - id op ## = arg_val; \ - return id; \ - } \ - template \ - static inline IntType \ - operator op(typename IntType::ValueType arg_val, \ - IntType id) { \ - IntType obj(arg_val); \ - obj op ## = id.value(); \ - return obj; \ +#define INT_TYPE_ARITHMETIC_OP(op) \ + template \ + static inline IntType operator op( \ + IntType id_1, \ + IntType id_2) { \ + id_1 op## = id_2.value(); \ + return id_1; \ + } \ + template \ + static inline IntType operator op( \ + IntType id, \ + typename IntType::ValueType arg_val) { \ + id op## = arg_val; \ + return id; \ + } \ + template \ + static inline IntType operator op( \ + typename IntType::ValueType arg_val, \ + IntType id) { \ + IntType obj(arg_val); \ + obj op## = id.value(); \ + return obj; \ } INT_TYPE_ARITHMETIC_OP(+); INT_TYPE_ARITHMETIC_OP(-); @@ -299,23 +301,23 @@ INT_TYPE_ARITHMETIC_OP(%); // IntType OP IntType // IntType OP ValueType // ValueType OP IntType -#define INT_TYPE_COMPARISON_OP(op) \ - template \ - static inline bool operator op(IntType id_1, \ - IntType id_2) { \ - return id_1.value() op id_2.value(); \ - } \ - template \ - static inline bool operator op( \ - IntType id, \ - typename IntType::ValueType val) { \ - return id.value() op val; \ - } \ - template \ - static inline bool operator op( \ - typename IntType::ValueType val, \ - IntType id) { \ - return val op id.value(); \ +#define INT_TYPE_COMPARISON_OP(op) \ + template \ + static inline bool operator op(IntType id_1, \ + IntType id_2) { \ + return id_1.value() op id_2.value(); \ + } \ + template \ + static inline bool operator op( \ + IntType id, \ + typename IntType::ValueType val) { \ + return id.value() op val; \ + } \ + template \ + static inline bool operator op( \ + typename IntType::ValueType val, \ + IntType id) { \ + return val op id.value(); \ } INT_TYPE_COMPARISON_OP(==); // NOLINT INT_TYPE_COMPARISON_OP(!=); // NOLINT diff --git a/src/base/int_type_indexed_vector.h b/src/base/int_type_indexed_vector.h index baf0b0f87f..b1474c00b3 100755 --- a/src/base/int_type_indexed_vector.h +++ b/src/base/int_type_indexed_vector.h @@ -65,7 +65,7 @@ #include "base/int_type.h" // STL vector ------------------------------------------------------------------ -template > +template > class ITIVector : protected std::vector { public: typedef std::vector ParentType; @@ -79,32 +79,31 @@ class ITIVector : protected std::vector { typedef typename ParentType::iterator iterator; typedef typename ParentType::const_iterator const_iterator; typedef typename ParentType::reverse_iterator reverse_iterator; - typedef typename ParentType::const_reverse_iterator - const_reverse_iterator; + typedef typename ParentType::const_reverse_iterator const_reverse_iterator; public: - ITIVector() { } - explicit ITIVector(const allocator_type& a) : ParentType(a) { } + ITIVector() {} + explicit ITIVector(const allocator_type& a) : ParentType(a) {} ITIVector(size_type n, const value_type& v = value_type(), const allocator_type& a = allocator_type()) - : ParentType(n, v, a) { } - ITIVector(const ITIVector& x) : ParentType(x.get()) { } - template + : ParentType(n, v, a) {} + ITIVector(const ITIVector& x) : ParentType(x.get()) {} + template ITIVector(InputIteratorType first, InputIteratorType last, const allocator_type& a = allocator_type()) - : ParentType(first, last, a) { } - ~ITIVector() { } + : ParentType(first, last, a) {} + ~ITIVector() {} // -- Accessors -------------------------------------------------------------- // This const accessor is useful in defining the comparison operators below. - const ParentType& get() const { return *this; } + const ParentType& get() const { return *this; } // The mutable accessor is useful when using auxiliar methods relying on // vector parameters such as JoinUsing(), SplitStringUsing(), etc. Methods // relying solely on iterators (e.g. STLDeleteElements) should work just fine // without the need for mutable_get(). NB: It should be used only in this // case and thus should not be abused to index the underlying vector without // the appropriate IntType. - ParentType* mutable_get() { return this; } + ParentType* mutable_get() { return this; } // -- Modified methods ------------------------------------------------------- reference operator[](IntType i) { @@ -113,59 +112,57 @@ class ITIVector : protected std::vector { const_reference operator[](IntType i) const { return ParentType::operator[](i.template value()); } - reference at(IntType i) { - return ParentType::at(i.template value()); - } + reference at(IntType i) { return ParentType::at(i.template value()); } const_reference at(IntType i) const { return ParentType::at(i.template value()); } // -- Pass-through methods to STL vector ------------------------------------- ITIVector& operator=(const ITIVector& x) { - ParentType::operator =(x.get()); + ParentType::operator=(x.get()); return *this; } void assign(size_type n, const value_type& val) { ParentType::assign(n, val); } - template - void assign(InputIt f, InputIt l) { ParentType::assign(f, l); } + template + void assign(InputIt f, InputIt l) { + ParentType::assign(f, l); + } - iterator begin() { return ParentType::begin(); } - const_iterator begin() const { return ParentType::begin(); } - iterator end() { return ParentType::end(); } - const_iterator end() const { return ParentType::end(); } - reverse_iterator rbegin() { return ParentType::rbegin(); } - const_reverse_iterator rbegin() const { return ParentType::rbegin(); } - reverse_iterator rend() { return ParentType::rend(); } - const_reverse_iterator rend() const { return ParentType::rend(); } + iterator begin() { return ParentType::begin(); } + const_iterator begin() const { return ParentType::begin(); } + iterator end() { return ParentType::end(); } + const_iterator end() const { return ParentType::end(); } + reverse_iterator rbegin() { return ParentType::rbegin(); } + const_reverse_iterator rbegin() const { return ParentType::rbegin(); } + reverse_iterator rend() { return ParentType::rend(); } + const_reverse_iterator rend() const { return ParentType::rend(); } - size_type size() const { return ParentType::size(); } - size_type max_size() const { return ParentType::max_size(); } + size_type size() const { return ParentType::size(); } + size_type max_size() const { return ParentType::max_size(); } void resize(size_type new_size, value_type x = value_type()) { ParentType::resize(new_size, x); } - size_type capacity() const { return ParentType::capacity(); } - bool empty() const { return ParentType::empty(); } - void reserve(size_type n) { ParentType::reserve(n); } - void push_back(const value_type& x) { ParentType::push_back(x); } - void pop_back() { ParentType::pop_back(); } - void swap(ITIVector& x) { ParentType::swap(*x.mutable_get()); } - void clear() { return ParentType::clear(); } + size_type capacity() const { return ParentType::capacity(); } + bool empty() const { return ParentType::empty(); } + void reserve(size_type n) { ParentType::reserve(n); } + void push_back(const value_type& x) { ParentType::push_back(x); } + void pop_back() { ParentType::pop_back(); } + void swap(ITIVector& x) { ParentType::swap(*x.mutable_get()); } + void clear() { return ParentType::clear(); } - reference front() { return ParentType::front(); } - const_reference front() const { return ParentType::front(); } - reference back() { return ParentType::back(); } - const_reference back() const { return ParentType::back(); } - pointer data() { return ParentType::data(); } - const_pointer data() const { return ParentType::data(); } + reference front() { return ParentType::front(); } + const_reference front() const { return ParentType::front(); } + reference back() { return ParentType::back(); } + const_reference back() const { return ParentType::back(); } + pointer data() { return ParentType::data(); } + const_pointer data() const { return ParentType::data(); } - iterator erase(iterator pos) { - return ParentType::erase(pos); - } + iterator erase(iterator pos) { return ParentType::erase(pos); } iterator erase(iterator first, iterator last) { return ParentType::erase(first, last); } @@ -175,24 +172,23 @@ class ITIVector : protected std::vector { void insert(iterator pos, size_type n, const value_type& x) { ParentType::insert(pos, n, x); } - template + template void insert(iterator pos, IIt first, IIt last) { ParentType::insert(pos, first, last); } }; -#define ITIVECTOR_COMPARISON_OP(op) \ - template \ - inline bool operator op( \ - const ITIVector& x, \ - const ITIVector& y) { \ - return x.get() op y.get(); \ +#define ITIVECTOR_COMPARISON_OP(op) \ + template \ + inline bool operator op(const ITIVector& x, \ + const ITIVector& y) { \ + return x.get() op y.get(); \ } -ITIVECTOR_COMPARISON_OP(==); // NOLINT -ITIVECTOR_COMPARISON_OP(<); // NOLINT -ITIVECTOR_COMPARISON_OP(<=); // NOLINT -ITIVECTOR_COMPARISON_OP(>); // NOLINT -ITIVECTOR_COMPARISON_OP(>=); // NOLINT +ITIVECTOR_COMPARISON_OP(== ); // NOLINT +ITIVECTOR_COMPARISON_OP(< ); // NOLINT +ITIVECTOR_COMPARISON_OP(<= ); // NOLINT +ITIVECTOR_COMPARISON_OP(> ); // NOLINT +ITIVECTOR_COMPARISON_OP(>= ); // NOLINT #undef ITIVECTOR_COMPARISON_OP template diff --git a/src/base/integral_types.h b/src/base/integral_types.h index b2c9733f59..7891021c29 100644 --- a/src/base/integral_types.h +++ b/src/base/integral_types.h @@ -18,14 +18,14 @@ #ifndef SWIG // Standard typedefs -typedef signed char schar; -typedef signed char int8; -typedef short int16; // NOLINT -typedef int int32; +typedef signed char schar; +typedef signed char int8; +typedef short int16; // NOLINT +typedef int int32; #ifdef COMPILER_MSVC -typedef __int64 int64; // NOLINT +typedef __int64 int64; // NOLINT #else -typedef long long int64; // NOLINT +typedef long long int64; // NOLINT #endif /* COMPILER_MSVC */ // NOTE: unsigned types are DANGEROUS in loops and other arithmetical @@ -34,11 +34,11 @@ typedef long long int64; // NOLINT // use 'unsigned' to express "this value should always be positive"; // use assertions for this. -typedef unsigned char uint8; -typedef unsigned short uint16; // NOLINT -typedef unsigned int uint32; +typedef unsigned char uint8; +typedef unsigned short uint16; // NOLINT +typedef unsigned int uint32; #ifdef COMPILER_MSVC -typedef unsigned __int64 uint64; +typedef unsigned __int64 uint64; #else typedef unsigned long long uint64; // NOLINT #endif /* COMPILER_MSVC */ @@ -47,7 +47,7 @@ typedef unsigned long long uint64; // NOLINT // such values require up to 21 bits. // (For type-checking on pointers, make this explicitly signed, // and it should always be the signed version of whatever int32 is.) -typedef signed int char32; +typedef signed int char32; // A type to represent a natural machine word (for e.g. efficiently // scanning through memory for checksums or index searching). Don't use @@ -56,7 +56,7 @@ typedef signed int char32; // (http://www.opengroup.org/public/tech/aspen/lp64_wp.htm), hence // their ints are only 32 bits. We want to use the same fundamental // type on all archs if possible to preserve *printf() compatability. -typedef unsigned long uword_t; // NOLINT +typedef unsigned long uword_t; // NOLINT // A signed natural machine word. In general you want to use "int" // rather than "sword_t" @@ -70,7 +70,7 @@ typedef long sword_t; // NOLINT #undef GG_ULONGLONG #undef GG_LL_FORMAT -#ifdef COMPILER_MSVC /* if Visual C++ */ +#ifdef COMPILER_MSVC /* if Visual C++ */ // VC++ long long suffixes #define GG_LONGLONG(x) x##I64 @@ -80,7 +80,7 @@ typedef long sword_t; // NOLINT #define GG_LL_FORMAT "I64" // As in printf("%I64d", ...) #define GG_LL_FORMAT_W L"I64" -#else /* not Visual C++ */ +#else /* not Visual C++ */ #define GG_LONGLONG(x) x##LL #define GG_ULONGLONG(x) x##ULL @@ -89,21 +89,20 @@ typedef long sword_t; // NOLINT #endif // COMPILER_MSVC - -static const uint8 kuint8max = static_cast(0xFF); +static const uint8 kuint8max = static_cast(0xFF); static const uint16 kuint16max = static_cast(0xFFFF); static const uint32 kuint32max = static_cast(0xFFFFFFFF); static const uint64 kuint64max = static_cast(GG_LONGLONG(0xFFFFFFFFFFFFFFFF)); -static const int8 kint8min = static_cast(0x80); -static const int8 kint8max = static_cast(0x7F); -static const int16 kint16min = static_cast(0x8000); -static const int16 kint16max = static_cast(0x7FFF); -static const int32 kint32min = static_cast(0x80000000); -static const int32 kint32max = static_cast(0x7FFFFFFF); -static const int64 kint64min = +static const int8 kint8min = static_cast(0x80); +static const int8 kint8max = static_cast(0x7F); +static const int16 kint16min = static_cast(0x8000); +static const int16 kint16max = static_cast(0x7FFF); +static const int32 kint32min = static_cast(0x80000000); +static const int32 kint32max = static_cast(0x7FFFFFFF); +static const int64 kint64min = static_cast(GG_LONGLONG(0x8000000000000000)); -static const int64 kint64max = +static const int64 kint64max = static_cast(GG_LONGLONG(0x7FFFFFFFFFFFFFFF)); #ifdef STLPORT diff --git a/src/base/jniutil.h b/src/base/jniutil.h index 9d15486fb6..1e46353886 100644 --- a/src/base/jniutil.h +++ b/src/base/jniutil.h @@ -33,7 +33,7 @@ class JNIUtil { if (str == NULL) return NULL; jsize length = env->GetStringUTFLength(str); const char* src = env->GetStringUTFChars(str, NULL); - char* dst = new char[length+1]; + char* dst = new char[length + 1]; memcpy(dst, src, length); dst[length] = '\0'; env->ReleaseStringUTFChars(str, src); diff --git a/src/base/join.cc b/src/base/join.cc index a39a18fbe9..18fc433e45 100644 --- a/src/base/join.cc +++ b/src/base/join.cc @@ -20,12 +20,12 @@ namespace operations_research { // ----- StrCat ----- -static char *Append1(char *out, const AlphaNum &x) { +static char* Append1(char* out, const AlphaNum& x) { memcpy(out, x.data(), x.size()); return out + x.size(); } -static char *Append2(char *out, const AlphaNum &x1, const AlphaNum &x2) { +static char* Append2(char* out, const AlphaNum& x1, const AlphaNum& x2) { memcpy(out, x1.data(), x1.size()); out += x1.size(); @@ -33,9 +33,8 @@ static char *Append2(char *out, const AlphaNum &x1, const AlphaNum &x2) { return out + x2.size(); } -static char *Append4(char *out, - const AlphaNum &x1, const AlphaNum &x2, - const AlphaNum &x3, const AlphaNum &x4) { +static char* Append4(char* out, const AlphaNum& x1, const AlphaNum& x2, + const AlphaNum& x3, const AlphaNum& x4) { memcpy(out, x1.data(), x1.size()); out += x1.size(); @@ -49,84 +48,82 @@ static char *Append4(char *out, return out + x4.size(); } -std::string StrCat(const AlphaNum &a) { - return std::string(a.data(), a.size()); -} +std::string StrCat(const AlphaNum& a) { return std::string(a.data(), a.size()); } -std::string StrCat(const AlphaNum &a, const AlphaNum &b) { +std::string StrCat(const AlphaNum& a, const AlphaNum& b) { std::string result; result.resize(a.size() + b.size()); - char *const begin = &*result.begin(); - char *out = Append2(begin, a, b); + char* const begin = &*result.begin(); + char* out = Append2(begin, a, b); DCHECK_EQ(out, begin + result.size()); return result; } -std::string StrCat(const AlphaNum &a, const AlphaNum &b, const AlphaNum &c) { +std::string StrCat(const AlphaNum& a, const AlphaNum& b, const AlphaNum& c) { std::string result; result.resize(a.size() + b.size() + c.size()); - char *const begin = &*result.begin(); - char *out = Append2(begin, a, b); + char* const begin = &*result.begin(); + char* out = Append2(begin, a, b); out = Append1(out, c); DCHECK_EQ(out, begin + result.size()); return result; } -std::string StrCat(const AlphaNum &a, const AlphaNum &b, const AlphaNum &c, - const AlphaNum &d) { +std::string StrCat(const AlphaNum& a, const AlphaNum& b, const AlphaNum& c, + const AlphaNum& d) { std::string result; result.resize(a.size() + b.size() + c.size() + d.size()); - char *const begin = &*result.begin(); - char *out = Append4(begin, a, b, c, d); + char* const begin = &*result.begin(); + char* out = Append4(begin, a, b, c, d); DCHECK_EQ(out, begin + result.size()); return result; } -std::string StrCat(const AlphaNum &a, const AlphaNum &b, const AlphaNum &c, - const AlphaNum &d, const AlphaNum &e) { +std::string StrCat(const AlphaNum& a, const AlphaNum& b, const AlphaNum& c, + const AlphaNum& d, const AlphaNum& e) { std::string result; result.resize(a.size() + b.size() + c.size() + d.size() + e.size()); - char *const begin = &*result.begin(); - char *out = Append4(begin, a, b, c, d); + char* const begin = &*result.begin(); + char* out = Append4(begin, a, b, c, d); out = Append1(out, e); DCHECK_EQ(out, begin + result.size()); return result; } -std::string StrCat(const AlphaNum &a, const AlphaNum &b, const AlphaNum &c, - const AlphaNum &d, const AlphaNum &e, const AlphaNum &f) { +std::string StrCat(const AlphaNum& a, const AlphaNum& b, const AlphaNum& c, + const AlphaNum& d, const AlphaNum& e, const AlphaNum& f) { std::string result; - result.resize(a.size() + b.size() + c.size() + d.size() + e.size() - + f.size()); - char *const begin = &*result.begin(); - char *out = Append4(begin, a, b, c, d); + result.resize(a.size() + b.size() + c.size() + d.size() + e.size() + + f.size()); + char* const begin = &*result.begin(); + char* out = Append4(begin, a, b, c, d); out = Append2(out, e, f); DCHECK_EQ(out, begin + result.size()); return result; } -std::string StrCat(const AlphaNum &a, const AlphaNum &b, const AlphaNum &c, - const AlphaNum &d, const AlphaNum &e, const AlphaNum &f, - const AlphaNum &g) { +std::string StrCat(const AlphaNum& a, const AlphaNum& b, const AlphaNum& c, + const AlphaNum& d, const AlphaNum& e, const AlphaNum& f, + const AlphaNum& g) { std::string result; - result.resize(a.size() + b.size() + c.size() + d.size() + e.size() - + f.size() + g.size()); - char *const begin = &*result.begin(); - char *out = Append4(begin, a, b, c, d); + result.resize(a.size() + b.size() + c.size() + d.size() + e.size() + + f.size() + g.size()); + char* const begin = &*result.begin(); + char* out = Append4(begin, a, b, c, d); out = Append2(out, e, f); out = Append1(out, g); DCHECK_EQ(out, begin + result.size()); return result; } -std::string StrCat(const AlphaNum &a, const AlphaNum &b, const AlphaNum &c, - const AlphaNum &d, const AlphaNum &e, const AlphaNum &f, - const AlphaNum &g, const AlphaNum &h) { +std::string StrCat(const AlphaNum& a, const AlphaNum& b, const AlphaNum& c, + const AlphaNum& d, const AlphaNum& e, const AlphaNum& f, + const AlphaNum& g, const AlphaNum& h) { std::string result; - result.resize(a.size() + b.size() + c.size() + d.size() + e.size() - + f.size() + g.size() + h.size()); - char *const begin = &*result.begin(); - char *out = Append4(begin, a, b, c, d); + result.resize(a.size() + b.size() + c.size() + d.size() + e.size() + + f.size() + g.size() + h.size()); + char* const begin = &*result.begin(); + char* out = Append4(begin, a, b, c, d); out = Append4(out, e, f, g, h); DCHECK_EQ(out, begin + result.size()); return result; diff --git a/src/base/join.h b/src/base/join.h index 745e897f39..201137d8f1 100644 --- a/src/base/join.h +++ b/src/base/join.h @@ -29,7 +29,8 @@ const int kFastToBufferSize = 32; // Writes output to the beginning of the given buffer. Returns a pointer to the // end of the std::string (i.e. to the NUL char). Buffer must be at least 12 bytes. // Not actually fast, but maybe someday! -template char* NumToBuffer(T i, char* buffer) { +template +char* NumToBuffer(T i, char* buffer) { std::stringstream ss; ss << i; const std::string s = ss.str(); @@ -53,15 +54,15 @@ struct AlphaNum { AlphaNum(uint64 u64) // NOLINT(runtime/explicit) : piece(digits, NumToBuffer(u64, digits) - &digits[0]) {} AlphaNum(float f) // NOLINT(runtime/explicit) - : piece(digits, strlen(NumToBuffer(f, digits))) {} + : piece(digits, strlen(NumToBuffer(f, digits))) {} AlphaNum(double f) // NOLINT(runtime/explicit) - : piece(digits, strlen(NumToBuffer(f, digits))) {} - AlphaNum(const char *c_str) : piece(c_str) {} // NOLINT(runtime/explicit) - AlphaNum(const StringPiece &pc) : piece(pc) {} // NOLINT(runtime/explicit) - AlphaNum(const std::string &s) : piece(s) {} // NOLINT(runtime/explicit) + : piece(digits, strlen(NumToBuffer(f, digits))) {} + AlphaNum(const char* c_str) : piece(c_str) {} // NOLINT(runtime/explicit) + AlphaNum(const StringPiece& pc) : piece(pc) {} // NOLINT(runtime/explicit) + AlphaNum(const std::string& s) : piece(s) {} // NOLINT(runtime/explicit) StringPiece::size_type size() const { return piece.size(); } - const char *data() const { return piece.data(); } + const char* data() const { return piece.data(); } private: // Use ":" not ':' @@ -70,21 +71,20 @@ struct AlphaNum { extern AlphaNum gEmptyAlphaNum; - -std::string StrCat(const AlphaNum &a); -std::string StrCat(const AlphaNum &a, const AlphaNum &b); -std::string StrCat(const AlphaNum &a, const AlphaNum &b, const AlphaNum &c); -std::string StrCat(const AlphaNum &a, const AlphaNum &b, const AlphaNum &c, - const AlphaNum &d); -std::string StrCat(const AlphaNum &a, const AlphaNum &b, const AlphaNum &c, - const AlphaNum &d, const AlphaNum &e); -std::string StrCat(const AlphaNum &a, const AlphaNum &b, const AlphaNum &c, - const AlphaNum &d, const AlphaNum &e, const AlphaNum &f); -std::string StrCat(const AlphaNum &a, const AlphaNum &b, const AlphaNum &c, - const AlphaNum &d, const AlphaNum &e, const AlphaNum &f, - const AlphaNum &g); -std::string StrCat(const AlphaNum &a, const AlphaNum &b, const AlphaNum &c, - const AlphaNum &d, const AlphaNum &e, const AlphaNum &f, - const AlphaNum &g, const AlphaNum &h); +std::string StrCat(const AlphaNum& a); +std::string StrCat(const AlphaNum& a, const AlphaNum& b); +std::string StrCat(const AlphaNum& a, const AlphaNum& b, const AlphaNum& c); +std::string StrCat(const AlphaNum& a, const AlphaNum& b, const AlphaNum& c, + const AlphaNum& d); +std::string StrCat(const AlphaNum& a, const AlphaNum& b, const AlphaNum& c, + const AlphaNum& d, const AlphaNum& e); +std::string StrCat(const AlphaNum& a, const AlphaNum& b, const AlphaNum& c, + const AlphaNum& d, const AlphaNum& e, const AlphaNum& f); +std::string StrCat(const AlphaNum& a, const AlphaNum& b, const AlphaNum& c, + const AlphaNum& d, const AlphaNum& e, const AlphaNum& f, + const AlphaNum& g); +std::string StrCat(const AlphaNum& a, const AlphaNum& b, const AlphaNum& c, + const AlphaNum& d, const AlphaNum& e, const AlphaNum& f, + const AlphaNum& g, const AlphaNum& h); } // namespace operations_research #endif // OR_TOOLS_BASE_JOIN_H_ diff --git a/src/base/logging.cc b/src/base/logging.cc index bff6c6ce2c..3501e9d8cf 100644 --- a/src/base/logging.cc +++ b/src/base/logging.cc @@ -17,8 +17,7 @@ #include "base/logging.h" DEFINE_int32(log_level, 0, "Log level (0 is the default)."); -DEFINE_bool(log_prefix, - true, +DEFINE_bool(log_prefix, true, "Prefix all log lines with the date, source file and line number."); namespace operations_research { @@ -35,8 +34,8 @@ char* const DateLogger::HumanDate() { time_t time_value = time(NULL); struct tm now; localtime_r(&time_value, &now); - snprintf(buffer_, sizeof(buffer_), "%02d:%02d:%02d\0", - now.tm_hour, now.tm_min, now.tm_sec); + snprintf(buffer_, sizeof(buffer_), "%02d:%02d:%02d\0", now.tm_hour, + now.tm_min, now.tm_sec); #endif return buffer_; } diff --git a/src/base/logging.h b/src/base/logging.h index 8d84137c4e..f81f62dd40 100644 --- a/src/base/logging.h +++ b/src/base/logging.h @@ -25,8 +25,10 @@ DECLARE_int32(log_level); DECLARE_bool(log_prefix); // Always-on checking -#define CHECK(x) \ - if (!(x)) LogMessageFatal(__FILE__, __LINE__).stream() << "Check failed: " #x +#define CHECK(x) \ + if (!(x)) \ + LogMessageFatal(__FILE__, __LINE__).stream() << "Check " \ + "failed: " #x #define CHECK_LT(x, y) CHECK((x) < (y)) #define CHECK_GT(x, y) CHECK((x) > (y)) #define CHECK_LE(x, y) CHECK((x) <= (y)) @@ -37,15 +39,22 @@ DECLARE_bool(log_prefix); // Debug-only checking. #ifdef NDEBUG -#define DCHECK(x) while (false) CHECK(x) -#define DCHECK_LT(x, y) while (false) CHECK((x) < (y)) -#define DCHECK_GT(x, y) while (false) CHECK((x) > (y)) -#define DCHECK_LE(x, y) while (false) CHECK((x) <= (y)) -#define DCHECK_GE(x, y) while (false) CHECK((x) >= (y)) -#define DCHECK_EQ(x, y) while (false) CHECK((x) == (y)) -#define DCHECK_NE(x, y) while (false) CHECK((x) != (y)) +#define DCHECK(x) \ + while (false) CHECK(x) +#define DCHECK_LT(x, y) \ + while (false) CHECK((x) < (y)) +#define DCHECK_GT(x, y) \ + while (false) CHECK((x) > (y)) +#define DCHECK_LE(x, y) \ + while (false) CHECK((x) <= (y)) +#define DCHECK_GE(x, y) \ + while (false) CHECK((x) >= (y)) +#define DCHECK_EQ(x, y) \ + while (false) CHECK((x) == (y)) +#define DCHECK_NE(x, y) \ + while (false) CHECK((x) != (y)) #else -#define DCHECK(x) CHECK(x) +#define DCHECK(x) CHECK(x) #define DCHECK_LT(x, y) CHECK((x) < (y)) #define DCHECK_GT(x, y) CHECK((x) > (y)) #define DCHECK_LE(x, y) CHECK((x) <= (y)) @@ -60,20 +69,20 @@ DECLARE_bool(log_prefix); #define LOG_FATAL LogMessageFatal(__FILE__, __LINE__) #define LOG_QFATAL LOG_FATAL -#define VLOG(x) if ((x) <= FLAGS_log_level) LOG_INFO.stream() +#define VLOG(x) \ + if ((x) <= FLAGS_log_level) LOG_INFO.stream() -#define LOG(severity) LOG_ ## severity.stream() +#define LOG(severity) LOG_##severity.stream() #define LG LOG_INFO.stream() #define LOG_IF(severity, condition) \ - !(condition) ? (void) 0 : LogMessageVoidify() & LOG(severity) + !(condition) ? (void)0 : LogMessageVoidify() & LOG(severity) #ifdef NDEBUG #define LOG_DFATAL LOG_ERROR #define DFATAL ERROR -#define DLOG(severity) \ - true ? (void) 0 : LogMessageVoidify() & LOG(severity) +#define DLOG(severity) true ? (void)0 : LogMessageVoidify() & LOG(severity) #define DLOG_IF(severity, condition) \ - (true || !(condition)) ? (void) 0 : LogMessageVoidify() & LOG(severity) + (true || !(condition)) ? (void)0 : LogMessageVoidify() & LOG(severity) #else #define LOG_DFATAL LOG_FATAL #define DFATAL FATAL @@ -86,6 +95,7 @@ class DateLogger { public: DateLogger(); char* const HumanDate(); + private: char buffer_[9]; }; @@ -93,24 +103,25 @@ class DateLogger { class LogMessage { public: - LogMessage(const char* file, int line) : + LogMessage(const char* file, int line) + : #ifdef __ANDROID__ - log_stream_(std::cout) + log_stream_(std::cout) #else - log_stream_(std::cerr) + log_stream_(std::cerr) #endif { if (FLAGS_log_prefix) { - log_stream_ << "[" << pretty_date_.HumanDate() << "] " - << file << ":" << line << ": "; + log_stream_ << "[" << pretty_date_.HumanDate() << "] " << file << ":" + << line << ": "; } } - ~LogMessage() { - log_stream_ << "\n"; - } + ~LogMessage() { log_stream_ << "\n"; } std::ostream& stream() { return log_stream_; } + protected: std::ostream& log_stream_; + private: operations_research::DateLogger pretty_date_; DISALLOW_COPY_AND_ASSIGN(LogMessage); @@ -118,12 +129,12 @@ class LogMessage { class LogMessageFatal : public LogMessage { public: - LogMessageFatal(const char* file, int line) - : LogMessage(file, line) { } + LogMessageFatal(const char* file, int line) : LogMessage(file, line) {} ~LogMessageFatal() { log_stream_ << "\n"; abort(); } + private: DISALLOW_COPY_AND_ASSIGN(LogMessageFatal); }; @@ -133,10 +144,10 @@ class LogMessageFatal : public LogMessage { // is not used" and "statement has no effect". class LogMessageVoidify { public: - LogMessageVoidify() { } + LogMessageVoidify() {} // This has to be an operator with a precedence lower than << but // higher than "?:". See its usage. - void operator&(std::ostream&) { } + void operator&(std::ostream&) {} }; #endif // OR_TOOLS_BASE_LOGGING_H_ diff --git a/src/base/macros.h b/src/base/macros.h index 5dc3020eca..83dabbe03b 100644 --- a/src/base/macros.h +++ b/src/base/macros.h @@ -23,7 +23,9 @@ // The FALLTHROUGH_INTENDED macro can be used to annotate implicit fall-through // between switch labels. #ifndef FALLTHROUGH_INTENDED -#define FALLTHROUGH_INTENDED do { } while (0) +#define FALLTHROUGH_INTENDED \ + do { \ + } while (0) #endif #endif // OR_TOOLS_BASE_MACROS_H_ diff --git a/src/base/map_util.h b/src/base/map_util.h index 2129551001..d81a2fb533 100644 --- a/src/base/map_util.h +++ b/src/base/map_util.h @@ -23,10 +23,10 @@ namespace operations_research { // If the key is present in the map then the value associated with that // key is returned, otherwise the value passed as a default is returned. template -const typename Collection::value_type::second_type& -FindWithDefault(const Collection& collection, - const typename Collection::value_type::first_type& key, - const typename Collection::value_type::second_type& value) { +const typename Collection::value_type::second_type& FindWithDefault( + const Collection& collection, + const typename Collection::value_type::first_type& key, + const typename Collection::value_type::second_type& value) { typename Collection::const_iterator it = collection.find(key); if (it == collection.end()) { return value; @@ -38,9 +38,9 @@ FindWithDefault(const Collection& collection, // If the key is present a const pointer to the associated value is returned, // otherwise a NULL pointer is returned. template -const typename Collection::value_type::second_type* -FindOrNull(const Collection& collection, - const typename Collection::value_type::first_type& key) { +const typename Collection::value_type::second_type* FindOrNull( + const Collection& collection, + const typename Collection::value_type::first_type& key) { typename Collection::const_iterator it = collection.find(key); if (it == collection.end()) { return 0; @@ -52,9 +52,9 @@ FindOrNull(const Collection& collection, // Same as above but the returned pointer is not const and can be used to change // the stored value. template -typename Collection::value_type::second_type* -FindOrNull(Collection& collection, // NOLINT - const typename Collection::value_type::first_type& key) { +typename Collection::value_type::second_type* FindOrNull( + Collection& collection, // NOLINT + const typename Collection::value_type::first_type& key) { typename Collection::iterator it = collection.find(key); if (it == collection.end()) { return 0; @@ -68,9 +68,9 @@ FindOrNull(Collection& collection, // NOLINT // This function does not distinguish between a missing key and a key mapped // to a NULL value. template -const typename Collection::value_type::second_type -FindPtrOrNull(const Collection& collection, - const typename Collection::value_type::first_type& key) { +const typename Collection::value_type::second_type FindPtrOrNull( + const Collection& collection, + const typename Collection::value_type::first_type& key) { typename Collection::const_iterator it = collection.find(key); if (it == collection.end()) { return 0; @@ -83,8 +83,8 @@ FindPtrOrNull(const Collection& collection, // otherwise the value is updated to be a copy of the value provided. // True indicates that an insert took place, false indicates an update. template -bool InsertOrUpdate(Collection * const collection, - const Key& key, const Value& value) { +bool InsertOrUpdate(Collection* const collection, const Key& key, + const Value& value) { std::pair ret = collection->insert(typename Collection::value_type(key, value)); if (!ret.second) { @@ -100,8 +100,8 @@ bool InsertOrUpdate(Collection * const collection, // inserted, otherwise nothing happens. True indicates that an insert // took place, false indicates the key was already present. template -bool InsertIfNotPresent(Collection * const collection, - const Key& key, const Value& value) { +bool InsertIfNotPresent(Collection* const collection, const Key& key, + const Value& value) { std::pair ret = collection->insert(typename Collection::value_type(key, value)); return ret.second; @@ -110,7 +110,7 @@ bool InsertIfNotPresent(Collection * const collection, // Inserts a new std::pair into a map or hash_map. // Insert a new key into a set or hash_set. // Dies if the key is already present. -template +template void InsertOrDie(Collection* const collection, const typename Collection::value_type& value) { CHECK(collection->insert(value).second) << "duplicate value: " << value; @@ -118,21 +118,20 @@ void InsertOrDie(Collection* const collection, // Inserts a new key/value into a map or hash_map. // Dies if the key is already present. -template +template void InsertOrDie(Collection* const collection, const typename Collection::value_type::first_type& key, const typename Collection::value_type::second_type& data) { typedef typename Collection::value_type value_type; CHECK(collection->insert(value_type(key, data)).second) - << "duplicate key: " << key; + << "duplicate key: " << key; } // Perform a lookup in map or hash_map. // If the key is present and value is non-NULL then a copy of the value // associated with the key is made into *value. Returns whether key was present. template -bool FindCopy(const Collection& collection, - const Key& key, +bool FindCopy(const Collection& collection, const Key& key, Value* const value) { typename Collection::const_iterator it = collection.find(key); if (it == collection.end()) { @@ -153,9 +152,9 @@ bool ContainsKey(const Collection& collection, const Key& key) { } template -const typename Collection::value_type::second_type& -FindOrDie(const Collection& collection, - const typename Collection::value_type::first_type& key) { +const typename Collection::value_type::second_type& FindOrDie( + const Collection& collection, + const typename Collection::value_type::first_type& key) { typename Collection::const_iterator it = collection.find(key); CHECK(it != collection.end()) << "Map key not found: " << key; return it->second; @@ -164,12 +163,12 @@ FindOrDie(const Collection& collection, // Lookup a key in a map or hash_map, insert it if it is not present. // Returns a reference to the value associated with the key. template -typename Collection::value_type::second_type& -LookupOrInsert(Collection * const collection, - const typename Collection::value_type::first_type& key, - const typename Collection::value_type::second_type& value) { +typename Collection::value_type::second_type& LookupOrInsert( + Collection* const collection, + const typename Collection::value_type::first_type& key, + const typename Collection::value_type::second_type& value) { std::pair ret = - collection->insert(typename Collection::value_type(key, value)); + collection->insert(typename Collection::value_type(key, value)); return ret.first->second; } } // namespace operations_research diff --git a/src/base/mathutil.h b/src/base/mathutil.h index 0f84b226e6..a8c66d6c8b 100644 --- a/src/base/mathutil.h +++ b/src/base/mathutil.h @@ -11,7 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - #ifndef OR_TOOLS_BASE_MATHUTIL_H_ #define OR_TOOLS_BASE_MATHUTIL_H_ @@ -35,31 +34,31 @@ class MathUtil { // IntegralType: any integral type, whether signed or not. // numerator: any integer: positive, negative, or zero. // denominator: a non-zero integer, positive or negative. - template + template static IntegralType CeilOfRatio(IntegralType numerator, IntegralType denominator) { DCHECK_NE(0, denominator); const IntegralType rounded_toward_zero = numerator / denominator; const IntegralType intermediate_product = rounded_toward_zero * denominator; - const bool needs_adjustment = (rounded_toward_zero >= 0) && + const bool needs_adjustment = + (rounded_toward_zero >= 0) && ((denominator > 0 && numerator > intermediate_product) || (denominator < 0 && numerator < intermediate_product)); - const IntegralType adjustment - = static_cast(needs_adjustment); + const IntegralType adjustment = static_cast(needs_adjustment); const IntegralType ceil_of_ratio = rounded_toward_zero + adjustment; return ceil_of_ratio; } - template + template static IntegralType FloorOfRatio(IntegralType numerator, IntegralType denominator) { DCHECK_NE(0, denominator); const IntegralType rounded_toward_zero = numerator / denominator; const IntegralType intermediate_product = rounded_toward_zero * denominator; - const bool needs_adjustment = (rounded_toward_zero <= 0) && + const bool needs_adjustment = + (rounded_toward_zero <= 0) && ((denominator > 0 && numerator < intermediate_product) || (denominator < 0 && numerator > intermediate_product)); - const IntegralType adjustment = - static_cast(needs_adjustment); + const IntegralType adjustment = static_cast(needs_adjustment); const IntegralType floor_of_ratio = rounded_toward_zero - adjustment; return floor_of_ratio; } @@ -91,12 +90,14 @@ class MathUtil { // for special floating point values. // Note: 0.0 and -0.0 are not differentiated by Abs (Abs(0.0) is -0.0), // which should be OK: see the comment for Max above. - template static T Abs(const T x) { + template + static T Abs(const T x) { return x > 0 ? x : -x; } // Returns the square of x - template static T Square(const T x) { + template + static T Square(const T x) { return x * x; } @@ -115,5 +116,4 @@ class MathUtil { }; } // namespace operations_research - #endif // OR_TOOLS_BASE_MATHUTIL_H_ diff --git a/src/base/mutex.cc b/src/base/mutex.cc index 09ef85e7fd..000892ccc1 100644 --- a/src/base/mutex.cc +++ b/src/base/mutex.cc @@ -25,9 +25,7 @@ tthread::mutex* Mutex::RealMutex() const { return real_mutex_.get(); } CondVar::CondVar() : real_condition_(new tthread::condition_variable) {} CondVar::~CondVar() {} -void CondVar::Wait(Mutex* const mu) { - real_condition_->wait(*mu->RealMutex()); -} +void CondVar::Wait(Mutex* const mu) { real_condition_->wait(*mu->RealMutex()); } void CondVar::Signal() { real_condition_->notify_one(); } void CondVar::SignalAll() { real_condition_->notify_all(); } } // namespace operations_research diff --git a/src/base/port.h b/src/base/port.h index eccc7b33e3..f651f3f85c 100644 --- a/src/base/port.h +++ b/src/base/port.h @@ -10,7 +10,7 @@ #if defined(SWIG) #define MUST_USE_RESULT #elif __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) -#define MUST_USE_RESULT __attribute__ ((warn_unused_result)) +#define MUST_USE_RESULT __attribute__((warn_unused_result)) #else #define MUST_USE_RESULT #endif diff --git a/src/base/python-swig.cc b/src/base/python-swig.cc index 8ec386d772..8c3a46b866 100644 --- a/src/base/python-swig.cc +++ b/src/base/python-swig.cc @@ -37,15 +37,18 @@ static inline int PyString_AsStringAndSize(PyObject* obj, char** buf, } #endif // Py3.3+ -template bool PyObjAs(PyObject* pystr, T* cstr) { +template +bool PyObjAs(PyObject* pystr, T* cstr) { T::undefined; // You need to define specialization PyObjAs } -template PyObject* PyObjFrom(const T& c) { +template +PyObject* PyObjFrom(const T& c) { T::undefined; // You need to define specialization PyObjFrom } #ifdef HAS_GLOBAL_STRING -template <> bool PyObjAs(PyObject* pystr, ::std::string* cstr) { +template <> +bool PyObjAs(PyObject* pystr, ::std::string* cstr) { char* buf; Py_ssize_t len; #if PY_VERSION_HEX >= 0x03030000 @@ -60,7 +63,8 @@ template <> bool PyObjAs(PyObject* pystr, ::std::string* cstr) { return true; } #endif -template bool PyObjAs(PyObject* pystr, std::string* cstr) { +template +bool PyObjAs(PyObject* pystr, std::string* cstr) { char* buf; Py_ssize_t len; #if PY_VERSION_HEX >= 0x03030000 @@ -75,11 +79,13 @@ template bool PyObjAs(PyObject* pystr, std::string* cstr) { return true; } #ifdef HAS_GLOBAL_STRING -template <> PyObject* PyObjFrom(const ::std::string& c) { +template <> +PyObject* PyObjFrom(const ::std::string& c) { return PyString_FromStringAndSize(c.data(), c.size()); } #endif -template <> PyObject* PyObjFrom(const std::string& c) { +template <> +PyObject* PyObjFrom(const std::string& c) { return PyString_FromStringAndSize(c.data(), c.size()); } @@ -87,7 +93,8 @@ template <> PyObject* PyObjFrom(const std::string& c) { #include -template <> bool PyObjAs(PyObject* py, int* c) { +template <> +bool PyObjAs(PyObject* py, int* c) { long i = PyInt_AsLong(py); // NOLINT if (i == -1 && PyErr_Occurred()) // TypeError or OverflowError. return false; // Not a Python int. @@ -98,7 +105,8 @@ template <> bool PyObjAs(PyObject* py, int* c) { return true; } -template <> bool PyObjAs(PyObject* py, unsigned int* c) { +template <> +bool PyObjAs(PyObject* py, unsigned int* c) { long i = PyInt_AsLong(py); // NOLINT if (i == -1 && PyErr_Occurred()) return false; // Not a Python int. if (i < 0 || i > std::numeric_limits::max()) return false; @@ -106,15 +114,17 @@ template <> bool PyObjAs(PyObject* py, unsigned int* c) { return true; } -template <> bool PyObjAs(PyObject* py, long* c) { // NOLINT - long i = PyInt_AsLong(py); // NOLINT - if (i == -1 && PyErr_Occurred()) return false; // Not a Python int. +template <> +bool PyObjAs(PyObject* py, long* c) { // NOLINT + long i = PyInt_AsLong(py); // NOLINT + if (i == -1 && PyErr_Occurred()) return false; // Not a Python int. if (c) *c = i; return true; } -template <> bool PyObjAs(PyObject* py, long long* c) { // NOLINT - long long i; // NOLINT +template <> +bool PyObjAs(PyObject* py, long long* c) { // NOLINT + long long i; // NOLINT #if PY_MAJOR_VERSION < 3 if (PyInt_Check(py)) { i = PyInt_AsLong(py); @@ -130,24 +140,26 @@ template <> bool PyObjAs(PyObject* py, long long* c) { // NOLINT return true; } -template <> bool PyObjAs(PyObject * py, unsigned long long * c) { // NOLINT - unsigned long long i; // NOLINT +template <> +bool PyObjAs(PyObject* py, unsigned long long* c) { // NOLINT + unsigned long long i; // NOLINT #if PY_MAJOR_VERSION < 3 if (PyInt_Check(py)) i = PyInt_AsUnsignedLongLongMask(py); else // NOLINT #endif - { + { if (!PyLong_Check(py)) return false; // Not a Python long. i = PyLong_AsUnsignedLongLong(py); - if (i == (unsigned long long) - 1 && PyErr_Occurred()) // NOLINT + if (i == (unsigned long long)-1 && PyErr_Occurred()) // NOLINT return false; } if (c) *c = i; return true; } -template <> bool PyObjAs(PyObject * py, double * c) { +template <> +bool PyObjAs(PyObject* py, double* c) { double d; if (PyFloat_Check(py)) { d = PyFloat_AsDouble(py); @@ -167,27 +179,30 @@ template <> bool PyObjAs(PyObject * py, double * c) { return true; } -template <> PyObject* PyObjFrom(const double & c) { +template <> +PyObject* PyObjFrom(const double& c) { return PyFloat_FromDouble(c); } -template <> bool PyObjAs(PyObject * py, float * c) { +template <> +bool PyObjAs(PyObject* py, float* c) { double d; if (!PyObjAs(py, &d)) return false; if (c) *c = static_cast(d); return true; } -template <> PyObject* PyObjFrom(const float & c) { +template <> +PyObject* PyObjFrom(const float& c) { return PyFloat_FromDouble(c); } -template <> bool PyObjAs(PyObject * py, bool * c) { +template <> +bool PyObjAs(PyObject* py, bool* c) { if (!PyBool_Check(py)) return false; // Not a Python bool. if (c) *c = PyObject_Not(py) ? false : true; return true; } - -int SwigPyIntOrLong_Check(PyObject * o) { +int SwigPyIntOrLong_Check(PyObject* o) { return (PyLong_Check(o) #if PY_MAJOR_VERSION <= 2 || PyInt_Check(o) @@ -195,27 +210,24 @@ int SwigPyIntOrLong_Check(PyObject * o) { ); // NOLINT } - - PyObject* SwigString_FromString(const std::string & s) { - return PyString_FromStringAndSize(s.data(), s.size()); -} - - - std::string SwigString_AsString(PyObject * o) { - return std::string(PyString_AsString(o)); +PyObject* SwigString_FromString(const std::string& s) { + return PyString_FromStringAndSize(s.data(), s.size()); } +std::string SwigString_AsString(PyObject* o) { return std::string(PyString_AsString(o)); } // STL std::vector for common types namespace { -template struct vector_pusher { +template +struct vector_pusher { typedef T* ptr; static void push(std::vector* o, ptr e) { o->push_back(*e); } }; -template struct vector_pusher { +template +struct vector_pusher { typedef T* ptr; static void push(std::vector* o, ptr e) { o->push_back(e); } }; @@ -223,8 +235,8 @@ template struct vector_pusher { }; // namespace template -bool vector_input_helper(PyObject * seq, std::vector * out, - bool(*convert)(PyObject*, T * const)) { +bool vector_input_helper(PyObject* seq, std::vector* out, + bool (*convert)(PyObject*, T* const)) { PyObject* item, *it = PyObject_GetIter(seq); if (!it) return false; T elem; @@ -242,8 +254,8 @@ bool vector_input_helper(PyObject * seq, std::vector * out, } template -bool vector_input_wrap_helper(PyObject * seq, std::vector * out, - swig_type_info * swig_Tp_type) { +bool vector_input_wrap_helper(PyObject* seq, std::vector* out, + swig_type_info* swig_Tp_type) { PyObject* item, *it = PyObject_GetIter(seq); if (!it) { PyErr_SetString(PyExc_TypeError, "sequence expected"); @@ -251,7 +263,8 @@ bool vector_input_wrap_helper(PyObject * seq, std::vector * out, } typename vector_pusher::ptr elem; while ((item = PyIter_Next(it))) { - if (SWIG_ConvertPtr(item, (void**)&elem, swig_Tp_type, 0) == -1) { // NOLINT + if (SWIG_ConvertPtr(item, reinterpret_cast(&elem), + swig_Tp_type, 0) == -1) { Py_DECREF(it); it = PyObject_Repr(item); Py_DECREF(item); @@ -268,14 +281,13 @@ bool vector_input_wrap_helper(PyObject * seq, std::vector * out, return true; } - // Helper function for turning a C++ std::vector (or any other instance that // supports the std::vector-like iterator interface) into a Python list of // Ts. // The converter function converts a C++ object of type const T or const T& // into the corresponding Python object. template -static PyObject* list_output_helper(const T * vec, Converter converter) { +static PyObject* list_output_helper(const T* vec, Converter converter) { if (vec == NULL) Py_RETURN_NONE; // Return a nice out-of-band value. PyObject* lst = PyList_New(vec->size()); if (lst == NULL) return NULL; @@ -291,7 +303,8 @@ static PyObject* list_output_helper(const T * vec, Converter converter) { return lst; } -template struct OutConverter { +template +struct OutConverter { PyObject* operator()(const T x) const { return SWIG_NewPointerObj((void*)x, type_, new_); // NOLINT } @@ -302,33 +315,31 @@ template struct OutConverter { }; template -static PyObject* vector_output_helper(const std::vector * vec, - PyObject * (*converter)(const TR x)) { +static PyObject* vector_output_helper(const std::vector* vec, + PyObject* (*converter)(const TR x)) { return list_output_helper(vec, converter); } template -static PyObject* vector_output_helper(const std::vector * vec, - const OutConverter & converter) { +static PyObject* vector_output_helper(const std::vector* vec, + const OutConverter& converter) { return list_output_helper(vec, converter); } template -static PyObject* vector_output_wrap_helper(const std::vector * vec, - swig_type_info * swig_Tp_type, +static PyObject* vector_output_wrap_helper(const std::vector* vec, + swig_type_info* swig_Tp_type, bool newobj = false) { #if 1 OutConverter converter(swig_Tp_type, newobj); return vector_output_helper(vec, converter); #else // Lambda version - auto converter = [](const T * x) { + auto converter = [](const T* x) { return SWIG_NewPointerObj((void*)x, swig_Tp_type, newobj); // NOLINT - } - return list_output_helper(vec, converter); + } return list_output_helper(vec, converter); #endif } - #if PY_MAJOR_VERSION > 2 /* SWIG 2's own C preprocessor macro for this is too strict. * It requires a (x) parameter which doesn't work for the case where the diff --git a/src/base/random.cc b/src/base/random.cc index fd5085974e..45adfd703c 100644 --- a/src/base/random.cc +++ b/src/base/random.cc @@ -12,16 +12,16 @@ // limitations under the License. #if defined(__GNUC__) -# include -# if defined(__linux__) -# include -# endif +#include +#if defined(__linux__) +#include +#endif #endif #if defined(_MSC_VER) -# include -# define PATH_MAX 4096 +#include +#define PATH_MAX 4096 #else -# include +#include #endif #include @@ -36,7 +36,7 @@ int32 ACMRandom::Next() { if (seed_ == 0) { seed_ = 0x14fd4603; // Arbitrary random constant } - const int32 M = 2147483647L; // 2^31-1 + const int32 M = 2147483647L; // 2^31-1 const int32 A = 16807; // In effect, we are computing seed_ = (seed_ * A) % M, where M = 2^31-1 uint32 lo = A * static_cast(seed_ & 0xFFFF); @@ -54,9 +54,7 @@ int32 ACMRandom::Next() { return (seed_ = static_cast(lo)); } -int32 ACMRandom::Uniform(int32 n) { - return n == 0 ? 0 :Next() % n; -} +int32 ACMRandom::Uniform(int32 n) { return n == 0 ? 0 : Next() % n; } int64 ACMRandom::Next64() { const int64 next = Next(); @@ -64,16 +62,15 @@ int64 ACMRandom::Next64() { } namespace { -static inline uint32 Word32At(const char *ptr) { - return ((static_cast(ptr[0])) + - (static_cast(ptr[1]) << 8) + +static inline uint32 Word32At(const char* ptr) { + return ((static_cast(ptr[0])) + (static_cast(ptr[1]) << 8) + (static_cast(ptr[2]) << 16) + (static_cast(ptr[3]) << 24)); } } // namespace int32 ACMRandom::HostnamePidTimeSeed() { - char name[PATH_MAX + 20]; // need 12 bytes for 3 'empty' uint32's + char name[PATH_MAX + 20]; // need 12 bytes for 3 'empty' uint32's assert(sizeof(name) - PATH_MAX > sizeof(uint32) * 3); // NOLINT if (gethostname(name, PATH_MAX) != 0) { @@ -81,7 +78,7 @@ int32 ACMRandom::HostnamePidTimeSeed() { } const int namelen = strlen(name); for (int i = 0; i < sizeof(uint32) * 3; ++i) { // NOLINT - name[namelen + i] = '\0'; // so we mix 0's once we get to end-of-std::string + name[namelen + i] = '\0'; // so we mix 0's once we get to end-of-std::string } #if defined(__GNUC__) uint32 a = getpid(); @@ -97,13 +94,13 @@ int32 ACMRandom::HostnamePidTimeSeed() { uint32 c = 0; for (int i = 0; i < namelen; i += sizeof(uint32) * 3) { // NOLINT a += Word32At(name + i); - b += Word32At(name + i + sizeof(uint32)); // NOLINT + b += Word32At(name + i + sizeof(uint32)); // NOLINT c += Word32At(name + i + sizeof(uint32) + sizeof(uint32)); // NOLINT mix(a, b, c); } - c += namelen; // one final mix + c += namelen; // one final mix mix(a, b, c); - return static_cast(c); // I guess the seed can be negative + return static_cast(c); // I guess the seed can be negative } int32 ACMRandom::DeterministicSeed() { return 0; } diff --git a/src/base/random.h b/src/base/random.h index 9a6bb2c0f4..af944674b7 100644 --- a/src/base/random.h +++ b/src/base/random.h @@ -48,25 +48,21 @@ class ACMRandom { double RandDouble() { return RndDouble(); } // Returns a double in [a, b). The distribution is uniform. - double UniformDouble(double a, double b) { - return a + (b - a) * RndDouble(); - } + double UniformDouble(double a, double b) { return a + (b - a) * RndDouble(); } void Reset(int32 seed) { seed_ = seed; } static int32 HostnamePidTimeSeed(); static int32 DeterministicSeed(); - // RandomNumberGenerator concept. Example: - // ACMRandom rand(my_seed); - // std::random_shuffle(myvec.begin(), myvec.end(), rand); +// RandomNumberGenerator concept. Example: +// ACMRandom rand(my_seed); +// std::random_shuffle(myvec.begin(), myvec.end(), rand); #if defined(_MSC_VER) typedef __int64 difference_type; // NOLINT #else typedef long long difference_type; // NOLINT #endif - int64 operator() (int64 val_max) { - return Next64() % val_max; - } + int64 operator()(int64 val_max) { return Next64() % val_max; } private: int32 seed_; @@ -77,11 +73,10 @@ class ACMRandom { // using ACMRandom. class MTRandom : public ACMRandom { public: - explicit MTRandom(int32 seed) : ACMRandom(seed) { } + explicit MTRandom(int32 seed) : ACMRandom(seed) {} // MTRandom also supports a std::string seed. explicit MTRandom(const std::string& str_seed) - : ACMRandom(GenerateInt32SeedFromString(str_seed)) { - } + : ACMRandom(GenerateInt32SeedFromString(str_seed)) {} MTRandom() : ACMRandom(ACMRandom::HostnamePidTimeSeed()) {} diff --git a/src/base/recordio.cc b/src/base/recordio.cc index f9f19f1e15..eb84e9a342 100644 --- a/src/base/recordio.cc +++ b/src/base/recordio.cc @@ -23,9 +23,7 @@ const int RecordWriter::kMagicNumber = 0x3ed7230a; RecordWriter::RecordWriter(File* const file) : file_(file), use_compression_(true) {} -bool RecordWriter::Close() { - return file_->Close(); -} +bool RecordWriter::Close() { return file_->Close(); } void RecordWriter::set_use_compression(bool use_compression) { use_compression_ = use_compression; @@ -33,14 +31,14 @@ void RecordWriter::set_use_compression(bool use_compression) { std::string RecordWriter::Compress(std::string const& s) const { const unsigned long source_size = s.size(); // NOLINT - const char * source = s.c_str(); + const char* source = s.c_str(); unsigned long dsize = source_size + (source_size * 0.1f) + 16; // NOLINT scoped_ptr destination(new char[dsize]); // Use compress() from zlib.h. const int result = - compress(reinterpret_cast(destination.get()), &dsize, - reinterpret_cast(source), source_size); + compress(reinterpret_cast(destination.get()), &dsize, + reinterpret_cast(source), source_size); if (result != Z_OK) { LOG(FATAL) << "Compress error occured! Error code: " << result; @@ -50,19 +48,16 @@ std::string RecordWriter::Compress(std::string const& s) const { RecordReader::RecordReader(File* const file) : file_(file) {} -bool RecordReader::Close() { - return file_->Close(); -} +bool RecordReader::Close() { return file_->Close(); } -void RecordReader::Uncompress(const char* const source, - uint64 source_size, - char* const output_buffer, - uint64 output_size) const { +void RecordReader::Uncompress(const char* const source, uint64 source_size, + char* const output_buffer, + uint64 output_size) const { unsigned long result_size = output_size; // NOLINT // Use uncompress() from zlib.h const int result = - uncompress(reinterpret_cast(output_buffer), &result_size, - reinterpret_cast(source), source_size); + uncompress(reinterpret_cast(output_buffer), &result_size, + reinterpret_cast(source), source_size); if (result != Z_OK) { LOG(FATAL) << "Uncompress error occured! Error code: " << result; } diff --git a/src/base/recordio.h b/src/base/recordio.h index 22152c073e..38e365a984 100644 --- a/src/base/recordio.h +++ b/src/base/recordio.h @@ -36,7 +36,8 @@ class RecordWriter { explicit RecordWriter(File* const file); - template bool WriteProtocolMessage(const P& proto) { + template + bool WriteProtocolMessage(const P& proto) { std::string uncompressed_buffer; proto.SerializeToString(&uncompressed_buffer); const uint64 uncompressed_size = uncompressed_buffer.size(); @@ -85,7 +86,8 @@ class RecordReader { public: explicit RecordReader(File* const file); - template bool ReadProtocolMessage(P* const proto) { + template + bool ReadProtocolMessage(P* const proto) { uint64 usize = 0; uint64 csize = 0; int magic_number = 0; @@ -123,10 +125,8 @@ class RecordReader { bool Close(); private: - void Uncompress(const char* const source, - uint64 source_size, - char* const output_buffer, - uint64 output_size) const; + void Uncompress(const char* const source, uint64 source_size, + char* const output_buffer, uint64 output_size) const; File* const file_; }; diff --git a/src/base/scoped_ptr.h b/src/base/scoped_ptr.h index 7ed2d135a1..18f9efb011 100644 --- a/src/base/scoped_ptr.h +++ b/src/base/scoped_ptr.h @@ -29,9 +29,12 @@ namespace operations_research { -template class scoped_ptr; -template class scoped_ptr_malloc; -template scoped_ptr make_scoped_ptr(C * param); +template +class scoped_ptr; +template +class scoped_ptr_malloc; +template +scoped_ptr make_scoped_ptr(C* param); // A scoped_ptr is like a T*, except that the destructor of scoped_ptr // automatically deletes the pointer it holds (if any). @@ -49,12 +52,14 @@ class scoped_ptr { // Constructor. Defaults to intializing with NULL. // There is no way to create an uninitialized scoped_ptr. // The input parameter must be allocated with new. - explicit scoped_ptr(C* p = NULL) : ptr_(p) { } + explicit scoped_ptr(C* p = NULL) : ptr_(p) {} // Destructor. If there is a C object, delete it. // We don't need to test ptr_ == NULL because C++ does that for us. ~scoped_ptr() { - enum { type_must_be_complete = sizeof(C) }; + enum { + type_must_be_complete = sizeof(C) + }; delete ptr_; } @@ -63,7 +68,9 @@ class scoped_ptr { // this->reset(this->get()) works. void reset(C* p = NULL) { if (p != ptr_) { - enum { type_must_be_complete = sizeof(C) }; + enum { + type_must_be_complete = sizeof(C) + }; delete ptr_; ptr_ = p; } @@ -75,7 +82,7 @@ class scoped_ptr { assert(ptr_ != NULL); return *ptr_; } - C* operator->() const { + C* operator->() const { assert(ptr_ != NULL); return ptr_; } @@ -110,13 +117,15 @@ class scoped_ptr { // friend class that can access copy ctor (although if it actually // calls a copy ctor, there will be a problem) see below - friend scoped_ptr make_scoped_ptr(C *p); + friend scoped_ptr make_scoped_ptr(C* p); // Forbid comparison of scoped_ptr types. If C2 != C, it totally doesn't // make sense, and if C2 == C, it still doesn't make sense because you should // never have the same object owned by two different scoped_ptrs. - template bool operator==(scoped_ptr const& p2) const; - template bool operator!=(scoped_ptr const& p2) const; + template + bool operator==(scoped_ptr const& p2) const; + template + bool operator!=(scoped_ptr const& p2) const; DISALLOW_COPY_AND_ASSIGN(scoped_ptr); }; @@ -138,7 +147,7 @@ bool operator!=(C* p1, const scoped_ptr& p2) { } template -scoped_ptr make_scoped_ptr(C *p) { +scoped_ptr make_scoped_ptr(C* p) { // This does nothing but to return a scoped_ptr of the type that the passed // pointer is of. (This eliminates the need to specify the name of T when // making a scoped_ptr that is used anonymously/temporarily.) From an @@ -167,13 +176,15 @@ class scoped_ptr { // Constructor. Defaults to intializing with NULL. // There is no way to create an uninitialized scoped_ptr. // The input parameter must be allocated with new. - explicit scoped_ptr(C* p = NULL) : ptr_(p) { } + explicit scoped_ptr(C* p = NULL) : ptr_(p) {} // Destructor. If there is a C object, delete it. // We don't need to test ptr_ == NULL because C++ does that for us. ~scoped_ptr() { - enum { type_must_be_complete = sizeof(C) }; - delete [] ptr_; + enum { + type_must_be_complete = sizeof(C) + }; + delete[] ptr_; } // Reset. Deletes the current owned object, if any. @@ -181,15 +192,17 @@ class scoped_ptr { // this->reset(this->get()) works. void reset(C* p = NULL) { if (p != ptr_) { - enum { type_must_be_complete = sizeof(C) }; - delete [] ptr_; + enum { + type_must_be_complete = sizeof(C) + }; + delete[] ptr_; ptr_ = p; } } // Accessors to get the owned object. // operator[] and operator-> will assert() if there is no current object. - C& operator[] (size_t i) const { + C& operator[](size_t i) const { assert(ptr_ != NULL); return ptr_[i]; } @@ -229,15 +242,13 @@ class scoped_ptr { // passed as a template argument to scoped_ptr_malloc below. class ScopedPtrMallocFree { public: - inline void operator()(void* x) const { - free(x); - } + inline void operator()(void* x) const { free(x); } }; // scoped_ptr_malloc<> is similar to scoped_ptr<>, but it accepts a // second template argument, the functor used to free the object. -template +template class scoped_ptr_malloc { public: // The element type @@ -248,12 +259,10 @@ class scoped_ptr_malloc { // The input parameter must be allocated with an allocator that matches the // Free functor. For the default Free functor, this is malloc, calloc, or // realloc. - explicit scoped_ptr_malloc(C* p = NULL): ptr_(p) {} + explicit scoped_ptr_malloc(C* p = NULL) : ptr_(p) {} // Destructor. If there is a C object, call the Free functor. - ~scoped_ptr_malloc() { - free_(ptr_); - } + ~scoped_ptr_malloc() { free_(ptr_); } // Reset. Calls the Free functor on the current owned object, if any. // Then takes ownership of a new object, if given. @@ -278,25 +287,19 @@ class scoped_ptr_malloc { return ptr_; } - C* get() const { - return ptr_; - } + C* get() const { return ptr_; } // Comparison operators. // These return whether a scoped_ptr_malloc and a plain pointer refer // to the same object, not just to two different but equal objects. // For compatibility wwith the boost-derived implementation, these // take non-const arguments. - bool operator==(C* p) const { - return ptr_ == p; - } + bool operator==(C* p) const { return ptr_ == p; } - bool operator!=(C* p) const { - return ptr_ != p; - } + bool operator!=(C* p) const { return ptr_ != p; } // Swap two scoped pointers. - void swap(scoped_ptr_malloc & b) { + void swap(scoped_ptr_malloc& b) { C* tmp = b.ptr_; b.ptr_ = ptr_; ptr_ = tmp; @@ -327,21 +330,21 @@ class scoped_ptr_malloc { DISALLOW_COPY_AND_ASSIGN(scoped_ptr_malloc); }; -template +template FP const scoped_ptr_malloc::free_ = FP(); -template inline -void swap(scoped_ptr_malloc& a, scoped_ptr_malloc& b) { +template +inline void swap(scoped_ptr_malloc& a, scoped_ptr_malloc& b) { a.swap(b); } -template inline -bool operator==(C* p, const scoped_ptr_malloc& b) { +template +inline bool operator==(C* p, const scoped_ptr_malloc& b) { return p == b.get(); } -template inline -bool operator!=(C* p, const scoped_ptr_malloc& b) { +template +inline bool operator!=(C* p, const scoped_ptr_malloc& b) { return p != b.get(); } } // namespace operations_research diff --git a/src/base/small_map.h b/src/base/small_map.h index d060e40acc..e6ddfcea69 100644 --- a/src/base/small_map.h +++ b/src/base/small_map.h @@ -1,8 +1,7 @@ #ifndef OR_TOOLS_BASE_SMALL_MAP_H_ #define OR_TOOLS_BASE_SMALL_MAP_H_ -template -class small_map : public T { -}; +template +class small_map : public T {}; #endif // OR_TOOLS_BASE_SMALL_MAP_H_ diff --git a/src/base/small_ordered_set.h b/src/base/small_ordered_set.h index 4f42a1a847..176c9f0915 100644 --- a/src/base/small_ordered_set.h +++ b/src/base/small_ordered_set.h @@ -1,8 +1,7 @@ #ifndef OR_TOOLS_BASE_SMALL_ORDERED_SET_H_ #define OR_TOOLS_BASE_SMALL_ORDERED_SET_H_ -template -class small_ordered_set : public T { -}; +template +class small_ordered_set : public T {}; #endif // OR_TOOLS_BASE_SMALL_ORDERED_SET_H_ diff --git a/src/base/sparsetable.h b/src/base/sparsetable.h index 3a502b751f..9990134dd1 100644 --- a/src/base/sparsetable.h +++ b/src/base/sparsetable.h @@ -19,7 +19,8 @@ namespace operations_research { // This class implement a simple block based sparse vector. -template class sparsetable { +template +class sparsetable { public: sparsetable() : size_(0) {} diff --git a/src/base/split.cc b/src/base/split.cc index 8fb0092f16..3d23d1ef0c 100644 --- a/src/base/split.cc +++ b/src/base/split.cc @@ -28,10 +28,9 @@ namespace operations_research { // the characters in the std::string, not the entire std::string as a single delimiter. // ---------------------------------------------------------------------- template -static inline -void SplitStringToIteratorUsing(const std::string& full, - const char* delim, - ITR& result) { // NOLINT +static inline void SplitStringToIteratorUsing(const std::string& full, + const char* delim, + ITR& result) { // NOLINT // Optimize the common case where delim is a single character. if (delim[0] != '\0' && delim[1] == '\0') { char c = delim[0]; @@ -42,7 +41,8 @@ void SplitStringToIteratorUsing(const std::string& full, ++p; } else { const char* start = p; - while (++p != end && *p != c) { } + while (++p != end && *p != c) { + } *result++ = std::string(start, p - start); } } @@ -62,10 +62,9 @@ void SplitStringToIteratorUsing(const std::string& full, } } -void SplitStringUsing(const std::string& full, - const char* delim, +void SplitStringUsing(const std::string& full, const char* delim, std::vector* result) { - std::back_insert_iterator< std::vector > it(*result); + std::back_insert_iterator > it(*result); SplitStringToIteratorUsing(full, delim, it); } diff --git a/src/base/stl_util.h b/src/base/stl_util.h index a2fe44b921..3a1eb2b35b 100644 --- a/src/base/stl_util.h +++ b/src/base/stl_util.h @@ -29,8 +29,7 @@ namespace operations_research { // advanced, which could result in the hash function trying to deference a // stale pointer. template -void STLDeleteContainerPointers(ForwardIterator begin, - ForwardIterator end) { +void STLDeleteContainerPointers(ForwardIterator begin, ForwardIterator end) { while (begin != end) { ForwardIterator temp = begin; ++begin; @@ -85,7 +84,7 @@ inline char* string_as_array(std::string* str) { // ElementDeleter (defined below), which ensures that your container's elements // are deleted when the ElementDeleter goes out of scope. template -void STLDeleteElements(T *container) { +void STLDeleteElements(T* container) { if (!container) return; STLDeleteContainerPointers(container->begin(), container->end()); container->clear(); @@ -96,7 +95,7 @@ void STLDeleteElements(T *container) { // in the case it's given a NULL pointer. template -void STLDeleteValues(T *v) { +void STLDeleteValues(T* v) { if (!v) return; for (typename T::iterator i = v->begin(); i != v->end(); ++i) { delete i->second; @@ -104,7 +103,7 @@ void STLDeleteValues(T *v) { v->clear(); } -template +template void STLClearObject(T* obj) { T tmp; tmp.swap(*obj); diff --git a/src/base/stringpiece.cc b/src/base/stringpiece.cc index 4ce5669f92..e73af776fd 100644 --- a/src/base/stringpiece.cc +++ b/src/base/stringpiece.cc @@ -30,19 +30,17 @@ bool operator==(const StringPiece& x, const StringPiece& y) { const char* p = x.data(); const char* p2 = y.data(); // Test last byte in case strings share large common prefix - if ((len > 0) && (p[len-1] != p2[len-1])) return false; + if ((len > 0) && (p[len - 1] != p2[len - 1])) return false; const char* p_limit = p + len; for (; p < p_limit; p++, p2++) { - if (*p != *p2) - return false; + if (*p != *p2) return false; } return true; } bool operator<(const operations_research::StringPiece& x, const operations_research::StringPiece& y) { - const int r = memcmp(x.data(), y.data(), - std::min(x.size(), y.size())); + const int r = memcmp(x.data(), y.data(), std::min(x.size(), y.size())); return ((r < 0) || ((r == 0) && (x.size() < y.size()))); } @@ -57,11 +55,10 @@ int StringPiece::copy(char* buf, size_type n, size_type pos) const { } int StringPiece::find(const StringPiece& s, size_type pos) const { - if (length_ < 0 || pos > static_cast(length_)) - return npos; + if (length_ < 0 || pos > static_cast(length_)) return npos; - const char* result = std::search(ptr_ + pos, ptr_ + length_, - s.ptr_, s.ptr_ + s.length_); + const char* result = + std::search(ptr_ + pos, ptr_ + length_, s.ptr_, s.ptr_ + s.length_); const size_type xpos = result - ptr_; return xpos + s.length_ <= length_ ? xpos : npos; } @@ -69,8 +66,10 @@ int StringPiece::find(const StringPiece& s, size_type pos) const { int StringPiece::compare(const StringPiece& x) const { int r = memcmp(ptr_, x.ptr_, std::min(length_, x.length_)); if (r == 0) { - if (length_ < x.length_) r = -1; - else if (length_ > x.length_) r = +1; + if (length_ < x.length_) + r = -1; + else if (length_ > x.length_) + r = +1; } return r; } @@ -95,8 +94,7 @@ int StringPiece::rfind(const StringPiece& s, size_type pos) const { int StringPiece::rfind(char c, size_type pos) const { if (length_ <= 0) return npos; - for (int i = std::min(pos, static_cast(length_ - 1)); - i >= 0; --i) { + for (int i = std::min(pos, static_cast(length_ - 1)); i >= 0; --i) { if (ptr_[i] == c) { return i; } diff --git a/src/base/stringpiece.h b/src/base/stringpiece.h index 5e3a8350ee..58b969c147 100644 --- a/src/base/stringpiece.h +++ b/src/base/stringpiece.h @@ -36,19 +36,21 @@ namespace operations_research { class StringPiece { private: - const char* ptr_; - int length_; + const char* ptr_; + int length_; public: // We provide non-explicit singleton constructors so users can pass // in a "const char*" or a "std::string" wherever a "StringPiece" is // expected. - StringPiece() : ptr_(NULL), length_(0) { } + StringPiece() : ptr_(NULL), length_(0) {} StringPiece(const char* str) // NOLINT - : ptr_(str), length_((str == NULL) ? 0 : static_cast(strlen(str))) { } + : ptr_(str), + length_((str == NULL) ? 0 : static_cast(strlen(str))) {} StringPiece(const std::string& str) // NOLINT - : ptr_(str.data()), length_(static_cast(str.size())) { } - StringPiece(const char* offset, int len) : ptr_(offset), length_(len) { } + : ptr_(str.data()), + length_(static_cast(str.size())) {} + StringPiece(const char* offset, int len) : ptr_(offset), length_(len) {} // data() may return a pointer to a buffer with embedded NULs, and the // returned buffer may or may not be null terminated. Therefore it is @@ -86,37 +88,30 @@ class StringPiece { length_ -= n; } - void remove_suffix(int n) { - length_ -= n; - } + void remove_suffix(int n) { length_ -= n; } int compare(const StringPiece& x) const; - std::string as_string() const { - return std::string(data(), size()); - } + std::string as_string() const { return std::string(data(), size()); } // We also define ToString() here, since many other std::string-like // interfaces name the routine that converts to a C++ std::string // "ToString", and it's confusing to have the method that does that // for a StringPiece be called "as_string()". We also leave the // "as_string()" method defined here for existing code. - std::string ToString() const { - return std::string(data(), size()); - } + std::string ToString() const { return std::string(data(), size()); } void CopyToString(std::string* target) const; void AppendToString(std::string* target) const; // Does "this" start with "x" bool starts_with(const StringPiece& x) const { - return ((length_ >= x.length_) && - (memcmp(ptr_, x.ptr_, x.length_) == 0)); + return ((length_ >= x.length_) && (memcmp(ptr_, x.ptr_, x.length_) == 0)); } // Does "this" end with "x" bool ends_with(const StringPiece& x) const { return ((length_ >= x.length_) && - (memcmp(ptr_ + (length_-x.length_), x.ptr_, x.length_) == 0)); + (memcmp(ptr_ + (length_ - x.length_), x.ptr_, x.length_) == 0)); } // standard STL container boilerplate @@ -136,9 +131,7 @@ class StringPiece { const_reverse_iterator rbegin() const { return const_reverse_iterator(ptr_ + length_); } - const_reverse_iterator rend() const { - return const_reverse_iterator(ptr_); - } + const_reverse_iterator rend() const { return const_reverse_iterator(ptr_); } // STLS says return size_type, but Google says return int int max_size() const { return length_; } int capacity() const { return length_; } diff --git a/src/base/stringprintf.cc b/src/base/stringprintf.cc index 5d6dd8a2a6..8e6deac6c0 100644 --- a/src/base/stringprintf.cc +++ b/src/base/stringprintf.cc @@ -20,9 +20,7 @@ namespace operations_research { -void StringAppendV(std::string* const dst, - const char* const format, - va_list ap) { +void StringAppendV(std::string* const dst, const char* const format, va_list ap) { // First try with a small fixed size buffer char space[1024]; @@ -52,13 +50,13 @@ void StringAppendV(std::string* const dst, length *= 2; } else { // We need exactly "result+1" characters - length = result+1; + length = result + 1; } char* const buf = new char[length]; - // Restore the va_list before we use it again +// Restore the va_list before we use it again #if defined(_MSC_VER) - backup_ap = ap; + backup_ap = ap; #else va_copy(backup_ap, ap); #endif diff --git a/src/base/strtoint.h b/src/base/strtoint.h index 19dad45dab..a4430fa74c 100644 --- a/src/base/strtoint.h +++ b/src/base/strtoint.h @@ -21,25 +21,25 @@ namespace operations_research { // Conversions to a 32-bit integer can pass the call to strto[u]l on 32-bit // platforms, but need a little extra work on 64-bit platforms. -inline int32 strto32(const char *nptr, char **endptr, int base) { +inline int32 strto32(const char* nptr, char** endptr, int base) { return strtol(nptr, endptr, base); // NOLINT } -inline uint32 strtou32(const char *nptr, char **endptr, int base) { +inline uint32 strtou32(const char* nptr, char** endptr, int base) { return strtoul(nptr, endptr, base); // NOLINT } // For now, long long is 64-bit on all the platforms we care about, so these // functions can simply pass the call to strto[u]ll. -inline int64 strto64(const char *nptr, char **endptr, int base) { +inline int64 strto64(const char* nptr, char** endptr, int base) { #if defined(_MSC_VER) return _strtoi64(nptr, endptr, base); // NOLINT #else - return strtoll(nptr, endptr, base); // NOLINT + return strtoll(nptr, endptr, base); // NOLINT #endif // _MSC_VER } -inline uint64 strtou64(const char *nptr, char **endptr, int base) { +inline uint64 strtou64(const char* nptr, char** endptr, int base) { #if defined(_MSC_VER) return _strtoui64(nptr, endptr, base); // NOLINT #else @@ -49,21 +49,13 @@ inline uint64 strtou64(const char *nptr, char **endptr, int base) { // Although it returns an int, atoi() is implemented in terms of strtol, and // so has differing overflow and underflow behavior. atol is the same. -inline int32 atoi32(const char *nptr) { - return strto32(nptr, NULL, 10); -} +inline int32 atoi32(const char* nptr) { return strto32(nptr, NULL, 10); } -inline int64 atoi64(const char *nptr) { - return strto64(nptr, NULL, 10); -} +inline int64 atoi64(const char* nptr) { return strto64(nptr, NULL, 10); } // Convenience versions of the above that take a std::string argument. -inline int32 atoi32(const std::string &s) { - return atoi32(s.c_str()); -} +inline int32 atoi32(const std::string& s) { return atoi32(s.c_str()); } -inline int64 atoi64(const std::string &s) { - return atoi64(s.c_str()); -} +inline int64 atoi64(const std::string& s) { return atoi64(s.c_str()); } } // namespace operations_research #endif // OR_TOOLS_BASE_STRTOINT_H_ diff --git a/src/base/strutil.h b/src/base/strutil.h index 4993f1773f..8a47fc84bb 100644 --- a/src/base/strutil.h +++ b/src/base/strutil.h @@ -11,21 +11,21 @@ // See the License for the specific language governing permissions and // limitations under the License. - #ifndef OR_TOOLS_BASE_STRUTIL_H_ #define OR_TOOLS_BASE_STRUTIL_H_ #include #include "base/stringpiece.h" +using std::string; + namespace operations_research { // ---------------------------------------------------------------------- // HasSuffixString() // Return true if str ends in suffix. // ---------------------------------------------------------------------- -inline bool HasSuffixString(const StringPiece& str, - const StringPiece& suffix) { +inline bool HasSuffixString(const StringPiece& str, const StringPiece& suffix) { return str.ends_with(suffix); } @@ -38,49 +38,42 @@ inline std::string StrCat(const std::string& str1, const std::string& str2, return str1 + str2 + str3; } -inline std::string StrCat(const std::string& str1, const std::string& str2, - const std::string& str3, const std::string& str4) { +inline std::string StrCat(const std::string& str1, const std::string& str2, const std::string& str3, + const std::string& str4) { return str1 + str2 + str3 + str4; } -inline std::string StrCat(const std::string& str1, const std::string& str2, - const std::string& str3, const std::string& str4, - const std::string& str5) { +inline std::string StrCat(const std::string& str1, const std::string& str2, const std::string& str3, + const std::string& str4, const std::string& str5) { return str1 + str2 + str3 + str4 + str5; } -inline std::string StrCat(const std::string& str1, const std::string& str2, - const std::string& str3, const std::string& str4, - const std::string& str5, const std::string& str6) { +inline std::string StrCat(const std::string& str1, const std::string& str2, const std::string& str3, + const std::string& str4, const std::string& str5, + const std::string& str6) { return str1 + str2 + str3 + str4 + str5 + str6; } -inline std::string StrCat(const std::string& str1, const std::string& str2, - const std::string& str3, const std::string& str4, - const std::string& str5, const std::string& str6, +inline std::string StrCat(const std::string& str1, const std::string& str2, const std::string& str3, + const std::string& str4, const std::string& str5, const std::string& str6, const std::string& str7) { return str1 + str2 + str3 + str4 + str5 + str6 + str7; } -inline std::string StrCat(const std::string& str1, const std::string& str2, - const std::string& str3, const std::string& str4, - const std::string& str5, const std::string& str6, +inline std::string StrCat(const std::string& str1, const std::string& str2, const std::string& str3, + const std::string& str4, const std::string& str5, const std::string& str6, const std::string& str7, const std::string& str8) { return str1 + str2 + str3 + str4 + str5 + str6 + str7 + str8; } -inline std::string StrCat(const std::string& str1, const std::string& str2, - const std::string& str3, const std::string& str4, - const std::string& str5, const std::string& str6, +inline std::string StrCat(const std::string& str1, const std::string& str2, const std::string& str3, + const std::string& str4, const std::string& str5, const std::string& str6, const std::string& str7, const std::string& str8, const std::string& str9) { return str1 + str2 + str3 + str4 + str5 + str6 + str7 + str8 + str9; } - -inline void StrAppend(std::string* str1, const std::string& str2) { - *str1 += str2; -} +inline void StrAppend(std::string* str1, const std::string& str2) { *str1 += str2; } inline void StrAppend(std::string* str1, const std::string& str2, const std::string& str3) { *str1 += str2 + str3; diff --git a/src/base/synchronization.h b/src/base/synchronization.h index 1c05fe6325..736d32786a 100644 --- a/src/base/synchronization.h +++ b/src/base/synchronization.h @@ -21,7 +21,7 @@ namespace operations_research { class Barrier { public: explicit Barrier(int num_threads) - : num_to_block_(num_threads), num_to_exit_(num_threads) {} + : num_to_block_(num_threads), num_to_exit_(num_threads) {} bool Block() { MutexLock l(&this->lock_); @@ -47,7 +47,7 @@ class Barrier { DISALLOW_COPY_AND_ASSIGN(Barrier); }; -template +template inline T ThreadSafeIncrement(T* value, Mutex* sm, TT inc) { MutexLock l(sm); return (*value) += inc; diff --git a/src/base/sysinfo.cc b/src/base/sysinfo.cc index 23daaca5dd..6d9c834852 100644 --- a/src/base/sysinfo.cc +++ b/src/base/sysinfo.cc @@ -12,14 +12,14 @@ // limitations under the License. #if defined(__GNUC__) && defined(__linux__) -# include +#include #endif #if defined(__APPLE__) && defined(__GNUC__) // Mac OS X -# include -# include +#include +#include #elif defined(_MSC_VER) // WINDOWS -# include -# include +#include +#include #endif #include @@ -36,16 +36,14 @@ int64 GetProcessMemoryUsage() { struct task_basic_info t_info; mach_msg_type_number_t t_info_count = TASK_BASIC_INFO_COUNT; - if (KERN_SUCCESS != task_info(mach_task_self(), - TASK_BASIC_INFO, - (task_info_t)&t_info, - &t_info_count)) { + if (KERN_SUCCESS != task_info(mach_task_self(), TASK_BASIC_INFO, + (task_info_t) & t_info, &t_info_count)) { return -1; } int64 resident_memory = t_info.resident_size; return resident_memory; } -#elif defined(__GNUC__) // LINUX +#elif defined(__GNUC__) // LINUX int64 GetProcessMemoryUsage() { unsigned size = 0; int result; @@ -62,8 +60,7 @@ int64 GetProcessMemoryUsage() { int64 GetProcessMemoryUsage() { HANDLE hProcess; PROCESS_MEMORY_COUNTERS pmc; - hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, - FALSE, + hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, GetCurrentProcessId()); int64 memory = 0; if (hProcess) { @@ -75,9 +72,7 @@ int64 GetProcessMemoryUsage() { return memory; } #else // Unknown, returning 0. -int64 GetProcessMemoryUsage() { - return 0; -} +int64 GetProcessMemoryUsage() { return 0; } #endif } // namespace operations_research diff --git a/src/base/timer.cc b/src/base/timer.cc index 889daaec59..7a464e92fc 100644 --- a/src/base/timer.cc +++ b/src/base/timer.cc @@ -30,14 +30,14 @@ namespace operations_research { #if !defined(_MSC_VER) namespace { -static inline int64 TimevalToUsec(const timeval &tv) { +static inline int64 TimevalToUsec(const timeval& tv) { return static_cast(1000000) * tv.tv_sec + tv.tv_usec; } } // namespace #endif WallTimer::WallTimer() - : start_usec_(0LL), sum_usec_(0LL), has_started_(false) {} + : start_usec_(0LL), sum_usec_(0LL), has_started_(false) {} void WallTimer::Start() { // Just save when we started #if defined(_MSC_VER) @@ -50,8 +50,8 @@ void WallTimer::Start() { // Just save when we started has_started_ = true; } -void WallTimer::Stop() { // Update total time, 1st time it's called - if (has_started_) { // so two Stop()s is safe +void WallTimer::Stop() { // Update total time, 1st time it's called + if (has_started_) { // so two Stop()s is safe #if defined(_MSC_VER) sum_usec_ += clock() - start_usec_; #elif defined(__GNUC__) @@ -75,21 +75,19 @@ void WallTimer::Restart() { Start(); } -bool WallTimer::IsRunning() const { - return has_started_; -} +bool WallTimer::IsRunning() const { return has_started_; } int64 WallTimer::GetInMs() const { #if defined(_MSC_VER) int64 local_sum_usec = sum_usec_; - if (has_started_) { // need to include current time too + if (has_started_) { // need to include current time too local_sum_usec += clock() - start_usec_; } return local_sum_usec; #elif defined(__GNUC__) static const int64 kMilliSecInMicroSec = 1000LL; int64 local_sum_usec = sum_usec_; - if (has_started_) { // need to include current time too + if (has_started_) { // need to include current time too struct timeval tv; gettimeofday(&tv, NULL); local_sum_usec += TimevalToUsec(tv) - start_usec_; @@ -123,13 +121,11 @@ int64 WallTimer::GetTimeInMicroSeconds() { struct timespec current; clock_gettime(CLOCK_PROCESS_CPUTIME_ID, ¤t); return current.tv_sec * kSecondInMicroSeconds + - current.tv_nsec / kMicroSecondsInNanoSeconds; + current.tv_nsec / kMicroSecondsInNanoSeconds; #endif } -double WallTimer::Get() const { - return GetInMs() / 1000.0; -} +double WallTimer::Get() const { return GetInMs() / 1000.0; } // ----- CycleTimer ----- CycleTimer::CycleTimer() : time_in_us_(0), state_(INIT) {} @@ -171,8 +167,7 @@ int64 CycleTimer::GetInMs() const { } ScopedWallTime::ScopedWallTime(double* aggregate_time) - : aggregate_time_(aggregate_time), - timer_() { + : aggregate_time_(aggregate_time), timer_() { DCHECK(aggregate_time != NULL); timer_.Start(); } diff --git a/src/base/timer.h b/src/base/timer.h index 7a26b8eff8..8158b615fc 100644 --- a/src/base/timer.h +++ b/src/base/timer.h @@ -56,6 +56,7 @@ class CycleTimer { int64 GetCycles() const; int64 GetInUsec() const; int64 GetInMs() const; + private: enum State { INIT, @@ -74,9 +75,7 @@ class CycleTimerBase { return static_cast(cycles) / 1000000.0; } - static int64 UsecToCycles(int64 usec) { - return usec; - } + static int64 UsecToCycles(int64 usec) { return usec; } }; class ScopedWallTime { diff --git a/src/base/unique_ptr.h b/src/base/unique_ptr.h index dcdde249fb..7eb90cd0dc 100644 --- a/src/base/unique_ptr.h +++ b/src/base/unique_ptr.h @@ -36,12 +36,14 @@ class unique_ptr { // Constructor. Defaults to intializing with NULL. // There is no way to create an uninitialized unique_ptr. // The input parameter must be allocated with new. - explicit unique_ptr(C* p = NULL) : ptr_(p) { } + explicit unique_ptr(C* p = NULL) : ptr_(p) {} // Destructor. If there is a C object, delete it. // We don't need to test ptr_ == NULL because C++ does that for us. ~unique_ptr() { - enum { type_must_be_complete = sizeof(C) }; + enum { + type_must_be_complete = sizeof(C) + }; delete ptr_; } @@ -50,7 +52,9 @@ class unique_ptr { // this->reset(this->get()) works. void reset(C* p = NULL) { if (p != ptr_) { - enum { type_must_be_complete = sizeof(C) }; + enum { + type_must_be_complete = sizeof(C) + }; delete ptr_; ptr_ = p; } @@ -62,7 +66,7 @@ class unique_ptr { assert(ptr_ != NULL); return *ptr_; } - C* operator->() const { + C* operator->() const { assert(ptr_ != NULL); return ptr_; } @@ -98,8 +102,10 @@ class unique_ptr { // Forbid comparison of unique_ptr types. If C2 != C, it totally doesn't // make sense, and if C2 == C, it still doesn't make sense because you should // never have the same object owned by two different unique_ptrs. - template bool operator==(unique_ptr const& p2) const; - template bool operator!=(unique_ptr const& p2) const; + template + bool operator==(unique_ptr const& p2) const; + template + bool operator!=(unique_ptr const& p2) const; DISALLOW_COPY_AND_ASSIGN(unique_ptr); }; @@ -136,13 +142,15 @@ class unique_ptr { // Constructor. Defaults to intializing with NULL. // There is no way to create an uninitialized unique_ptr. // The input parameter must be allocated with new. - explicit unique_ptr(C* p = NULL) : ptr_(p) { } + explicit unique_ptr(C* p = NULL) : ptr_(p) {} // Destructor. If there is a C object, delete it. // We don't need to test ptr_ == NULL because C++ does that for us. ~unique_ptr() { - enum { type_must_be_complete = sizeof(C) }; - delete [] ptr_; + enum { + type_must_be_complete = sizeof(C) + }; + delete[] ptr_; } // Reset. Deletes the current owned object, if any. @@ -150,15 +158,17 @@ class unique_ptr { // this->reset(this->get()) works. void reset(C* p = NULL) { if (p != ptr_) { - enum { type_must_be_complete = sizeof(C) }; - delete [] ptr_; + enum { + type_must_be_complete = sizeof(C) + }; + delete[] ptr_; ptr_ = p; } } // Accessors to get the owned object. // operator[] and operator-> will assert() if there is no current object. - C& operator[] (size_t i) const { + C& operator[](size_t i) const { assert(ptr_ != NULL); return ptr_[i]; } diff --git a/src/constraint_solver/alldiff_cst.cc b/src/constraint_solver/alldiff_cst.cc index 7c6d18a97b..ffbcee9158 100644 --- a/src/constraint_solver/alldiff_cst.cc +++ b/src/constraint_solver/alldiff_cst.cc @@ -178,10 +178,8 @@ class RangeBipartiteMatching { // This method sorts the min_sorted_ and max_sorted_ arrays and fill // the bounds_ array (and set the active_size_ counter). void SortArray() { - std::sort(min_sorted_.get(), min_sorted_.get() + size_, - CompareIntervalMin()); - std::sort(max_sorted_.get(), max_sorted_.get() + size_, - CompareIntervalMax()); + std::sort(min_sorted_.get(), min_sorted_.get() + size_, CompareIntervalMin()); + std::sort(max_sorted_.get(), max_sorted_.get() + size_, CompareIntervalMax()); int64 min = min_sorted_[0]->min; int64 max = max_sorted_[0]->max + 1; @@ -571,8 +569,7 @@ class AllDifferentExcept : public Constraint { virtual std::string DebugString() const { return StringPrintf("AllDifferentExcept([%s], %" GG_LL_FORMAT "d", - JoinDebugStringPtr(vars_, ", ").c_str(), - escape_value_); + JoinDebugStringPtr(vars_, ", ").c_str(), escape_value_); } virtual void Accept(ModelVisitor* const visitor) const { diff --git a/src/constraint_solver/assignment.cc b/src/constraint_solver/assignment.cc index 10696ce899..3364f812e3 100644 --- a/src/constraint_solver/assignment.cc +++ b/src/constraint_solver/assignment.cc @@ -851,13 +851,13 @@ SequenceVarElement* Assignment::FastAdd(SequenceVar* const v) { return sequence_var_container_.FastAdd(v); } -const std::vector& Assignment::ForwardSequence( - const SequenceVar* const v) const { +const std::vector& Assignment::ForwardSequence(const SequenceVar* const v) + const { return sequence_var_container_.Element(v).ForwardSequence(); } -const std::vector& Assignment::BackwardSequence( - const SequenceVar* const v) const { +const std::vector& Assignment::BackwardSequence(const SequenceVar* const v) + const { return sequence_var_container_.Element(v).BackwardSequence(); } diff --git a/src/constraint_solver/constraint_solver.cc b/src/constraint_solver/constraint_solver.cc index 5460209bf7..a593ef5dda 100644 --- a/src/constraint_solver/constraint_solver.cc +++ b/src/constraint_solver/constraint_solver.cc @@ -1430,8 +1430,8 @@ Solver::Solver(const std::string& name) : name_(name), parameters_(), queue_(new Queue(this)), - trail_(new Trail(parameters_.trail_block_size, - parameters_.compress_trail)), + trail_( + new Trail(parameters_.trail_block_size, parameters_.compress_trail)), state_(OUTSIDE_SEARCH), branches_(0), fails_(0), @@ -1948,9 +1948,9 @@ void Solver::NewSearch(DecisionBuilder* const db, // The print_trace needs to be last to detect propagation from the objective. if (nested) { if (print_trace_ != nullptr) { // Was installed at the top level? - print_trace_->Install(); // Propagates to nested search. + print_trace_->Install(); // Propagates to nested search. } - } else { // Top level search + } else { // Top level search print_trace_ = nullptr; // Clears it first. if (FLAGS_cp_trace_propagation) { print_trace_ = BuildPrintTrace(this); diff --git a/src/constraint_solver/constraint_solver.h b/src/constraint_solver/constraint_solver.h index 42f84a4ee7..099a8c49b4 100644 --- a/src/constraint_solver/constraint_solver.h +++ b/src/constraint_solver/constraint_solver.h @@ -99,7 +99,6 @@ template class ResultCallback; - namespace operations_research { class Action; @@ -1101,8 +1100,8 @@ class Solver { SequenceVariableBuilder* const builder); ConstraintBuilder* GetConstraintBuilder(const std::string& tag) const; - IntegerExpressionBuilder* GetIntegerExpressionBuilder( - const std::string& tag) const; + IntegerExpressionBuilder* GetIntegerExpressionBuilder(const std::string& tag) + const; IntervalVariableBuilder* GetIntervalVariableBuilder(const std::string& tag) const; SequenceVariableBuilder* GetSequenceVariableBuilder(const std::string& tag) const; #endif // SWIG @@ -1611,12 +1610,12 @@ class Solver { Constraint* MakeInverse(const std::vector& left, const std::vector& right); - // Creates a constraint that states that all variables in the first - // vector are different from all variables from the second - // group. Thus the set of values in the first vector does not - // intersect the set of values in the second vector. - Constraint* MakeNullIntersect(const std::vector& first_vars, - const std::vector& second_vars); + // Creates a constraint that states that all variables in the first + // vector are different from all variables from the second + // group. Thus the set of values in the first vector does not + // intersect the set of values in the second vector. + Constraint* MakeNullIntersect(const std::vector& first_vars, + const std::vector& second_vars); // Creates a constraint that states that all variables in the first // vector are different from all variables from the second group, @@ -2365,8 +2364,7 @@ class Solver { IntVarStrategy var_str, IndexEvaluator2* val_eval); DecisionBuilder* MakePhase( - const std::vector& vars, - IntVarStrategy var_str, + const std::vector& vars, IntVarStrategy var_str, // var_val1_val2_comparator(var, val1, val2) is true iff assigning value // "val1" to variable "var" is better than assigning value "val2". // Takes ownership of "var_val1_val2_comparator". @@ -2656,11 +2654,9 @@ class Solver { const std::vector& vars, DecisionBuilder* const first_solution, LocalSearchPhaseParameters* const parameters); DecisionBuilder* MakeLocalSearchPhase( - const std::vector& vars, - DecisionBuilder* const first_solution, + const std::vector& vars, DecisionBuilder* const first_solution, LocalSearchPhaseParameters* const parameters); - // Solution Pool. SolutionPool* MakeDefaultSolutionPool(); @@ -4400,8 +4396,8 @@ class IntervalVarElement : public AssignmentElement { void Restore(); void LoadFromProto( const IntervalVarAssignmentProto& interval_var_assignment_proto); - void WriteToProto( - IntervalVarAssignmentProto* interval_var_assignment_proto) const; + void WriteToProto(IntervalVarAssignmentProto* interval_var_assignment_proto) + const; int64 StartMin() const { return start_min_; } int64 StartMax() const { return start_max_; } @@ -4512,8 +4508,8 @@ class SequenceVarElement : public AssignmentElement { void Restore(); void LoadFromProto( const SequenceVarAssignmentProto& sequence_var_assignment_proto); - void WriteToProto( - SequenceVarAssignmentProto* sequence_var_assignment_proto) const; + void WriteToProto(SequenceVarAssignmentProto* sequence_var_assignment_proto) + const; const std::vector& ForwardSequence() const; const std::vector& BackwardSequence() const; @@ -4577,9 +4573,7 @@ class AssignmentContainer { } // Advanced usage: Resizes the container, potentially adding elements with // null variables. - void Resize(size_t size) { - elements_.resize(size); - } + void Resize(size_t size) { elements_.resize(size); } bool Empty() const { return elements_.empty(); } // Copies intersection of containers. void Copy(const AssignmentContainer& container) { diff --git a/src/constraint_solver/constraints.cc b/src/constraint_solver/constraints.cc index 0615075578..ef18969f1a 100644 --- a/src/constraint_solver/constraints.cc +++ b/src/constraint_solver/constraints.cc @@ -11,6 +11,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include #include #include "base/unique_ptr.h" #include diff --git a/src/constraint_solver/count_cst.cc b/src/constraint_solver/count_cst.cc index a01d95e2e5..73bccad6cf 100644 --- a/src/constraint_solver/count_cst.cc +++ b/src/constraint_solver/count_cst.cc @@ -370,8 +370,8 @@ void FastDistribute::OneDomain(int index) { const int64 oldmax = var->OldMax(); const int64 vmin = var->Min(); const int64 vmax = var->Max(); - for (int64 card_index = std::max(oldmin, 0LL); - card_index < std::min(vmin, card_size()); ++card_index) { + for (int64 card_index = std::max(oldmin, 0LL); card_index < std::min(vmin, card_size()); + ++card_index) { if (undecided_.IsSet(index, card_index)) { SetRevCannotContribute(index, card_index); } @@ -786,8 +786,8 @@ void BoundedFastDistribute::OneDomain(int index) { const int64 oldmax = var->OldMax(); const int64 vmin = var->Min(); const int64 vmax = var->Max(); - for (int64 card_index = std::max(oldmin, 0LL); - card_index < std::min(vmin, card_size()); ++card_index) { + for (int64 card_index = std::max(oldmin, 0LL); card_index < std::min(vmin, card_size()); + ++card_index) { if (undecided_.IsSet(index, card_index)) { SetRevCannotContribute(index, card_index); } diff --git a/src/constraint_solver/demon_profiler.cc b/src/constraint_solver/demon_profiler.cc index 66fcd1ad00..c034e45142 100644 --- a/src/constraint_solver/demon_profiler.cc +++ b/src/constraint_solver/demon_profiler.cc @@ -264,19 +264,15 @@ class DemonProfiler : public PropagationMonitor { std::vector to_sort; for (hash_map::const_iterator it = constraint_map_.begin(); - it != constraint_map_.end(); - ++it) { + it != constraint_map_.end(); ++it) { const Constraint* const ct = it->first; int64 fails = 0; int64 demon_invocations = 0; int64 initial_propagation_runtime = 0; int64 total_demon_runtime = 0; int demon_count = 0; - ExportInformation(ct, - &fails, - &initial_propagation_runtime, - &demon_invocations, - &total_demon_runtime, + ExportInformation(ct, &fails, &initial_propagation_runtime, + &demon_invocations, &total_demon_runtime, &demon_count); to_sort.push_back( Container(ct, total_demon_runtime + initial_propagation_runtime)); @@ -290,11 +286,8 @@ class DemonProfiler : public PropagationMonitor { int64 initial_propagation_runtime = 0; int64 total_demon_runtime = 0; int demon_count = 0; - ExportInformation(ct, - &fails, - &initial_propagation_runtime, - &demon_invocations, - &total_demon_runtime, + ExportInformation(ct, &fails, &initial_propagation_runtime, + &demon_invocations, &total_demon_runtime, &demon_count); const std::string constraint_message = StringPrintf(kConstraintFormat, ct->DebugString().c_str(), fails, diff --git a/src/constraint_solver/element.cc b/src/constraint_solver/element.cc index aea9ed02f3..bb434616c1 100644 --- a/src/constraint_solver/element.cc +++ b/src/constraint_solver/element.cc @@ -1318,12 +1318,11 @@ IntExpr* Solver::MakeElement(const std::vector& vars, IntVar* const ind } } const std::string vname = - size > 10 - ? StringPrintf("ElementVar(var array of size %d, %s)", size, - index->DebugString().c_str()) - : StringPrintf("ElementVar([%s], %s)", - JoinNamePtr(vars, ", ").c_str(), - index->name().c_str()); + size > 10 ? StringPrintf("ElementVar(var array of size %d, %s)", size, + index->DebugString().c_str()) + : StringPrintf("ElementVar([%s], %s)", + JoinNamePtr(vars, ", ").c_str(), + index->name().c_str()); IntVar* const element_var = MakeIntVar(emin, emax, vname); AddConstraint( RevAlloc(new IntExprArrayElementCt(this, vars, index, element_var))); @@ -1395,8 +1394,7 @@ IntExpr* Solver::MakeIndexExpression(const std::vector& vars, int64 val return cache->Var(); } else { const std::string name = StringPrintf("Index(%s, %" GG_LL_FORMAT "d)", - JoinNamePtr(vars, ", ").c_str(), - value); + JoinNamePtr(vars, ", ").c_str(), value); IntVar* const index = MakeIntVar(0, vars.size() - 1, name); AddConstraint(MakeIndexOfConstraint(vars, index, value)); model_cache_->InsertVarArrayConstantExpression( diff --git a/src/constraint_solver/expr_array.cc b/src/constraint_solver/expr_array.cc index 48796818ed..d83ca237bb 100644 --- a/src/constraint_solver/expr_array.cc +++ b/src/constraint_solver/expr_array.cc @@ -1032,8 +1032,7 @@ class ArrayBoolOrEq : public CastConstraint { } std::string DebugString() const { - return StringPrintf("Or(%s) == %s", - JoinDebugStringPtr(vars_, ", ").c_str(), + return StringPrintf("Or(%s) == %s", JoinDebugStringPtr(vars_, ", ").c_str(), target_var_->DebugString().c_str()); } @@ -2773,8 +2772,7 @@ IntExpr* Solver::MakeSum(const std::vector& vars) { const bool all_booleans = AreAllBooleans(vars); if (all_booleans) { const std::string name = - StringPrintf("BooleanSum([%s])", - JoinNamePtr(vars, ", ").c_str()); + StringPrintf("BooleanSum([%s])", JoinNamePtr(vars, ", ").c_str()); sum_var = MakeIntVar(new_min, new_max, name); AddConstraint(RevAlloc(new SumBooleanEqualToVar(this, vars, sum_var))); } else if (new_min != kint64min && new_max != kint64max) { diff --git a/src/constraint_solver/hybrid.cc b/src/constraint_solver/hybrid.cc index a0dfc0abac..1190ad7786 100644 --- a/src/constraint_solver/hybrid.cc +++ b/src/constraint_solver/hybrid.cc @@ -501,8 +501,9 @@ class Linearizer : public ModelParser { *objective_ = const_cast(Top()->FindIntegerExpressionArgumentOrDie( ModelVisitor::kExpressionArgument))->Var(); - mp_solver_->SetObjectiveCoefficient(Translated(*objective_), 1.0); - mp_solver_->SetOptimizationDirection(*maximize_); + MPObjective* const objective = mp_solver_->MutableObjective(); + objective->SetCoefficient(Translated(*objective_), 1.0); + objective->SetOptimizationDirection(*maximize_); } MPSolver* const mp_solver_; @@ -562,7 +563,7 @@ class AutomaticLinearization : public SearchMonitor { if (objective_ != nullptr) { switch (mp_solver_.Solve()) { case MPSolver::OPTIMAL: { - const double obj_value = mp_solver_.objective_value(); + const double obj_value = mp_solver_.Objective().Value(); if (maximize_) { const int64 int_obj_value = static_cast(ceil(obj_value)); objective_->SetMax(int_obj_value); diff --git a/src/constraint_solver/interval.cc b/src/constraint_solver/interval.cc index bd9d65b385..9811a728fa 100644 --- a/src/constraint_solver/interval.cc +++ b/src/constraint_solver/interval.cc @@ -250,18 +250,10 @@ class AlwaysPerformedIntervalVarWrapper : public IntervalVar { } return end_expr_; } - IntExpr* PerformedExpr() { - return solver()->MakeIntConst(1); - } - IntExpr* SafeStartExpr(int64 unperformed_value) { - return StartExpr(); - } - IntExpr* SafeDurationExpr(int64 unperformed_value) { - return DurationExpr(); - } - IntExpr* SafeEndExpr(int64 unperformed_value) { - return EndExpr(); - } + IntExpr* PerformedExpr() { return solver()->MakeIntConst(1); } + IntExpr* SafeStartExpr(int64 unperformed_value) { return StartExpr(); } + IntExpr* SafeDurationExpr(int64 unperformed_value) { return DurationExpr(); } + IntExpr* SafeEndExpr(int64 unperformed_value) { return EndExpr(); } protected: IntervalVar* const underlying() const { return t_; } diff --git a/src/constraint_solver/io.cc b/src/constraint_solver/io.cc index 6214684726..8456558979 100644 --- a/src/constraint_solver/io.cc +++ b/src/constraint_solver/io.cc @@ -2311,8 +2311,7 @@ bool CPModelLoader::BuildFromProto(const CPIntegerExpressionProto& proto) { if (!built) { return false; } - expressions_.resize( - std::max(static_cast(expressions_.size()), index + 1)); + expressions_.resize(std::max(static_cast(expressions_.size()), index + 1)); expressions_[index] = built; return true; } diff --git a/src/constraint_solver/local_search.cc b/src/constraint_solver/local_search.cc index 9bf51378f5..c96efd7c8b 100644 --- a/src/constraint_solver/local_search.cc +++ b/src/constraint_solver/local_search.cc @@ -1889,8 +1889,7 @@ void CompoundOperator::Start(const Assignment* assignment) { operators_[i]->Start(assignment); } OperatorComparator comparator(evaluator_.get(), operator_indices_[index_]); - std::sort(operator_indices_.get(), operator_indices_.get() + size_, - comparator); + std::sort(operator_indices_.get(), operator_indices_.get() + size_, comparator); index_ = 0; } } diff --git a/src/constraint_solver/resource.cc b/src/constraint_solver/resource.cc index 93e1d906d3..a4b498352d 100644 --- a/src/constraint_solver/resource.cc +++ b/src/constraint_solver/resource.cc @@ -138,8 +138,7 @@ struct ThetaNode { void Compute(const ThetaNode& left, const ThetaNode& right) { total_processing = left.total_processing + right.total_processing; - total_ect = - std::max(left.total_ect + right.total_processing, right.total_ect); + total_ect = std::max(left.total_ect + right.total_processing, right.total_ect); } bool IsIdentity() const { @@ -250,8 +249,8 @@ struct LambdaThetaNode { // associated with such sets. void Compute(const LambdaThetaNode& left, const LambdaThetaNode& right) { energy = left.energy + right.energy; - energetic_end_min = std::max(right.energetic_end_min, - left.energetic_end_min + right.energy); + energetic_end_min = + std::max(right.energetic_end_min, left.energetic_end_min + right.energy); const int64 energy_left_opt = left.energy_opt + right.energy; const int64 energy_right_opt = left.energy + right.energy_opt; if (energy_left_opt > energy_right_opt) { @@ -402,8 +401,7 @@ bool NotLast::Propagate() { // ---- Init ---- std::sort(by_start_max_.begin(), by_start_max_.end(), StartMaxLessThan); - std::sort(by_end_max_.begin(), by_end_max_.end(), - EndMaxLessThan); + std::sort(by_end_max_.begin(), by_end_max_.end(), EndMaxLessThan); // Update start min positions std::sort(by_start_min_.begin(), by_start_min_.end(), StartMinLessThan); @@ -527,8 +525,7 @@ void EdgeFinderAndDetectablePrecedences::UpdateEst() { void EdgeFinderAndDetectablePrecedences::OverloadChecking() { // Initialization. UpdateEst(); - std::sort(by_end_max_.begin(), by_end_max_.end(), - EndMaxLessThan); + std::sort(by_end_max_.begin(), by_end_max_.end(), EndMaxLessThan); theta_tree_.Clear(); for (int i = 0; i < size(); ++i) { @@ -548,8 +545,7 @@ bool EdgeFinderAndDetectablePrecedences::DetectablePrecedences() { } // Propagate in one direction - std::sort(by_end_min_.begin(), by_end_min_.end(), - EndMinLessThan); + std::sort(by_end_min_.begin(), by_end_min_.end(), EndMinLessThan); std::sort(by_start_max_.begin(), by_start_max_.end(), StartMaxLessThan); theta_tree_.Clear(); @@ -600,8 +596,7 @@ bool EdgeFinderAndDetectablePrecedences::EdgeFinder() { } // Push in one direction. - std::sort(by_end_max_.begin(), by_end_max_.end(), - EndMaxLessThan); + std::sort(by_end_max_.begin(), by_end_max_.end(), EndMaxLessThan); lt_tree_.Clear(); for (int i = 0; i < size(); ++i) { lt_tree_.Insert(*by_start_min_[i]); @@ -1029,9 +1024,8 @@ struct DualCapacityThetaNode { const CumulativeTask& task) : energy(task.EnergyMin()), energetic_end_min(capacity * task.interval->StartMin() + energy), - residual_energetic_end_min(residual_capacity * - task.interval->StartMin() + - energy) {} + residual_energetic_end_min( + residual_capacity * task.interval->StartMin() + energy) {} // Sets this DualCapacityThetaNode to the result of the natural binary // operation over the two given operands, corresponding to the following set @@ -1042,8 +1036,8 @@ struct DualCapacityThetaNode { void Compute(const DualCapacityThetaNode& left, const DualCapacityThetaNode& right) { energy = left.energy + right.energy; - energetic_end_min = std::max(left.energetic_end_min + right.energy, - right.energetic_end_min); + energetic_end_min = + std::max(left.energetic_end_min + right.energy, right.energetic_end_min); residual_energetic_end_min = std::max(left.residual_energetic_end_min + right.energy, right.residual_energetic_end_min); @@ -1383,8 +1377,8 @@ class EdgeFinder : public Constraint { const int64 end_min = task->interval->EndMin(); while (end_max_index < by_start_min_.size() && by_end_max_[end_max_index]->interval->EndMax() <= end_min) { - max_start_min = std::max( - max_start_min, by_end_max_[end_max_index]->interval->StartMin()); + max_start_min = std::max(max_start_min, + by_end_max_[end_max_index]->interval->StartMin()); ++end_max_index; } if (end_max_index > 0 && task->interval->StartMin() <= max_start_min && diff --git a/src/constraint_solver/routing.cc b/src/constraint_solver/routing.cc index 8a0398cf40..ceefa5e570 100644 --- a/src/constraint_solver/routing.cc +++ b/src/constraint_solver/routing.cc @@ -1183,8 +1183,8 @@ void RoutingModel::AddLocalSearchOperator(LocalSearchOperator* ls_operator) { int64 RoutingModel::GetDepot() const { return vehicles() > 0 ? Start(0) : -1; } void RoutingModel::SetDepot(NodeIndex depot) { - std::vector > start_end( - vehicles_, std::make_pair(depot, depot)); + std::vector > start_end(vehicles_, + std::make_pair(depot, depot)); SetStartEnd(start_end); } @@ -1416,8 +1416,8 @@ void RoutingModel::CloseModel() { } struct Link { - Link(std::pair link, double value, int vehicle_class, - int64 start_depot, int64 end_depot) + Link(std::pair link, double value, int vehicle_class, int64 start_depot, + int64 end_depot) : link(link), value(value), vehicle_class(vehicle_class), @@ -1574,8 +1574,8 @@ class RouteConstructor { } std::sort(final_routes_.begin(), final_routes_.end(), RouteComparator); - const int extra_vehicles = std::max( - 0, static_cast(final_chains_.size()) - model_->vehicles()); + const int extra_vehicles = + std::max(0, static_cast(final_chains_.size()) - model_->vehicles()); // Bind the Start and End of each chain int chain_index = 0; for (chain_index = extra_vehicles; chain_index < final_chains_.size(); @@ -2044,8 +2044,8 @@ class SavingsBuilder : public DecisionBuilder { const double saving = costs_[node][start_depot] + costs_[end_depot][neighbor] - route_shape_parameter_ * costs_[node][neighbor]; - Link link(std::make_pair(node, neighbor), saving, - vehicle_class_index, start_depot, end_depot); + Link link(std::make_pair(node, neighbor), saving, vehicle_class_index, + start_depot, end_depot); savings_list_.push_back(link); } } @@ -2180,8 +2180,7 @@ class SweepBuilder : public DecisionBuilder { const int64 first_index = model_->NodeToIndex(first); const int64 second_index = model_->NodeToIndex(second); if (first_index != depot_ && second_index != depot_) { - Link link(std::make_pair(first_index, second_index), 0, 0, depot_, - depot_); + Link link(std::make_pair(first_index, second_index), 0, 0, depot_, depot_); links_.push_back(link); } } diff --git a/src/constraint_solver/routing.h b/src/constraint_solver/routing.h index fd28e2cd60..f527c484de 100644 --- a/src/constraint_solver/routing.h +++ b/src/constraint_solver/routing.h @@ -409,7 +409,7 @@ class RoutingModel { // their transit evaluator (the raw version that takes var index, not Node // Index) and their span cost coefficient, we just store those. // This is sorted by the natural operator < (and *not* by DimensionIndex). - std::vector> + std::vector > dimension_transit_evaluator_and_cost_coefficient; explicit CostClass(NodeEvaluator2* arc_cost_evaluator) @@ -1364,8 +1364,8 @@ class RoutingDimension { // depot. Used in the Sweep first solution heuristic. class SweepArranger { public: - explicit SweepArranger(const ITIVector >& points); + explicit SweepArranger( + const ITIVector >& points); virtual ~SweepArranger() {} void ArrangeNodes(std::vector* nodes); void SetSectors(int sectors) { sectors_ = sectors; } diff --git a/src/constraint_solver/routing_search.cc b/src/constraint_solver/routing_search.cc index d0a7b405bf..3f2baccdaf 100644 --- a/src/constraint_solver/routing_search.cc +++ b/src/constraint_solver/routing_search.cc @@ -652,9 +652,9 @@ bool PathCumulFilter::FinalizeAcceptPath() { if (ContainsKey(delta_paths_, r)) { continue; } - new_min_start = std::min(new_min_start, - ComputePathMaxStartFromEndCumul( - current_path_transits_, r, new_max_end)); + new_min_start = + std::min(new_min_start, ComputePathMaxStartFromEndCumul( + current_path_transits_, r, new_max_end)); } } else if (new_min_start > current_min_start_.cumul_value) { // Delta min start is greater than the current solution one. diff --git a/src/constraint_solver/sched_constraints.cc b/src/constraint_solver/sched_constraints.cc index 9bf7764090..02bec0d11f 100644 --- a/src/constraint_solver/sched_constraints.cc +++ b/src/constraint_solver/sched_constraints.cc @@ -505,14 +505,12 @@ class CoverConstraint : public TreeArrayConstraint { if (performed != UNPERFORMED) { *bucket_start_min = std::min(*bucket_start_min, StartMin(parent_depth + 1, k)); - *bucket_end_max = - std::max(*bucket_end_max, EndMax(parent_depth + 1, k)); + *bucket_end_max = std::max(*bucket_end_max, EndMax(parent_depth + 1, k)); may_be_performed_count++; if (performed == PERFORMED) { *bucket_start_max = std::min(*bucket_start_max, StartMax(parent_depth + 1, k)); - *bucket_end_min = - std::max(*bucket_end_min, EndMin(parent_depth + 1, k)); + *bucket_end_min = std::max(*bucket_end_min, EndMin(parent_depth + 1, k)); must_be_performed_count++; } } diff --git a/src/constraint_solver/search.cc b/src/constraint_solver/search.cc index 9b8299a78a..4055d2fc6c 100644 --- a/src/constraint_solver/search.cc +++ b/src/constraint_solver/search.cc @@ -564,8 +564,8 @@ Decision* TryDecisionBuilder::Next(Solver* const solver) { } std::string TryDecisionBuilder::DebugString() const { - return StringPrintf( - "TryDecisionBuilder(%s)", JoinDebugStringPtr(builders_, ", ").c_str()); + return StringPrintf("TryDecisionBuilder(%s)", + JoinDebugStringPtr(builders_, ", ").c_str()); } void TryDecisionBuilder::AdvanceToNextBuilder(Solver* const solver) { @@ -2039,8 +2039,7 @@ DecisionBuilder* Solver::MakePhase( } DecisionBuilder* Solver::MakePhase( - const std::vector& vars, - IntVarStrategy var_str, + const std::vector& vars, IntVarStrategy var_str, ResultCallback3* var_val1_val2_comparator) { VariableSelector* const var_selector = BaseAssignVariables::MakeVariableSelector(this, vars, var_str); @@ -3216,8 +3215,7 @@ class GuidedLocalSearch : public Metaheuristic { protected: struct Comparator { - bool operator()(const std::pair& i, - const std::pair& j) { + bool operator()(const std::pair& i, const std::pair& j) { return i.second > j.second; } }; @@ -3789,10 +3787,10 @@ bool RegularLimit::Check() { int RegularLimit::ProgressPercent() { Solver* const s = solver(); int64 progress = GetPercent(s->branches(), branches_offset_, branches_); - progress = std::max(progress, - GetPercent(s->failures(), failures_offset_, failures_)); - progress = std::max(progress, - GetPercent(s->solutions(), solutions_offset_, solutions_)); + progress = + std::max(progress, GetPercent(s->failures(), failures_offset_, failures_)); + progress = + std::max(progress, GetPercent(s->solutions(), solutions_offset_, solutions_)); if (wall_time_ < kint64max) { progress = std::max(progress, (100 * TimeDelta()) / wall_time_); } @@ -3833,7 +3831,7 @@ std::string RegularLimit::DebugString() const { return StringPrintf("RegularLimit(crossed = %i, wall_time = %" GG_LL_FORMAT "d, " "branches = %" GG_LL_FORMAT "d, failures = %" GG_LL_FORMAT - "d, solutions = %" GG_LL_FORMAT "d cumulative = %s)", + "d, solutions = %" GG_LL_FORMAT "d cumulative = %s", crossed(), wall_time_, branches_, failures_, solutions_, (cumulative_ ? "true" : "false")); } diff --git a/src/constraint_solver/search_limit.proto b/src/constraint_solver/search_limit.proto index e584e3f19a..d56bcc941a 100644 --- a/src/constraint_solver/search_limit.proto +++ b/src/constraint_solver/search_limit.proto @@ -15,6 +15,7 @@ syntax = "proto2"; + package operations_research; // A search limit diff --git a/src/constraint_solver/table.cc b/src/constraint_solver/table.cc index 3b43acbfaa..204c5d6846 100644 --- a/src/constraint_solver/table.cc +++ b/src/constraint_solver/table.cc @@ -1232,12 +1232,10 @@ class TransitionConstraint : public Constraint { int64 state_max = kint64min; const int nb_vars = vars_.size(); for (int i = 0; i < transition_table_.NumTuples(); ++i) { - state_max = - std::max(state_max, transition_table_.Value(i, kStatePosition)); + state_max = std::max(state_max, transition_table_.Value(i, kStatePosition)); state_max = std::max(state_max, transition_table_.Value(i, kNextStatePosition)); - state_min = - std::min(state_min, transition_table_.Value(i, kStatePosition)); + state_min = std::min(state_min, transition_table_.Value(i, kStatePosition)); state_min = std::min(state_min, transition_table_.Value(i, kNextStatePosition)); } @@ -1284,8 +1282,7 @@ class TransitionConstraint : public Constraint { return StringPrintf( "TransitionConstraint([%s], %d transitions, initial = %" GG_LL_FORMAT "d, final = [%s])", - JoinDebugStringPtr(vars_, ", ").c_str(), - transition_table_.NumTuples(), + JoinDebugStringPtr(vars_, ", ").c_str(), transition_table_.NumTuples(), initial_state_, IntVectorToString(final_states_, ", ").c_str()); } diff --git a/src/constraint_solver/timetabling.cc b/src/constraint_solver/timetabling.cc index 3294c4c5b0..8f779fe02f 100644 --- a/src/constraint_solver/timetabling.cc +++ b/src/constraint_solver/timetabling.cc @@ -25,14 +25,14 @@ namespace operations_research { // ----- interval date ----- namespace { -const char* kUnaryNames[] = {"ENDS_AFTER", "ENDS_AT", "ENDS_BEFORE", - "STARTS_AFTER", "STARTS_AT", "STARTS_BEFORE", - "CROSS_DATE", "AVOID_DATE", }; +const char* kUnaryNames[] = {"ENDS_AFTER", "ENDS_AT", "ENDS_BEFORE", + "STARTS_AFTER", "STARTS_AT", "STARTS_BEFORE", + "CROSS_DATE", "AVOID_DATE", }; const char* kBinaryNames[] = { - "ENDS_AFTER_END", "ENDS_AFTER_START", "ENDS_AT_END", "ENDS_AT_START", - "STARTS_AFTER_END", "STARTS_AFTER_START", "STARTS_AT_END", - "STARTS_AT_START", "STAYS_IN_SYNC"}; + "ENDS_AFTER_END", "ENDS_AFTER_START", "ENDS_AT_END", + "ENDS_AT_START", "STARTS_AFTER_END", "STARTS_AFTER_START", + "STARTS_AT_END", "STARTS_AT_START", "STAYS_IN_SYNC"}; class IntervalUnaryRelation : public Constraint { public: diff --git a/src/constraint_solver/visitor.cc b/src/constraint_solver/visitor.cc index 695d6dc4a9..2a837c28cb 100644 --- a/src/constraint_solver/visitor.cc +++ b/src/constraint_solver/visitor.cc @@ -81,13 +81,13 @@ void ArgumentHolder::SetSequenceArrayArgument( sequence_array_argument_[arg_name] = vars; } -bool ArgumentHolder::HasIntegerExpressionArgument( - const std::string& arg_name) const { +bool ArgumentHolder::HasIntegerExpressionArgument(const std::string& arg_name) + const { return ContainsKey(integer_expression_argument_, arg_name); } -bool ArgumentHolder::HasIntegerVariableArrayArgument( - const std::string& arg_name) const { +bool ArgumentHolder::HasIntegerVariableArrayArgument(const std::string& arg_name) + const { return ContainsKey(integer_variable_array_argument_, arg_name); } diff --git a/src/flatzinc/flatzinc.cc b/src/flatzinc/flatzinc.cc index b211fe6873..6f27f10b5b 100644 --- a/src/flatzinc/flatzinc.cc +++ b/src/flatzinc/flatzinc.cc @@ -111,7 +111,9 @@ void FlatZincModel::NewIntVar(const std::string& name, IntVarSpec* const vs, integer_variables_[int_var_count++] = var; } -void FlatZincModel::SkipIntVar() { integer_variables_[int_var_count++] = nullptr; } +void FlatZincModel::SkipIntVar() { + integer_variables_[int_var_count++] = nullptr; +} void FlatZincModel::NewBoolVar(const std::string& name, BoolVarSpec* const vs) { IntVar* var = nullptr; diff --git a/src/flatzinc/flatzinc_constraints.cc b/src/flatzinc/flatzinc_constraints.cc index f169585875..ec490865f1 100644 --- a/src/flatzinc/flatzinc_constraints.cc +++ b/src/flatzinc/flatzinc_constraints.cc @@ -420,96 +420,6 @@ class BooleanSumInRange : public Constraint { NumericalRev num_always_true_vars_; }; -// ----- Lex constraint ----- - -class Lex : public Constraint { - public: - Lex(Solver* const s, const std::vector& left, - const std::vector& right, bool strict) - : Constraint(s), - left_(left), - right_(right), - active_var_(0), - strict_(strict) { - CHECK_EQ(left.size(), right.size()); - } - - virtual ~Lex() {} - - virtual void Post() { - const int position = FindNextValidVar(0); - active_var_.SetValue(solver(), position); - if (position < left_.size()) { - Demon* const demon = MakeConstraintDemon1(solver(), this, &Lex::Propagate, - "Propagate", position); - left_[position]->WhenRange(demon); - right_[position]->WhenRange(demon); - } - } - - virtual void InitialPropagate() { Propagate(active_var_.Value()); } - - void Propagate(int var_index) { - DCHECK_EQ(var_index, active_var_.Value()); - const int position = FindNextValidVar(var_index); - if (position >= left_.size()) { - if (strict_) { - solver()->Fail(); - } - return; - } - if (position != var_index) { - Demon* const demon = MakeConstraintDemon1(solver(), this, &Lex::Propagate, - "Propagate", position); - left_[position]->WhenRange(demon); - right_[position]->WhenRange(demon); - active_var_.SetValue(solver(), position); - } - if ((strict_ && position == left_.size() - 1) || - (position < left_.size() - 1 && - left_[position + 1]->Min() > right_[position + 1]->Max())) { - // We need to be strict if we are the last in the array, or if - // the next one is impossible. - left_[position]->SetMax(right_[position]->Max() - 1); - right_[position]->SetMin(left_[position]->Min() + 1); - } else { - left_[position]->SetMax(right_[position]->Max()); - right_[position]->SetMin(left_[position]->Min()); - } - } - - virtual std::string DebugString() const { - return StringPrintf( - "Lex([%s], [%s]%s)", JoinDebugStringPtr(left_, ", ").c_str(), - JoinDebugStringPtr(right_, ", ").c_str(), strict_ ? ", strict" : ""); - } - - virtual void Accept(ModelVisitor* const visitor) const { - visitor->BeginVisitConstraint("Lex", this); - visitor->VisitIntegerVariableArrayArgument(ModelVisitor::kLeftArgument, - left_); - visitor->VisitIntegerVariableArrayArgument(ModelVisitor::kRightArgument, - right_); - visitor->EndVisitConstraint("Lex", this); - } - - private: - int FindNextValidVar(int start_position) const { - int position = start_position; - while (position < left_.size() && left_[position]->Bound() && - right_[position]->Bound() && - left_[position]->Min() == right_[position]->Min()) { - position++; - } - return position; - } - - std::vector left_; - std::vector right_; - NumericalRev active_var_; - const bool strict_; -}; - // ----- Inverse constraint ----- // This constraints maintains: left[i] == j <=> right_[j] == i. @@ -1003,11 +913,6 @@ Constraint* MakeStrongScalProdEquality(Solver* const solver, return solver->MakeAllowedAssignments(variables, tuples); } -Constraint* MakeLexLess(Solver* const solver, const std::vector& left, - const std::vector& right, bool strict) { - return solver->RevAlloc(new Lex(solver, left, right, strict)); -} - Constraint* MakeInverse(Solver* const solver, const std::vector& left, const std::vector& right) { return solver->RevAlloc(new Inverse(solver, left, right)); diff --git a/src/flatzinc/flatzinc_constraints.h b/src/flatzinc/flatzinc_constraints.h index f53a7e7e88..1adca8781d 100644 --- a/src/flatzinc/flatzinc_constraints.h +++ b/src/flatzinc/flatzinc_constraints.h @@ -91,12 +91,6 @@ Constraint* MakeBooleanSumInRange(Solver* const solver, Constraint* MakeBooleanSumOdd(Solver* const solver, const std::vector& variables); -Constraint* MakeLexLess(Solver* const solver, const std::vector& left, - const std::vector& right, bool strict); - -Constraint* MakeInverse(Solver* const solver, const std::vector& left, - const std::vector& right); - Constraint* MakeVariableCumulative(Solver* const solver, const std::vector& starts, const std::vector& durations, diff --git a/src/flatzinc/fz.cc b/src/flatzinc/fz.cc index 66cc663ad3..5992c63bd9 100644 --- a/src/flatzinc/fz.cc +++ b/src/flatzinc/fz.cc @@ -63,6 +63,8 @@ DEFINE_bool(verbose_mt, false, "Verbose Multi-Thread"); DECLARE_bool(log_prefix); DECLARE_bool(logging); +using std::string; +using operations_research::scoped_ptr; using operations_research::ThreadPool; namespace operations_research { diff --git a/src/graph/assignment.cc b/src/graph/assignment.cc index ee7df045ff..6569fe89ad 100644 --- a/src/graph/assignment.cc +++ b/src/graph/assignment.cc @@ -20,8 +20,9 @@ namespace operations_research { SimpleLinearSumAssignment::SimpleLinearSumAssignment() : num_nodes_(0) {} -ArcIndex SimpleLinearSumAssignment::AddArcWithCost( - NodeIndex left_node, NodeIndex righ_node, CostValue cost) { +ArcIndex SimpleLinearSumAssignment::AddArcWithCost(NodeIndex left_node, + NodeIndex righ_node, + CostValue cost) { const ArcIndex num_arcs = arc_cost_.size(); num_nodes_ = std::max(num_nodes_, left_node + 1); num_nodes_ = std::max(num_nodes_, righ_node + 1); @@ -31,13 +32,9 @@ ArcIndex SimpleLinearSumAssignment::AddArcWithCost( return num_arcs; } -NodeIndex SimpleLinearSumAssignment::NumNodes() const { - return num_nodes_; -} +NodeIndex SimpleLinearSumAssignment::NumNodes() const { return num_nodes_; } -ArcIndex SimpleLinearSumAssignment::NumArcs() const { - return arc_cost_.size(); -} +ArcIndex SimpleLinearSumAssignment::NumArcs() const { return arc_cost_.size(); } NodeIndex SimpleLinearSumAssignment::LeftNode(ArcIndex arc) const { return arc_tail_[arc]; diff --git a/src/graph/assignment.h b/src/graph/assignment.h index 7192b40c4b..14cba87e93 100644 --- a/src/graph/assignment.h +++ b/src/graph/assignment.h @@ -65,8 +65,8 @@ class SimpleLinearSumAssignment { // must cover [0, n), same for "right_node". // * The arc cost can be any integer, negative, positive or zero. // * After the method finishes, NumArcs() == the returned ArcIndex + 1. - ArcIndex AddArcWithCost( - NodeIndex left_node, NodeIndex right_node, CostValue cost); + ArcIndex AddArcWithCost(NodeIndex left_node, NodeIndex right_node, + CostValue cost); // Returns the current number of left nodes which is the same as the // number of right nodes. This is one greater than the largest node @@ -93,9 +93,7 @@ class SimpleLinearSumAssignment { // Returns the cost of an assignment with minimal cost. // This is 0 if the last Solve() didn't return OPTIMAL. - CostValue OptimalCost() const { - return optimal_cost_; - } + CostValue OptimalCost() const { return optimal_cost_; } // Returns the right node assigned to the given left node in the // last solution computed by Solve(). This works only if Solve() diff --git a/src/graph/bellman_ford.cc b/src/graph/bellman_ford.cc index f9e4f388c9..db05f9bc54 100644 --- a/src/graph/bellman_ford.cc +++ b/src/graph/bellman_ford.cc @@ -23,8 +23,7 @@ class BellmanFord { public: static const int64 kInfinity = kint64max / 2; - BellmanFord(int node_count, - int start_node, + BellmanFord(int node_count, int start_node, ResultCallback2* const graph, int64 disconnected_distance) : node_count_(node_count), @@ -112,12 +111,9 @@ bool BellmanFord::ShortestPath(int end_node, std::vector* nodes) { return true; } -bool BellmanFordShortestPath(int node_count, - int start_node, - int end_node, +bool BellmanFordShortestPath(int node_count, int start_node, int end_node, ResultCallback2* const graph, - int64 disconnected_distance, - std::vector* nodes) { + int64 disconnected_distance, std::vector* nodes) { BellmanFord bf(node_count, start_node, graph, disconnected_distance); return bf.ShortestPath(end_node, nodes); } diff --git a/src/graph/cliques.cc b/src/graph/cliques.cc index b7dc601718..3b1db680df 100644 --- a/src/graph/cliques.cc +++ b/src/graph/cliques.cc @@ -29,11 +29,8 @@ namespace { // TODO(user) : rewrite this algorithm without the recursivity. void Search(ResultCallback2* const graph, ResultCallback1&>* const callback, - int* input_candidates, - int input_size, - int input_candidate_size, - std::vector* actual, - bool* stop) { + int* input_candidates, int input_size, int input_candidate_size, + std::vector* actual, bool* stop) { std::vector actual_candidates(input_candidate_size); int pre_increment = 0; int pivot = 0; @@ -107,8 +104,8 @@ void Search(ResultCallback2* const graph, *stop = callback->Run(*actual); } else { if (actual_candidate_size < actual_size) { - Search(graph, callback, actual_candidates.data(), - actual_candidate_size, actual_size, actual, stop); + Search(graph, callback, actual_candidates.data(), actual_candidate_size, + actual_size, actual, stop); if (*stop) { return; } @@ -135,15 +132,13 @@ void Search(ResultCallback2* const graph, class FindAndEliminate { public: - FindAndEliminate(ResultCallback2* const graph, - int node_count, + FindAndEliminate(ResultCallback2* const graph, int node_count, ResultCallback1&>* const callback) : graph_(graph), node_count_(node_count), callback_(callback) {} bool GraphCallback(int node1, int node2) { - if (visited_.find( - std::make_pair(std::min(node1, node2), - std::max(node1, node2))) != visited_.end()) { + if (visited_.find(std::make_pair(std::min(node1, node2), std::max(node1, node2))) != + visited_.end()) { return false; } return graph_->Run(node1, node2); @@ -177,8 +172,7 @@ class FindAndEliminate { // This method implements the 'version2' of the Bron-Kerbosch // algorithm to find all maximal cliques in a undirected graph. -void FindCliques(ResultCallback2* const graph, - int node_count, +void FindCliques(ResultCallback2* const graph, int node_count, ResultCallback1&>* const callback) { graph->CheckIsRepeatable(); callback->CheckIsRepeatable(); @@ -198,10 +192,8 @@ void FindCliques(ResultCallback2* const graph, &stop); } - void CoverArcsByCliques( - ResultCallback2* const graph, - int node_count, + ResultCallback2* const graph, int node_count, ResultCallback1&>* const callback) { graph->CheckIsRepeatable(); callback->CheckIsRepeatable(); @@ -224,10 +216,8 @@ void CoverArcsByCliques( } bool stop = false; - Search(cached_graph.get(), cached_callback.get(), - initial_candidates.get(), 0, + Search(cached_graph.get(), cached_callback.get(), initial_candidates.get(), 0, node_count, &actual, &stop); } - } // namespace operations_research diff --git a/src/graph/cliques.h b/src/graph/cliques.h index 9afd5026f3..04e7997793 100644 --- a/src/graph/cliques.h +++ b/src/graph/cliques.h @@ -28,8 +28,10 @@ #include "base/callback.h" #include "base/scoped_ptr.h" -template class ResultCallback2; -template class ResultCallback1; +template +class ResultCallback2; +template +class ResultCallback1; namespace operations_research { @@ -38,8 +40,7 @@ namespace operations_research { // if there is an arc between i and j. // This function takes ownership of 'callback' and deletes it after it has run. // If 'callback' returns true, then the search for cliques stops. -void FindCliques(ResultCallback2* const graph, - int node_count, +void FindCliques(ResultCallback2* const graph, int node_count, ResultCallback1&>* const callback); // Covers the maximum number of arcs of the graph with cliques. The graph @@ -49,8 +50,7 @@ void FindCliques(ResultCallback2* const graph, // It calls 'callback' upon each clique. // It ignores cliques of size 1. void CoverArcsByCliques( - ResultCallback2* const graph, - int node_count, + ResultCallback2* const graph, int node_count, ResultCallback1&>* const callback); } // namespace operations_research diff --git a/src/graph/connectivity.h b/src/graph/connectivity.h index 383f09134a..82fd397450 100644 --- a/src/graph/connectivity.h +++ b/src/graph/connectivity.h @@ -67,18 +67,17 @@ namespace operations_research { class ConnectedComponents { public: - ConnectedComponents() : min_index_(0), - max_index_(StarGraph::kMaxNumNodes), - max_seen_index_(0), - class_(), - class_size_() {} + ConnectedComponents() + : min_index_(0), + max_index_(StarGraph::kMaxNumNodes), + max_seen_index_(0), + class_(), + class_size_() {} ~ConnectedComponents() {} // Reserves memory for num_nodes and resets the data structures. - void Init(NodeIndex num_nodes) { - Init(0, num_nodes - 1); - } + void Init(NodeIndex num_nodes) { Init(0, num_nodes - 1); } // Adds the information that NodeIndex tail and NodeIndex head are connected. void AddArc(NodeIndex tail, NodeIndex head); @@ -106,14 +105,14 @@ class ConnectedComponents { void Init(NodeIndex min_index, NodeIndex max_index); // The minimum index for nodes in the graph. - NodeIndex min_index_; + NodeIndex min_index_; // The exact number of nodes in the graph. - NodeIndex max_index_; + NodeIndex max_index_; // The maximum node index seen during AddArc. (set to Graph::num_nodes() by // AddGraph.) - NodeIndex max_seen_index_; + NodeIndex max_seen_index_; // The equivalence class representative for each node. NodeIndexArray class_; diff --git a/src/graph/dijkstra.cc b/src/graph/dijkstra.cc index 36c30acd77..a91d4ebcee 100644 --- a/src/graph/dijkstra.cc +++ b/src/graph/dijkstra.cc @@ -20,7 +20,6 @@ #include "base/scoped_ptr.h" #include "base/adjustable_priority_queue.h" - namespace operations_research { namespace { @@ -28,7 +27,7 @@ namespace { class Element { public: Element() : heap_index_(-1), distance_(0), node_(-1) {} - bool operator <(const Element& other) const { + bool operator<(const Element& other) const { return distance_ > other.distance_; } void SetHeapIndex(int h) { heap_index_ = h; } @@ -37,6 +36,7 @@ class Element { int64 distance() const { return distance_; } void set_node(int node) { node_ = node; } int node() const { return node_; } + private: int heap_index_; int64 distance_; @@ -48,8 +48,7 @@ class DijkstraSP { public: static const int64 kInfinity = kint64max / 2; - DijkstraSP(int node_count, - int start_node, + DijkstraSP(int node_count, int start_node, ResultCallback2* const graph, int64 disconnected_distance) : node_count_(node_count), @@ -105,8 +104,7 @@ int DijkstraSP::SelectClosestNode(int64* distance) { void DijkstraSP::Update(int node) { for (hash_set::const_iterator it = not_visited_.begin(); - it != not_visited_.end(); - ++it) { + it != not_visited_.end(); ++it) { const int other_node = *it; const int64 graph_node_i = graph_->Run(node, other_node); if (graph_node_i != disconnected_distance_) { @@ -155,12 +153,9 @@ bool DijkstraSP::ShortestPath(int end_node, std::vector* nodes) { return found; } -bool DijkstraShortestPath(int node_count, - int start_node, - int end_node, +bool DijkstraShortestPath(int node_count, int start_node, int end_node, ResultCallback2* const graph, - int64 disconnected_distance, - std::vector* nodes) { + int64 disconnected_distance, std::vector* nodes) { DijkstraSP bf(node_count, start_node, graph, disconnected_distance); return bf.ShortestPath(end_node, nodes); } diff --git a/src/graph/ebert_graph.h b/src/graph/ebert_graph.h index baf0c7176d..cb52268725 100644 --- a/src/graph/ebert_graph.h +++ b/src/graph/ebert_graph.h @@ -182,14 +182,15 @@ #include "util/permutation.h" #include "util/zvector.h" - namespace operations_research { // Forward declarations. -template class EbertGraph; -template class ForwardEbertGraph; -template class ForwardStaticGraph; +template +class EbertGraph; +template +class ForwardEbertGraph; +template +class ForwardStaticGraph; // Standard instantiation of ForwardEbertGraph (named 'ForwardStarGraph') of // EbertGraph (named 'StarGraph'); and relevant type shortcuts. Unless their use @@ -209,8 +210,8 @@ typedef ZVector ArcIndexArray; typedef ZVector QuantityArray; typedef ZVector CostArray; -template class StarGraphBase { +template +class StarGraphBase { public: // The index of the 'nil' node in the graph. static const NodeIndexType kNilNode; @@ -244,16 +245,12 @@ template NextOutgoingArc(tail, arc)) { if (Head(arc) == head) { return arc; @@ -380,8 +374,7 @@ template +template class PermutationIndexComparisonByArcHead { public: explicit PermutationIndexComparisonByArcHead( const ZVector& head) - : head_(head) { } + : head_(head) {} bool operator()(ArcIndexType a, ArcIndexType b) const { return head_[a] < head_[b]; @@ -569,21 +562,19 @@ class ForwardStaticGraph typedef NodeIndexType NodeIndex; typedef ArcIndexType ArcIndex; - // TODO(user): Configure SWIG to handle the - // CycleHandlerForAnnotatedArcs class. +// TODO(user): Configure SWIG to handle the +// CycleHandlerForAnnotatedArcs class. #if !SWIG class CycleHandlerForAnnotatedArcs : public ArrayIndexCycleHandler { - typedef ArrayIndexCycleHandler Base; + typedef ArrayIndexCycleHandler Base; public: CycleHandlerForAnnotatedArcs( PermutationCycleHandler* annotation_handler, NodeIndexType* data) - : ArrayIndexCycleHandler( - &data[kFirstArc]), - annotation_handler_(annotation_handler) { } + : ArrayIndexCycleHandler(&data[kFirstArc]), + annotation_handler_(annotation_handler) {} virtual void SetTempFromIndex(ArcIndexType source) { Base::SetTempFromIndex(source); @@ -626,15 +617,14 @@ class ForwardStaticGraph // node (according to sort_arcs_by_head), that sorting implies // an additional permutation on the arcs. ForwardStaticGraph( - const NodeIndexType num_nodes, - const ArcIndexType num_arcs, + const NodeIndexType num_nodes, const ArcIndexType num_arcs, const bool sort_arcs_by_head, std::vector >* client_input_arcs, // TODO(user): For some reason, SWIG breaks if the // operations_research namespace is not explicit in the // following argument declaration. - operations_research::PermutationCycleHandler* - const client_cycle_handler) { + operations_research::PermutationCycleHandler* const + client_cycle_handler) { max_num_arcs_ = num_arcs; num_arcs_ = num_arcs; max_num_nodes_ = num_nodes; @@ -656,12 +646,10 @@ class ForwardStaticGraph first_incident_arc_[kFirstNode + input_arcs[arc].first] += 1; // Take this opportunity to see how many nodes are really // mentioned in the arc list. - num_nodes_ = std::max( - num_nodes_, - static_cast(input_arcs[arc].first + 1)); - num_nodes_ = std::max( - num_nodes_, - static_cast(input_arcs[arc].second + 1)); + num_nodes_ = std::max(num_nodes_, + static_cast(input_arcs[arc].first + 1)); + num_nodes_ = std::max(num_nodes_, + static_cast(input_arcs[arc].second + 1)); } ArcIndexType next_arc = kFirstArc; for (NodeIndexType node = 0; node < num_nodes; ++node) { @@ -717,8 +705,7 @@ class ForwardStaticGraph // counting each one has done through its incident arcs. Note that // there is a special sentry element at the end of // first_incident_arc_. - for (NodeIndexType node = kFirstNode + num_nodes; - node > /* kFirstNode */ 0; + for (NodeIndexType node = kFirstNode + num_nodes; node > /* kFirstNode */ 0; --node) { first_incident_arc_[node] = first_incident_arc_[node - 1]; } @@ -750,12 +737,10 @@ class ForwardStaticGraph } } } - if (client_cycle_handler != NULL && - num_arcs > 0) { + if (client_cycle_handler != NULL && num_arcs > 0) { // Apply the computed permutation if we haven't already. - CycleHandlerForAnnotatedArcs - handler_for_constructor(client_cycle_handler, - &head_[kFirstArc] - kFirstArc); + CycleHandlerForAnnotatedArcs handler_for_constructor( + client_cycle_handler, &head_[kFirstArc] - kFirstArc); // We use a permutation cycle handler to place the head array // indices and permute the client's arc annotation data along // with them. @@ -780,8 +765,7 @@ class ForwardStaticGraph // It is exported so that users of the ForwardStaticGraph class can use it. // To be used in a DCHECK. bool CheckArcBounds(const ArcIndexType arc) const { - return ((arc == kNilArc) || - (arc >= kFirstArc && arc < max_num_arcs_)); + return ((arc == kNilArc) || (arc >= kFirstArc && arc < max_num_arcs_)); } // Utility function to check that an arc index is within the bounds AND @@ -789,14 +773,12 @@ class ForwardStaticGraph // It is exported so that users of the ForwardStaticGraph class can use it. // To be used in a DCHECK. bool CheckArcValidity(const ArcIndexType arc) const { - return ((arc != kNilArc) && - (arc >= kFirstArc && arc < max_num_arcs_)); + return ((arc != kNilArc) && (arc >= kFirstArc && arc < max_num_arcs_)); } // Returns true if arc is a valid index into the (*tail_) array. bool CheckTailIndexValidity(const ArcIndexType arc) const { - return ((tail_ != NULL) && - (arc >= kFirstArc) && + return ((tail_ != NULL) && (arc >= kFirstArc) && (arc <= tail_->max_index())); } @@ -817,15 +799,13 @@ class ForwardStaticGraph std::string DebugString() const { std::string result = "Arcs:(node) :\n"; for (ArcIndexType arc = kFirstArc; arc < num_arcs_; ++arc) { - result += " " + ArcDebugString(arc) + ":(" - + NodeDebugString(head_[arc]) + ")\n"; + result += " " + ArcDebugString(arc) + ":(" + NodeDebugString(head_[arc]) + + ")\n"; } result += "Node:First arc :\n"; - for (NodeIndexType node = kFirstNode; - node <= num_nodes_; - ++node) { - result += " " + NodeDebugString(node) + ":" - + ArcDebugString(first_incident_arc_[node]) + "\n"; + for (NodeIndexType node = kFirstNode; node <= num_nodes_; ++node) { + result += " " + NodeDebugString(node) + ":" + + ArcDebugString(first_incident_arc_[node]) + "\n"; } return result; } @@ -858,9 +838,7 @@ class ForwardStaticGraph return true; } - void ReleaseTailArray() { - tail_.reset(NULL); - } + void ReleaseTailArray() { tail_.reset(NULL); } // To be used in a DCHECK(). bool TailArrayComplete() const { @@ -885,8 +863,7 @@ class ForwardStaticGraph DCHECK(RepresentationClean()); DCHECK(IsNodeValid(node)); ArcIndexType result = first_incident_arc_[node]; - return ((result != first_incident_arc_[node + 1]) ? - result : kNilArc); + return ((result != first_incident_arc_[node + 1]) ? result : kNilArc); } // Utility method that finds the next outgoing arc. @@ -914,44 +891,38 @@ class ForwardStaticGraph }; // The index of the 'nil' node in the graph. -template -const NodeIndexType StarGraphBase::kNilNode = -1; +template +const NodeIndexType + StarGraphBase::kNilNode = -1; // The index of the 'nil' arc in the graph. -template -const ArcIndexType StarGraphBase::kNilArc = - std::numeric_limits::min(); +template +const ArcIndexType + StarGraphBase::kNilArc = + std::numeric_limits::min(); // The index of the first node in the graph. -template -const NodeIndexType StarGraphBase::kFirstNode = 0; +template +const NodeIndexType + StarGraphBase::kFirstNode = 0; // The index of the first arc in the graph. -template -const ArcIndexType StarGraphBase::kFirstArc = 0; +template +const ArcIndexType + StarGraphBase::kFirstArc = 0; // The maximum possible node index in the graph. -template -const NodeIndexType StarGraphBase::kMaxNumNodes = - std::numeric_limits::max(); +template +const NodeIndexType + StarGraphBase::kMaxNumNodes = + std::numeric_limits::max(); // The maximum possible number of arcs in the graph. // (The maximum index is kMaxNumArcs-1, since indices start at 0.) -template -const ArcIndexType StarGraphBase::kMaxNumArcs = - std::numeric_limits::max(); +template +const ArcIndexType + StarGraphBase::kMaxNumArcs = + std::numeric_limits::max(); // A template for the base class that holds the functionality that exists in // common between the EbertGraph<> template and the ForwardEbertGraph<> @@ -970,7 +941,7 @@ const ArcIndexType StarGraphBase +template class EbertGraphBase : public StarGraphBase { typedef StarGraphBase Base; @@ -1002,12 +973,10 @@ class EbertGraphBase // It can be used to enlarge the graph, but does not shrink memory // if called with smaller values. bool Reserve(NodeIndexType new_max_num_nodes, ArcIndexType new_max_num_arcs) { - if (new_max_num_nodes < 0 || - new_max_num_nodes > kMaxNumNodes) { + if (new_max_num_nodes < 0 || new_max_num_nodes > kMaxNumNodes) { return false; } - if (new_max_num_arcs < 0 || - new_max_num_arcs > kMaxNumArcs) { + if (new_max_num_arcs < 0 || new_max_num_arcs > kMaxNumArcs) { return false; } first_incident_arc_.Reserve(kFirstNode, new_max_num_nodes - 1); @@ -1027,12 +996,12 @@ class EbertGraphBase // already-existing arc between tail and head: Another arc is created // instead. This makes it possible to handle multi-graphs. ArcIndexType AddArc(NodeIndexType tail, NodeIndexType head) { - if (num_arcs_ >= max_num_arcs_ - || !IsNodeValid(tail) || !IsNodeValid(head)) { + if (num_arcs_ >= max_num_arcs_ || !IsNodeValid(tail) || + !IsNodeValid(head)) { return kNilArc; } if (tail + 1 > num_nodes_) { - num_nodes_ = tail + 1; // max does not work on int16. + num_nodes_ = tail + 1; // max does not work on int16. } if (head + 1 > num_nodes_) { num_nodes_ = head + 1; @@ -1043,8 +1012,8 @@ class EbertGraphBase return arc; } - // TODO(user): Configure SWIG to handle the GroupForwardArcsByFunctor - // member template and the CycleHandlerForAnnotatedArcs class. +// TODO(user): Configure SWIG to handle the GroupForwardArcsByFunctor +// member template and the CycleHandlerForAnnotatedArcs class. #if !SWIG template void GroupForwardArcsByFunctor( @@ -1058,8 +1027,7 @@ class EbertGraphBase // Start with the identity permutation. arc_permutation[i] = i; } - std::sort(&arc_permutation[kFirstArc], - &arc_permutation[end_arc_index()], + std::sort(&arc_permutation[kFirstArc], &arc_permutation[end_arc_index()], compare); // Now we actually permute the head_ array and the @@ -1073,8 +1041,8 @@ class EbertGraphBase ThisAsDerived()->BuildRepresentation(); } - class CycleHandlerForAnnotatedArcs : - public PermutationCycleHandler { + class CycleHandlerForAnnotatedArcs + : public PermutationCycleHandler { public: CycleHandlerForAnnotatedArcs( PermutationCycleHandler* annotation_handler, @@ -1082,7 +1050,7 @@ class EbertGraphBase : annotation_handler_(annotation_handler), graph_(graph), head_temp_(kNilNode), - tail_temp_(kNilNode) { } + tail_temp_(kNilNode) {} virtual void SetTempFromIndex(ArcIndexType source) { if (annotation_handler_ != NULL) { @@ -1121,7 +1089,7 @@ class EbertGraphBase return permutation_element != kNilArc; } - virtual ~CycleHandlerForAnnotatedArcs() { } + virtual ~CycleHandlerForAnnotatedArcs() {} private: PermutationCycleHandler* annotation_handler_; @@ -1134,14 +1102,11 @@ class EbertGraphBase #endif // SWIG protected: - EbertGraphBase() - : next_adjacent_arc_(), - representation_clean_(true) {} + EbertGraphBase() : next_adjacent_arc_(), representation_clean_(true) {} ~EbertGraphBase() {} - void Initialize(NodeIndexType max_num_nodes, - ArcIndexType max_num_arcs) { + void Initialize(NodeIndexType max_num_nodes, ArcIndexType max_num_arcs) { if (!Reserve(max_num_nodes, max_num_arcs)) { LOG(DFATAL) << "Could not reserve memory for " << static_cast(max_num_nodes) << " nodes and " @@ -1200,9 +1165,7 @@ class EbertGraphBase next_adjacent_arc_.SetAll(kNilArc); } - bool RepresentationClean() const { - return representation_clean_; - } + bool RepresentationClean() const { return representation_clean_; } // Using the SetHead() method implies that the BuildRepresentation() // method must be called to restore consistency before the graph is @@ -1215,7 +1178,8 @@ class EbertGraphBase // Most users should only use StarGraph, which is EbertGraph, and // other type shortcuts; see the bottom of this file. -template class EbertGraph +template +class EbertGraph : public EbertGraphBase > { typedef EbertGraphBase class EbertGraph // This constructor takes an arc as extra argument and makes the iterator // start at arc. - IncidentArcIterator(const EbertGraph& graph, - NodeIndexType node, + IncidentArcIterator(const EbertGraph& graph, NodeIndexType node, ArcIndexType arc) : graph_(graph), node_(graph_.StartNode(node)), @@ -1286,7 +1249,7 @@ template class EbertGraph // Can only assign from an iterator on the same graph. void operator=(const IncidentArcIterator& iterator) { - DCHECK(&iterator.graph_ == &graph_); + DCHECK(&iterator.graph_ == &graph_); node_ = iterator.node_; arc_ = iterator.arc_; } @@ -1316,7 +1279,7 @@ template class EbertGraph // A reference to the current EbertGraph considered. const EbertGraph& graph_; - // The index of the node on which arcs are iterated. + // The index of the node on which arcs are iterated. NodeIndexType node_; // The index of the current arc considered. @@ -1340,8 +1303,7 @@ template class EbertGraph // This constructor takes an arc as extra argument and makes the iterator // start at arc. - IncomingArcIterator(const EbertGraph& graph, - NodeIndexType node, + IncomingArcIterator(const EbertGraph& graph, NodeIndexType node, ArcIndexType arc) : graph_(graph), node_(graph_.StartNode(node)), @@ -1351,7 +1313,7 @@ template class EbertGraph // Can only assign from an iterator on the same graph. void operator=(const IncomingArcIterator& iterator) { - DCHECK(&iterator.graph_ == &graph_); + DCHECK(&iterator.graph_ == &graph_); node_ = iterator.node_; arc_ = iterator.arc_; } @@ -1477,7 +1439,7 @@ template class EbertGraph // criterion, for example. void BuildRepresentation() { first_incident_arc_.SetAll(kNilArc); - for (ArcIndexType arc = kFirstArc; arc < max_num_arcs_; ++arc) { + for (ArcIndexType arc = kFirstArc; arc < max_num_arcs_; ++arc) { Attach(arc); } representation_clean_ = true; @@ -1489,13 +1451,13 @@ template class EbertGraph DCHECK(representation_clean_); std::string result = "Arcs:(node, next arc) :\n"; for (ArcIndexType arc = -num_arcs_; arc < num_arcs_; ++arc) { - result += " " + ArcDebugString(arc) + ":(" + NodeDebugString(head_[arc]) - + "," + ArcDebugString(next_adjacent_arc_[arc]) + ")\n"; + result += " " + ArcDebugString(arc) + ":(" + NodeDebugString(head_[arc]) + + "," + ArcDebugString(next_adjacent_arc_[arc]) + ")\n"; } result += "Node:First arc :\n"; for (NodeIndexType node = kFirstNode; node < num_nodes_; ++node) { - result += " " + NodeDebugString(node) + ":" - + ArcDebugString(first_incident_arc_[node]) + "\n"; + result += " " + NodeDebugString(node) + ":" + + ArcDebugString(first_incident_arc_[node]) + "\n"; } return result; } @@ -1588,7 +1550,7 @@ template class EbertGraph // A forward-star-only graph representation for greater efficiency in // those algorithms that don't need reverse arcs. -template +template class ForwardEbertGraph : public EbertGraphBase > { @@ -1674,7 +1636,7 @@ class ForwardEbertGraph void BuildRepresentation() { first_incident_arc_.SetAll(kNilArc); DCHECK(TailArrayComplete()); - for (ArcIndexType arc = kFirstArc; arc < max_num_arcs_; ++arc) { + for (ArcIndexType arc = kFirstArc; arc < max_num_arcs_; ++arc) { DCHECK(CheckTailIndexValidity(arc)); Attach((*tail_)[arc], arc); } @@ -1709,9 +1671,7 @@ class ForwardEbertGraph return true; } - void ReleaseTailArray() { - tail_.reset(NULL); - } + void ReleaseTailArray() { tail_.reset(NULL); } // To be used in a DCHECK(). bool TailArrayComplete() const { @@ -1729,14 +1689,13 @@ class ForwardEbertGraph DCHECK(representation_clean_); std::string result = "Arcs:(node, next arc) :\n"; for (ArcIndexType arc = kFirstArc; arc < num_arcs_; ++arc) { - result += " " + ArcDebugString(arc) + ":(" - + NodeDebugString(head_[arc]) - + "," + ArcDebugString(next_adjacent_arc_[arc]) + ")\n"; + result += " " + ArcDebugString(arc) + ":(" + NodeDebugString(head_[arc]) + + "," + ArcDebugString(next_adjacent_arc_[arc]) + ")\n"; } result += "Node:First arc :\n"; for (NodeIndexType node = kFirstNode; node < num_nodes_; ++node) { - result += " " + NodeDebugString(node) + ":" - + ArcDebugString(first_incident_arc_[node]) + "\n"; + result += " " + NodeDebugString(node) + ":" + + ArcDebugString(first_incident_arc_[node]) + "\n"; } return result; } @@ -1756,8 +1715,7 @@ class ForwardEbertGraph // reserving additional space for new arcs that haven't been // added yet. if (tail_->Reserve(kFirstArc, new_max_num_arcs - 1)) { - for (ArcIndexType arc = tail_->max_index() + 1; - arc < new_max_num_arcs; + for (ArcIndexType arc = tail_->max_index() + 1; arc < new_max_num_arcs; ++arc) { tail_->Set(arc, kNilNode); } @@ -1876,7 +1834,8 @@ class ForwardEbertGraph // The default is to assume reverse arcs so if someone forgets to // specialize the traits of a new forward-only graph type, they will // get errors from tests rather than incomplete testing. -template struct graph_traits { +template +struct graph_traits { static const bool has_reverse_arcs = true; static const bool is_dynamic = true; }; @@ -1899,23 +1858,21 @@ namespace internal { // clients. It is a helper for the TailArrayManager template. // // The TailArrayBuilder for graphs with reverse arcs does nothing. -template struct TailArrayBuilder { +template +struct TailArrayBuilder { explicit TailArrayBuilder(GraphType* unused_graph) {} - bool BuildTailArray() const { - return true; - } + bool BuildTailArray() const { return true; } }; // The TailArrayBuilder for graphs without reverse arcs calls the // appropriate method on the graph from the TailArrayBuilder // constructor. -template struct TailArrayBuilder { +template +struct TailArrayBuilder { explicit TailArrayBuilder(GraphType* graph) : graph_(graph) {} - bool BuildTailArray() const { - return graph_->BuildTailArray(); - } + bool BuildTailArray() const { return graph_->BuildTailArray(); } GraphType* const graph_; }; @@ -1924,7 +1881,8 @@ template struct TailArrayBuilder { // clients. It is a helper for the TailArrayManager template. // // The TailArrayReleaser for graphs with reverse arcs does nothing. -template struct TailArrayReleaser { +template +struct TailArrayReleaser { explicit TailArrayReleaser(GraphType* unused_graph) {} void ReleaseTailArray() const {} @@ -1933,33 +1891,33 @@ template struct TailArrayReleaser { // The TailArrayReleaser for graphs without reverse arcs calls the // appropriate method on the graph from the TailArrayReleaser // constructor. -template struct TailArrayReleaser { +template +struct TailArrayReleaser { explicit TailArrayReleaser(GraphType* graph) : graph_(graph) {} - void ReleaseTailArray() const { - graph_->ReleaseTailArray(); - } + void ReleaseTailArray() const { graph_->ReleaseTailArray(); } GraphType* const graph_; }; } // namespace internal -template class TailArrayManager { +template +class TailArrayManager { public: explicit TailArrayManager(GraphType* g) : graph_(g) {} bool BuildTailArrayFromAdjacencyListsIfForwardGraph() const { - internal::TailArrayBuilder< - GraphType, graph_traits::has_reverse_arcs> - tail_array_builder(graph_); + internal::TailArrayBuilder::has_reverse_arcs> + tail_array_builder(graph_); return tail_array_builder.BuildTailArray(); } void ReleaseTailArrayIfForwardGraph() const { - internal::TailArrayReleaser< - GraphType, graph_traits::has_reverse_arcs> - tail_array_releaser(graph_); + internal::TailArrayReleaser::has_reverse_arcs> + tail_array_releaser(graph_); tail_array_releaser.ReleaseTailArray(); } @@ -1967,11 +1925,11 @@ template class TailArrayManager { GraphType* graph_; }; -template +template class ArcFunctorOrderingByTailAndHead { public: explicit ArcFunctorOrderingByTailAndHead(const GraphType& graph) - : graph_(graph) { } + : graph_(graph) {} bool operator()(typename GraphType::ArcIndex a, typename GraphType::ArcIndex b) const { @@ -1991,7 +1949,8 @@ namespace internal { // template. // // Deletes itself upon returning the graph! -template class GraphBuilderFromArcs { +template +class GraphBuilderFromArcs { public: GraphBuilderFromArcs(typename GraphType::NodeIndex max_num_nodes, typename GraphType::ArcIndex max_num_arcs, @@ -2019,9 +1978,8 @@ template class GraphBuilderFromArcs { } // Builds the graph from the given arcs. - GraphType* Graph( - PermutationCycleHandler* - client_cycle_handler) { + GraphType* Graph(PermutationCycleHandler* + client_cycle_handler) { GraphType* graph = new GraphType(max_num_nodes_, num_arcs_, sort_arcs_, &arcs_, client_cycle_handler); delete this; @@ -2041,8 +1999,8 @@ template class GraphBuilderFromArcs { typename GraphType::ArcIndex max_num_arcs_; typename GraphType::ArcIndex num_arcs_; - std::vector > arcs_; + std::vector > + arcs_; const bool sort_arcs_; }; @@ -2050,13 +2008,14 @@ template class GraphBuilderFromArcs { // Trivial delegating specialization for dynamic graphs. // // Deletes itself upon returning the graph! -template class GraphBuilderFromArcs { +template +class GraphBuilderFromArcs { public: GraphBuilderFromArcs(typename GraphType::NodeIndex max_num_nodes, typename GraphType::ArcIndex max_num_arcs, bool sort_arcs) : graph_(new GraphType(max_num_nodes, max_num_arcs)), - sort_arcs_(sort_arcs) { } + sort_arcs_(sort_arcs) {} bool Reserve(const typename GraphType::NodeIndex new_max_num_nodes, const typename GraphType::ArcIndex new_max_num_arcs) { @@ -2090,17 +2049,17 @@ template class GraphBuilderFromArcs { } // namespace internal -template +template class AnnotatedGraphBuildManager : public internal::GraphBuilderFromArcs< - GraphType, graph_traits::is_dynamic> { + GraphType, graph_traits::is_dynamic> { public: AnnotatedGraphBuildManager(typename GraphType::NodeIndex num_nodes, typename GraphType::ArcIndex num_arcs, bool sort_arcs) : internal::GraphBuilderFromArcs< - GraphType, graph_traits::is_dynamic>( - num_nodes, num_arcs, sort_arcs) { } + GraphType, graph_traits::is_dynamic>(num_nodes, num_arcs, + sort_arcs) {} }; // Builds a directed line graph for 'graph' (see "directed line graph" in @@ -2114,8 +2073,8 @@ class AnnotatedGraphBuildManager // This method expects that 'line_graph' is an empty graph (it has no nodes // and no arcs). // Returns false on an error. -template bool BuildLineGraph(const GraphType& graph, - GraphType* const line_graph) { +template +bool BuildLineGraph(const GraphType& graph, GraphType* const line_graph) { if (line_graph == NULL) { LOG(DFATAL) << "line_graph must not be NULL"; return false; @@ -2128,25 +2087,21 @@ template bool BuildLineGraph(const GraphType& graph, typedef typename GraphType::OutgoingArcIterator OutgoingArcIterator; // Sizing then filling. typename GraphType::ArcIndex num_arcs = 0; - for (ArcIterator arc_iterator(graph); - arc_iterator.Ok(); + for (ArcIterator arc_iterator(graph); arc_iterator.Ok(); arc_iterator.Next()) { const typename GraphType::ArcIndex arc = arc_iterator.Index(); const typename GraphType::NodeIndex head = graph.Head(arc); - for (OutgoingArcIterator iterator(graph, head); - iterator.Ok(); + for (OutgoingArcIterator iterator(graph, head); iterator.Ok(); iterator.Next()) { ++num_arcs; } } line_graph->Reserve(graph.num_arcs(), num_arcs); - for (ArcIterator arc_iterator(graph); - arc_iterator.Ok(); + for (ArcIterator arc_iterator(graph); arc_iterator.Ok(); arc_iterator.Next()) { const typename GraphType::ArcIndex arc = arc_iterator.Index(); const typename GraphType::NodeIndex head = graph.Head(arc); - for (OutgoingArcIterator iterator(graph, head); - iterator.Ok(); + for (OutgoingArcIterator iterator(graph, head); iterator.Ok(); iterator.Next()) { line_graph->AddArc(arc, iterator.Index()); } diff --git a/src/graph/graph.h b/src/graph/graph.h index 712b6f81a8..ce1af9e4f0 100644 --- a/src/graph/graph.h +++ b/src/graph/graph.h @@ -152,7 +152,8 @@ namespace operations_research { // Forward declaration. -template class SVector; +template +class SVector; // Base class of all Graphs implemented here. The default value for the graph // index types is int32 since allmost all graphs that fit into memory do not @@ -160,9 +161,8 @@ template class SVector; // // Note: The type can be unsigned, except for the graphs with reverse arcs // where the ArcIndexType must be signed, but not necessarly the NodeIndexType. -template +template class BaseGraph { public: // Typedef so you can use Graph::NodeIndex and Graph::ArcIndex to be generic @@ -199,7 +199,7 @@ class BaseGraph { // Returns true if the given arc is a valid arc of the graph. // Note that the arc validity range changes for graph with reverse arcs. bool IsArcValid(ArcIndexType arc) const { - return (HasReverseArcs ? - num_arcs_ : 0) <= arc && arc < num_arcs_; + return (HasReverseArcs ? -num_arcs_ : 0) <= arc && arc < num_arcs_; } // Capacity reserved for future nodes, always >= num_nodes_. @@ -232,10 +232,10 @@ class BaseGraph { protected: // Functions commented when defined because they are implementation details. - void ComputeCumulativeSum(std::vector *v); - void BuildStartAndForwardHead( - SVector *head, std::vector *start, - std::vector *permutation); + void ComputeCumulativeSum(std::vector* v); + void BuildStartAndForwardHead(SVector* head, + std::vector* start, + std::vector* permutation); class BaseStaticArcIterator; NodeIndexType num_nodes_; @@ -257,9 +257,8 @@ class BaseGraph { // + (ArcIndexType + NodeIndexType) * arc_capacity(). // - Has an efficient Tail() but need an extra NodeIndexType/arc memory for it. // - Never changes the initial arc index returned by AddArc(). -template class ListGraph - : public BaseGraph { +template +class ListGraph : public BaseGraph { typedef BaseGraph Base; using Base::num_arcs_; using Base::num_nodes_; @@ -302,7 +301,7 @@ template *permutation); + void Build(std::vector* permutation); // Do not use directly. // TODO(user): make it private when no one depends on it. @@ -357,9 +356,8 @@ template class StaticGraph - : public BaseGraph { +template +class StaticGraph : public BaseGraph { typedef BaseGraph Base; using Base::num_arcs_; using Base::num_nodes_; @@ -380,8 +378,8 @@ template OutgoingArcs(NodeIndexType node) const; - IntegerRange OutgoingArcsStartingFrom( - NodeIndexType node, ArcIndexType from) const; + IntegerRange OutgoingArcsStartingFrom(NodeIndexType node, + ArcIndexType from) const; // This loops over the heads of the OutgoingArcs(node). It is just a more // convenient way to achieve this. Moreover this interface is used by some @@ -394,7 +392,7 @@ template *permutation); + void Build(std::vector* permutation); void BuildTailArray(); void FreeTailArray(); @@ -421,8 +419,8 @@ template class ReverseArcListGraph +template +class ReverseArcListGraph : public BaseGraph { typedef BaseGraph Base; using Base::num_arcs_; @@ -463,12 +461,12 @@ template OutgoingArcs(NodeIndexType node) const; BeginEndWrapper IncomingArcs(NodeIndexType node) const; BeginEndWrapper IncidentArcs(NodeIndexType node) const; - BeginEndWrapper - OutgoingArcsStartingFrom(NodeIndexType node, ArcIndexType from) const; - BeginEndWrapper - IncomingArcsStartingFrom(NodeIndexType node, ArcIndexType from) const; - BeginEndWrapper - IncidentArcsStartingFrom(NodeIndexType node, ArcIndexType from) const; + BeginEndWrapper OutgoingArcsStartingFrom( + NodeIndexType node, ArcIndexType from) const; + BeginEndWrapper IncomingArcsStartingFrom( + NodeIndexType node, ArcIndexType from) const; + BeginEndWrapper IncidentArcsStartingFrom( + NodeIndexType node, ArcIndexType from) const; NodeIndexType Head(ArcIndexType arc) const; NodeIndexType Tail(ArcIndexType arc) const; @@ -479,7 +477,7 @@ template *permutation); + void Build(std::vector* permutation); void BuildTailArray() {} void FreeTailArray() {} @@ -502,8 +500,8 @@ template class ReverseArcStaticGraph +template +class ReverseArcStaticGraph : public BaseGraph { typedef BaseGraph Base; using Base::num_arcs_; @@ -530,12 +528,12 @@ template OutgoingArcs(NodeIndexType node) const; IntegerRange IncomingArcs(NodeIndexType node) const; BeginEndWrapper IncidentArcs(NodeIndexType node) const; - IntegerRange - OutgoingArcsStartingFrom(NodeIndexType node, ArcIndexType from) const; - IntegerRange - IncomingArcsStartingFrom(NodeIndexType node, ArcIndexType from) const; - BeginEndWrapper - IncidentArcsStartingFrom(NodeIndexType node, ArcIndexType from) const; + IntegerRange OutgoingArcsStartingFrom(NodeIndexType node, + ArcIndexType from) const; + IntegerRange IncomingArcsStartingFrom(NodeIndexType node, + ArcIndexType from) const; + BeginEndWrapper IncidentArcsStartingFrom( + NodeIndexType node, ArcIndexType from) const; ArcIndexType OppositeArc(ArcIndexType arc) const; NodeIndexType Head(ArcIndexType arc) const; @@ -547,7 +545,7 @@ template *permutation); + void Build(std::vector* permutation); void BuildTailArray() {} void FreeTailArray() {} @@ -573,8 +571,8 @@ template class ReverseArcMixedGraph +template +class ReverseArcMixedGraph : public BaseGraph { typedef BaseGraph Base; using Base::num_arcs_; @@ -601,12 +599,12 @@ template OutgoingArcs(NodeIndexType node) const; BeginEndWrapper IncomingArcs(NodeIndexType node) const; BeginEndWrapper IncidentArcs(NodeIndexType node) const; - IntegerRange - OutgoingArcsStartingFrom(NodeIndexType node, ArcIndexType from) const; - BeginEndWrapper - IncomingArcsStartingFrom(NodeIndexType node, ArcIndexType from) const; - BeginEndWrapper - IncidentArcsStartingFrom(NodeIndexType node, ArcIndexType from) const; + IntegerRange OutgoingArcsStartingFrom(NodeIndexType node, + ArcIndexType from) const; + BeginEndWrapper IncomingArcsStartingFrom( + NodeIndexType node, ArcIndexType from) const; + BeginEndWrapper IncidentArcsStartingFrom( + NodeIndexType node, ArcIndexType from) const; ArcIndexType OppositeArc(ArcIndexType arc) const; NodeIndexType Head(ArcIndexType arc) const; @@ -618,7 +616,7 @@ template *permutation); + void Build(std::vector* permutation); void BuildTailArray() {} void FreeTailArray() {} @@ -648,9 +646,10 @@ template -void PermuteWithExplicitElementType( - const IntVector& permutation, Array* array_to_permute, ElementType unused) { +template +void PermuteWithExplicitElementType(const IntVector& permutation, + Array* array_to_permute, + ElementType unused) { std::vector temp(permutation.size()); for (int i = 0; i < permutation.size(); ++i) { temp[i] = (*array_to_permute)[i]; @@ -660,13 +659,13 @@ void PermuteWithExplicitElementType( } } -template +template void Permute(const IntVector& permutation, Array* array_to_permute) { if (permutation.size() == 0) { return; } - PermuteWithExplicitElementType( - permutation, array_to_permute, (*array_to_permute)[0]); + PermuteWithExplicitElementType(permutation, array_to_permute, + (*array_to_permute)[0]); } // A vector-like class where valid indices are in [- size_, size_) and reserved @@ -683,7 +682,7 @@ void Permute(const IntVector& permutation, Array* array_to_permute) { // v.clear(); // v.swap(new_v); // std:swap(v[i], v[~i]); -template +template class SVector { public: SVector() : base_(NULL), size_(0), capacity_(0) {} @@ -697,25 +696,25 @@ class SVector { T& operator[](int n) { DCHECK_LT(n, size_); - DCHECK_GE(n, - size_); + DCHECK_GE(n, -size_); return base_[n]; } const T& operator[](int n) const { DCHECK_LT(n, size_); - DCHECK_GE(n, - size_); + DCHECK_GE(n, -size_); return base_[n]; } void resize(int n, T left = T(), T right = T()) { reserve(n); - for (int i = -n; i < - size_; ++i) { - new(base_ + i) T(left); + for (int i = -n; i < -size_; ++i) { + new (base_ + i) T(left); } for (int i = size_; i < n; ++i) { - new(base_ + i) T(right); + new (base_ + i) T(right); } - for (int i = - size_; i < -n; ++i) { + for (int i = -size_; i < -n; ++i) { base_[i].~T(); } for (int i = n; i < size_; ++i) { @@ -724,11 +723,9 @@ class SVector { size_ = n; } - void clear() { - resize(0); - } + void clear() { resize(0); } - void swap(SVector &x) { + void swap(SVector& x) { std::swap(base_, x.base_); std::swap(size_, x.size_); std::swap(capacity_, x.capacity_); @@ -740,18 +737,17 @@ class SVector { if (n > capacity_) { int new_capacity = n; size_t requested_block_size = 2LL * new_capacity * sizeof(T); - T *new_storage = static_cast(malloc(requested_block_size)); + T* new_storage = static_cast(malloc(requested_block_size)); CHECK(new_storage != NULL); -size_t block_size = requested_block_size; + size_t block_size = requested_block_size; if (block_size > 0) { DCHECK_GE(block_size, requested_block_size); - new_capacity = static_cast(std::min( - static_cast(max_size()), - block_size / (2 * sizeof(T)))); + new_capacity = static_cast( + std::min(static_cast(max_size()), block_size / (2 * sizeof(T)))); } - T *new_base = new_storage + new_capacity; - for (int i = - size_; i < size_; ++i) { - new(new_base + i) T(base_[i]); + T* new_base = new_storage + new_capacity; + for (int i = -size_; i < size_; ++i) { + new (new_base + i) T(base_[i]); } int temp = size_; clear(); @@ -771,27 +767,21 @@ size_t block_size = requested_block_size; T left_copy(left); T right_copy(right); reserve(NewCapacity(1)); - new(base_ + size_) T(right_copy); - new(base_ - size_ - 1) T(left_copy); + new (base_ + size_) T(right_copy); + new (base_ - size_ - 1) T(left_copy); ++size_; } else { - new(base_ + size_) T(right); - new(base_ - size_ - 1) T(left); + new (base_ + size_) T(right); + new (base_ - size_ - 1) T(left); ++size_; } } - int size() const { - return size_; - } + int size() const { return size_; } - int capacity() const { - return capacity_; - } + int capacity() const { return capacity_; } - int max_size() const { - return std::numeric_limits::max(); - } + int max_size() const { return std::numeric_limits::max(); } private: int NewCapacity(int delta) { @@ -807,54 +797,54 @@ size_t block_size = requested_block_size; return capacity_ + delta; } - T *base_; // Pointer to the element of index 0. - int size_; // Valid index are [- size_, size_). + T* base_; // Pointer to the element of index 0. + int size_; // Valid index are [- size_, size_). int capacity_; // Reserved index are [- capacity_, capacity_). DISALLOW_COPY_AND_ASSIGN(SVector); }; // BaseGraph definition ------------------------------------------------------ -template +template IntegerRange - BaseGraph - ::AllNodes() const { +BaseGraph::AllNodes() const { return IntegerRange(0, num_nodes_); } -template +template IntegerRange - BaseGraph - ::AllForwardArcs() const { +BaseGraph::AllForwardArcs() const { return IntegerRange(0, num_arcs_); } -template -const NodeIndexType BaseGraph - ::kNilNode = std::numeric_limits::max(); +template +const NodeIndexType + BaseGraph::kNilNode = + std::numeric_limits::max(); -template -const ArcIndexType BaseGraph - ::kNilArc = std::numeric_limits::max(); +template +const ArcIndexType + BaseGraph::kNilArc = + std::numeric_limits::max(); -template -NodeIndexType BaseGraph - ::node_capacity() const { +template +NodeIndexType +BaseGraph::node_capacity() const { // TODO(user): Is it needed? remove completely? return the real capacities // at the cost of having a different implementation for each graphs? return node_capacity_ > num_nodes_ ? node_capacity_ : num_nodes_; } -template -ArcIndexType BaseGraph - ::arc_capacity() const { +template +ArcIndexType +BaseGraph::arc_capacity() const { // TODO(user): Same questions as the ones in node_capacity(). return arc_capacity_ > num_arcs_ ? arc_capacity_ : num_arcs_; } -template -void BaseGraph - ::FreezeCapacities() { +template +void +BaseGraph::FreezeCapacities() { // TODO(user): Only define this in debug mode at the cost of having a lot // of ifndef NDEBUG all over the place? remove the function completely ? const_capacities_ = true; @@ -864,9 +854,9 @@ void BaseGraph // Computes the cummulative sum of the entry in v. We only use it with // in/out degree distribution, hence the Check() at the end. -template -void BaseGraph - ::ComputeCumulativeSum(std::vector *v) { +template +void BaseGraph::ComputeCumulativeSum(std::vector* v) { ArcIndexType sum = 0; for (int i = 0; i < num_nodes_; ++i) { ArcIndexType temp = (*v)[i]; @@ -877,20 +867,16 @@ void BaseGraph } // Base class for StaticGraph arc iterator. -template -class BaseGraph - ::BaseStaticArcIterator { +template +class BaseGraph::BaseStaticArcIterator { public: BaseStaticArcIterator(ArcIndexType index, ArcIndexType limit) : index_(index), limit_(limit) {} - bool Ok() const { - return index_ < limit_; - } + bool Ok() const { return index_ < limit_; } - ArcIndexType Index() const { - return index_; - } + ArcIndexType Index() const { return index_; } void Next() { DCHECK(Ok()); @@ -907,12 +893,11 @@ class BaseGraph // - Put the head of the new arc #i in (*head)[i]. // - Put in start[i] the index of the first arc with tail >= i. // - Update "permutation" to reflect the change, unless it is NULL. -template -void BaseGraph - ::BuildStartAndForwardHead( - SVector *head, - std::vector *start, - std::vector *permutation) { +template +void BaseGraph:: + BuildStartAndForwardHead(SVector* head, + std::vector* start, + std::vector* permutation) { // Computes the outgoing degree of each nodes and check if we need to permute // something or not. Note that the tails are currently stored in the positive // range of the SVector head. @@ -972,54 +957,51 @@ void BaseGraph // - c: the class name. // - t: the iteration type (Outgoing, Incoming or Incident). // - e: the "end" ArcIndexType. -#define DECLARE_ARC_ITERATION(c, t, e) \ -template \ -BeginEndWrapper::t##ArcIterator> \ - c::t##Arcs(NodeIndexType node) const { \ - return BeginEndWrapper( \ - t##ArcIterator(*this, node), \ - t##ArcIterator(*this, node, e)); \ -} \ -template \ -BeginEndWrapper::t##ArcIterator> \ - c::t##ArcsStartingFrom( \ - NodeIndexType node, ArcIndexType from) const { \ - return BeginEndWrapper( \ - t##ArcIterator(*this, node, from), \ - t##ArcIterator(*this, node, e)); \ -} +#define DECLARE_ARC_ITERATION(c, t, e) \ + template \ + BeginEndWrapper::t##ArcIterator> \ + c::t##Arcs(NodeIndexType node) const { \ + return BeginEndWrapper(t##ArcIterator(*this, node), \ + t##ArcIterator(*this, node, e)); \ + } \ + template \ + BeginEndWrapper::t##ArcIterator> \ + c::t##ArcsStartingFrom( \ + NodeIndexType node, ArcIndexType from) const { \ + return BeginEndWrapper(t##ArcIterator(*this, node, from), \ + t##ArcIterator(*this, node, e)); \ + } // Adapt our old iteration style to support range-based for loops. #define DECLARE_STL_ITERATOR_FUNCTIONS(iterator_class_name) \ -bool operator!=(const iterator_class_name& other) const { \ - return index_ != other.index_; \ -} \ -ArcIndexType operator*() const { return index_; } \ -void operator++() { Next(); } + bool operator!=(const iterator_class_name& other) const { \ + return index_ != other.index_; \ + } \ + ArcIndexType operator*() const { return index_; } \ + void operator++() { Next(); } // ListGraph definition ------------------------------------------------------ DECLARE_ARC_ITERATION(ListGraph, Outgoing, Base::kNilArc); -template -NodeIndexType ListGraph - ::Head(ArcIndexType arc) const { +template +NodeIndexType ListGraph::Head(ArcIndexType arc) + const { DCHECK(IsArcValid(arc)); return head_[arc]; } -template -void ListGraph - ::AddNode(NodeIndexType node) { +template +void ListGraph::AddNode(NodeIndexType node) { if (node < num_nodes_) return; DCHECK(!const_capacities_ || node < node_capacity_); num_nodes_ = node + 1; start_.resize(num_nodes_, Base::kNilArc); } -template -ArcIndexType ListGraph - ::AddArc(NodeIndexType tail, NodeIndexType head) { +template +ArcIndexType ListGraph::AddArc( + NodeIndexType tail, NodeIndexType head) { AddNode(tail > head ? tail : head); head_.push_back(head); next_.push_back(start_[tail]); @@ -1028,9 +1010,8 @@ ArcIndexType ListGraph return num_arcs_++; } -template -void ListGraph - ::ReserveNodes(NodeIndexType bound) { +template +void ListGraph::ReserveNodes(NodeIndexType bound) { DCHECK(!const_capacities_); DCHECK_GE(bound, num_nodes_); if (bound <= num_nodes_) return; @@ -1038,9 +1019,8 @@ void ListGraph start_.reserve(bound); } -template -void ListGraph - ::ReserveArcs(ArcIndexType bound) { +template +void ListGraph::ReserveArcs(ArcIndexType bound) { DCHECK(!const_capacities_); DCHECK_GE(bound, num_arcs_); if (bound <= num_arcs_) return; @@ -1049,17 +1029,17 @@ void ListGraph next_.reserve(bound); } -template -void ListGraph - ::Build(std::vector *permutation) { +template +void ListGraph::Build( + std::vector* permutation) { if (permutation != NULL) { permutation->clear(); } } -template -NodeIndexType ListGraph - ::Tail(ArcIndexType arc) const { +template +NodeIndexType ListGraph::Tail(ArcIndexType arc) + const { DCHECK(IsArcValid(arc)); // Build the full tail array if needed. @@ -1074,38 +1054,32 @@ NodeIndexType ListGraph return tail_[arc]; } -template -void ListGraph - ::BuildTailArray() { +template +void ListGraph::BuildTailArray() { Tail(num_arcs_ - 1); } -template -void ListGraph - ::FreeTailArray() { +template +void ListGraph::FreeTailArray() { std::vector tmp; tmp.swap(tail_); } -template +template class ListGraph::OutgoingArcIterator { public: - OutgoingArcIterator(const ListGraph &graph, NodeIndexType node) + OutgoingArcIterator(const ListGraph& graph, NodeIndexType node) : graph_(&graph), index_(graph.start_[node]) { DCHECK(graph.IsNodeValid(node)); } - OutgoingArcIterator( - const ListGraph &graph, NodeIndexType node, ArcIndexType arc) + OutgoingArcIterator(const ListGraph& graph, NodeIndexType node, + ArcIndexType arc) : graph_(&graph), index_(arc) { DCHECK(graph.IsNodeValid(node)); DCHECK(arc == Base::kNilArc || graph.Tail(arc) == node); } - bool Ok() const { - return index_ != Base::kNilArc; - } - ArcIndexType Index() const { - return index_; - } + bool Ok() const { return index_ != Base::kNilArc; } + ArcIndexType Index() const { return index_; } void Next() { DCHECK(Ok()); index_ = graph_->next_[index_]; @@ -1114,34 +1088,35 @@ class ListGraph::OutgoingArcIterator { DECLARE_STL_ITERATOR_FUNCTIONS(OutgoingArcIterator); private: - const ListGraph *graph_; + const ListGraph* graph_; ArcIndexType index_; }; // StaticGraph definition ---------------------------------------------------- -template -IntegerRange StaticGraph - ::OutgoingArcs(NodeIndexType node) const { +template +IntegerRange StaticGraph< + NodeIndexType, ArcIndexType>::OutgoingArcs(NodeIndexType node) const { return IntegerRange(start_[node], DirectArcLimit(node)); } -template -BeginEndWrapper StaticGraph - ::operator[](NodeIndexType node) const { - return BeginEndWrapper(&(head_[start_[node]]), - &(head_[DirectArcLimit(node)])); +template +BeginEndWrapper StaticGraph:: +operator[](NodeIndexType node) const { + return BeginEndWrapper( + head_.data() + start_[node], head_.data() + DirectArcLimit(node)); } -template -IntegerRange StaticGraph - ::OutgoingArcsStartingFrom(NodeIndexType node, ArcIndexType from) const { +template +IntegerRange +StaticGraph::OutgoingArcsStartingFrom( + NodeIndexType node, ArcIndexType from) const { return IntegerRange(from, DirectArcLimit(node)); } -template -void StaticGraph - ::ReserveNodes(NodeIndexType bound) { +template +void StaticGraph::ReserveNodes( + NodeIndexType bound) { DCHECK(!const_capacities_); DCHECK_GE(bound, num_nodes_); if (bound <= num_nodes_) return; @@ -1149,9 +1124,8 @@ void StaticGraph start_.reserve(bound); } -template -void StaticGraph - ::ReserveArcs(ArcIndexType bound) { +template +void StaticGraph::ReserveArcs(ArcIndexType bound) { DCHECK(!const_capacities_); DCHECK_GE(bound, num_arcs_); if (bound <= num_arcs_) return; @@ -1162,18 +1136,17 @@ void StaticGraph } } -template -void StaticGraph - ::AddNode(NodeIndexType node) { +template +void StaticGraph::AddNode(NodeIndexType node) { if (node < num_nodes_) return; DCHECK(!const_capacities_ || node < node_capacity_); num_nodes_ = node + 1; start_.resize(num_nodes_, 0); } -template -ArcIndexType StaticGraph - ::AddArc(NodeIndexType tail, NodeIndexType head) { +template +ArcIndexType StaticGraph::AddArc( + NodeIndexType tail, NodeIndexType head) { AddNode(tail > head ? tail : head); if (arc_in_order_) { if (tail >= last_tail_seen_) { @@ -1198,17 +1171,17 @@ ArcIndexType StaticGraph return num_arcs_++; } -template -NodeIndexType StaticGraph - ::Head(ArcIndexType arc) const { +template +NodeIndexType StaticGraph::Head(ArcIndexType arc) + const { DCHECK(is_built_); DCHECK(IsArcValid(arc)); return head_[arc]; } -template -NodeIndexType StaticGraph - ::Tail(ArcIndexType arc) const { +template +NodeIndexType StaticGraph::Tail(ArcIndexType arc) + const { DCHECK(is_built_); DCHECK(IsArcValid(arc)); @@ -1236,9 +1209,9 @@ NodeIndexType StaticGraph // possibly random access to degree[i]. // - When the degrees are needed, we compute them in one go, maximizing the // chance of cache hit during the computation. -template -void StaticGraph - ::Build(std::vector *permutation) { +template +void StaticGraph::Build( + std::vector* permutation) { DCHECK(!is_built_); if (is_built_) return; is_built_ = true; @@ -1287,33 +1260,31 @@ void StaticGraph start_[0] = 0; } -template -void StaticGraph - ::BuildTailArray() { +template +void StaticGraph::BuildTailArray() { DCHECK(is_built_); Tail(num_arcs_ - 1); } -template -void StaticGraph - ::FreeTailArray() { +template +void StaticGraph::FreeTailArray() { DCHECK(is_built_); std::vector tmp; tmp.swap(tail_); } -template -class StaticGraph - ::OutgoingArcIterator : public Base::BaseStaticArcIterator { +template +class StaticGraph::OutgoingArcIterator + : public Base::BaseStaticArcIterator { public: - OutgoingArcIterator(const StaticGraph &graph, NodeIndexType node) - : Base::BaseStaticArcIterator( - graph.start_[node], graph.DirectArcLimit(node)) { + OutgoingArcIterator(const StaticGraph& graph, NodeIndexType node) + : Base::BaseStaticArcIterator(graph.start_[node], + graph.DirectArcLimit(node)) { DCHECK(graph.is_built_); DCHECK(graph.IsNodeValid(node)); } - OutgoingArcIterator( - const StaticGraph &graph, NodeIndexType node, ArcIndexType arc) + OutgoingArcIterator(const StaticGraph& graph, NodeIndexType node, + ArcIndexType arc) : Base::BaseStaticArcIterator(arc, graph.DirectArcLimit(node)) { DCHECK(graph.is_built_); DCHECK(graph.IsNodeValid(node)); @@ -1327,29 +1298,29 @@ DECLARE_ARC_ITERATION(ReverseArcListGraph, Outgoing, Base::kNilArc); DECLARE_ARC_ITERATION(ReverseArcListGraph, Incoming, Base::kNilArc); DECLARE_ARC_ITERATION(ReverseArcListGraph, Incident, Base::kNilArc); -template -ArcIndexType ReverseArcListGraph - ::OppositeArc(ArcIndexType arc) const { +template +ArcIndexType ReverseArcListGraph::OppositeArc( + ArcIndexType arc) const { DCHECK(IsArcValid(arc)); return ~arc; } -template -NodeIndexType ReverseArcListGraph - ::Head(ArcIndexType arc) const { +template +NodeIndexType ReverseArcListGraph::Head( + ArcIndexType arc) const { DCHECK(IsArcValid(arc)); return head_[arc]; } -template -NodeIndexType ReverseArcListGraph - ::Tail(ArcIndexType arc) const { +template +NodeIndexType ReverseArcListGraph::Tail( + ArcIndexType arc) const { return head_[OppositeArc(arc)]; } -template -void ReverseArcListGraph - ::ReserveNodes(NodeIndexType bound) { +template +void ReverseArcListGraph::ReserveNodes( + NodeIndexType bound) { DCHECK(!const_capacities_); DCHECK_GE(bound, num_nodes_); if (bound <= num_nodes_) return; @@ -1358,9 +1329,9 @@ void ReverseArcListGraph reverse_start_.reserve(bound); } -template -void ReverseArcListGraph - ::ReserveArcs(ArcIndexType bound) { +template +void ReverseArcListGraph::ReserveArcs( + ArcIndexType bound) { DCHECK(!const_capacities_); DCHECK_GE(bound, num_arcs_); if (bound <= num_arcs_) return; @@ -1369,9 +1340,9 @@ void ReverseArcListGraph next_.reserve(bound); } -template -void ReverseArcListGraph - ::AddNode(NodeIndexType node) { +template +void ReverseArcListGraph::AddNode( + NodeIndexType node) { if (node < num_nodes_) return; DCHECK(!const_capacities_ || node < node_capacity_); num_nodes_ = node + 1; @@ -1379,9 +1350,9 @@ void ReverseArcListGraph reverse_start_.resize(num_nodes_, Base::kNilArc); } -template -ArcIndexType ReverseArcListGraph - ::AddArc(NodeIndexType tail, NodeIndexType head) { +template +ArcIndexType ReverseArcListGraph::AddArc( + NodeIndexType tail, NodeIndexType head) { AddNode(tail > head ? tail : head); head_.grow(tail, head); next_.grow(reverse_start_[head], start_[tail]); @@ -1391,25 +1362,21 @@ ArcIndexType ReverseArcListGraph return num_arcs_++; } -template -void ReverseArcListGraph - ::Build(std::vector *permutation) { +template +void ReverseArcListGraph::Build( + std::vector* permutation) { if (permutation != NULL) { permutation->clear(); } } -template +template class ReverseArcListGraph::BaseArcIterator { public: - BaseArcIterator(const ReverseArcListGraph &graph, ArcIndexType index) + BaseArcIterator(const ReverseArcListGraph& graph, ArcIndexType index) : graph_(&graph), index_(index) {} - bool Ok() const { - return index_ != Base::kNilArc; - } - ArcIndexType Index() const { - return index_; - } + bool Ok() const { return index_ != Base::kNilArc; } + ArcIndexType Index() const { return index_; } void Next() { DCHECK(Ok()); index_ = graph_->next_[index_]; @@ -1418,56 +1385,58 @@ class ReverseArcListGraph::BaseArcIterator { DECLARE_STL_ITERATOR_FUNCTIONS(BaseArcIterator); protected: - const ReverseArcListGraph *graph_; + const ReverseArcListGraph* graph_; ArcIndexType index_; }; -template -class ReverseArcListGraph - ::OutgoingArcIterator : public BaseArcIterator { +template +class ReverseArcListGraph::OutgoingArcIterator + : public BaseArcIterator { public: - OutgoingArcIterator(const ReverseArcListGraph &graph, NodeIndexType node) + OutgoingArcIterator(const ReverseArcListGraph& graph, NodeIndexType node) : BaseArcIterator(graph, graph.start_[node]) { DCHECK(graph.IsNodeValid(node)); } - OutgoingArcIterator(const ReverseArcListGraph &graph, - NodeIndexType node, ArcIndexType arc) : BaseArcIterator(graph, arc) { + OutgoingArcIterator(const ReverseArcListGraph& graph, NodeIndexType node, + ArcIndexType arc) + : BaseArcIterator(graph, arc) { DCHECK(graph.IsNodeValid(node)); DCHECK(arc == Base::kNilArc || arc >= 0); DCHECK(arc == Base::kNilArc || graph.Tail(arc) == node); } }; -template -class ReverseArcListGraph - ::IncomingArcIterator : public BaseArcIterator { +template +class ReverseArcListGraph::IncomingArcIterator + : public BaseArcIterator { public: - IncomingArcIterator(const ReverseArcListGraph &graph, NodeIndexType node) + IncomingArcIterator(const ReverseArcListGraph& graph, NodeIndexType node) : BaseArcIterator(graph, graph.reverse_start_[node]) { DCHECK(graph.IsNodeValid(node)); } - IncomingArcIterator(const ReverseArcListGraph &graph, - NodeIndexType node, ArcIndexType arc) : BaseArcIterator(graph, arc) { + IncomingArcIterator(const ReverseArcListGraph& graph, NodeIndexType node, + ArcIndexType arc) + : BaseArcIterator(graph, arc) { DCHECK(graph.IsNodeValid(node)); DCHECK(arc == Base::kNilArc || arc < 0); DCHECK(arc == Base::kNilArc || graph.Tail(arc) == node); } }; -template -class ReverseArcListGraph - ::IncidentArcIterator : public BaseArcIterator { +template +class ReverseArcListGraph::IncidentArcIterator + : public BaseArcIterator { using BaseArcIterator::graph_; using BaseArcIterator::index_; public: - IncidentArcIterator(const ReverseArcListGraph &graph, NodeIndexType node) + IncidentArcIterator(const ReverseArcListGraph& graph, NodeIndexType node) : BaseArcIterator(graph, graph.reverse_start_[node]), node_(node) { DCHECK(graph.IsNodeValid(node)); if (index_ == Base::kNilArc) index_ = graph.start_[node]; } - IncidentArcIterator(const ReverseArcListGraph &graph, - NodeIndexType node, ArcIndexType arc) + IncidentArcIterator(const ReverseArcListGraph& graph, NodeIndexType node, + ArcIndexType arc) : BaseArcIterator(graph, arc), node_(node) { DCHECK(graph.IsNodeValid(node)); DCHECK(arc == Base::kNilArc || graph.Tail(arc) == node); @@ -1492,68 +1461,70 @@ class ReverseArcListGraph // ReverseArcStaticGraph definition ------------------------------------------ -template -IntegerRange ReverseArcStaticGraph - ::OutgoingArcs(NodeIndexType node) const { +template +IntegerRange ReverseArcStaticGraph< + NodeIndexType, ArcIndexType>::OutgoingArcs(NodeIndexType node) const { return IntegerRange(start_[node], DirectArcLimit(node)); } -template -IntegerRange ReverseArcStaticGraph - ::OutgoingArcsStartingFrom(NodeIndexType node, ArcIndexType from) const { +template +IntegerRange +ReverseArcStaticGraph::OutgoingArcsStartingFrom( + NodeIndexType node, ArcIndexType from) const { return IntegerRange(from, DirectArcLimit(node)); } -template -IntegerRange ReverseArcStaticGraph - ::IncomingArcs(NodeIndexType node) const { - return IntegerRange( - reverse_start_[node], ReverseArcLimit(node)); +template +IntegerRange ReverseArcStaticGraph< + NodeIndexType, ArcIndexType>::IncomingArcs(NodeIndexType node) const { + return IntegerRange(reverse_start_[node], + ReverseArcLimit(node)); } -template -IntegerRange ReverseArcStaticGraph - ::IncomingArcsStartingFrom(NodeIndexType node, ArcIndexType from) const { +template +IntegerRange +ReverseArcStaticGraph::IncomingArcsStartingFrom( + NodeIndexType node, ArcIndexType from) const { return IntegerRange(from, ReverseArcLimit(node)); } DECLARE_ARC_ITERATION(ReverseArcStaticGraph, Incident, DirectArcLimit(node)); -template -ArcIndexType ReverseArcStaticGraph - ::OppositeArc(ArcIndexType arc) const { +template +ArcIndexType ReverseArcStaticGraph::OppositeArc( + ArcIndexType arc) const { DCHECK(is_built_); DCHECK(IsArcValid(arc)); return opposite_[arc]; } -template -NodeIndexType ReverseArcStaticGraph - ::Head(ArcIndexType arc) const { +template +NodeIndexType ReverseArcStaticGraph::Head( + ArcIndexType arc) const { DCHECK(is_built_); DCHECK(IsArcValid(arc)); return head_[arc]; } -template -NodeIndexType ReverseArcStaticGraph - ::Tail(ArcIndexType arc) const { +template +NodeIndexType ReverseArcStaticGraph::Tail( + ArcIndexType arc) const { DCHECK(is_built_); return head_[OppositeArc(arc)]; } -template -void ReverseArcStaticGraph - ::ReserveNodes(NodeIndexType bound) { +template +void ReverseArcStaticGraph::ReserveNodes( + NodeIndexType bound) { DCHECK(!const_capacities_); DCHECK_GE(bound, num_nodes_); if (bound <= num_nodes_) return; node_capacity_ = bound; } -template -void ReverseArcStaticGraph - ::ReserveArcs(ArcIndexType bound) { +template +void ReverseArcStaticGraph::ReserveArcs( + ArcIndexType bound) { DCHECK(!const_capacities_); DCHECK_GE(bound, num_arcs_); if (bound <= num_arcs_) return; @@ -1561,17 +1532,17 @@ void ReverseArcStaticGraph head_.reserve(bound); } -template -void ReverseArcStaticGraph - ::AddNode(NodeIndexType node) { +template +void ReverseArcStaticGraph::AddNode( + NodeIndexType node) { if (node < num_nodes_) return; DCHECK(!const_capacities_ || node < node_capacity_); num_nodes_ = node + 1; } -template -ArcIndexType ReverseArcStaticGraph - ::AddArc(NodeIndexType tail, NodeIndexType head) { +template +ArcIndexType ReverseArcStaticGraph::AddArc( + NodeIndexType tail, NodeIndexType head) { AddNode(tail > head ? tail : head); // We inverse head and tail here because it is more convenient this way @@ -1581,9 +1552,9 @@ ArcIndexType ReverseArcStaticGraph return num_arcs_++; } -template -void ReverseArcStaticGraph - ::Build(std::vector *permutation) { +template +void ReverseArcStaticGraph::Build( + std::vector* permutation) { DCHECK(!is_built_); if (is_built_) return; is_built_ = true; @@ -1626,19 +1597,18 @@ void ReverseArcStaticGraph } } -template -class ReverseArcStaticGraph - ::OutgoingArcIterator : public Base::BaseStaticArcIterator { +template +class ReverseArcStaticGraph::OutgoingArcIterator + : public Base::BaseStaticArcIterator { public: - OutgoingArcIterator( - const ReverseArcStaticGraph &graph, NodeIndexType node) - : Base::BaseStaticArcIterator( - graph.start_[node], graph.DirectArcLimit(node)) { + OutgoingArcIterator(const ReverseArcStaticGraph& graph, NodeIndexType node) + : Base::BaseStaticArcIterator(graph.start_[node], + graph.DirectArcLimit(node)) { DCHECK(graph.is_built_); DCHECK(graph.IsNodeValid(node)); } - OutgoingArcIterator(const ReverseArcStaticGraph &graph, - NodeIndexType node, ArcIndexType arc) + OutgoingArcIterator(const ReverseArcStaticGraph& graph, NodeIndexType node, + ArcIndexType arc) : Base::BaseStaticArcIterator(arc, graph.DirectArcLimit(node)) { DCHECK(graph.is_built_); DCHECK(graph.IsNodeValid(node)); @@ -1646,19 +1616,18 @@ class ReverseArcStaticGraph } }; -template -class ReverseArcStaticGraph - ::IncomingArcIterator : public Base::BaseStaticArcIterator { +template +class ReverseArcStaticGraph::IncomingArcIterator + : public Base::BaseStaticArcIterator { public: - IncomingArcIterator( - const ReverseArcStaticGraph &graph, NodeIndexType node) - : Base::BaseStaticArcIterator( - graph.reverse_start_[node], graph.ReverseArcLimit(node)) { + IncomingArcIterator(const ReverseArcStaticGraph& graph, NodeIndexType node) + : Base::BaseStaticArcIterator(graph.reverse_start_[node], + graph.ReverseArcLimit(node)) { DCHECK(graph.is_built_); DCHECK(graph.IsNodeValid(node)); } - IncomingArcIterator(const ReverseArcStaticGraph &graph, - NodeIndexType node, ArcIndexType arc) + IncomingArcIterator(const ReverseArcStaticGraph& graph, NodeIndexType node, + ArcIndexType arc) : Base::BaseStaticArcIterator(arc, graph.ReverseArcLimit(node)) { DCHECK(graph.is_built_); DCHECK(graph.IsNodeValid(node)); @@ -1666,31 +1635,31 @@ class ReverseArcStaticGraph } }; -template -class ReverseArcStaticGraph - ::IncidentArcIterator : public Base::BaseStaticArcIterator { +template +class ReverseArcStaticGraph::IncidentArcIterator + : public Base::BaseStaticArcIterator { using Base::BaseStaticArcIterator::index_; using Base::BaseStaticArcIterator::limit_; public: - IncidentArcIterator(const ReverseArcStaticGraph &graph, NodeIndexType node) - : Base::BaseStaticArcIterator( - graph.reverse_start_[node], graph.DirectArcLimit(node)), + IncidentArcIterator(const ReverseArcStaticGraph& graph, NodeIndexType node) + : Base::BaseStaticArcIterator(graph.reverse_start_[node], + graph.DirectArcLimit(node)), next_start_(graph.start_[node]), first_limit_(graph.ReverseArcLimit(node)) { if (index_ == first_limit_) index_ = next_start_; DCHECK(graph.IsNodeValid(node)); - DCHECK((index_ >= graph.reverse_start_[node] && index_ < first_limit_) - || (index_ >= next_start_)); + DCHECK((index_ >= graph.reverse_start_[node] && index_ < first_limit_) || + (index_ >= next_start_)); } - IncidentArcIterator(const ReverseArcStaticGraph &graph, - NodeIndexType node, ArcIndexType arc) + IncidentArcIterator(const ReverseArcStaticGraph& graph, NodeIndexType node, + ArcIndexType arc) : Base::BaseStaticArcIterator(arc, graph.DirectArcLimit(node)), next_start_(graph.start_[node]), first_limit_(graph.ReverseArcLimit(node)) { DCHECK(graph.IsNodeValid(node)); - DCHECK((index_ >= graph.reverse_start_[node] && index_ < first_limit_) - || (index_ >= next_start_)); + DCHECK((index_ >= graph.reverse_start_[node] && index_ < first_limit_) || + (index_ >= next_start_)); } void Next() { DCHECK(Base::BaseStaticArcIterator::Ok()); @@ -1709,55 +1678,56 @@ class ReverseArcStaticGraph // ReverseArcMixedGraph definition ------------------------------------------- -template -IntegerRange ReverseArcMixedGraph - ::OutgoingArcs(NodeIndexType node) const { +template +IntegerRange ReverseArcMixedGraph< + NodeIndexType, ArcIndexType>::OutgoingArcs(NodeIndexType node) const { return IntegerRange(start_[node], DirectArcLimit(node)); } -template -IntegerRange ReverseArcMixedGraph - ::OutgoingArcsStartingFrom(NodeIndexType node, ArcIndexType from) const { +template +IntegerRange +ReverseArcMixedGraph::OutgoingArcsStartingFrom( + NodeIndexType node, ArcIndexType from) const { return IntegerRange(from, DirectArcLimit(node)); } DECLARE_ARC_ITERATION(ReverseArcMixedGraph, Incoming, Base::kNilArc); DECLARE_ARC_ITERATION(ReverseArcMixedGraph, Incident, DirectArcLimit(node)); -template -ArcIndexType ReverseArcMixedGraph - ::OppositeArc(ArcIndexType arc) const { +template +ArcIndexType ReverseArcMixedGraph::OppositeArc( + ArcIndexType arc) const { DCHECK(IsArcValid(arc)); return ~arc; } -template -NodeIndexType ReverseArcMixedGraph - ::Head(ArcIndexType arc) const { +template +NodeIndexType ReverseArcMixedGraph::Head( + ArcIndexType arc) const { DCHECK(is_built_); DCHECK(IsArcValid(arc)); return head_[arc]; } -template -NodeIndexType ReverseArcMixedGraph - ::Tail(ArcIndexType arc) const { +template +NodeIndexType ReverseArcMixedGraph::Tail( + ArcIndexType arc) const { DCHECK(is_built_); return head_[OppositeArc(arc)]; } -template -void ReverseArcMixedGraph - ::ReserveNodes(NodeIndexType bound) { +template +void ReverseArcMixedGraph::ReserveNodes( + NodeIndexType bound) { DCHECK(!const_capacities_); DCHECK_GE(bound, num_nodes_); if (bound <= num_nodes_) return; node_capacity_ = bound; } -template -void ReverseArcMixedGraph - ::ReserveArcs(ArcIndexType bound) { +template +void ReverseArcMixedGraph::ReserveArcs( + ArcIndexType bound) { DCHECK(!const_capacities_); DCHECK_GE(bound, num_arcs_); if (bound <= num_arcs_) return; @@ -1765,17 +1735,17 @@ void ReverseArcMixedGraph head_.reserve(bound); } -template -void ReverseArcMixedGraph - ::AddNode(NodeIndexType node) { +template +void ReverseArcMixedGraph::AddNode( + NodeIndexType node) { if (node < num_nodes_) return; DCHECK(!const_capacities_ || node < node_capacity_); num_nodes_ = node + 1; } -template -ArcIndexType ReverseArcMixedGraph - ::AddArc(NodeIndexType tail, NodeIndexType head) { +template +ArcIndexType ReverseArcMixedGraph::AddArc( + NodeIndexType tail, NodeIndexType head) { AddNode(tail > head ? tail : head); // We inverse head and tail here because it is more convenient this way @@ -1785,9 +1755,9 @@ ArcIndexType ReverseArcMixedGraph return num_arcs_++; } -template -void ReverseArcMixedGraph - ::Build(std::vector *permutation) { +template +void ReverseArcMixedGraph::Build( + std::vector* permutation) { DCHECK(!is_built_); if (is_built_) return; is_built_ = true; @@ -1812,19 +1782,18 @@ void ReverseArcMixedGraph } } -template -class ReverseArcMixedGraph - ::OutgoingArcIterator : public Base::BaseStaticArcIterator { +template +class ReverseArcMixedGraph::OutgoingArcIterator + : public Base::BaseStaticArcIterator { public: - OutgoingArcIterator( - const ReverseArcMixedGraph &graph, NodeIndexType node) - : Base::BaseStaticArcIterator( - graph.start_[node], graph.DirectArcLimit(node)) { + OutgoingArcIterator(const ReverseArcMixedGraph& graph, NodeIndexType node) + : Base::BaseStaticArcIterator(graph.start_[node], + graph.DirectArcLimit(node)) { DCHECK(graph.is_built_); DCHECK(graph.IsNodeValid(node)); } - OutgoingArcIterator(const ReverseArcMixedGraph &graph, - NodeIndexType node, ArcIndexType arc) + OutgoingArcIterator(const ReverseArcMixedGraph& graph, NodeIndexType node, + ArcIndexType arc) : Base::BaseStaticArcIterator(arc, graph.DirectArcLimit(node)) { DCHECK(graph.is_built_); DCHECK(graph.IsNodeValid(node)); @@ -1832,29 +1801,26 @@ class ReverseArcMixedGraph } }; -template +template class ReverseArcMixedGraph::IncomingArcIterator { public: - IncomingArcIterator(const ReverseArcMixedGraph &graph, - NodeIndexType node) : graph_(&graph) { + IncomingArcIterator(const ReverseArcMixedGraph& graph, NodeIndexType node) + : graph_(&graph) { DCHECK(graph.is_built_); DCHECK(graph.IsNodeValid(node)); index_ = graph.reverse_start_[node]; } - IncomingArcIterator(const ReverseArcMixedGraph &graph, - NodeIndexType node, ArcIndexType arc) : graph_(&graph) { + IncomingArcIterator(const ReverseArcMixedGraph& graph, NodeIndexType node, + ArcIndexType arc) + : graph_(&graph) { DCHECK(graph.is_built_); DCHECK(graph.IsNodeValid(node)); DCHECK(arc == Base::kNilArc || arc < 0); DCHECK(arc == Base::kNilArc || graph.Tail(arc) == node); index_ = arc; } - bool Ok() const { - return index_ != Base::kNilArc; - } - ArcIndexType Index() const { - return index_; - } + bool Ok() const { return index_ != Base::kNilArc; } + ArcIndexType Index() const { return index_; } void Next() { DCHECK(Ok()); index_ = graph_->next_[~index_]; @@ -1863,15 +1829,15 @@ class ReverseArcMixedGraph::IncomingArcIterator { DECLARE_STL_ITERATOR_FUNCTIONS(IncomingArcIterator); private: - const ReverseArcMixedGraph *graph_; + const ReverseArcMixedGraph* graph_; ArcIndexType index_; }; -template +template class ReverseArcMixedGraph::IncidentArcIterator { public: - IncidentArcIterator(const ReverseArcMixedGraph &graph, - NodeIndexType node) : graph_(&graph) { + IncidentArcIterator(const ReverseArcMixedGraph& graph, NodeIndexType node) + : graph_(&graph) { DCHECK(graph.is_built_); DCHECK(graph.IsNodeValid(node)); index_ = graph.reverse_start_[node]; @@ -1881,8 +1847,9 @@ class ReverseArcMixedGraph::IncidentArcIterator { index_ = restart_; } } - IncidentArcIterator(const ReverseArcMixedGraph &graph, - NodeIndexType node, ArcIndexType arc) : graph_(&graph) { + IncidentArcIterator(const ReverseArcMixedGraph& graph, NodeIndexType node, + ArcIndexType arc) + : graph_(&graph) { DCHECK(graph.is_built_); DCHECK(graph.IsNodeValid(node)); index_ = arc; @@ -1894,9 +1861,7 @@ class ReverseArcMixedGraph::IncidentArcIterator { // Note that we always have limit_ <= Base::kNilArc. return index_ < limit_; } - ArcIndexType Index() const { - return index_; - } + ArcIndexType Index() const { return index_; } void Next() { DCHECK(Ok()); if (index_ < 0) { @@ -1912,7 +1877,7 @@ class ReverseArcMixedGraph::IncidentArcIterator { DECLARE_STL_ITERATOR_FUNCTIONS(IncidentArcIterator); private: - const ReverseArcMixedGraph *graph_; + const ReverseArcMixedGraph* graph_; ArcIndexType index_; ArcIndexType restart_; ArcIndexType limit_; diff --git a/src/graph/graphs.h b/src/graph/graphs.h index 342a100259..cd28dc9f70 100644 --- a/src/graph/graphs.h +++ b/src/graph/graphs.h @@ -23,7 +23,7 @@ namespace operations_research { // Since StarGraph does not have exactly the same interface as the other // graphs, we define a correspondance there. -template +template struct Graphs { typedef typename Graph::ArcIndex ArcIndex; typedef typename Graph::NodeIndex NodeIndex; @@ -39,15 +39,13 @@ struct Graphs { static ArcIndex ArcReservation(const Graph& graph) { return graph.arc_capacity(); } - static void Build(Graph* graph) { - graph->Build(); - } - static void Build(Graph* graph, std::vector *permutation) { + static void Build(Graph* graph) { graph->Build(); } + static void Build(Graph* graph, std::vector* permutation) { graph->Build(permutation); } }; -template<> +template <> struct Graphs { typedef operations_research::StarGraph Graph; #if defined(_MSC_VER) @@ -69,8 +67,8 @@ struct Graphs { static ArcIndex ArcReservation(const Graph& graph) { return graph.max_num_arcs(); } - static void Build(Graph *graph) {} - static void Build(Graph* graph, std::vector *permutation) { + static void Build(Graph* graph) {} + static void Build(Graph* graph, std::vector* permutation) { permutation->clear(); } }; diff --git a/src/graph/hamiltonian_path.h b/src/graph/hamiltonian_path.h index 83a1294869..2efb8353fb 100644 --- a/src/graph/hamiltonian_path.h +++ b/src/graph/hamiltonian_path.h @@ -90,17 +90,19 @@ namespace operations_research { typedef int PathNodeIndex; -template class HamiltonianPathSolver { -// HamiltonianPathSolver computes a minimum Hamiltonian path over a graph -// defined by a cost matrix. The cost matrix need not be symmetric. -// The Hamiltonian path can be closed, in this case it's a Hamiltonian cycle, -// i.e. the algorithm solves the Travelling Salesman Problem. -// Example: +template +class HamiltonianPathSolver { + // HamiltonianPathSolver computes a minimum Hamiltonian path over a graph + // defined by a cost matrix. The cost matrix need not be symmetric. + // The Hamiltonian path can be closed, in this case it's a Hamiltonian cycle, + // i.e. the algorithm solves the Travelling Salesman Problem. + // Example: -// std::vector > cost_mat; -// ... fill in cost matrix -// HamiltonianPathSolver mhp(cost_mat); // no computation done -// printf("%d\n", mhp.TravelingSalesmanCost()); // computation done and stored + // std::vector > cost_mat; + // ... fill in cost matrix + // HamiltonianPathSolver mhp(cost_mat); // no computation done + // printf("%d\n", mhp.TravelingSalesmanCost()); // computation done and + // stored public: // Currently in 2010, 26 is the maximum you can solve with @@ -156,21 +158,20 @@ template class HamiltonianPathSolver { void Free(); // Computes path by looking at the information in memory_. - void Path(PathNodeIndex end, - std::vector* path); + void Path(PathNodeIndex end, std::vector* path); // Does all the Dynamic Progamming iterations. Calls ComputeShortestPath. void Solve(); - bool robust_; - bool triangle_inequality_ok_; - bool robustness_checked_; - bool triangle_inequality_checked_; - bool solved_; - PathNodeIndex num_nodes_; - T** cost_; - NodeSet two_power_num_nodes_; - T** memory_; + bool robust_; + bool triangle_inequality_ok_; + bool robustness_checked_; + bool triangle_inequality_checked_; + bool solved_; + PathNodeIndex num_nodes_; + T** cost_; + NodeSet two_power_num_nodes_; + T** memory_; }; static const int kHamiltonianPathSolverPadValue = 1557; @@ -189,26 +190,26 @@ HamiltonianPathSolver::HamiltonianPathSolver(const std::vector Init(cost); } -template HamiltonianPathSolver::~HamiltonianPathSolver() { +template +HamiltonianPathSolver::~HamiltonianPathSolver() { Free(); } template void HamiltonianPathSolver::Free() { if (num_nodes_ > 0) { - delete [] memory_[0]; - delete [] memory_; + delete[] memory_[0]; + delete[] memory_; for (int i = 0; i < num_nodes_; ++i) { - delete [] cost_[i]; + delete[] cost_[i]; } - delete [] cost_; + delete[] cost_; } } - - -template void HamiltonianPathSolver:: - ChangeCostMatrix(const std::vector >& cost) { +template +void HamiltonianPathSolver::ChangeCostMatrix( + const std::vector >& cost) { robustness_checked_ = false; triangle_inequality_checked_ = false; solved_ = false; @@ -264,8 +265,8 @@ void HamiltonianPathSolver::CheckRobustness() { if (min_cost < 0) { robust_ = false; } else { - robust_ = (min_cost > - num_nodes_ * max_cost * std::numeric_limits::epsilon()); + robust_ = + (min_cost > num_nodes_ * max_cost * std::numeric_limits::epsilon()); } robustness_checked_ = true; } @@ -291,7 +292,7 @@ template void HamiltonianPathSolver::Init(const std::vector >& cost) { num_nodes_ = cost.size(); if (num_nodes_ > 0) { - cost_ = new T*[num_nodes_]; + cost_ = new T* [num_nodes_]; for (int i = 0; i < num_nodes_; ++i) { cost_[i] = new T[num_nodes_]; } @@ -308,12 +309,12 @@ void HamiltonianPathSolver::Init(const std::vector >& cost) { // number. // This results in a 20 to 30% gain depending on architectures. - const int padded_size = two_power_num_nodes_ - + kHamiltonianPathSolverPadValue; - memory_ = new T * [num_nodes_]; + const int padded_size = + two_power_num_nodes_ + kHamiltonianPathSolverPadValue; + memory_ = new T* [num_nodes_]; memory_[0] = new T[num_nodes_ * padded_size]; for (int i = 1; i < num_nodes_; ++i) { - memory_[i] = memory_[i-1] + padded_size; + memory_[i] = memory_[i - 1] + padded_size; } } } @@ -330,7 +331,7 @@ void HamiltonianPathSolver::ComputeShortestPath(NodeSet subset, const NodeSet first_singleton = LeastSignificantBitWord32(subset); const PathNodeIndex first_src = - LeastSignificantBitPosition32(first_singleton); + LeastSignificantBitPosition32(first_singleton); NodeSet start_subset = subset - first_singleton; T min_cost = memory_[first_src][start_subset] + cost_[first_src][dest]; NodeSet copy = start_subset; @@ -347,7 +348,8 @@ void HamiltonianPathSolver::ComputeShortestPath(NodeSet subset, memory_[dest][subset] = min_cost; } -template void HamiltonianPathSolver::Solve() { +template +void HamiltonianPathSolver::Solve() { if (solved_) return; for (PathNodeIndex dest = 0; dest < num_nodes_; ++dest) { memory_[dest][0] = cost_[0][dest]; @@ -360,8 +362,8 @@ template void HamiltonianPathSolver::Solve() { solved_ = true; } - -template T HamiltonianPathSolver::HamiltonianCost() { +template +T HamiltonianPathSolver::HamiltonianCost() { if (num_nodes_ <= 1) { return 0; } @@ -369,8 +371,8 @@ template T HamiltonianPathSolver::HamiltonianCost() { return memory_[num_nodes_ - 1][two_power_num_nodes_ - 1]; } -template void HamiltonianPathSolver:: - HamiltonianPath(std::vector* path) { +template +void HamiltonianPathSolver::HamiltonianPath(std::vector* path) { if (num_nodes_ <= 1) { path->resize(1); (*path)[0] = 0; @@ -426,12 +428,12 @@ void HamiltonianPathSolver::Path(PathNodeIndex end, const PathNodeIndex src = LeastSignificantBitPosition32(singleton); const NodeSet incumbent_set = current_set - singleton; const double current_cost = memory_[dest][current_set]; - const double incumbent_cost = memory_[src][incumbent_set] - + cost_[src][dest]; + const double incumbent_cost = + memory_[src][incumbent_set] + cost_[src][dest]; // We take precision into account in case T is float or double. // There is no visible penalty in the case T is an integer type. - if (fabs(current_cost - incumbent_cost) - <= std::numeric_limits::epsilon() * current_cost) { + if (fabs(current_cost - incumbent_cost) <= + std::numeric_limits::epsilon() * current_cost) { current_set = incumbent_set; dest = src; (*path)[i] = dest; @@ -443,7 +445,8 @@ void HamiltonianPathSolver::Path(PathNodeIndex end, } } -template T HamiltonianPathSolver::TravelingSalesmanCost() { +template +T HamiltonianPathSolver::TravelingSalesmanCost() { if (num_nodes_ <= 1) { return 0; } @@ -451,8 +454,9 @@ template T HamiltonianPathSolver::TravelingSalesmanCost() { return memory_[0][two_power_num_nodes_ - 1]; } -template void HamiltonianPathSolver:: - TravelingSalesmanPath(std::vector* path) { +template +void HamiltonianPathSolver::TravelingSalesmanPath( + std::vector* path) { if (num_nodes_ <= 1) { path->resize(1); (*path)[0] = 0; diff --git a/src/graph/linear_assignment.h b/src/graph/linear_assignment.h index 7dbf602e79..0c3547f59d 100644 --- a/src/graph/linear_assignment.h +++ b/src/graph/linear_assignment.h @@ -188,7 +188,6 @@ #include "graph/ebert_graph.h" #include "util/permutation.h" - #ifndef SWIG DECLARE_int64(assignment_alpha); DECLARE_int32(assignment_progress_logging_period); @@ -198,7 +197,8 @@ DECLARE_bool(assignment_stack_order); namespace operations_research { // This class does not take ownership of its underlying graph. -template class LinearSumAssignment { +template +class LinearSumAssignment { public: // Constructor for the case in which we will build the graph // incrementally as we discover arc costs, as might be done with any @@ -223,9 +223,7 @@ template class LinearSumAssignment { // Sets the cost-scaling divisor, i.e., the amount by which we // divide the scaling parameter on each iteration. - void SetCostScalingDivisor(CostValue factor) { - alpha_ = factor; - } + void SetCostScalingDivisor(CostValue factor) { alpha_ = factor; } // Returns a permutation cycle handler that can be passed to the // TransformToForwardStaticGraph method so that arc costs get @@ -258,9 +256,7 @@ template class LinearSumAssignment { // expose them to clients so that client code that doesn't have // direct access to the graph can learn about the optimum assignment // once it is computed. - inline NodeIndex Head(ArcIndex arc) const { - return graph_->Head(arc); - } + inline NodeIndex Head(ArcIndex arc) const { return graph_->Head(arc); } // Returns the original arc cost for use by a client that's // iterating over the optimum assignment. @@ -270,8 +266,7 @@ template class LinearSumAssignment { } // Sets the cost of an arc already present in the given graph. - virtual void SetArcCost(ArcIndex arc, - CostValue cost); + virtual void SetArcCost(ArcIndex arc, CostValue cost); // Completes initialization after the problem is fully specified. // Returns true if we successfully prove that arithmetic @@ -309,9 +304,7 @@ template class LinearSumAssignment { // Returns the number of nodes on the left side of the given // problem. - virtual NodeIndex NumLeftNodes() const { - return num_left_nodes_; - } + virtual NodeIndex NumLeftNodes() const { return num_left_nodes_; } // Returns the arc through which the given node is matched. inline ArcIndex GetAssignmentArc(NodeIndex left_node) const { @@ -333,19 +326,16 @@ template class LinearSumAssignment { return Head(matching_arc); } - std::string StatsString() const { - return total_stats_.StatsString(); - } + std::string StatsString() const { return total_stats_.StatsString(); } class BipartiteLeftNodeIterator { public: BipartiteLeftNodeIterator(const GraphType& graph, NodeIndex num_left_nodes) - : num_left_nodes_(num_left_nodes), - node_iterator_(graph) { } + : num_left_nodes_(num_left_nodes), node_iterator_(graph) {} explicit BipartiteLeftNodeIterator(const LinearSumAssignment& assignment) : num_left_nodes_(assignment.NumLeftNodes()), - node_iterator_(assignment.Graph()) { } + node_iterator_(assignment.Graph()) {} NodeIndex Index() const { return node_iterator_.Index(); } @@ -362,11 +352,7 @@ template class LinearSumAssignment { private: struct Stats { - Stats() - : pushes_(0), - double_pushes_(0), - relabelings_(0), - refinements_(0) { } + Stats() : pushes_(0), double_pushes_(0), relabelings_(0), refinements_(0) {} void Clear() { pushes_ = 0; double_pushes_ = 0; @@ -380,12 +366,10 @@ template class LinearSumAssignment { refinements_ += that.refinements_; } std::string StatsString() const { - return StringPrintf("%lld refinements; %lld relabelings; " - "%lld double pushes; %lld pushes", - refinements_, - relabelings_, - double_pushes_, - pushes_); + return StringPrintf( + "%lld refinements; %lld relabelings; " + "%lld double pushes; %lld pushes", + refinements_, relabelings_, double_pushes_, pushes_); } int64 pushes_; int64 double_pushes_; @@ -406,13 +390,9 @@ template class LinearSumAssignment { public: virtual ~ActiveNodeStack() {} - virtual bool Empty() const { - return v_.empty(); - } + virtual bool Empty() const { return v_.empty(); } - virtual void Add(NodeIndex node) { - v_.push_back(node); - } + virtual void Add(NodeIndex node) { v_.push_back(node); } virtual NodeIndex Get() { DCHECK(!Empty()); @@ -429,17 +409,13 @@ template class LinearSumAssignment { public: virtual ~ActiveNodeQueue() {} - virtual bool Empty() const { - return q_.empty(); - } + virtual bool Empty() const { return q_.empty(); } - virtual void Add(NodeIndex node) { - q_.push_front(node); - } + virtual void Add(NodeIndex node) { q_.push_front(node); } virtual NodeIndex Get() { DCHECK(!Empty()); - NodeIndex result= q_.back(); + NodeIndex result = q_.back(); q_.pop_back(); return result; } @@ -971,15 +947,15 @@ LinearSumAssignment::LinearSumAssignment( slack_relabeling_price_(0), largest_scaled_cost_magnitude_(0), total_excess_(0), - price_(num_left_nodes + GraphType::kFirstNode, - 2 * num_left_nodes - 1), + price_(num_left_nodes + GraphType::kFirstNode, 2 * num_left_nodes - 1), matched_arc_(GraphType::kFirstNode, num_left_nodes - 1), matched_node_(num_left_nodes, 2 * num_left_nodes - 1), scaled_arc_cost_(GraphType::kFirstArc, graph.max_end_arc_index() - 1), - active_nodes_( - FLAGS_assignment_stack_order ? - static_cast(new ActiveNodeStack()) : - static_cast(new ActiveNodeQueue())) { } + active_nodes_(FLAGS_assignment_stack_order + ? static_cast( + new ActiveNodeStack()) + : static_cast( + new ActiveNodeQueue())) {} template LinearSumAssignment::LinearSumAssignment( @@ -994,40 +970,36 @@ LinearSumAssignment::LinearSumAssignment( slack_relabeling_price_(0), largest_scaled_cost_magnitude_(0), total_excess_(0), - price_(num_left_nodes + GraphType::kFirstNode, - 2 * num_left_nodes - 1), + price_(num_left_nodes + GraphType::kFirstNode, 2 * num_left_nodes - 1), matched_arc_(GraphType::kFirstNode, GraphType::kFirstNode + num_left_nodes - 1), matched_node_(num_left_nodes, 2 * num_left_nodes - 1), scaled_arc_cost_(GraphType::kFirstArc, GraphType::kFirstArc + num_arcs - 1), - active_nodes_( - FLAGS_assignment_stack_order ? - static_cast(new ActiveNodeStack()) : - static_cast(new ActiveNodeQueue())) { } + active_nodes_(FLAGS_assignment_stack_order + ? static_cast( + new ActiveNodeStack()) + : static_cast( + new ActiveNodeQueue())) {} template void LinearSumAssignment::SetArcCost(ArcIndex arc, CostValue cost) { - DCHECK(graph_ == NULL || - graph_->CheckArcValidity(arc)); + DCHECK(graph_ == NULL || graph_->CheckArcValidity(arc)); if (graph_ != NULL) { NodeIndex head = Head(arc); DCHECK_LE(num_left_nodes_, head); } cost *= cost_scaling_factor_; const CostValue cost_magnitude = abs(cost); - largest_scaled_cost_magnitude_ = std::max(largest_scaled_cost_magnitude_, - cost_magnitude); + largest_scaled_cost_magnitude_ = + std::max(largest_scaled_cost_magnitude_, cost_magnitude); scaled_arc_cost_.Set(arc, cost); } template -class CostValueCycleHandler - : public PermutationCycleHandler { +class CostValueCycleHandler : public PermutationCycleHandler { public: - explicit CostValueCycleHandler(CostArray* cost) - : temp_(0), - cost_(cost) { } + explicit CostValueCycleHandler(CostArray* cost) : temp_(0), cost_(cost) {} virtual void SetTempFromIndex(ArcIndexType source) { temp_ = cost_->Value(source); @@ -1042,7 +1014,7 @@ class CostValueCycleHandler cost_->Set(destination, temp_); } - virtual ~CostValueCycleHandler() { } + virtual ~CostValueCycleHandler() {} private: CostValue temp_; @@ -1057,10 +1029,10 @@ class CostValueCycleHandler // instantiation of member templates with function-scoped types as // template parameters, which in turn is because those function-scoped // types lack linkage. -template class ArcIndexOrderingByTailNode { +template +class ArcIndexOrderingByTailNode { public: - explicit ArcIndexOrderingByTailNode(const GraphType& graph) - : graph_(graph) { } + explicit ArcIndexOrderingByTailNode(const GraphType& graph) : graph_(graph) {} // Says ArcIndex a is less than ArcIndex b if arc a's tail is less // than arc b's tail. If their tails are equal, orders according to @@ -1094,8 +1066,8 @@ void LinearSumAssignment::OptimizeGraphLayout(GraphType* graph) { // nonsense. DCHECK_EQ(graph_, graph); const ArcIndexOrderingByTailNode compare(*graph_); - CostValueCycleHandler - cycle_handler(&scaled_arc_cost_); + CostValueCycleHandler cycle_handler( + &scaled_arc_cost_); TailArrayManager tail_array_manager(graph); tail_array_manager.BuildTailArrayFromAdjacencyListsIfForwardGraph(); graph->GroupForwardArcsByFunctor(compare, &cycle_handler); @@ -1124,8 +1096,8 @@ bool LinearSumAssignment::UpdateEpsilon() { // For production code that checks whether a left-side node is active. template -inline bool LinearSumAssignment::IsActive( - NodeIndex left_node) const { +inline bool LinearSumAssignment::IsActive(NodeIndex left_node) + const { DCHECK_LT(left_node, num_left_nodes_); return matched_arc_[left_node] == GraphType::kNilArc; } @@ -1134,8 +1106,8 @@ inline bool LinearSumAssignment::IsActive( // so that method can assert that its argument is a left-side node, // while for debugging we need to be able to test any node. template -inline bool LinearSumAssignment::IsActiveForDebugging( - NodeIndex node) const { +inline bool LinearSumAssignment::IsActiveForDebugging(NodeIndex node) + const { if (node < num_left_nodes_) { return IsActive(node); } else { @@ -1147,8 +1119,7 @@ template void LinearSumAssignment::InitializeActiveNodeContainer() { DCHECK(active_nodes_->Empty()); for (BipartiteLeftNodeIterator node_it(*graph_, num_left_nodes_); - node_it.Ok(); - node_it.Next()) { + node_it.Ok(); node_it.Next()) { const NodeIndex node = node_it.Index(); if (IsActive(node)) { active_nodes_->Add(node); @@ -1170,8 +1141,7 @@ template void LinearSumAssignment::SaturateNegativeArcs() { total_excess_ = 0; for (BipartiteLeftNodeIterator node_it(*graph_, num_left_nodes_); - node_it.Ok(); - node_it.Next()) { + node_it.Ok(); node_it.Next()) { const NodeIndex node = node_it.Index(); if (IsActive(node)) { // This can happen in the first iteration when nothing is @@ -1297,8 +1267,9 @@ LinearSumAssignment::BestArcAndGap(NodeIndex left_node) const { // // Requires the precondition, explicitly computed in FinalizeSetup(), // that every left-side node has at least one incident arc. -template inline CostValue -LinearSumAssignment::ImplicitPrice(NodeIndex left_node) const { +template +inline CostValue LinearSumAssignment::ImplicitPrice( + NodeIndex left_node) const { DCHECK_GT(num_left_nodes_, left_node); DCHECK_GT(epsilon_, 0); typename GraphType::OutgoingArcIterator arc_it(*graph_, left_node); @@ -1334,8 +1305,7 @@ LinearSumAssignment::ImplicitPrice(NodeIndex left_node) const { // Only for debugging. template bool LinearSumAssignment::AllMatched() const { - for (typename GraphType::NodeIterator node_it(*graph_); - node_it.Ok(); + for (typename GraphType::NodeIterator node_it(*graph_); node_it.Ok(); node_it.Next()) { if (IsActiveForDebugging(node_it.Index())) { return false; @@ -1348,18 +1318,15 @@ bool LinearSumAssignment::AllMatched() const { template bool LinearSumAssignment::EpsilonOptimal() const { for (BipartiteLeftNodeIterator node_it(*graph_, num_left_nodes_); - node_it.Ok(); - node_it.Next()) { + node_it.Ok(); node_it.Next()) { const NodeIndex left_node = node_it.Index(); // Get the implicit price of left_node and make sure the reduced // costs of left_node's incident arcs are in bounds. CostValue left_node_price = ImplicitPrice(left_node); for (typename GraphType::OutgoingArcIterator arc_it(*graph_, left_node); - arc_it.Ok(); - arc_it.Next()) { + arc_it.Ok(); arc_it.Next()) { const ArcIndex arc = arc_it.Index(); - const CostValue reduced_cost = - left_node_price + PartialReducedCost(arc); + const CostValue reduced_cost = left_node_price + PartialReducedCost(arc); // Note the asymmetric definition of epsilon-optimality that we // use because it means we can saturate all admissible arcs in // the beginning of Refine() just by unmatching all matched @@ -1389,10 +1356,9 @@ bool LinearSumAssignment::FinalizeSetup() { // epsilon_ must be greater than kMinEpsilon so that in the case // where the largest arc cost is zero, we still do a Refine() // iteration. - epsilon_ = std::max(largest_scaled_cost_magnitude_, - kMinEpsilon + 1); - VLOG(2) << "Largest given cost magnitude: " << - largest_scaled_cost_magnitude_ / cost_scaling_factor_; + epsilon_ = std::max(largest_scaled_cost_magnitude_, kMinEpsilon + 1); + VLOG(2) << "Largest given cost magnitude: " + << largest_scaled_cost_magnitude_ / cost_scaling_factor_; // Initialize left-side node-indexed arrays and check incidence // precondition. typename GraphType::NodeIterator node_it(*graph_); @@ -1420,10 +1386,9 @@ bool LinearSumAssignment::FinalizeSetup() { CostValue old_error_parameter = epsilon_; do { new_error_parameter = NewEpsilon(old_error_parameter); - double_price_lower_bound -= 2.0 * - static_cast(PriceChangeBound(old_error_parameter, - new_error_parameter, - &in_range)); + double_price_lower_bound -= + 2.0 * static_cast(PriceChangeBound( + old_error_parameter, new_error_parameter, &in_range)); old_error_parameter = new_error_parameter; } while (new_error_parameter != kMinEpsilon); const double limit = @@ -1482,9 +1447,7 @@ CostValue LinearSumAssignment::GetCost() const { // an optimum assignment. DCHECK(success_); CostValue cost = 0; - for (BipartiteLeftNodeIterator node_it(*this); - node_it.Ok(); - node_it.Next()) { + for (BipartiteLeftNodeIterator node_it(*this); node_it.Ok(); node_it.Next()) { cost += GetAssignmentCost(node_it.Index()); } return cost; diff --git a/src/graph/max_flow.cc b/src/graph/max_flow.cc index 63816997c9..80155b9da6 100644 --- a/src/graph/max_flow.cc +++ b/src/graph/max_flow.cc @@ -22,8 +22,8 @@ namespace operations_research { SimpleMaxFlow::SimpleMaxFlow() : num_nodes_(0) {} -ArcIndex SimpleMaxFlow::AddArcWithCapacity( - NodeIndex tail, NodeIndex head, FlowQuantity capacity) { +ArcIndex SimpleMaxFlow::AddArcWithCapacity(NodeIndex tail, NodeIndex head, + FlowQuantity capacity) { const ArcIndex num_arcs = arc_tail_.size(); num_nodes_ = std::max(num_nodes_, tail + 1); num_nodes_ = std::max(num_nodes_, head + 1); @@ -33,21 +33,13 @@ ArcIndex SimpleMaxFlow::AddArcWithCapacity( return num_arcs; } -NodeIndex SimpleMaxFlow::NumNodes() const { - return num_nodes_; -} +NodeIndex SimpleMaxFlow::NumNodes() const { return num_nodes_; } -ArcIndex SimpleMaxFlow::NumArcs() const { - return arc_tail_.size(); -} +ArcIndex SimpleMaxFlow::NumArcs() const { return arc_tail_.size(); } -NodeIndex SimpleMaxFlow::Tail(ArcIndex arc) const { - return arc_tail_[arc]; -} +NodeIndex SimpleMaxFlow::Tail(ArcIndex arc) const { return arc_tail_[arc]; } -NodeIndex SimpleMaxFlow::Head(ArcIndex arc) const { - return arc_head_[arc]; -} +NodeIndex SimpleMaxFlow::Head(ArcIndex arc) const { return arc_head_[arc]; } FlowQuantity SimpleMaxFlow::Capacity(ArcIndex arc) const { return arc_capacity_[arc]; @@ -72,8 +64,8 @@ SimpleMaxFlow::Status SimpleMaxFlow::Solve(NodeIndex source, NodeIndex sink) { underlying_graph_->AddArc(arc_tail_[arc], arc_head_[arc]); } underlying_graph_->Build(&arc_permutation_); - underlying_max_flow_.reset(new GenericMaxFlow( - underlying_graph_.get(), source, sink)); + underlying_max_flow_.reset( + new GenericMaxFlow(underlying_graph_.get(), source, sink)); for (ArcIndex arc = 0; arc < num_arcs; ++arc) { ArcIndex permuted_arc = arc < arc_permutation_.size() ? arc_permutation_[arc] : arc; @@ -90,22 +82,23 @@ SimpleMaxFlow::Status SimpleMaxFlow::Solve(NodeIndex source, NodeIndex sink) { // Translate the GenericMaxFlow::Status. It is different because NOT_SOLVED // does not make sense in the simple api. switch (underlying_max_flow_->status()) { - case GenericMaxFlow::NOT_SOLVED : return BAD_RESULT; - case GenericMaxFlow::OPTIMAL : return OPTIMAL; - case GenericMaxFlow::POSSIBLE_OVERFLOW : return POSSIBLE_OVERFLOW; - case GenericMaxFlow::BAD_INPUT : return BAD_INPUT; - case GenericMaxFlow::BAD_RESULT : return BAD_RESULT; + case GenericMaxFlow::NOT_SOLVED: + return BAD_RESULT; + case GenericMaxFlow::OPTIMAL: + return OPTIMAL; + case GenericMaxFlow::POSSIBLE_OVERFLOW: + return POSSIBLE_OVERFLOW; + case GenericMaxFlow::BAD_INPUT: + return BAD_INPUT; + case GenericMaxFlow::BAD_RESULT: + return BAD_RESULT; } return BAD_RESULT; } -FlowQuantity SimpleMaxFlow::OptimalFlow() const { - return optimal_flow_; -} +FlowQuantity SimpleMaxFlow::OptimalFlow() const { return optimal_flow_; } -FlowQuantity SimpleMaxFlow::Flow(ArcIndex arc) const { - return arc_flow_[arc]; -} +FlowQuantity SimpleMaxFlow::Flow(ArcIndex arc) const { return arc_flow_[arc]; } void SimpleMaxFlow::GetSourceSideMinCut(std::vector* result) { if (underlying_max_flow_.get() == NULL) return; @@ -117,9 +110,8 @@ void SimpleMaxFlow::GetSinkSideMinCut(std::vector* result) { underlying_max_flow_->GetSinkSideMinCut(result); } -template -GenericMaxFlow::GenericMaxFlow(const Graph* graph, - NodeIndex source, +template +GenericMaxFlow::GenericMaxFlow(const Graph* graph, NodeIndex source, NodeIndex sink) : graph_(graph), node_excess_(), @@ -156,7 +148,7 @@ GenericMaxFlow::GenericMaxFlow(const Graph* graph, } } -template +template bool GenericMaxFlow::CheckInputConsistency() const { SCOPED_TIME_STAT(&stats_); bool ok = true; @@ -168,9 +160,9 @@ bool GenericMaxFlow::CheckInputConsistency() const { return ok; } -template -void GenericMaxFlow::SetArcCapacity( - ArcIndex arc, FlowQuantity new_capacity) { +template +void GenericMaxFlow::SetArcCapacity(ArcIndex arc, + FlowQuantity new_capacity) { SCOPED_TIME_STAT(&stats_); DCHECK_LE(0, new_capacity); DCHECK(IsArcDirect(arc)); @@ -202,7 +194,7 @@ void GenericMaxFlow::SetArcCapacity( } } -template +template void GenericMaxFlow::SetArcFlow(ArcIndex arc, FlowQuantity new_flow) { SCOPED_TIME_STAT(&stats_); DCHECK(IsArcValid(arc)); @@ -218,23 +210,23 @@ void GenericMaxFlow::SetArcFlow(ArcIndex arc, FlowQuantity new_flow) { status_ = NOT_SOLVED; } -template +template void GenericMaxFlow::GetSourceSideMinCut(std::vector* result) { ComputeReachableNodes(source_, result); } -template +template void GenericMaxFlow::GetSinkSideMinCut(std::vector* result) { ComputeReachableNodes(sink_, result); } -template +template bool GenericMaxFlow::CheckResult() const { SCOPED_TIME_STAT(&stats_); bool ok = true; if (node_excess_[source_] != -node_excess_[sink_]) { - LOG(DFATAL) << "-node_excess_[source_] = " << -node_excess_[source_] - << " != node_excess_[sink_] = " << node_excess_[sink_]; + LOG(DFATAL) << "-node_excess_[source_] = " << -node_excess_[source_] + << " != node_excess_[sink_] = " << node_excess_[sink_]; ok = false; } for (NodeIndex node = 0; node < graph_->num_nodes(); ++node) { @@ -251,26 +243,26 @@ bool GenericMaxFlow::CheckResult() const { const FlowQuantity direct_capacity = residual_arc_capacity_[arc]; const FlowQuantity opposite_capacity = residual_arc_capacity_[opposite]; if (direct_capacity < 0) { - LOG(DFATAL) << "residual_arc_capacity_[" << arc << "] = " - << direct_capacity << " < 0"; + LOG(DFATAL) << "residual_arc_capacity_[" << arc + << "] = " << direct_capacity << " < 0"; ok = false; } if (opposite_capacity < 0) { - LOG(DFATAL) << "residual_arc_capacity_[" << opposite << "] = " - << opposite_capacity << " < 0"; + LOG(DFATAL) << "residual_arc_capacity_[" << opposite + << "] = " << opposite_capacity << " < 0"; ok = false; } // The initial capacity of the direct arcs is non-negative. if (direct_capacity + opposite_capacity < 0) { - LOG(DFATAL) << "initial capacity [" << arc << "] = " - << direct_capacity + opposite_capacity << " < 0"; + LOG(DFATAL) << "initial capacity [" << arc + << "] = " << direct_capacity + opposite_capacity << " < 0"; ok = false; } } return ok; } -template +template bool GenericMaxFlow::CheckRelabelPrecondition(NodeIndex node) const { DCHECK(IsActive(node)); for (IncidentArcIterator it(*graph_, node); it.Ok(); it.Next()) { @@ -280,23 +272,23 @@ bool GenericMaxFlow::CheckRelabelPrecondition(NodeIndex node) const { return true; } -template -std::string GenericMaxFlow::DebugString( - const std::string& context, ArcIndex arc) const { +template +std::string GenericMaxFlow::DebugString(const std::string& context, + ArcIndex arc) const { const NodeIndex tail = Tail(arc); const NodeIndex head = Head(arc); - return StringPrintf("%s Arc %d, from %d to %d, " - "Capacity = %lld, Residual capacity = %lld, " - "Flow = residual capacity for reverse arc = %lld, " - "Height(tail) = %d, Height(head) = %d, " - "Excess(tail) = %lld, Excess(head) = %lld", - context.c_str(), arc, tail, head, Capacity(arc), - residual_arc_capacity_[arc], Flow(arc), - node_potential_[tail], node_potential_[head], - node_excess_[tail], node_excess_[head]); + return StringPrintf( + "%s Arc %d, from %d to %d, " + "Capacity = %lld, Residual capacity = %lld, " + "Flow = residual capacity for reverse arc = %lld, " + "Height(tail) = %d, Height(head) = %d, " + "Excess(tail) = %lld, Excess(head) = %lld", + context.c_str(), arc, tail, head, Capacity(arc), + residual_arc_capacity_[arc], Flow(arc), node_potential_[tail], + node_potential_[head], node_excess_[tail], node_excess_[head]); } -template +template bool GenericMaxFlow::Solve() { status_ = NOT_SOLVED; if (check_input_ && !CheckInputConsistency()) { @@ -335,7 +327,7 @@ bool GenericMaxFlow::Solve() { return true; } -template +template void GenericMaxFlow::InitializePreflow() { SCOPED_TIME_STAT(&stats_); // InitializePreflow() clears the whole flow that could have been computed @@ -362,7 +354,7 @@ void GenericMaxFlow::InitializePreflow() { } } -template +template void GenericMaxFlow::PushFlowExcessBackToSource() { SCOPED_TIME_STAT(&stats_); const NodeIndex num_nodes = graph_->num_nodes(); @@ -426,8 +418,8 @@ void GenericMaxFlow::PushFlowExcessBackToSource() { // The node is a new unexplored node, add all its outgoing arcs with // positive flow to the stack and go deeper in the dfs. DCHECK(!stored[node]); - DCHECK(index_branch.empty() - || (arc_stack.size() - 1 > index_branch.back())); + DCHECK(index_branch.empty() || + (arc_stack.size() - 1 > index_branch.back())); visited[node] = true; index_branch.push_back(arc_stack.size() - 1); @@ -444,8 +436,8 @@ void GenericMaxFlow::PushFlowExcessBackToSource() { // arc_stack[index_branch[cycle_begin]] will be the first arc on the // cycle. int cycle_begin = index_branch.size(); - while (cycle_begin > 0 - && Head(arc_stack[index_branch[cycle_begin - 1]]) != head) { + while (cycle_begin > 0 && + Head(arc_stack[index_branch[cycle_begin - 1]]) != head) { --cycle_begin; } @@ -500,14 +492,14 @@ void GenericMaxFlow::PushFlowExcessBackToSource() { // Return the flow to the sink. Note that the sink_ and the source_ are not // stored in reverse_topological_order. - for (int i = 0 ; i < reverse_topological_order.size(); i++) { + for (int i = 0; i < reverse_topological_order.size(); i++) { const NodeIndex node = reverse_topological_order[i]; if (node_excess_[node] == 0) continue; for (IncomingArcIterator it(*graph_, node); it.Ok(); it.Next()) { const ArcIndex arc = it.Index(); if (residual_arc_capacity_[arc] > 0) { - const FlowQuantity flow = std::min( - node_excess_[node], residual_arc_capacity_[arc]); + const FlowQuantity flow = + std::min(node_excess_[node], residual_arc_capacity_[arc]); PushFlow(flow, arc); if (node_excess_[node] == 0) break; } @@ -517,7 +509,7 @@ void GenericMaxFlow::PushFlowExcessBackToSource() { DCHECK_EQ(-node_excess_[source_], node_excess_[sink_]); } -template +template void GenericMaxFlow::GlobalUpdate() { SCOPED_TIME_STAT(&stats_); bfs_queue_.clear(); @@ -571,8 +563,8 @@ void GenericMaxFlow::GlobalUpdate() { // Note(user): I haven't seen this anywhere in the literature. // TODO(user): Investigate more and maybe write a publication :) if (node_excess_[head] > 0) { - const FlowQuantity flow = std::min( - node_excess_[head], residual_arc_capacity_[opposite_arc]); + const FlowQuantity flow = + std::min(node_excess_[head], residual_arc_capacity_[opposite_arc]); PushFlow(flow, opposite_arc); // If the arc became saturated, it is no longer in the residual @@ -619,7 +611,7 @@ void GenericMaxFlow::GlobalUpdate() { } } -template +template bool GenericMaxFlow::SaturateOutgoingArcsFromSource() { SCOPED_TIME_STAT(&stats_); const NodeIndex num_nodes = graph_->num_nodes(); @@ -661,7 +653,7 @@ bool GenericMaxFlow::SaturateOutgoingArcsFromSource() { return flow_pushed; } -template +template void GenericMaxFlow::PushFlow(FlowQuantity flow, ArcIndex arc) { SCOPED_TIME_STAT(&stats_); // TODO(user): Do not allow a zero flow after fixing the UniformMaxFlow code. @@ -683,7 +675,7 @@ void GenericMaxFlow::PushFlow(FlowQuantity flow, ArcIndex arc) { node_excess_[Head(arc)] += flow; } -template +template void GenericMaxFlow::InitializeActiveNodeContainer() { SCOPED_TIME_STAT(&stats_); DCHECK(IsEmptyActiveNodeContainer()); @@ -698,7 +690,7 @@ void GenericMaxFlow::InitializeActiveNodeContainer() { } } -template +template void GenericMaxFlow::Refine() { SCOPED_TIME_STAT(&stats_); // Usually SaturateOutgoingArcsFromSource() will saturate all the arcs from @@ -728,7 +720,7 @@ void GenericMaxFlow::Refine() { } } -template +template void GenericMaxFlow::RefineWithGlobalUpdate() { SCOPED_TIME_STAT(&stats_); @@ -781,15 +773,14 @@ void GenericMaxFlow::RefineWithGlobalUpdate() { } } -template +template void GenericMaxFlow::Discharge(NodeIndex node) { SCOPED_TIME_STAT(&stats_); const NodeIndex num_nodes = graph_->num_nodes(); while (true) { DCHECK(IsActive(node)); for (IncidentArcIterator it(*graph_, node, first_admissible_arc_[node]); - it.Ok(); - it.Next()) { + it.Ok(); it.Next()) { const ArcIndex arc = it.Index(); if (IsAdmissible(arc)) { DCHECK(IsActive(node)); @@ -813,7 +804,7 @@ void GenericMaxFlow::Discharge(NodeIndex node) { } } -template +template void GenericMaxFlow::Relabel(NodeIndex node) { SCOPED_TIME_STAT(&stats_); // Because we use a relaxed version, this is no longer true if the @@ -837,36 +828,37 @@ void GenericMaxFlow::Relabel(NodeIndex node) { } } DCHECK_NE(first_admissible_arc, Graph::kNilArc); - node_potential_[node] = min_height + 1; + node_potential_[node] = min_height + 1; // Note that after a Relabel(), the loop will continue in Discharge(), and // we are sure that all the arcs before first_admissible_arc are not // admissible since their height is > min_height. - first_admissible_arc_[node] = first_admissible_arc; + first_admissible_arc_[node] = first_admissible_arc; } -template +template typename Graph::ArcIndex GenericMaxFlow::Opposite(ArcIndex arc) const { return Graphs::OppositeArc(*graph_, arc); } -template +template bool GenericMaxFlow::IsArcDirect(ArcIndex arc) const { return IsArcValid(arc) && arc >= 0; } -template +template bool GenericMaxFlow::IsArcValid(ArcIndex arc) const { return Graphs::IsArcValid(*graph_, arc); } -template +template const FlowQuantity GenericMaxFlow::kMaxFlowQuantity = std::numeric_limits::max(); -template template -void GenericMaxFlow::ComputeReachableNodes( - NodeIndex start, std::vector* result) { +template +template +void GenericMaxFlow::ComputeReachableNodes(NodeIndex start, + std::vector* result) { // If start is not a valid node index, it can reach only itself. // Note(user): This is needed because source and sink are given independently // of the graph and sometimes before it is even constructed. diff --git a/src/graph/max_flow.h b/src/graph/max_flow.h index f0feae67e6..b8a6fbe995 100644 --- a/src/graph/max_flow.h +++ b/src/graph/max_flow.h @@ -127,11 +127,11 @@ #include "util/stats.h" #include "util/zvector.h" - namespace operations_research { // Forward declaration. -template class GenericMaxFlow; +template +class GenericMaxFlow; // A simple and efficient max-cost flow interface. This is as fast as // GenericMaxFlow, which is the fastest, but uses @@ -150,8 +150,8 @@ class SimpleMaxFlow { // * Node indices and capacity must be non-negative (>= 0). // * Self-looping and duplicate arcs are supported. // * After the method finishes, NumArcs() == the returned ArcIndex + 1. - ArcIndex AddArcWithCapacity( - NodeIndex tail, NodeIndex head, FlowQuantity capacity); + ArcIndex AddArcWithCapacity(NodeIndex tail, NodeIndex head, + FlowQuantity capacity); // Returns the current number of nodes. This is one more than the largest // node index seen so far in AddArcWithCapacity(). @@ -287,7 +287,8 @@ class MaxFlowStatusClass { // Generic MaxFlow (there is a default MaxFlow specialization defined below) // that works with StarGraph and all the reverse arc graphs from graph.h, see // the end of max_flow.cc for the exact types this class is compiled for. -template class GenericMaxFlow : public MaxFlowStatusClass { +template +class GenericMaxFlow : public MaxFlowStatusClass { public: typedef typename Graph::NodeIndex NodeIndex; typedef typename Graph::ArcIndex ArcIndex; @@ -348,8 +349,8 @@ template class GenericMaxFlow : public MaxFlowStatusClass { // residual_arc_capacity_. FlowQuantity Capacity(ArcIndex arc) const { if (IsArcDirect(arc)) { - return residual_arc_capacity_[arc] - + residual_arc_capacity_[Opposite(arc)]; + return residual_arc_capacity_[arc] + + residual_arc_capacity_[Opposite(arc)]; } else { return 0; } @@ -393,8 +394,8 @@ template class GenericMaxFlow : public MaxFlowStatusClass { protected: // Returns true if arc is admissible. bool IsAdmissible(ArcIndex arc) const { - return residual_arc_capacity_[arc] > 0 - && node_potential_[Tail(arc)] == node_potential_[Head(arc)] + 1; + return residual_arc_capacity_[arc] > 0 && + node_potential_[Tail(arc)] == node_potential_[Head(arc)] + 1; } // Returns true if node is active, i.e. if its excess is positive and it @@ -502,7 +503,7 @@ template class GenericMaxFlow : public MaxFlowStatusClass { // Returns the set of nodes reachable from start in the residual graph or in // the reverse residual graph (if reverse is true). - template + template void ComputeReachableNodes(NodeIndex start, std::vector* result); // Maximum manageable flow. @@ -619,8 +620,7 @@ template class GenericMaxFlow : public MaxFlowStatusClass { class MaxFlow : public GenericMaxFlow { public: MaxFlow(const StarGraph* graph, NodeIndex source, NodeIndex target) - : GenericMaxFlow(graph, source, target) { - } + : GenericMaxFlow(graph, source, target) {} }; #endif // SWIG diff --git a/src/graph/min_cost_flow.cc b/src/graph/min_cost_flow.cc index f662c410bd..6a90384a6c 100644 --- a/src/graph/min_cost_flow.cc +++ b/src/graph/min_cost_flow.cc @@ -268,18 +268,18 @@ std::string GenericMinCostFlow::DebugStri // ReducedCost fails. const CostValue reduced_cost = scaled_arc_unit_cost_[arc] + node_potential_[tail] - node_potential_[head]; - return StringPrintf("%s Arc %d, from %d to %d, " - "Capacity = %lld, Residual capacity = %lld, " - "Flow = residual capacity for reverse arc = %lld, " - "Height(tail) = %lld, Height(head) = %lld, " - "Excess(tail) = %lld, Excess(head) = %lld, " - "Cost = %lld, Reduced cost = %lld, ", - context.c_str(), arc, tail, head, Capacity(arc), - static_cast(residual_arc_capacity_[arc]), - Flow(arc), node_potential_[tail], node_potential_[head], - node_excess_[tail], node_excess_[head], - static_cast(scaled_arc_unit_cost_[arc]), - reduced_cost); + return StringPrintf( + "%s Arc %d, from %d to %d, " + "Capacity = %lld, Residual capacity = %lld, " + "Flow = residual capacity for reverse arc = %lld, " + "Height(tail) = %lld, Height(head) = %lld, " + "Excess(tail) = %lld, Excess(head) = %lld, " + "Cost = %lld, Reduced cost = %lld, ", + context.c_str(), arc, tail, head, Capacity(arc), + static_cast(residual_arc_capacity_[arc]), Flow(arc), + node_potential_[tail], node_potential_[head], node_excess_[tail], + node_excess_[head], static_cast(scaled_arc_unit_cost_[arc]), + reduced_cost); } template @@ -421,16 +421,16 @@ FlowQuantity GenericMinCostFlow::Supply( } template -FlowQuantity -GenericMinCostFlow::InitialSupply( - NodeIndex node) const { +FlowQuantity GenericMinCostFlow< + Graph, ArcFlowType, ArcScaledCostType>::InitialSupply(NodeIndex node) + const { return initial_node_excess_[node]; } template -FlowQuantity -GenericMinCostFlow::FeasibleSupply( - NodeIndex node) const { +FlowQuantity GenericMinCostFlow< + Graph, ArcFlowType, ArcScaledCostType>::FeasibleSupply(NodeIndex node) + const { return feasible_node_excess_[node]; } @@ -972,8 +972,8 @@ template class GenericMinCostFlow >; // A more memory-efficient version for large graphs. template class GenericMinCostFlow, - /*ArcFlowType=*/ int16, - /*ArcScaledCostType=*/ int32>; + /*ArcFlowType=*/int16, + /*ArcScaledCostType=*/int32>; SimpleMinCostFlow::SimpleMinCostFlow() {} diff --git a/src/graph/min_cost_flow.h b/src/graph/min_cost_flow.h index d716055127..6c9dc74eb3 100644 --- a/src/graph/min_cost_flow.h +++ b/src/graph/min_cost_flow.h @@ -181,7 +181,6 @@ #include "util/stats.h" #include "util/zvector.h" - namespace operations_research { // Forward declaration. @@ -616,5 +615,5 @@ class MinCostFlow : public GenericMinCostFlow { #endif // SWIG -} // namespace operations_research +} // namespace operations_research #endif // OR_TOOLS_GRAPH_MIN_COST_FLOW_H_ diff --git a/src/graph/shortestpaths.h b/src/graph/shortestpaths.h index 009b6b4796..ceefbe269c 100644 --- a/src/graph/shortestpaths.h +++ b/src/graph/shortestpaths.h @@ -35,12 +35,9 @@ namespace operations_research { // two nodes. Ownership of the callback is taken by the function that // will delete it in the end. This function returns true if // 'start_node' and 'end_node' are connected, false otherwise. -bool DijkstraShortestPath(int node_count, - int start_node, - int end_node, +bool DijkstraShortestPath(int node_count, int start_node, int end_node, ResultCallback2* const graph, - int64 disconnected_distance, - std::vector* nodes); + int64 disconnected_distance, std::vector* nodes); // Bellman-Ford Shortest path with callback-based description of the // graph. The callback returns the distance between two nodes, a @@ -50,12 +47,9 @@ bool DijkstraShortestPath(int node_count, // 'start_node' and 'end_node' are connected, false otherwise. If // true, it will fill the 'nodes' vector with the sequence of nodes on // the shortest path between 'start_node' and 'end_node'. -bool BellmanFordShortestPath(int node_count, - int start_node, - int end_node, +bool BellmanFordShortestPath(int node_count, int start_node, int end_node, ResultCallback2* const graph, - int64 disconnected_distance, - std::vector* nodes); + int64 disconnected_distance, std::vector* nodes); } // namespace operations_research #endif // OR_TOOLS_GRAPH_SHORTESTPATHS_H_ diff --git a/src/linear_solver/cbc_interface.cc b/src/linear_solver/cbc_interface.cc index fa59613798..62860af93d 100644 --- a/src/linear_solver/cbc_interface.cc +++ b/src/linear_solver/cbc_interface.cc @@ -81,8 +81,7 @@ class CBCInterface : public MPSolverInterface { // Change a coefficient in a constraint. virtual void SetCoefficient(MPConstraint* const constraint, const MPVariable* const variable, - double new_value, - double old_value) { + double new_value, double old_value) { sync_status_ = MUST_RELOAD; } // Clear a constraint from all its terms. @@ -96,13 +95,9 @@ class CBCInterface : public MPSolverInterface { sync_status_ = MUST_RELOAD; } // Change the constant term in the linear objective. - virtual void SetObjectiveOffset(double value) { - sync_status_ = MUST_RELOAD; - } + virtual void SetObjectiveOffset(double value) { sync_status_ = MUST_RELOAD; } // Clear the objective from all its terms. - virtual void ClearObjective() { - sync_status_ = MUST_RELOAD; - } + virtual void ClearObjective() { sync_status_ = MUST_RELOAD; } // Number of simplex iterations virtual int64 iterations() const; @@ -126,16 +121,12 @@ class CBCInterface : public MPSolverInterface { virtual void ExtractNewConstraints() {} virtual void ExtractObjective() {} - virtual std::string SolverVersion() const { - return "Cbc " CBC_VERSION; - } + virtual std::string SolverVersion() const { return "Cbc " CBC_VERSION; } // TODO(user): Maybe we should expose the CbcModel build from osi_ // instead, but a new CbcModel is built every time Solve is called, // so it is not possible right now. - virtual void* underlying_solver() { - return reinterpret_cast(&osi_); - } + virtual void* underlying_solver() { return reinterpret_cast(&osi_); } private: // Reset best objective bound to +/- infinity depending on the @@ -166,7 +157,8 @@ class CBCInterface : public MPSolverInterface { // Creates a LP/MIP instance with the specified name and minimization objective. CBCInterface::CBCInterface(MPSolver* const solver) : MPSolverInterface(solver), - iterations_(0), nodes_(0), + iterations_(0), + nodes_(0), best_objective_bound_(-std::numeric_limits::infinity()), relative_mip_gap_(MPSolverParameters::kDefaultRelativeMipGap) { osi_.setStrParam(OsiProbName, solver_->name_); @@ -269,16 +261,16 @@ MPSolver::ResultStatus CBCInterface::Solve(const MPSolverParameters& param) { Reset(); CoinModel build; // Create dummy variable for objective offset. - build.addColumn(0, NULL, NULL, 1.0, 1.0, - solver_->Objective().offset(), "dummy", false); + build.addColumn(0, NULL, NULL, 1.0, 1.0, solver_->Objective().offset(), + "dummy", false); const int nb_vars = solver_->variables_.size(); for (int i = 0; i < nb_vars; ++i) { MPVariable* const var = solver_->variables_[i]; var->set_index(i + 1); // offset by 1 because of dummy variable. const double obj_coeff = solver_->Objective().GetCoefficient(var); if (var->name().empty()) { - build.addColumn(0, NULL, NULL, var->lb(), var->ub(), obj_coeff, - NULL, var->integer()); + build.addColumn(0, NULL, NULL, var->lb(), var->ub(), obj_coeff, NULL, + var->integer()); } else { build.addColumn(0, NULL, NULL, var->lb(), var->ub(), obj_coeff, var->name().c_str(), var->integer()); @@ -299,7 +291,7 @@ MPSolver::ResultStatus CBCInterface::Solve(const MPSolverParameters& param) { std::unique_ptr coefs(new double[max_row_length]); for (int i = 0; i < solver_->constraints_.size(); ++i) { - MPConstraint* const ct = solver_->constraints_[i]; + MPConstraint* const ct = solver_->constraints_[i]; const int size = ct->coefficients_.size(); int j = 0; for (CoeffEntry entry : ct->coefficients_) { @@ -319,12 +311,8 @@ MPSolver::ResultStatus CBCInterface::Solve(const MPSolverParameters& param) { osi_.loadFromCoinModel(build); break; } - case MODEL_SYNCHRONIZED: { - break; - } - case SOLUTION_SYNCHRONIZED: { - break; - } + case MODEL_SYNCHRONIZED: { break; } + case SOLUTION_SYNCHRONIZED: { break; } } // Changing optimization direction through OSI so that the model file @@ -407,9 +395,8 @@ MPSolver::ResultStatus CBCInterface::Solve(const MPSolverParameters& param) { } else if (model.isProvenInfeasible()) { result_status_ = MPSolver::INFEASIBLE; } else { - LOG(FATAL) - << "Unknown solver status! Secondary status: " - << model.secondaryStatus(); + LOG(FATAL) << "Unknown solver status! Secondary status: " + << model.secondaryStatus(); } break; case 1: @@ -446,8 +433,7 @@ MPSolver::ResultStatus CBCInterface::Solve(const MPSolverParameters& param) { const int constraint_index = ct->index(); const double row_activity = row_activities[constraint_index]; ct->set_activity(row_activity); - VLOG(4) << "row " << ct->index() - << ": activity = " << row_activity; + VLOG(4) << "row " << ct->index() << ": activity = " << row_activity; } } } @@ -520,9 +506,7 @@ void CBCInterface::SetPresolveMode(int value) { // CBC presolve is always on. break; } - default: { - SetUnsupportedIntegerParam(MPSolverParameters::PRESOLVE); - } + default: { SetUnsupportedIntegerParam(MPSolverParameters::PRESOLVE); } } } diff --git a/src/linear_solver/clp_interface.cc b/src/linear_solver/clp_interface.cc index 7abcd99f32..31299e0410 100644 --- a/src/linear_solver/clp_interface.cc +++ b/src/linear_solver/clp_interface.cc @@ -72,8 +72,7 @@ class CLPInterface : public MPSolverInterface { // Change a coefficient in a constraint. virtual void SetCoefficient(MPConstraint* const constraint, const MPVariable* const variable, - double new_value, - double old_value); + double new_value, double old_value); // Clear a constraint from all its terms. virtual void ClearConstraint(MPConstraint* const constraint); @@ -108,9 +107,7 @@ class CLPInterface : public MPSolverInterface { virtual void ExtractNewConstraints(); virtual void ExtractObjective(); - virtual std::string SolverVersion() const { - return "Clp " CLP_VERSION; - } + virtual std::string SolverVersion() const { return "Clp " CLP_VERSION; } virtual void* underlying_solver() { return reinterpret_cast(clp_.get()); @@ -135,8 +132,8 @@ class CLPInterface : public MPSolverInterface { virtual void SetLpAlgorithm(int value); // Transforms basis status from CLP enum to MPSolver::BasisStatus. - MPSolver::BasisStatus - TransformCLPBasisStatus(ClpSimplex::Status clp_basis_status) const; + MPSolver::BasisStatus TransformCLPBasisStatus( + ClpSimplex::Status clp_basis_status) const; std::unique_ptr clp_; // TODO(user) : remove pointer. std::unique_ptr options_; // For parameter setting. @@ -146,10 +143,9 @@ class CLPInterface : public MPSolverInterface { // Creates a LP/MIP instance with the specified name and minimization objective. CLPInterface::CLPInterface(MPSolver* const solver) - : MPSolverInterface(solver), - clp_(new ClpSimplex), options_(new ClpSolve) { - clp_->setStrParam(ClpProbName, solver_->name_); - clp_->setOptimizationDirection(1); + : MPSolverInterface(solver), clp_(new ClpSimplex), options_(new ClpSolve) { + clp_->setStrParam(ClpProbName, solver_->name_); + clp_->setOptimizationDirection(1); } CLPInterface::~CLPInterface() {} @@ -195,8 +191,7 @@ void CLPInterface::SetConstraintBounds(int index, double lb, double ub) { void CLPInterface::SetCoefficient(MPConstraint* const constraint, const MPVariable* const variable, - double new_value, - double old_value) { + double new_value, double old_value) { InvalidateSolutionSynchronization(); const int constraint_index = constraint->index(); const int variable_index = variable->index(); @@ -356,7 +351,7 @@ void CLPInterface::ExtractNewConstraints() { CoinBuild build_object; // Add each new constraint. for (int i = last_constraint_index_; i < total_num_rows; ++i) { - MPConstraint* const ct = solver_->constraints_[i]; + MPConstraint* const ct = solver_->constraints_[i]; DCHECK_NE(kNoIndex, ct->index()); int size = ct->coefficients_.size(); if (size == 0) { @@ -373,11 +368,7 @@ void CLPInterface::ExtractNewConstraints() { coefs[j] = entry.second; j++; } - build_object.addRow(size, - indices.get(), - coefs.get(), - ct->lb(), - ct->ub()); + build_object.addRow(size, indices.get(), coefs.get(), ct->lb(), ct->ub()); } // Add and name the rows. clp_->addRows(build_object); @@ -501,8 +492,7 @@ MPSolver::ResultStatus CLPInterface::Solve(const MPSolverParameters& param) { ct->set_activity(row_activity); const double dual_value = dual_values[constraint_index]; ct->set_dual_value(dual_value); - VLOG(4) << "row " << ct->index() - << ": activity = " << row_activity + VLOG(4) << "row " << ct->index() << ": activity = " << row_activity << " dual value = " << dual_value; } } diff --git a/src/linear_solver/gurobi_interface.cc b/src/linear_solver/gurobi_interface.cc index 8a29bbe757..ed18ab4ec6 100644 --- a/src/linear_solver/gurobi_interface.cc +++ b/src/linear_solver/gurobi_interface.cc @@ -32,7 +32,7 @@ #if defined(USE_GUROBI) extern "C" { - #include "gurobi_c.h" +#include "gurobi_c.h" } #define CHECKED_GUROBI_CALL(x) CHECK_EQ(0, x) @@ -68,8 +68,7 @@ class GurobiInterface : public MPSolverInterface { // Changes a coefficient in a constraint. virtual void SetCoefficient(MPConstraint* const constraint, const MPVariable* const variable, - double new_value, - double old_value); + double new_value, double old_value); // Clears a constraint from all its terms. virtual void ClearConstraint(MPConstraint* const constraint); // Changes a coefficient in the linear objective @@ -106,29 +105,23 @@ class GurobiInterface : public MPSolverInterface { virtual std::string SolverVersion() const { int major, minor, technical; GRBversion(&major, &minor, &technical); - return StringPrintf("Gurobi library version %d.%d.%d\n", - major, - minor, + return StringPrintf("Gurobi library version %d.%d.%d\n", major, minor, technical); } - virtual void* underlying_solver() { - return reinterpret_cast(model_); - } + virtual void* underlying_solver() { return reinterpret_cast(model_); } virtual double ComputeExactConditionNumber() const { if (!IsContinuous()) { - LOG(DFATAL) - << "ComputeExactConditionNumber not implemented for" - << " GUROBI_MIXED_INTEGER_PROGRAMMING"; + LOG(DFATAL) << "ComputeExactConditionNumber not implemented for" + << " GUROBI_MIXED_INTEGER_PROGRAMMING"; return 0.0; } // TODO(user,user): Not yet working. - LOG(DFATAL) - << "ComputeExactConditionNumber not implemented for" - << " GUROBI_LINEAR_PROGRAMMING"; - return 0.0; + LOG(DFATAL) << "ComputeExactConditionNumber not implemented for" + << " GUROBI_LINEAR_PROGRAMMING"; + return 0.0; // double cond = 0.0; // const int status = GRBgetdblattr(model_, GRB_DBL_ATTR_KAPPA, &cond); @@ -155,11 +148,10 @@ class GurobiInterface : public MPSolverInterface { virtual bool ReadParameterFile(const std::string& filename); virtual std::string ValidFileExtensionForParameterFile() const; - MPSolver::BasisStatus - TransformGRBVarBasisStatus(int gurobi_basis_status) const; - MPSolver::BasisStatus - TransformGRBConstraintBasisStatus(int gurobi_basis_status, - int constraint_index) const; + MPSolver::BasisStatus TransformGRBVarBasisStatus(int gurobi_basis_status) + const; + MPSolver::BasisStatus TransformGRBConstraintBasisStatus( + int gurobi_basis_status, int constraint_index) const; private: GRBmodel* model_; @@ -169,26 +161,20 @@ class GurobiInterface : public MPSolverInterface { // Creates a LP/MIP instance with the specified name and minimization objective. GurobiInterface::GurobiInterface(MPSolver* const solver, bool mip) - : MPSolverInterface(solver), - model_(0), - env_(0), - mip_(mip) { - if (GRBloadenv(&env_, NULL) != 0 || env_ == NULL) { + : MPSolverInterface(solver), model_(0), env_(0), mip_(mip) { + if (GRBloadenv(&env_, NULL) != 0 || env_ == NULL) { LOG(FATAL) << "Error: could not create environment"; } - CHECKED_GUROBI_CALL(GRBnewmodel(env_, - &model_, - solver_->name_.c_str(), - 0, // numvars - NULL, // obj - NULL, // lb - NULL, // ub - NULL, // vtype + CHECKED_GUROBI_CALL(GRBnewmodel(env_, &model_, solver_->name_.c_str(), + 0, // numvars + NULL, // obj + NULL, // lb + NULL, // ub + NULL, // vtype NULL)); // varnanes - CHECKED_GUROBI_CALL(GRBsetintattr(model_, - GRB_INT_ATTR_MODELSENSE, - maximize_ ? -1 : 1)); + CHECKED_GUROBI_CALL( + GRBsetintattr(model_, GRB_INT_ATTR_MODELSENSE, maximize_ ? -1 : 1)); } GurobiInterface::~GurobiInterface() { @@ -200,14 +186,12 @@ GurobiInterface::~GurobiInterface() { void GurobiInterface::Reset() { CHECKED_GUROBI_CALL(GRBfreemodel(model_)); - CHECKED_GUROBI_CALL(GRBnewmodel(env_, - &model_, - solver_->name_.c_str(), - 0, // numvars - NULL, // obj - NULL, // lb - NULL, // ub - NULL, // vtype + CHECKED_GUROBI_CALL(GRBnewmodel(env_, &model_, solver_->name_.c_str(), + 0, // numvars + NULL, // obj + NULL, // lb + NULL, // ub + NULL, // vtype NULL)); // varnames ResetExtractionInformation(); } @@ -228,14 +212,12 @@ void GurobiInterface::SetVariableBounds(int var_index, double lb, double ub) { // Modifies integrality of an extracted variable. void GurobiInterface::SetVariableInteger(int index, bool integer) { char current_type; - CHECKED_GUROBI_CALL(GRBgetcharattrelement(model_, - GRB_CHAR_ATTR_VTYPE, - index, - ¤t_type)); + CHECKED_GUROBI_CALL( + GRBgetcharattrelement(model_, GRB_CHAR_ATTR_VTYPE, index, ¤t_type)); - if ((integer && (current_type == GRB_INTEGER || - current_type == GRB_BINARY)) - || (!integer && current_type == GRB_CONTINUOUS)) + if ((integer && + (current_type == GRB_INTEGER || current_type == GRB_BINARY)) || + (!integer && current_type == GRB_CONTINUOUS)) return; InvalidateSolutionSynchronization(); @@ -246,10 +228,8 @@ void GurobiInterface::SetVariableInteger(int index, bool integer) { } else { type_var = GRB_CONTINUOUS; } - CHECKED_GUROBI_CALL(GRBsetcharattrelement(model_, - GRB_CHAR_ATTR_VTYPE, - index, - type_var)); + CHECKED_GUROBI_CALL( + GRBsetcharattrelement(model_, GRB_CHAR_ATTR_VTYPE, index, type_var)); } else { sync_status_ = MUST_RELOAD; } @@ -269,8 +249,7 @@ void GurobiInterface::AddVariable(MPVariable* const ct) { void GurobiInterface::SetCoefficient(MPConstraint* const constraint, const MPVariable* const variable, - double new_value, - double old_value) { + double new_value, double old_value) { sync_status_ = MUST_RELOAD; } @@ -293,9 +272,7 @@ void GurobiInterface::SetObjectiveOffset(double value) { // CHECKED_GUROBI_CALL(GRBupdatemodel(model_)); } -void GurobiInterface::ClearObjective() { - sync_status_ = MUST_RELOAD; -} +void GurobiInterface::ClearObjective() { sync_status_ = MUST_RELOAD; } // ------ Query statistics on the solution and the solve ------ @@ -338,8 +315,8 @@ double GurobiInterface::best_objective_bound() const { } } -MPSolver::BasisStatus -GurobiInterface::TransformGRBVarBasisStatus(int gurobi_basis_status) const { +MPSolver::BasisStatus GurobiInterface::TransformGRBVarBasisStatus( + int gurobi_basis_status) const { switch (gurobi_basis_status) { case GRB_BASIC: return MPSolver::BASIC; @@ -356,29 +333,22 @@ GurobiInterface::TransformGRBVarBasisStatus(int gurobi_basis_status) const { } MPSolver::BasisStatus GurobiInterface::TransformGRBConstraintBasisStatus( - int gurobi_basis_status, - int constraint_index) const { + int gurobi_basis_status, int constraint_index) const { switch (gurobi_basis_status) { case GRB_BASIC: return MPSolver::BASIC; - default: { + default: { // Non basic. double slack = 0.0; double tolerance = 0.0; - CHECKED_GUROBI_CALL(GRBgetdblparam(GRBgetenv(model_), - GRB_DBL_PAR_FEASIBILITYTOL, - &tolerance)); - CHECKED_GUROBI_CALL(GRBgetdblattrelement(model_, - GRB_DBL_ATTR_SLACK, - constraint_index, - &slack)); + CHECKED_GUROBI_CALL(GRBgetdblparam( + GRBgetenv(model_), GRB_DBL_PAR_FEASIBILITYTOL, &tolerance)); + CHECKED_GUROBI_CALL(GRBgetdblattrelement(model_, GRB_DBL_ATTR_SLACK, + constraint_index, &slack)); char sense; - CHECKED_GUROBI_CALL(GRBgetcharattrelement(model_, - GRB_CHAR_ATTR_SENSE, - constraint_index, - &sense)); - VLOG(4) << "constraint " << constraint_index - << " , slack = " << slack + CHECKED_GUROBI_CALL(GRBgetcharattrelement(model_, GRB_CHAR_ATTR_SENSE, + constraint_index, &sense)); + VLOG(4) << "constraint " << constraint_index << " , slack = " << slack << " , sense = " << sense; if (fabs(slack) <= tolerance) { switch (sense) { @@ -412,10 +382,8 @@ MPSolver::BasisStatus GurobiInterface::row_status(int constraint_index) const { return MPSolver::FREE; } int gurobi_basis_status = 0; - CHECKED_GUROBI_CALL(GRBgetintattrelement(model_, - GRB_INT_ATTR_CBASIS, - constraint_index, - &gurobi_basis_status)); + CHECKED_GUROBI_CALL(GRBgetintattrelement( + model_, GRB_INT_ATTR_CBASIS, constraint_index, &gurobi_basis_status)); return TransformGRBConstraintBasisStatus(gurobi_basis_status, constraint_index); } @@ -435,10 +403,8 @@ MPSolver::BasisStatus GurobiInterface::column_status(int variable_index) const { return MPSolver::FREE; } int gurobi_basis_status = 0; - CHECKED_GUROBI_CALL(GRBgetintattrelement(model_, - GRB_INT_ATTR_VBASIS, - variable_index, - &gurobi_basis_status)); + CHECKED_GUROBI_CALL(GRBgetintattrelement( + model_, GRB_INT_ATTR_VBASIS, variable_index, &gurobi_basis_status)); return TransformGRBVarBasisStatus(gurobi_basis_status); } @@ -459,7 +425,7 @@ void GurobiInterface::ExtractNewVariables() { new const char* [num_new_variables]); for (int j = 0; j < num_new_variables; ++j) { - MPVariable* const var = solver_->variables_[last_variable_index_+j]; + MPVariable* const var = solver_->variables_[last_variable_index_ + j]; var->set_index(last_variable_index_ + j); lb[j] = var->lb(); ub[j] = var->ub(); @@ -470,17 +436,9 @@ void GurobiInterface::ExtractNewVariables() { obj_coefs[j] = solver_->objective_->GetCoefficient(var); } - CHECKED_GUROBI_CALL(GRBaddvars(model_, - num_new_variables, - 0, - NULL, - NULL, - NULL, - obj_coefs.get(), - lb.get(), - ub.get(), - ctype.get(), - const_cast(colname.get()))); + CHECKED_GUROBI_CALL(GRBaddvars( + model_, num_new_variables, 0, NULL, NULL, NULL, obj_coefs.get(), + lb.get(), ub.get(), ctype.get(), const_cast(colname.get()))); } CHECKED_GUROBI_CALL(GRBupdatemodel(model_)); } @@ -522,12 +480,8 @@ void GurobiInterface::ExtractNewConstraints() { } char* const name = ct->name().empty() ? NULL : const_cast(ct->name().c_str()); - CHECKED_GUROBI_CALL(GRBaddrangeconstr(model_, - size, - col_indices.get(), - coefs.get(), - ct->lb(), - ct->ub(), + CHECKED_GUROBI_CALL(GRBaddrangeconstr(model_, size, col_indices.get(), + coefs.get(), ct->lb(), ct->ub(), name)); } } @@ -535,11 +489,9 @@ void GurobiInterface::ExtractNewConstraints() { } void GurobiInterface::ExtractObjective() { - CHECKED_GUROBI_CALL(GRBsetintattr(model_, - GRB_INT_ATTR_MODELSENSE, - maximize_ ? -1 : 1)); - CHECKED_GUROBI_CALL(GRBsetdblattr(model_, - GRB_DBL_ATTR_OBJCON, + CHECKED_GUROBI_CALL( + GRBsetintattr(model_, GRB_INT_ATTR_MODELSENSE, maximize_ ? -1 : 1)); + CHECKED_GUROBI_CALL(GRBsetdblattr(model_, GRB_DBL_ATTR_OBJCON, solver_->Objective().offset())); } @@ -554,9 +506,8 @@ void GurobiInterface::SetParameters(const MPSolverParameters& param) { void GurobiInterface::SetRelativeMipGap(double value) { if (mip_) { - CHECKED_GUROBI_CALL(GRBsetdblparam(GRBgetenv(model_), - GRB_DBL_PAR_MIPGAP, - value)); + CHECKED_GUROBI_CALL( + GRBsetdblparam(GRBgetenv(model_), GRB_DBL_PAR_MIPGAP, value)); } else { LOG(WARNING) << "The relative MIP gap is only available " << "for discrete problems."; @@ -564,9 +515,8 @@ void GurobiInterface::SetRelativeMipGap(double value) { } void GurobiInterface::SetPrimalTolerance(double value) { - CHECKED_GUROBI_CALL(GRBsetdblparam(GRBgetenv(model_), - GRB_DBL_PAR_FEASIBILITYTOL, - value)); + CHECKED_GUROBI_CALL( + GRBsetdblparam(GRBgetenv(model_), GRB_DBL_PAR_FEASIBILITYTOL, value)); } void GurobiInterface::SetDualTolerance(double value) { @@ -577,15 +527,13 @@ void GurobiInterface::SetDualTolerance(double value) { void GurobiInterface::SetPresolveMode(int value) { switch (value) { case MPSolverParameters::PRESOLVE_OFF: { - CHECKED_GUROBI_CALL(GRBsetintparam(GRBgetenv(model_), - GRB_INT_PAR_PRESOLVE, - false)); + CHECKED_GUROBI_CALL( + GRBsetintparam(GRBgetenv(model_), GRB_INT_PAR_PRESOLVE, false)); break; } case MPSolverParameters::PRESOLVE_ON: { - CHECKED_GUROBI_CALL(GRBsetintparam(GRBgetenv(model_), - GRB_INT_PAR_PRESOLVE, - true)); + CHECKED_GUROBI_CALL( + GRBsetintparam(GRBgetenv(model_), GRB_INT_PAR_PRESOLVE, true)); break; } default: { @@ -598,17 +546,14 @@ void GurobiInterface::SetPresolveMode(int value) { void GurobiInterface::SetScalingMode(int value) { switch (value) { case MPSolverParameters::SCALING_OFF: - CHECKED_GUROBI_CALL(GRBsetintparam(GRBgetenv(model_), - GRB_INT_PAR_SCALEFLAG, - false)); + CHECKED_GUROBI_CALL( + GRBsetintparam(GRBgetenv(model_), GRB_INT_PAR_SCALEFLAG, false)); break; case MPSolverParameters::SCALING_ON: - CHECKED_GUROBI_CALL(GRBsetintparam(GRBgetenv(model_), - GRB_INT_PAR_SCALEFLAG, - true)); - CHECKED_GUROBI_CALL(GRBsetdblparam(GRBgetenv(model_), - GRB_DBL_PAR_OBJSCALE, - 0.0)); + CHECKED_GUROBI_CALL( + GRBsetintparam(GRBgetenv(model_), GRB_INT_PAR_SCALEFLAG, true)); + CHECKED_GUROBI_CALL( + GRBsetdblparam(GRBgetenv(model_), GRB_DBL_PAR_OBJSCALE, 0.0)); break; default: // Leave the parameters untouched. @@ -621,18 +566,15 @@ void GurobiInterface::SetScalingMode(int value) { void GurobiInterface::SetLpAlgorithm(int value) { switch (value) { case MPSolverParameters::DUAL: - CHECKED_GUROBI_CALL(GRBsetintparam(GRBgetenv(model_), - GRB_INT_PAR_METHOD, + CHECKED_GUROBI_CALL(GRBsetintparam(GRBgetenv(model_), GRB_INT_PAR_METHOD, GRB_METHOD_DUAL)); break; case MPSolverParameters::PRIMAL: - CHECKED_GUROBI_CALL(GRBsetintparam(GRBgetenv(model_), - GRB_INT_PAR_METHOD, + CHECKED_GUROBI_CALL(GRBsetintparam(GRBgetenv(model_), GRB_INT_PAR_METHOD, GRB_METHOD_PRIMAL)); break; case MPSolverParameters::BARRIER: - CHECKED_GUROBI_CALL(GRBsetintparam(GRBgetenv(model_), - GRB_INT_PAR_METHOD, + CHECKED_GUROBI_CALL(GRBsetintparam(GRBgetenv(model_), GRB_INT_PAR_METHOD, GRB_METHOD_BARRIER)); break; default: @@ -641,7 +583,6 @@ void GurobiInterface::SetLpAlgorithm(int value) { } } - MPSolver::ResultStatus GurobiInterface::Solve(const MPSolverParameters& param) { WallTimer timer; timer.Start(); @@ -657,9 +598,8 @@ MPSolver::ResultStatus GurobiInterface::Solve(const MPSolverParameters& param) { } // Set log level. - CHECKED_GUROBI_CALL(GRBsetintparam(GRBgetenv(model_), - GRB_INT_PAR_OUTPUTFLAG, - !quiet_)); + CHECKED_GUROBI_CALL( + GRBsetintparam(GRBgetenv(model_), GRB_INT_PAR_OUTPUTFLAG, !quiet_)); ExtractModel(); // Sync solver. @@ -670,8 +610,7 @@ MPSolver::ResultStatus GurobiInterface::Solve(const MPSolverParameters& param) { // Time limit. if (solver_->time_limit() != 0) { VLOG(1) << "Setting time limit = " << solver_->time_limit() << " ms."; - CHECKED_GUROBI_CALL(GRBsetdblparam(GRBgetenv(model_), - GRB_DBL_PAR_TIMELIMIT, + CHECKED_GUROBI_CALL(GRBsetdblparam(GRBgetenv(model_), GRB_DBL_PAR_TIMELIMIT, solver_->time_limit_in_secs())); } @@ -691,14 +630,12 @@ MPSolver::ResultStatus GurobiInterface::Solve(const MPSolverParameters& param) { // Get the status. int optimization_status = 0; - CHECKED_GUROBI_CALL(GRBgetintattr(model_, - GRB_INT_ATTR_STATUS, - &optimization_status)); + CHECKED_GUROBI_CALL( + GRBgetintattr(model_, GRB_INT_ATTR_STATUS, &optimization_status)); VLOG(1) << StringPrintf("Solution status %d.\n", optimization_status); int solution_count = 0; - CHECKED_GUROBI_CALL(GRBgetintattr(model_, - GRB_INT_ATTR_SOLCOUNT, - &solution_count)); + CHECKED_GUROBI_CALL( + GRBgetintattr(model_, GRB_INT_ATTR_SOLCOUNT, &solution_count)); switch (optimization_status) { case GRB_OPTIMAL: @@ -740,35 +677,19 @@ MPSolver::ResultStatus GurobiInterface::Solve(const MPSolverParameters& param) { std::unique_ptr rhs(new double[total_num_rows]); std::unique_ptr reduced_costs(new double[total_num_cols]); - CHECKED_GUROBI_CALL(GRBgetdblattr(model_, - GRB_DBL_ATTR_OBJVAL, - &objective_value_)); - CHECKED_GUROBI_CALL(GRBgetdblattrarray(model_, - GRB_DBL_ATTR_X, - 0, - total_num_cols, - values.get())); - CHECKED_GUROBI_CALL(GRBgetdblattrarray(model_, - GRB_DBL_ATTR_SLACK, - 0, - total_num_rows, - slacks.get())); - CHECKED_GUROBI_CALL(GRBgetdblattrarray(model_, - GRB_DBL_ATTR_RHS, - 0, - total_num_rows, - rhs.get())); + CHECKED_GUROBI_CALL( + GRBgetdblattr(model_, GRB_DBL_ATTR_OBJVAL, &objective_value_)); + CHECKED_GUROBI_CALL(GRBgetdblattrarray(model_, GRB_DBL_ATTR_X, 0, + total_num_cols, values.get())); + CHECKED_GUROBI_CALL(GRBgetdblattrarray(model_, GRB_DBL_ATTR_SLACK, 0, + total_num_rows, slacks.get())); + CHECKED_GUROBI_CALL(GRBgetdblattrarray(model_, GRB_DBL_ATTR_RHS, 0, + total_num_rows, rhs.get())); if (!mip_) { - CHECKED_GUROBI_CALL(GRBgetdblattrarray(model_, - GRB_DBL_ATTR_RC, - 0, - total_num_cols, - reduced_costs.get())); - CHECKED_GUROBI_CALL(GRBgetdblattrarray(model_, - GRB_DBL_ATTR_PI, - 0, - total_num_rows, - dual_values.get())); + CHECKED_GUROBI_CALL(GRBgetdblattrarray( + model_, GRB_DBL_ATTR_RC, 0, total_num_cols, reduced_costs.get())); + CHECKED_GUROBI_CALL(GRBgetdblattrarray( + model_, GRB_DBL_ATTR_PI, 0, total_num_rows, dual_values.get())); } VLOG(1) << "objective = " << objective_value_; @@ -786,15 +707,12 @@ MPSolver::ResultStatus GurobiInterface::Solve(const MPSolverParameters& param) { MPConstraint* const ct = solver_->constraints_[i]; ct->set_activity(rhs[i] - slacks[i]); if (mip_) { - VLOG(4) << "row " << ct->index() - << ", slack = " << slacks[i] + VLOG(4) << "row " << ct->index() << ", slack = " << slacks[i] << ", rhs = " << rhs[i]; } else { ct->set_dual_value(dual_values[i]); - VLOG(4) << "row " << ct->index() - << ", slack = " << slacks[i] - << ", rhs = " << rhs[i] - << ", dual value = " << dual_values[i]; + VLOG(4) << "row " << ct->index() << ", slack = " << slacks[i] + << ", rhs = " << rhs[i] << ", dual value = " << dual_values[i]; } } } @@ -813,7 +731,7 @@ std::string GurobiInterface::ValidFileExtensionForParameterFile() const { return ".prm"; } -MPSolverInterface* BuildGurobiInterface(MPSolver* const solver, bool mip) { +MPSolverInterface* BuildGurobiInterface(bool mip, MPSolver* const solver) { return new GurobiInterface(solver, mip); } diff --git a/src/linear_solver/linear_solver.cc b/src/linear_solver/linear_solver.cc index 6cdf334dfe..2a144c2e47 100644 --- a/src/linear_solver/linear_solver.cc +++ b/src/linear_solver/linear_solver.cc @@ -195,13 +195,9 @@ void MPObjective::SetOptimizationDirection(bool maximize) { interface_->SetOptimizationDirection(maximize); } -bool MPObjective::maximization() const { - return interface_->maximize_; -} +bool MPObjective::maximization() const { return interface_->maximize_; } -bool MPObjective::minimization() const { - return !interface_->maximize_; -} +bool MPObjective::minimization() const { return !interface_->maximize_; } double MPObjective::Value() const { // Note(user): implementation-wise, the objective value belongs more @@ -269,17 +265,13 @@ void MPVariable::SetInteger(bool integer) { // ----- Objective (DEPRECATED methods) ----- -double MPSolver::objective_value() const { - return Objective().Value(); -} +double MPSolver::objective_value() const { return Objective().Value(); } double MPSolver::best_objective_bound() const { return Objective().BestBound(); } -void MPSolver::ClearObjective() { - MutableObjective()->Clear(); -} +void MPSolver::ClearObjective() { MutableObjective()->Clear(); } void MPSolver::SetObjectiveCoefficient(const MPVariable* const var, double coeff) { @@ -298,25 +290,17 @@ void MPSolver::SetOptimizationDirection(bool maximize) { MutableObjective()->SetOptimizationDirection(maximize); } -bool MPSolver::Maximization() const { - return Objective().maximization(); -} +bool MPSolver::Maximization() const { return Objective().maximization(); } -bool MPSolver::Minimization() const { - return Objective().minimization(); -} +bool MPSolver::Minimization() const { return Objective().minimization(); } // ----- Version ----- -std::string MPSolver::SolverVersion() const { - return interface_->SolverVersion(); -} +std::string MPSolver::SolverVersion() const { return interface_->SolverVersion(); } // ---- Underlying solver ---- -void* MPSolver::underlying_solver() { - return interface_->underlying_solver(); -} +void* MPSolver::underlying_solver() { return interface_->underlying_solver(); } // ---- Solver-specific parameters ---- @@ -330,20 +314,20 @@ bool MPSolver::SetSolverSpecificParametersAsString(const std::string& parameters // them; some (eg. SCIP, Gurobi) need to re-parse the parameters every time // they do Solve(). We just store the parameters std::string anyway. std::string extension = interface_->ValidFileExtensionForParameterFile(); -#if defined(__linux) - int32 tid = static_cast(pthread_self()); -#else // defined(__linux__) - int32 tid = 123; -#endif // defined(__linux__) -#if !defined(_MSC_VER) - int32 pid = static_cast(getpid()); -#else // _MSC_VER - int32 pid = 456; -#endif // _MSC_VER - int64 now = WallTimer::GetTimeInMicroSeconds(); - std::string filename = StringPrintf("/tmp/parameters-tempfile-%x-%d-%llx%s", - tid, pid, now, extension.c_str()); - bool no_error_so_far = true; + #if defined(__linux) + int32 tid = static_cast(pthread_self()); + #else // defined(__linux__) + int32 tid = 123; + #endif // defined(__linux__) + #if !defined(_MSC_VER) + int32 pid = static_cast(getpid()); + #else // _MSC_VER + int32 pid = 456; + #endif // _MSC_VER + int64 now = WallTimer::GetTimeInMicroSeconds(); + std::string filename = StringPrintf("/tmp/parameters-tempfile-%x-%d-%llx%s", + tid, pid, now, extension.c_str()); + bool no_error_so_far = true; if (no_error_so_far) { no_error_so_far = file::SetContents(filename, parameters, file::Defaults()).ok(); @@ -353,15 +337,14 @@ bool MPSolver::SetSolverSpecificParametersAsString(const std::string& parameters // We need to clean up the file even if ReadParameterFile() returned // false. In production we can continue even if the deletion failed. if (!File::Delete(filename.c_str())) { - LOG(DFATAL) << "Couldn't delete temporary parameters file: " - << filename; + LOG(DFATAL) << "Couldn't delete temporary parameters file: " << filename; } } if (!no_error_so_far) { LOG(WARNING) << "Error in SetSolverSpecificParametersAsString() " - << "for solver type: " - << MPModelRequest::SolverType_Name( - static_cast(ProblemType())); + << "for solver type: " + << MPModelRequest::SolverType_Name( + static_cast(ProblemType())); } return no_error_so_far; } @@ -433,8 +416,8 @@ MPSolverInterface* BuildSolverInterface(MPSolver* const solver) { namespace { int NumDigits(int n) { - // Number of digits needed to write a non-negative integer in base 10. - // Note(user): std::max(1, log(0) + 1) == std::max(1, -inf) == 1. +// Number of digits needed to write a non-negative integer in base 10. +// Note(user): std::max(1, log(0) + 1) == std::max(1, -inf) == 1. #if defined(_MSC_VER) return static_cast(std::max(1.0L, log(1.0L * n) / log(10.0L) + 1.0)); #else @@ -460,9 +443,7 @@ MPSolver::MPSolver(const std::string& name, OptimizationProblemType problem_type objective_.reset(new MPObjective(interface_.get())); } -MPSolver::~MPSolver() { - Clear(); -} +MPSolver::~MPSolver() { Clear(); } MPVariable* MPSolver::LookupVariableOrNull(const std::string& var_name) const { @@ -472,8 +453,8 @@ MPVariable* MPSolver::LookupVariableOrNull(const std::string& var_name) const { return variables_[it->second]; } -MPConstraint* MPSolver::LookupConstraintOrNull( - const std::string& constraint_name) const { +MPConstraint* MPSolver::LookupConstraintOrNull(const std::string& constraint_name) + const { hash_map::const_iterator it = constraint_name_to_index_.find(constraint_name); if (it == constraint_name_to_index_.end()) return NULL; @@ -484,6 +465,7 @@ MPConstraint* MPSolver::LookupConstraintOrNull( MPSolver::LoadStatus MPSolver::LoadModelFromProto( const new_proto::MPModelProto& input_model) { + MPObjective* const objective = MutableObjective(); for (int i = 0; i < input_model.variable_size(); ++i) { const new_proto::MPVariableProto& var_proto = input_model.variable(i); @@ -494,20 +476,20 @@ MPSolver::LoadStatus MPSolver::LoadModelFromProto( // the given name argument is empty. // // Note(user): The auto assigned id limits the number of variables to 10^9. - MPVariable* variable = MakeNumVar( - var_proto.lower_bound(), var_proto.upper_bound(), /*name=*/ ""); + MPVariable* variable = MakeNumVar(var_proto.lower_bound(), + var_proto.upper_bound(), /*name=*/""); variable->SetInteger(var_proto.is_integer()); - SetObjectiveCoefficient(variable, var_proto.objective_coefficient()); + objective->SetCoefficient(variable, var_proto.objective_coefficient()); } for (int i = 0; i < input_model.constraint_size(); ++i) { const new_proto::MPConstraintProto& ct_proto = input_model.constraint(i); - MPConstraint* const ct = MakeRowConstraint(ct_proto.lower_bound(), - ct_proto.upper_bound(), - ct_proto.name()); + MPConstraint* const ct = MakeRowConstraint( + ct_proto.lower_bound(), ct_proto.upper_bound(), ct_proto.name()); if (ct_proto.var_index_size() != ct_proto.coefficient_size()) { LOG(ERROR) << "In constraint #" << i << " (name: '" << ct_proto.name() - << "'):" << " var_index_size() != coefficient_size()" + << "'):" + << " var_index_size() != coefficient_size()" << ct_proto.DebugString(); // TODO(user): add new error type to MPSolver and return it here. // TODO(user): add unit test of this error. @@ -535,15 +517,15 @@ namespace { new_proto::MPSolutionResponse::Status ResultStatusToMPSolutionResponse( MPSolver::ResultStatus status) { switch (status) { - case MPSolver::OPTIMAL : + case MPSolver::OPTIMAL: return new_proto::MPSolutionResponse::OPTIMAL; - case MPSolver::FEASIBLE : + case MPSolver::FEASIBLE: return new_proto::MPSolutionResponse::FEASIBLE; - case MPSolver::INFEASIBLE : + case MPSolver::INFEASIBLE: return new_proto::MPSolutionResponse::INFEASIBLE; - case MPSolver::UNBOUNDED : + case MPSolver::UNBOUNDED: return new_proto::MPSolutionResponse::UNBOUNDED; - case MPSolver::ABNORMAL : + case MPSolver::ABNORMAL: return new_proto::MPSolutionResponse::ABNORMAL; default: return new_proto::MPSolutionResponse::UNKNOWN; @@ -559,7 +541,7 @@ void MPSolver::FillSolutionResponseProto( ResultStatusToMPSolutionResponse(interface_->result_status_)); if (interface_->result_status_ == MPSolver::OPTIMAL || interface_->result_status_ == MPSolver::FEASIBLE) { - response->set_objective_value(objective_value()); + response->set_objective_value(Objective().Value()); for (int i = 0; i < variables_.size(); ++i) { response->add_variable_value(variables_[i]->solution_value()); } @@ -567,14 +549,12 @@ void MPSolver::FillSolutionResponseProto( } // static -void MPSolver::SolveWithProto( - const new_proto::MPModelRequest& model_request, - new_proto::MPSolutionResponse* response) { +void MPSolver::SolveWithProto(const new_proto::MPModelRequest& model_request, + new_proto::MPSolutionResponse* response) { CHECK_NOTNULL(response); const new_proto::MPModelProto& model = model_request.model(); - MPSolver solver(model.name(), - static_cast( - model_request.solver_type())); + MPSolver solver(model.name(), static_cast( + model_request.solver_type())); const MPSolver::LoadStatus loadStatus = solver.LoadModelFromProto(model); if (loadStatus != MPSolver::NO_ERROR) { LOG(WARNING) << "Loading model from protocol buffer failed, " @@ -594,8 +574,8 @@ void MPSolver::SolveWithProto( solver.FillSolutionResponseProto(response); } -void MPSolver::ExportModelToNewProto( - new_proto::MPModelProto* output_model) const { +void MPSolver::ExportModelToNewProto(new_proto::MPModelProto* output_model) + const { DCHECK(output_model != NULL); output_model->Clear(); // Name @@ -603,8 +583,8 @@ void MPSolver::ExportModelToNewProto( // Variables for (int j = 0; j < variables_.size(); ++j) { const MPVariable* const var = variables_[j]; - new_proto::MPVariableProto* const variable_proto - = output_model->add_variable(); + new_proto::MPVariableProto* const variable_proto = + output_model->add_variable(); // TODO(user): Add option to avoid filling the var name to avoid overly // large protocol buffers. variable_proto->set_name(var->name()); @@ -631,8 +611,8 @@ void MPSolver::ExportModelToNewProto( // Constraints for (int i = 0; i < constraints_.size(); ++i) { MPConstraint* const constraint = constraints_[i]; - new_proto::MPConstraintProto* const constraint_proto - = output_model->add_constraint(); + new_proto::MPConstraintProto* const constraint_proto = + output_model->add_constraint(); constraint_proto->set_name(constraint->name()); constraint_proto->set_lower_bound(constraint->lb()); constraint_proto->set_upper_bound(constraint->ub()); @@ -662,8 +642,7 @@ void MPSolver::ExportModelToNewProto( bool MPSolver::LoadSolutionFromNewProto( const new_proto::MPSolutionResponse& response) { - interface_->result_status_ = - static_cast(response.status()); + interface_->result_status_ = static_cast(response.status()); if (response.status() != new_proto::MPSolutionResponse::OPTIMAL && response.status() != new_proto::MPSolutionResponse::FEASIBLE) { LOG(ERROR) @@ -674,16 +653,15 @@ bool MPSolver::LoadSolutionFromNewProto( // each variable of the MPSolver must have its value listed exactly once, and // each listed solution should correspond to a known variable. if (response.variable_value_size() != variables_.size()) { - LOG(ERROR) - << "Trying to load a solution whose number of variables does not" - << " correspond to the Solver."; + LOG(ERROR) << "Trying to load a solution whose number of variables does not" + << " correspond to the Solver."; return false; } double largest_error = 0; interface_->ExtractModel(); int num_vars_out_of_bounds = 0; const double tolerance = MPSolverParameters::kDefaultPrimalTolerance; - for (int i = 0; i< response.variable_value_size(); ++i) { + for (int i = 0; i < response.variable_value_size(); ++i) { // Look further: verify the bounds. Since linear solvers yield (small) // numerical errors, though, we just log a warning if the variables look // like they are out of their bounds. The user should inspect the values. @@ -716,7 +694,7 @@ bool MPSolver::LoadSolutionFromNewProto( } void MPSolver::Clear() { - ClearObjective(); + MutableObjective()->Clear(); STLDeleteElements(&variables_); STLDeleteElements(&constraints_); variables_.clear(); @@ -726,23 +704,17 @@ void MPSolver::Clear() { interface_->Reset(); } -void MPSolver::Reset() { - interface_->Reset(); -} +void MPSolver::Reset() { interface_->Reset(); } -void MPSolver::EnableOutput() { - interface_->set_quiet(false); -} +void MPSolver::EnableOutput() { interface_->set_quiet(false); } -void MPSolver::SuppressOutput() { - interface_->set_quiet(true); -} +void MPSolver::SuppressOutput() { interface_->set_quiet(true); } -MPVariable* MPSolver::MakeVar( - double lb, double ub, bool integer, const std::string& name) { +MPVariable* MPSolver::MakeVar(double lb, double ub, bool integer, + const std::string& name) { const int var_index = NumVariables(); - const std::string fixed_name = name.empty() - ? StringPrintf("auto_v_%09d", var_index) : name; + const std::string fixed_name = + name.empty() ? StringPrintf("auto_v_%09d", var_index) : name; if (var_and_constraint_names_allow_export_) { var_and_constraint_names_allow_export_ &= MPModelProtoExporter::CheckNameValidity(fixed_name); @@ -754,13 +726,11 @@ MPVariable* MPSolver::MakeVar( return v; } -MPVariable* MPSolver::MakeNumVar( - double lb, double ub, const std::string& name) { +MPVariable* MPSolver::MakeNumVar(double lb, double ub, const std::string& name) { return MakeVar(lb, ub, false, name); } -MPVariable* MPSolver::MakeIntVar( - double lb, double ub, const std::string& name) { +MPVariable* MPSolver::MakeIntVar(double lb, double ub, const std::string& name) { return MakeVar(lb, ub, true, name); } @@ -768,12 +738,8 @@ MPVariable* MPSolver::MakeBoolVar(const std::string& name) { return MakeVar(0.0, 1.0, true, name); } -void MPSolver::MakeVarArray(int nb, - double lb, - double ub, - bool integer, - const std::string& name, - std::vector* vars) { +void MPSolver::MakeVarArray(int nb, double lb, double ub, bool integer, + const std::string& name, std::vector* vars) { DCHECK_GE(nb, 0); if (nb <= 0) return; const int num_digits = NumDigits(nb); @@ -787,24 +753,17 @@ void MPSolver::MakeVarArray(int nb, } } -void MPSolver::MakeNumVarArray(int nb, - double lb, - double ub, - const std::string& name, +void MPSolver::MakeNumVarArray(int nb, double lb, double ub, const std::string& name, std::vector* vars) { MakeVarArray(nb, lb, ub, false, name, vars); } -void MPSolver::MakeIntVarArray(int nb, - double lb, - double ub, - const std::string& name, +void MPSolver::MakeIntVarArray(int nb, double lb, double ub, const std::string& name, std::vector* vars) { MakeVarArray(nb, lb, ub, true, name, vars); } -void MPSolver::MakeBoolVarArray(int nb, - const std::string& name, +void MPSolver::MakeBoolVarArray(int nb, const std::string& name, std::vector* vars) { MakeVarArray(nb, 0.0, 1.0, true, name, vars); } @@ -820,8 +779,8 @@ MPConstraint* MPSolver::MakeRowConstraint() { MPConstraint* MPSolver::MakeRowConstraint(double lb, double ub, const std::string& name) { const int constraint_index = NumConstraints(); - const std::string fixed_name = name.empty() - ? StringPrintf("auto_c_%09d", constraint_index) : name; + const std::string fixed_name = + name.empty() ? StringPrintf("auto_c_%09d", constraint_index) : name; if (var_and_constraint_names_allow_export_) { var_and_constraint_names_allow_export_ &= MPModelProtoExporter::CheckNameValidity(fixed_name); @@ -856,8 +815,8 @@ bool MPSolver::HasInfeasibleConstraints() const { bool hasInfeasibleConstraints = false; for (int i = 0; i < constraints_.size(); ++i) { if (constraints_[i]->lb() > constraints_[i]->ub()) { - LOG(WARNING) << "Constraint " << constraints_[i]->name() - << " (" << i << ") has contradictory bounds:" + LOG(WARNING) << "Constraint " << constraints_[i]->name() << " (" << i + << ") has contradictory bounds:" << " lower bound = " << constraints_[i]->lb() << " upper bound = " << constraints_[i]->ub(); hasInfeasibleConstraints = true; @@ -871,7 +830,7 @@ MPSolver::ResultStatus MPSolver::Solve() { return Solve(default_param); } -MPSolver::ResultStatus MPSolver::Solve(const MPSolverParameters ¶m) { +MPSolver::ResultStatus MPSolver::Solve(const MPSolverParameters& param) { // Special case for infeasible constraints so that all solvers have // the same behavior. if (HasInfeasibleConstraints()) { @@ -886,8 +845,8 @@ MPSolver::ResultStatus MPSolver::Solve(const MPSolverParameters ¶m) { VLOG(1) << "--verify_solution enabled, but the solver did not find an" << " optimal solution: skipping the verification."; } else if (!VerifySolution( - param.GetDoubleParam(MPSolverParameters::PRIMAL_TOLERANCE), - FLAGS_log_verification_errors)) { + param.GetDoubleParam(MPSolverParameters::PRIMAL_TOLERANCE), + FLAGS_log_verification_errors)) { status = MPSolver::ABNORMAL; interface_->result_status_ = status; } @@ -899,8 +858,7 @@ MPSolver::ResultStatus MPSolver::Solve(const MPSolverParameters ¶m) { namespace { std::string PrettyPrintVar(const MPVariable& var) { const std::string prefix = "Variable '" + var.name() + "': domain = "; - if (var.lb() >= MPSolver::infinity() || - var.ub() <= -MPSolver::infinity() || + if (var.lb() >= MPSolver::infinity() || var.ub() <= -MPSolver::infinity() || var.lb() > var.ub()) { return prefix + "∅"; // Empty set. } @@ -921,14 +879,12 @@ std::string PrettyPrintVar(const MPVariable& var) { if (var.lb() == var.ub()) { return StringPrintf("%s{ %f }", prefix.c_str(), var.lb()); } - return prefix - + (var.integer() ? "Integer" : "Real") - + " in " - + (var.lb() <= -MPSolver::infinity() - ? std::string("]-∞") : StringPrintf("[%f", var.lb())) - + ", " - + (var.ub() >= MPSolver::infinity() - ? std::string("+∞[") : StringPrintf("%f]", var.ub())); + return prefix + (var.integer() ? "Integer" : "Real") + " in " + + (var.lb() <= -MPSolver::infinity() ? std::string("]-∞") + : StringPrintf("[%f", var.lb())) + + ", " + + (var.ub() >= MPSolver::infinity() ? std::string("+∞[") + : StringPrintf("%f]", var.ub())); } std::string PrettyPrintConstraint(const MPConstraint& constraint) { @@ -954,8 +910,8 @@ std::string PrettyPrintConstraint(const MPConstraint& constraint) { if (constraint.ub() >= MPSolver::infinity()) { return StringPrintf("%s ≥ %f", prefix.c_str(), constraint.lb()); } - return StringPrintf("%s ∈ [%f, %f]", - prefix.c_str(), constraint.lb(), constraint.ub()); + return StringPrintf("%s ∈ [%f, %f]", prefix.c_str(), constraint.lb(), + constraint.ub()); } } // namespace @@ -981,8 +937,8 @@ bool MPSolver::VerifySolution(double tolerance, bool log_errors) const { if (value < var.lb() - tolerance) { ++num_errors; max_observed_error = std::max(max_observed_error, var.lb() - value); - LOG_IF(ERROR, log_errors) - << "Value " << value << " too low for " << PrettyPrintVar(var); + LOG_IF(ERROR, log_errors) << "Value " << value << " too low for " + << PrettyPrintVar(var); } } // Check upper bound. @@ -990,18 +946,18 @@ bool MPSolver::VerifySolution(double tolerance, bool log_errors) const { if (value > var.ub() + tolerance) { ++num_errors; max_observed_error = std::max(max_observed_error, value - var.ub()); - LOG_IF(ERROR, log_errors) - << "Value " << value << " too high for " << PrettyPrintVar(var); + LOG_IF(ERROR, log_errors) << "Value " << value << " too high for " + << PrettyPrintVar(var); } } // Check integrality. if (var.integer()) { if (fabs(value - round(value)) > tolerance) { ++num_errors; - max_observed_error = std::max(max_observed_error, - fabs(value - round(value))); - LOG_IF(ERROR, log_errors) - << "Non-integer value "<< value << " for " << PrettyPrintVar(var); + max_observed_error = + std::max(max_observed_error, fabs(value - round(value))); + LOG_IF(ERROR, log_errors) << "Non-integer value " << value << " for " + << PrettyPrintVar(var); } } } @@ -1022,19 +978,18 @@ bool MPSolver::VerifySolution(double tolerance, bool log_errors) const { if (isnan(activity) || isnan(inaccurate_activity)) { ++num_errors; max_observed_error = infinity(); - LOG_IF(ERROR, log_errors) - << "NaN value for " << PrettyPrintConstraint(constraint); + LOG_IF(ERROR, log_errors) << "NaN value for " + << PrettyPrintConstraint(constraint); continue; } // Check bounds. if (constraint.lb() != -infinity()) { if (activity < constraint.lb() - tolerance) { ++num_errors; - max_observed_error = std::max(max_observed_error, - constraint.lb() - activity); - LOG_IF(ERROR, log_errors) - << "Activity " << activity << " too low for " - << PrettyPrintConstraint(constraint); + max_observed_error = + std::max(max_observed_error, constraint.lb() - activity); + LOG_IF(ERROR, log_errors) << "Activity " << activity << " too low for " + << PrettyPrintConstraint(constraint); } else if (inaccurate_activity < constraint.lb() - tolerance) { LOG_IF(WARNING, log_errors) << "Activity " << activity << ", computed with the (inaccurate)" @@ -1045,11 +1000,10 @@ bool MPSolver::VerifySolution(double tolerance, bool log_errors) const { if (constraint.ub() != infinity()) { if (activity > constraint.ub() + tolerance) { ++num_errors; - max_observed_error = std::max(max_observed_error, - activity - constraint.ub()); - LOG_IF(ERROR, log_errors) - << "Activity " << activity << " too high for " - << PrettyPrintConstraint(constraint); + max_observed_error = + std::max(max_observed_error, activity - constraint.ub()); + LOG_IF(ERROR, log_errors) << "Activity " << activity << " too high for " + << PrettyPrintConstraint(constraint); } else if (inaccurate_activity > constraint.ub() + tolerance) { LOG_IF(WARNING, log_errors) << "Activity " << activity << ", computed with the (inaccurate)" @@ -1070,42 +1024,36 @@ bool MPSolver::VerifySolution(double tolerance, bool log_errors) const { inaccurate_objective_value += term; } const double actual_objective_value = objective_sum.Value(); - if (!AreWithinAbsoluteOrRelativeTolerances(objective.Value(), - actual_objective_value, - tolerance, - tolerance)) { + if (!AreWithinAbsoluteOrRelativeTolerances( + objective.Value(), actual_objective_value, tolerance, tolerance)) { ++num_errors; - max_observed_error = std::max( - max_observed_error, fabs(actual_objective_value - objective.Value())); - LOG_IF(ERROR, log_errors) - << "Objective value " << objective.Value() << " isn't accurate" - << ", it should be " << actual_objective_value - << " (delta=" << actual_objective_value - objective.Value() << ")."; + max_observed_error = std::max(max_observed_error, + fabs(actual_objective_value - objective.Value())); + LOG_IF(ERROR, log_errors) << "Objective value " << objective.Value() + << " isn't accurate" + << ", it should be " << actual_objective_value + << " (delta=" << actual_objective_value - + objective.Value() << ")."; } else if (!AreWithinAbsoluteOrRelativeTolerances(objective.Value(), inaccurate_objective_value, - tolerance, - tolerance)) { + tolerance, tolerance)) { LOG_IF(WARNING, log_errors) << "Objective value " << objective.Value() << " doesn't correspond" << " to the value computed with the standard (and therefore inaccurate)" << " sum of its terms."; } if (num_errors > 0) { - LOG_IF(ERROR, log_errors) - << "There were " << num_errors << " errors above the tolerance (" - << tolerance << "), the largest was " << max_observed_error; + LOG_IF(ERROR, log_errors) << "There were " << num_errors + << " errors above the tolerance (" << tolerance + << "), the largest was " << max_observed_error; return false; } return true; } -int64 MPSolver::iterations() const { - return interface_->iterations(); -} +int64 MPSolver::iterations() const { return interface_->iterations(); } -int64 MPSolver::nodes() const { - return interface_->nodes(); -} +int64 MPSolver::nodes() const { return interface_->nodes(); } double MPSolver::ComputeExactConditionNumber() const { return interface_->ComputeExactConditionNumber(); @@ -1122,7 +1070,6 @@ bool MPSolver::OwnsVariable(const MPVariable* var) const { return variables_[var_index] == var; } - bool MPSolver::ExportModelAsLpFormat(bool obfuscate, std::string* output) { MPModelProto proto; ExportModelToNewProto(&proto); @@ -1130,8 +1077,8 @@ bool MPSolver::ExportModelAsLpFormat(bool obfuscate, std::string* output) { return exporter.ExportModelAsLpFormat(obfuscate, output); } -bool MPSolver::ExportModelAsMpsFormat( - bool fixed_format, bool obfuscate, std::string* output) { +bool MPSolver::ExportModelAsMpsFormat(bool fixed_format, bool obfuscate, + std::string* output) { MPModelProto proto; ExportModelToNewProto(&proto); MPModelProtoExporter exporter(proto); @@ -1143,10 +1090,14 @@ bool MPSolver::ExportModelAsMpsFormat( const int MPSolverInterface::kDummyVariableIndex = 0; MPSolverInterface::MPSolverInterface(MPSolver* const solver) - : solver_(solver), sync_status_(MODEL_SYNCHRONIZED), - result_status_(MPSolver::NOT_SOLVED), maximize_(false), - last_constraint_index_(0), last_variable_index_(0), - objective_value_(0.0), quiet_(true) {} + : solver_(solver), + sync_status_(MODEL_SYNCHRONIZED), + result_status_(MPSolver::NOT_SOLVED), + maximize_(false), + last_constraint_index_(0), + last_variable_index_(0), + objective_value_(0.0), + quiet_(true) {} MPSolverInterface::~MPSolverInterface() {} @@ -1206,9 +1157,8 @@ bool MPSolverInterface::CheckSolutionIsSynchronized() const { bool MPSolverInterface::CheckSolutionExists() const { if (result_status_ != MPSolver::OPTIMAL && result_status_ != MPSolver::FEASIBLE) { - LOG(DFATAL) - << "No solution exists. MPSolverInterface::result_status_ = " - << result_status_; + LOG(DFATAL) << "No solution exists. MPSolverInterface::result_status_ = " + << result_status_; return false; } return true; @@ -1219,9 +1169,8 @@ bool MPSolverInterface::CheckSolutionExists() const { bool MPSolverInterface::CheckBestObjectiveBoundExists() const { if (result_status_ != MPSolver::OPTIMAL && result_status_ != MPSolver::FEASIBLE) { - LOG(DFATAL) - << "No information is available for the best objective bound." - << " MPSolverInterface::result_status_ = " << result_status_; + LOG(DFATAL) << "No information is available for the best objective bound." + << " MPSolverInterface::result_status_ = " << result_status_; return false; } return true; @@ -1245,21 +1194,21 @@ void MPSolverInterface::InvalidateSolutionSynchronization() { double MPSolverInterface::ComputeExactConditionNumber() const { // Override this method in interfaces that actually support it. - LOG(DFATAL) - << "ComputeExactConditionNumber not implemented for " - << MPModelRequest::SolverType_Name( - static_cast(solver_->ProblemType())); + LOG(DFATAL) << "ComputeExactConditionNumber not implemented for " + << MPModelRequest::SolverType_Name( + static_cast( + solver_->ProblemType())); return 0.0; } void MPSolverInterface::SetCommonParameters(const MPSolverParameters& param) { - // By default, we let GLOP keep its own default tolerance, much more accurate - // than for the rest of the solvers. +// By default, we let GLOP keep its own default tolerance, much more accurate +// than for the rest of the solvers. #if defined(USE_GLOP) if (solver_->ProblemType() != MPSolver::GLOP_LINEAR_PROGRAMMING) { #endif - SetPrimalTolerance(param.GetDoubleParam( - MPSolverParameters::PRIMAL_TOLERANCE)); + SetPrimalTolerance( + param.GetDoubleParam(MPSolverParameters::PRIMAL_TOLERANCE)); SetDualTolerance(param.GetDoubleParam(MPSolverParameters::DUAL_TOLERANCE)); #if defined(USE_GLOP) } @@ -1313,10 +1262,10 @@ const double MPSolverParameters::kDefaultRelativeMipGap = 1e-4; const double MPSolverParameters::kDefaultPrimalTolerance = 1e-7; const double MPSolverParameters::kDefaultDualTolerance = 1e-7; const MPSolverParameters::PresolveValues MPSolverParameters::kDefaultPresolve = - MPSolverParameters::PRESOLVE_ON; + MPSolverParameters::PRESOLVE_ON; const MPSolverParameters::IncrementalityValues -MPSolverParameters::kDefaultIncrementality = -MPSolverParameters::INCREMENTALITY_ON; + MPSolverParameters::kDefaultIncrementality = + MPSolverParameters::INCREMENTALITY_ON; const double MPSolverParameters::kDefaultDoubleParamValue = -1.0; const int MPSolverParameters::kDefaultIntegerParamValue = -1; @@ -1453,18 +1402,12 @@ void MPSolverParameters::Reset() { ResetIntegerParam(INCREMENTALITY); } -double MPSolverParameters::GetDoubleParam( - MPSolverParameters::DoubleParam param) const { +double MPSolverParameters::GetDoubleParam(MPSolverParameters::DoubleParam param) + const { switch (param) { - case RELATIVE_MIP_GAP: { - return relative_mip_gap_value_; - } - case PRIMAL_TOLERANCE: { - return primal_tolerance_value_; - } - case DUAL_TOLERANCE: { - return dual_tolerance_value_; - } + case RELATIVE_MIP_GAP: { return relative_mip_gap_value_; } + case PRIMAL_TOLERANCE: { return primal_tolerance_value_; } + case DUAL_TOLERANCE: { return dual_tolerance_value_; } default: { LOG(ERROR) << "Trying to get an unknown parameter: " << param << "."; return kUnknownDoubleParamValue; @@ -1472,22 +1415,16 @@ double MPSolverParameters::GetDoubleParam( } } -int MPSolverParameters::GetIntegerParam( - MPSolverParameters::IntegerParam param) const { +int MPSolverParameters::GetIntegerParam(MPSolverParameters::IntegerParam param) + const { switch (param) { - case PRESOLVE: { - return presolve_value_; - } + case PRESOLVE: { return presolve_value_; } case LP_ALGORITHM: { if (lp_algorithm_is_default_) return kDefaultIntegerParamValue; return lp_algorithm_value_; } - case INCREMENTALITY: { - return incrementality_value_; - } - case SCALING: { - return scaling_value_; - } + case INCREMENTALITY: { return incrementality_value_; } + case SCALING: { return scaling_value_; } default: { LOG(ERROR) << "Trying to get an unknown parameter: " << param << "."; return kUnknownIntegerParamValue; diff --git a/src/linear_solver/linear_solver.h b/src/linear_solver/linear_solver.h index b2a6cd917e..12d1b320d8 100644 --- a/src/linear_solver/linear_solver.h +++ b/src/linear_solver/linear_solver.h @@ -157,9 +157,9 @@ class MPVariable; // The new MP protocol buffer format. New clients that want to work with // protocol buffers should use this. namespace new_proto { - class MPModelProto; - class MPModelRequest; - class MPSolutionResponse; +class MPModelProto; +class MPModelRequest; +class MPSolutionResponse; } // namespace new_proto // This mathematical programming (MP) solver class is the main class @@ -247,28 +247,16 @@ class MPSolver { // created, the function crashes in non-opt mode. // @param name the prefix of the variable names. Variables are named // name0, name1, ... - void MakeVarArray(int nb, - double lb, - double ub, - bool integer, - const std::string& name_prefix, - std::vector* vars); + void MakeVarArray(int nb, double lb, double ub, bool integer, + const std::string& name_prefix, std::vector* vars); // Creates an array of continuous variables. - void MakeNumVarArray(int nb, - double lb, - double ub, - const std::string& name, + void MakeNumVarArray(int nb, double lb, double ub, const std::string& name, std::vector* vars); // Creates an array of integer variables. - void MakeIntVarArray(int nb, - double lb, - double ub, - const std::string& name, + void MakeIntVarArray(int nb, double lb, double ub, const std::string& name, std::vector* vars); // Creates an array of boolean variables. - void MakeBoolVarArray(int nb, - const std::string& name, - std::vector* vars); + void MakeBoolVarArray(int nb, const std::string& name, std::vector* vars); // ----- Constraints ----- // Returns the number of constraints. @@ -347,7 +335,7 @@ class MPSolver { // The status of loading the problem from a protocol buffer. enum LoadStatus { - NO_ERROR = 0, // no error has been encountered. + NO_ERROR = 0, // no error has been encountered. // Skip value '1' to stay consistent with the .proto. DUPLICATE_VARIABLE_ID = 2, // error: two variables have the same id. UNKNOWN_VARIABLE_ID = 3, // error: a variable has an unknown id. @@ -367,9 +355,8 @@ class MPSolver { // end. If you want to keep the MPSolver alive (for debugging, or for // incremental solving), you should write another version of this function // that creates the MPSolver object on the heap and returns it. - static void SolveWithProto( - const new_proto::MPModelRequest& model_request, - new_proto::MPSolutionResponse* response); + static void SolveWithProto(const new_proto::MPModelRequest& model_request, + new_proto::MPSolutionResponse* response); // Exports model to protocol buffer. // TODO(user): rename to ExportModelToProto when possible. @@ -405,16 +392,15 @@ class MPSolver { // Note: the variable and objective values aren't checked. You can use // VerifySolution() for that. // TODO(user): rename to LoadSolutionFromProto when possible. - bool LoadSolutionFromNewProto( - const new_proto::MPSolutionResponse& response); + bool LoadSolutionFromNewProto(const new_proto::MPSolutionResponse& response); // ----- Export model to files or strings ----- // Shortcuts to the homonymous MPModelProtoExporter methods, via // exporting to a MPModelProto with ExportModelToNewProto() (see above). bool ExportModelAsLpFormat(bool obfuscated, std::string* model_str); - bool ExportModelAsMpsFormat( - bool fixed_format, bool obfuscated, std::string* model_str); + bool ExportModelAsMpsFormat(bool fixed_format, bool obfuscated, + std::string* model_str); // ----- Misc ----- @@ -438,9 +424,7 @@ class MPSolver { }; // Infinity. You can use -MPSolver::infinity() for negative infinity. - static double infinity() { - return std::numeric_limits::infinity(); - } + static double infinity() { return std::numeric_limits::infinity(); } // Suppresses all output from the underlying solver. void SuppressOutput(); @@ -457,9 +441,7 @@ class MPSolver { } // In milliseconds. - int64 time_limit() const { - return time_limit_; - } + int64 time_limit() const { return time_limit_; } // In seconds. Note that this returns a double. double time_limit_in_secs() const { @@ -468,11 +450,8 @@ class MPSolver { return static_cast(time_limit_) / 1000.0; } - // Returns wall_time() in milliseconds since the creation of the solver. - int64 wall_time() const { - return timer_.GetInMs(); - } + int64 wall_time() const { return timer_.GetInMs(); } // Returns the number of simplex iterations. int64 iterations() const; @@ -608,10 +587,11 @@ class MPSolver { class CoeffMap : public hash_map { public: explicit CoeffMap(int num_buckets) - #if !defined(_MSC_VER) // Visual C++ doesn't support this constructor - : hash_map(num_buckets) - #endif // _MSC_VER - { } +#if !defined(_MSC_VER) // Visual C++ doesn't support this constructor + : hash_map(num_buckets) +#endif // _MSC_VER + { + } }; #endif // SWIG @@ -754,8 +734,14 @@ class MPVariable { // several models. MPVariable(double lb, double ub, bool integer, const std::string& name, MPSolverInterface* const interface) - : lb_(lb), ub_(ub), integer_(integer), name_(name), index_(-1), - solution_value_(0.0), reduced_cost_(0.0), interface_(interface) {} + : lb_(lb), + ub_(ub), + integer_(integer), + name_(name), + index_(-1), + solution_value_(0.0), + reduced_cost_(0.0), + interface_(interface) {} void set_index(int index) { index_ = index; } void set_solution_value(double value) { solution_value_ = value; } @@ -844,12 +830,17 @@ class MPConstraint { // Constructor. A constraint points to a single MPSolverInterface // that is specified in the constructor. A constraint cannot belong // to several models. - MPConstraint(double lb, - double ub, - const std::string& name, + MPConstraint(double lb, double ub, const std::string& name, MPSolverInterface* const interface) - : coefficients_(1), lb_(lb), ub_(ub), name_(name), is_lazy_(false), - index_(-1), dual_value_(0.0), activity_(0.0), interface_(interface) {} + : coefficients_(1), + lb_(lb), + ub_(ub), + name_(name), + is_lazy_(false), + index_(-1), + dual_value_(0.0), + activity_(0.0), + interface_(interface) {} void set_index(int index) { index_ = index; } void set_activity(double activity) { activity_ = activity; } @@ -883,8 +874,6 @@ class MPConstraint { DISALLOW_COPY_AND_ASSIGN(MPConstraint); }; - - // This class stores parameter settings for LP and MIP solvers. // Some parameters are marked as advanced: do not change their values // unless you know what you are doing! @@ -943,9 +932,9 @@ class MPSolverParameters { }; enum LpAlgorithmValues { - DUAL = 10, // Dual simplex. - PRIMAL = 11, // Primal simplex. - BARRIER = 12 // Barrier algorithm. + DUAL = 10, // Dual simplex. + PRIMAL = 11, // Primal simplex. + BARRIER = 12 // Barrier algorithm. }; enum IncrementalityValues { @@ -1010,7 +999,7 @@ class MPSolverParameters { // Returns the value of a parameter. double GetDoubleParam(MPSolverParameters::DoubleParam param) const; int GetIntegerParam(MPSolverParameters::IntegerParam param) const; - // @} +// @} private: @@ -1036,7 +1025,6 @@ class MPSolverParameters { DISALLOW_COPY_AND_ASSIGN(MPSolverParameters); }; - // This class wraps the actual mathematical programming solvers. Each // solver (CLP, CBC, GLPK, SCIP) has its own interface class that // derives from this abstract class. This class is never directly @@ -1104,8 +1092,7 @@ class MPSolverInterface { // Changes a coefficient in a constraint. virtual void SetCoefficient(MPConstraint* const constraint, const MPVariable* const variable, - double new_value, - double old_value) = 0; + double new_value, double old_value) = 0; // Clears a constraint from all its terms. virtual void ClearConstraint(MPConstraint* const constraint) = 0; @@ -1170,18 +1157,12 @@ class MPSolverInterface { virtual bool IsMIP() const = 0; // Returns the index of the last variable extracted. - int last_variable_index() const { - return last_variable_index_; - } + int last_variable_index() const { return last_variable_index_; } // Returns the boolean indicating the verbosity of the solver output. - bool quiet() const { - return quiet_; - } + bool quiet() const { return quiet_; } // Sets the boolean indicating the verbosity of the solver output. - void set_quiet(bool quiet_value) { - quiet_ = quiet_value; - } + void set_quiet(bool quiet_value) { quiet_ = quiet_value; } // Returns the result status of the last solve. MPSolver::ResultStatus result_status() const { diff --git a/src/linear_solver/model_exporter.cc b/src/linear_solver/model_exporter.cc index 9b3dd9d43c..436d0c4121 100644 --- a/src/linear_solver/model_exporter.cc +++ b/src/linear_solver/model_exporter.cc @@ -30,19 +30,18 @@ using new_proto::MPConstraintProto; using new_proto::MPModelProto; using new_proto::MPVariableProto; -MPModelProtoExporter::MPModelProtoExporter(const MPModelProto& proto) : - proto_(proto), - var_id_to_index_map_(), - num_integer_variables_(0), - num_binary_variables_(0), - num_continuous_variables_(0), - num_digits_for_variables_(0), - num_digits_for_constraints_(0), - current_mps_column_(0), - use_fixed_mps_format_(false), - use_obfuscated_names_(false), - setup_done_(false) { -} +MPModelProtoExporter::MPModelProtoExporter(const MPModelProto& proto) + : proto_(proto), + var_id_to_index_map_(), + num_integer_variables_(0), + num_binary_variables_(0), + num_continuous_variables_(0), + num_digits_for_variables_(0), + num_digits_for_constraints_(0), + current_mps_column_(0), + use_fixed_mps_format_(false), + use_obfuscated_names_(false), + setup_done_(false) {} // Note(user): This method is static. It is also used by MPSolver. bool MPModelProtoExporter::CheckNameValidity(const std::string& name) { @@ -53,8 +52,8 @@ bool MPModelProtoExporter::CheckNameValidity(const std::string& name) { // Allow names that conform to the LP and MPS format. const int kMaxNameLength = 255; if (name.size() > kMaxNameLength) { - LOG(WARNING) << "Invalid name " << name - << ": length > " << kMaxNameLength << "." + LOG(WARNING) << "Invalid name " << name << ": length > " << kMaxNameLength + << "." << " Will be unable to write model to file."; return false; } @@ -76,7 +75,6 @@ bool MPModelProtoExporter::CheckNameValidity(const std::string& name) { return true; } - std::string MPModelProtoExporter::GetVariableName(int var_index) const { const new_proto::MPVariableProto& var_proto = proto_.variable(var_index); if (use_obfuscated_names_ || !var_proto.has_name()) { @@ -95,8 +93,8 @@ std::string MPModelProtoExporter::GetConstraintName(int cst_index) const { } } -void MPModelProtoExporter::AppendComments( - const std::string& separator, std::string* output) const { +void MPModelProtoExporter::AppendComments(const std::string& separator, + std::string* output) const { const char* const sep = separator.c_str(); StringAppendF(output, "%s Generated by MPModelProtoExporter\n", sep); StringAppendF(output, "%s %-16s : %s\n", sep, "Name", @@ -122,23 +120,22 @@ bool MPModelProtoExporter::AppendLpTerm(int var_index, double coefficient, return false; } if (coefficient == 0.0) return true; - StringAppendF(output, "%+.16G %-s ", - coefficient, GetVariableName(var_index).c_str()); + StringAppendF(output, "%+.16G %-s ", coefficient, + GetVariableName(var_index).c_str()); return true; } namespace { bool IsBoolean(const MPVariableProto& var) { return var.is_integer() && ceil(var.lower_bound()) == 0.0 && - floor(var.upper_bound()) == 1.0; + floor(var.upper_bound()) == 1.0; } } // namespace bool MPModelProtoExporter::Setup() { num_digits_for_constraints_ = StringPrintf("%d", proto_.constraint_size()).size(); - num_digits_for_variables_ = - StringPrintf("%d", proto_.variable_size()).size(); + num_digits_for_variables_ = StringPrintf("%d", proto_.variable_size()).size(); num_binary_variables_ = 0; num_integer_variables_ = 0; for (const MPVariableProto& var : proto_.variable()) { @@ -150,8 +147,8 @@ bool MPModelProtoExporter::Setup() { } } } - num_continuous_variables_ = proto_.variable_size() - num_binary_variables_ - - num_integer_variables_; + num_continuous_variables_ = + proto_.variable_size() - num_binary_variables_ - num_integer_variables_; return true; } @@ -213,24 +210,24 @@ bool MPModelProtoExporter::ExportModelAsLpFormat(bool obfuscated, const double ub = ct_proto.upper_bound(); std::string name = GetConstraintName(cst_index); if (lb == ub) { - StringAppendF(output, " %s: %s = %-.16G\n", - name.c_str(), term.c_str(), ub); + StringAppendF(output, " %s: %s = %-.16G\n", name.c_str(), term.c_str(), + ub); } else { if (ub != +std::numeric_limits::infinity()) { std::string rhs_name = name; if (lb != -std::numeric_limits::infinity()) { rhs_name += "_rhs"; } - StringAppendF(output, " %s: %s <= %-.16G\n", - rhs_name.c_str(), term.c_str(), ub); + StringAppendF(output, " %s: %s <= %-.16G\n", rhs_name.c_str(), + term.c_str(), ub); } if (lb != -std::numeric_limits::infinity()) { std::string lhs_name = name; if (ub != +std::numeric_limits::infinity()) { lhs_name += "_lhs"; } - StringAppendF(output, " %s: %s >= %-.16G\n", - lhs_name.c_str(), term.c_str(), lb); + StringAppendF(output, " %s: %s >= %-.16G\n", lhs_name.c_str(), + term.c_str(), lb); } } } @@ -245,8 +242,8 @@ bool MPModelProtoExporter::ExportModelAsLpFormat(bool obfuscated, const double lb = var_proto.lower_bound(); const double ub = var_proto.upper_bound(); if (var_proto.is_integer() && lb == round(lb) && ub == round(ub)) { - StringAppendF(output, " %.0f <= %s <= %.0f\n", - lb, GetVariableName(var_index).c_str(), ub); + StringAppendF(output, " %.0f <= %s <= %.0f\n", lb, + GetVariableName(var_index).c_str(), ub); } else { if (lb != -std::numeric_limits::infinity()) { StringAppendF(output, " %-.16G <= ", lb); @@ -284,8 +281,8 @@ bool MPModelProtoExporter::ExportModelAsLpFormat(bool obfuscated, return true; } -void MPModelProtoExporter::AppendMpsPair( - const std::string& name, double value, std::string* output) const { +void MPModelProtoExporter::AppendMpsPair(const std::string& name, double value, + std::string* output) const { const int kFixedMpsDoubleWidth = 12; if (use_fixed_mps_format_) { int precision = kFixedMpsDoubleWidth; @@ -295,17 +292,17 @@ void MPModelProtoExporter::AppendMpsPair( --precision; value_str = StringPrintf("%.*G", precision, value); } - StringAppendF(output, " %-8s %*s ", - name.c_str(), kFixedMpsDoubleWidth, value_str.c_str()); + StringAppendF(output, " %-8s %*s ", name.c_str(), kFixedMpsDoubleWidth, + value_str.c_str()); } else { StringAppendF(output, " %-16s %21.16G ", name.c_str(), value); } } -void MPModelProtoExporter::AppendMpsLineHeader( - const std::string& id, const std::string& name, std::string* output) const { - StringAppendF(output, - use_fixed_mps_format_ ? " %-2s %-8s" : " %-2s %-16s", +void MPModelProtoExporter::AppendMpsLineHeader(const std::string& id, + const std::string& name, + std::string* output) const { + StringAppendF(output, use_fixed_mps_format_ ? " %-2s %-8s" : " %-2s %-16s", id.c_str(), name.c_str()); } @@ -315,9 +312,10 @@ void MPModelProtoExporter::AppendMpsLineHeaderWithNewLine( *output += "\n"; } - -void MPModelProtoExporter::AppendMpsTermWithContext( - const std::string& head_name, const std::string& name, double value, std::string* output) { +void MPModelProtoExporter::AppendMpsTermWithContext(const std::string& head_name, + const std::string& name, + double value, + std::string* output) { if (current_mps_column_ == 0) { AppendMpsLineHeader("", head_name, output); } @@ -325,9 +323,9 @@ void MPModelProtoExporter::AppendMpsTermWithContext( AppendNewLineIfTwoColumns(output); } -void MPModelProtoExporter::AppendMpsBound( - const std::string& bound_type, const std::string& name, double value, - std::string* output) const { +void MPModelProtoExporter::AppendMpsBound(const std::string& bound_type, + const std::string& name, double value, + std::string* output) const { AppendMpsLineHeader(bound_type, "BOUND", output); AppendMpsPair(name, value, output); *output += "\n"; @@ -345,8 +343,8 @@ void MPModelProtoExporter::AppendNewLineIfTwoColumns(std::string* output) { bool MPModelProtoExporter::CanUseFixedMpsFormat() const { const int kMpsFieldSize = 8; if (use_obfuscated_names_) { - return num_digits_for_constraints_ < kMpsFieldSize - && num_digits_for_variables_ < kMpsFieldSize; + return num_digits_for_constraints_ < kMpsFieldSize && + num_digits_for_variables_ < kMpsFieldSize; } for (const MPConstraintProto& ct_proto : proto_.constraint()) { if (ct_proto.name().size() > kMpsFieldSize) return false; @@ -413,7 +411,7 @@ bool MPModelProtoExporter::ExportModelAsMpsFormat(bool fixed_format, for (int cst_index = 0; cst_index < proto_.constraint_size(); ++cst_index) { const MPConstraintProto& ct_proto = proto_.constraint(cst_index); for (int k = 0; k < ct_proto.var_index_size(); ++k) { - const int var_index = ct_proto.var_index(k); + const int var_index = ct_proto.var_index(k); if (var_index < 0 || var_index >= proto_.variable_size()) { LOG(DFATAL) << "In constraint #" << cst_index << ", var_index #" << k << " is " << var_index << ", which is out of bounds."; @@ -435,24 +433,24 @@ bool MPModelProtoExporter::ExportModelAsMpsFormat(bool fixed_format, const std::string var_name = GetVariableName(var_index); current_mps_column_ = 0; if (var_proto.is_integer()) { - StringAppendF(&columns_section, kIntMarkerFormat, - "INTSTART", "'MARKER'", "'INTORG'"); + StringAppendF(&columns_section, kIntMarkerFormat, "INTSTART", "'MARKER'", + "'INTORG'"); } if (var_proto.objective_coefficient() != 0.0) { - AppendMpsTermWithContext( - var_name, "COST", var_proto.objective_coefficient(), - &columns_section); + AppendMpsTermWithContext(var_name, "COST", + var_proto.objective_coefficient(), + &columns_section); } for (const std::pair cst_index_and_coeff : transpose[var_index]) { const std::string cst_name = GetConstraintName(cst_index_and_coeff.first); - AppendMpsTermWithContext( - var_name, cst_name, cst_index_and_coeff.second, &columns_section); + AppendMpsTermWithContext(var_name, cst_name, cst_index_and_coeff.second, + &columns_section); } if (var_proto.is_integer()) { columns_section += "\n"; current_mps_column_ = 0; - StringAppendF(&columns_section, kIntMarkerFormat, - "INTEND", "'MARKER'", "'INTEND'"); + StringAppendF(&columns_section, kIntMarkerFormat, "INTEND", "'MARKER'", + "'INTEND'"); } AppendNewLineIfTwoColumns(&columns_section); } @@ -516,8 +514,8 @@ bool MPModelProtoExporter::ExportModelAsMpsFormat(bool fixed_format, } } } else { - if (lb == -std::numeric_limits::infinity() - && ub == +std::numeric_limits::infinity()) { + if (lb == -std::numeric_limits::infinity() && + ub == +std::numeric_limits::infinity()) { AppendMpsLineHeader("FR", "BOUND", &bounds_section); StringAppendF(&bounds_section, " %s\n", var_name.c_str()); } else if (lb == ub) { diff --git a/src/linear_solver/model_exporter.h b/src/linear_solver/model_exporter.h index 23a2146023..f07b7ed5ad 100644 --- a/src/linear_solver/model_exporter.h +++ b/src/linear_solver/model_exporter.h @@ -18,7 +18,6 @@ #include "base/macros.h" #include "base/hash.h" - namespace operations_research { class MPConstraint; @@ -70,8 +69,7 @@ class MPModelProtoExporter { // http://tinyurl.com/mps-extensions-by-cplex // Gurobi's description: // http://www.gurobi.com/documentation/5.1/reference-manual/node869 - bool ExportModelAsMpsFormat(bool fixed_format, - bool obfuscated, + bool ExportModelAsMpsFormat(bool fixed_format, bool obfuscated, std::string* model_str); // Checks the validity of a variable or constraint name. diff --git a/src/linear_solver/proto_tools.cc b/src/linear_solver/proto_tools.cc index f37016ad22..9ceeb6f4bf 100644 --- a/src/linear_solver/proto_tools.cc +++ b/src/linear_solver/proto_tools.cc @@ -37,7 +37,7 @@ namespace operations_research { bool ReadFileToProto(const std::string& file_name, google::protobuf::Message* proto) { std::string data; file::GetContents(file_name, &data, file::Defaults()).CheckSuccess(); -// Note that gzipped files are currently not supported. + // Note that gzipped files are currently not supported. // Try binary format first, then text format, then give up. if (proto->ParseFromString(data)) return true; if (google::protobuf::TextFormat::ParseFromString(data, proto)) return true; @@ -45,11 +45,10 @@ bool ReadFileToProto(const std::string& file_name, google::protobuf::Message* pr return false; } -bool WriteProtoToFile( - const std::string& file_name, const google::protobuf::Message& proto, - bool binary, bool gzipped) { -// Note that gzipped files are currently not supported. - gzipped = false; +bool WriteProtoToFile(const std::string& file_name, const google::protobuf::Message& proto, + bool binary, bool gzipped) { + // Note that gzipped files are currently not supported. + gzipped = false; std::string output_string; google::protobuf::io::StringOutputStream stream(&output_string); @@ -68,7 +67,7 @@ bool WriteProtoToFile( VLOG(1) << "Writing " << output_string.size() << " bytes to " << output_file_name; if (!file::SetContents(output_file_name, output_string, file::Defaults()) - .ok()) { + .ok()) { LOG(WARNING) << "Writing to file failed."; return false; } @@ -76,8 +75,8 @@ bool WriteProtoToFile( } namespace { -void WriteFullProtocolMessage(const google::protobuf::Message& message, - int indent_level, std::string* out) { +void WriteFullProtocolMessage(const google::protobuf::Message& message, int indent_level, + std::string* out) { std::string temp_string; const std::string indent(indent_level * 2, ' '); const Descriptor* desc = message.GetDescriptor(); @@ -91,9 +90,9 @@ void WriteFullProtocolMessage(const google::protobuf::Message& message, StrAppend(out, indent, fd->name()); if (fd->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) { StrAppend(out, " {\n"); - const google::protobuf::Message& nested_message = repeated - ? refl->GetRepeatedMessage(message, fd, j) - : refl->GetMessage(message, fd); + const google::protobuf::Message& nested_message = + repeated ? refl->GetRepeatedMessage(message, fd, j) + : refl->GetMessage(message, fd); WriteFullProtocolMessage(nested_message, indent_level + 1, out); StrAppend(out, indent, "}\n"); } else { @@ -105,8 +104,8 @@ void WriteFullProtocolMessage(const google::protobuf::Message& message, } } // namespace -std::string FullProtocolMessageAsString( - const google::protobuf::Message& message, int indent_level) { +std::string FullProtocolMessageAsString(const google::protobuf::Message& message, + int indent_level) { std::string message_str; WriteFullProtocolMessage(message, indent_level, &message_str); return message_str; diff --git a/src/linear_solver/proto_tools.h b/src/linear_solver/proto_tools.h index afeaae4926..005703814d 100644 --- a/src/linear_solver/proto_tools.h +++ b/src/linear_solver/proto_tools.h @@ -33,8 +33,8 @@ bool WriteProtoToFile(const std::string& file_name, const google::protobuf::Mess // Prints a proto2 message as a std::string, it behaves like TextFormat::Print() // but also prints the default values of unset fields which is useful for // printing parameters. -std::string FullProtocolMessageAsString( - const google::protobuf::Message& message, int indent_level); +std::string FullProtocolMessageAsString(const google::protobuf::Message& message, + int indent_level); } // namespace operations_research #endif // OR_TOOLS_LINEAR_SOLVER_PROTO_TOOLS_H_ diff --git a/src/linear_solver/scip_interface.cc b/src/linear_solver/scip_interface.cc index 70d9673f3a..9ec499e11b 100644 --- a/src/linear_solver/scip_interface.cc +++ b/src/linear_solver/scip_interface.cc @@ -76,8 +76,7 @@ class SCIPInterface : public MPSolverInterface { // Change a coefficient in a constraint. virtual void SetCoefficient(MPConstraint* const constraint, const MPVariable* const variable, - double new_value, - double old_value); + double new_value, double old_value); // Clear a constraint from all its terms. virtual void ClearConstraint(MPConstraint* const constraint); // Change a coefficient in the linear objective @@ -118,14 +117,12 @@ class SCIPInterface : public MPSolverInterface { virtual void ExtractObjective(); virtual std::string SolverVersion() const { - return StringPrintf("SCIP %d.%d.%d [LP solver: %s]", - SCIPmajorVersion(), SCIPminorVersion(), - SCIPtechVersion(), SCIPlpiGetSolverName()); + return StringPrintf("SCIP %d.%d.%d [LP solver: %s]", SCIPmajorVersion(), + SCIPminorVersion(), SCIPtechVersion(), + SCIPlpiGetSolverName()); } - virtual void* underlying_solver() { - return reinterpret_cast(scip_); - } + virtual void* underlying_solver() { return reinterpret_cast(scip_); } private: // Set all parameters in the underlying solver. @@ -156,9 +153,7 @@ SCIPInterface::SCIPInterface(MPSolver* const solver) } // Frees the LP memory allocations. -SCIPInterface::~SCIPInterface() { - DeleteSCIP(); -} +SCIPInterface::~SCIPInterface() { DeleteSCIP(); } void SCIPInterface::Reset() { DeleteSCIP(); @@ -169,9 +164,8 @@ void SCIPInterface::Reset() { void SCIPInterface::CreateSCIP() { ORTOOLS_SCIP_CALL(SCIPcreate(&scip_)); ORTOOLS_SCIP_CALL(SCIPincludeDefaultPlugins(scip_)); - ORTOOLS_SCIP_CALL(SCIPcreateProb( - scip_, solver_->name_.c_str(), - NULL, NULL, NULL, NULL, NULL, NULL, NULL)); + ORTOOLS_SCIP_CALL(SCIPcreateProb(scip_, solver_->name_.c_str(), NULL, NULL, + NULL, NULL, NULL, NULL, NULL)); ORTOOLS_SCIP_CALL(SCIPsetObjsense( scip_, maximize_ ? SCIP_OBJSENSE_MAXIMIZE : SCIP_OBJSENSE_MINIMIZE)); // SCIPaddObjoffset cannot be used at the problem building stage. So @@ -179,11 +173,9 @@ void SCIPInterface::CreateSCIP() { SCIP_VAR* scip_var = NULL; // The true objective coefficient will be set in ExtractObjective. double dummy_obj_coef = 0.0; - ORTOOLS_SCIP_CALL(SCIPcreateVar( - scip_, &scip_var, "dummy", - 1.0, 1.0, dummy_obj_coef, - SCIP_VARTYPE_CONTINUOUS, - true, false, NULL, NULL, NULL, NULL, NULL)); + ORTOOLS_SCIP_CALL(SCIPcreateVar(scip_, &scip_var, "dummy", 1.0, 1.0, + dummy_obj_coef, SCIP_VARTYPE_CONTINUOUS, true, + false, NULL, NULL, NULL, NULL, NULL)); ORTOOLS_SCIP_CALL(SCIPaddVar(scip_, scip_var)); scip_variables_.push_back(scip_var); } @@ -234,8 +226,7 @@ void SCIPInterface::SetVariableInteger(int var_index, bool integer) { SCIP_Bool infeasible = false; ORTOOLS_SCIP_CALL(SCIPchgVarType( scip_, scip_variables_[var_index], - integer ? SCIP_VARTYPE_INTEGER : SCIP_VARTYPE_CONTINUOUS, - &infeasible)); + integer ? SCIP_VARTYPE_INTEGER : SCIP_VARTYPE_CONTINUOUS, &infeasible)); #else ORTOOLS_SCIP_CALL(SCIPchgVarType( scip_, scip_variables_[var_index], @@ -261,8 +252,7 @@ void SCIPInterface::SetConstraintBounds(int index, double lb, double ub) { void SCIPInterface::SetCoefficient(MPConstraint* const constraint, const MPVariable* const variable, - double new_value, - double old_value) { + double new_value, double old_value) { InvalidateSolutionSynchronization(); const int constraint_index = constraint->index(); const int variable_index = variable->index(); @@ -296,16 +286,16 @@ void SCIPInterface::ClearConstraint(MPConstraint* const constraint) { DCHECK_NE(kNoIndex, var_index); ORTOOLS_SCIP_CALL(SCIPfreeTransform(scip_)); // Set coefficient to zero by substracting the old coefficient value. - ORTOOLS_SCIP_CALL(SCIPaddCoefLinear( - scip_, scip_constraints_[constraint_index], - scip_variables_[var_index], -old_coef_value)); + ORTOOLS_SCIP_CALL( + SCIPaddCoefLinear(scip_, scip_constraints_[constraint_index], + scip_variables_[var_index], -old_coef_value)); } } } // Cached void SCIPInterface::SetObjectiveCoefficient(const MPVariable* const variable, - double coefficient) { + double coefficient) { sync_status_ = MUST_RELOAD; } @@ -354,10 +344,10 @@ void SCIPInterface::ExtractNewVariables() { // The true objective coefficient will be set later in ExtractObjective. double tmp_obj_coef = 0.0; ORTOOLS_SCIP_CALL(SCIPcreateVar( - scip_, &scip_var, var->name().c_str(), - var->lb(), var->ub(), tmp_obj_coef, - var->integer() ? SCIP_VARTYPE_INTEGER : SCIP_VARTYPE_CONTINUOUS, - true, false, NULL, NULL, NULL, NULL, NULL)); + scip_, &scip_var, var->name().c_str(), var->lb(), var->ub(), + tmp_obj_coef, + var->integer() ? SCIP_VARTYPE_INTEGER : SCIP_VARTYPE_CONTINUOUS, true, + false, NULL, NULL, NULL, NULL, NULL)); ORTOOLS_SCIP_CALL(SCIPaddVar(scip_, scip_var)); scip_variables_.push_back(scip_var); } @@ -371,9 +361,9 @@ void SCIPInterface::ExtractNewVariables() { // The variable is new (index offset by 1 because of the // dummy variable), so we know the previous coefficient // value was 0 and we can directly add the coefficient. - ORTOOLS_SCIP_CALL(SCIPaddCoefLinear( - scip_, scip_constraints_[i], - scip_variables_[var_index], entry.second)); + ORTOOLS_SCIP_CALL(SCIPaddCoefLinear(scip_, scip_constraints_[i], + scip_variables_[var_index], + entry.second)); } } } @@ -416,10 +406,8 @@ void SCIPInterface::ExtractNewConstraints() { // http://scip.zib.de/doc/html/cons__linear_8h.shtml#aa7aed137a4130b35b168812414413481 // for an explanation of the parameters. ORTOOLS_SCIP_CALL(SCIPcreateConsLinear( - scip_, &scip_constraint, - ct->name().empty() ? "" : ct->name().c_str(), - size, vars.get(), coefs.get(), - ct->lb(), ct->ub(), + scip_, &scip_constraint, ct->name().empty() ? "" : ct->name().c_str(), + size, vars.get(), coefs.get(), ct->lb(), ct->ub(), !is_lazy, // 'initial' parameter. true, // 'separate' parameter. true, // 'enforce' parameter. @@ -443,13 +431,13 @@ void SCIPInterface::ExtractObjective() { for (CoeffEntry entry : solver_->objective_->coefficients_) { int var_index = entry.first->index(); double obj_coef = entry.second; - ORTOOLS_SCIP_CALL(SCIPchgVarObj( - scip_, scip_variables_[var_index], obj_coef)); + ORTOOLS_SCIP_CALL( + SCIPchgVarObj(scip_, scip_variables_[var_index], obj_coef)); } // Constant term: change objective coefficient of dummy variable. - ORTOOLS_SCIP_CALL(SCIPchgVarObj( - scip_, scip_variables_[0], solver_->Objective().offset())); + ORTOOLS_SCIP_CALL( + SCIPchgVarObj(scip_, scip_variables_[0], solver_->Objective().offset())); } // Extracts model and solve the LP/MIP. Returns the status of the search. @@ -480,9 +468,8 @@ MPSolver::ResultStatus SCIPInterface::Solve(const MPSolverParameters& param) { // Time limit. if (solver_->time_limit() != 0) { VLOG(1) << "Setting time limit = " << solver_->time_limit() << " ms."; - ORTOOLS_SCIP_CALL(SCIPsetRealParam(scip_, - "limits/time", - solver_->time_limit_in_secs())); + ORTOOLS_SCIP_CALL( + SCIPsetRealParam(scip_, "limits/time", solver_->time_limit_in_secs())); } else { ORTOOLS_SCIP_CALL(SCIPresetParam(scip_, "limits/time")); } @@ -507,21 +494,18 @@ MPSolver::ResultStatus SCIPInterface::Solve(const MPSolverParameters& param) { for (int i = 0; i < solver_->variables_.size(); ++i) { MPVariable* const var = solver_->variables_[i]; const int var_index = var->index(); - const double val = SCIPgetSolVal(scip_, solution, - scip_variables_[var_index]); + const double val = + SCIPgetSolVal(scip_, solution, scip_variables_[var_index]); var->set_solution_value(val); VLOG(3) << var->name() << "=" << val; } for (int i = 0; i < solver_->constraints_.size(); ++i) { MPConstraint* const ct = solver_->constraints_[i]; const int constraint_index = ct->index(); - const double row_activity = - SCIPgetActivityLinear(scip_, - scip_constraints_[constraint_index], - solution); + const double row_activity = SCIPgetActivityLinear( + scip_, scip_constraints_[constraint_index], solution); ct->set_activity(row_activity); - VLOG(4) << "row " << ct->index() - << ": activity = " << row_activity; + VLOG(4) << "row " << ct->index() << ": activity = " << row_activity; } } else { VLOG(1) << "No feasible solution found."; diff --git a/src/sat/boolean_problem.cc b/src/sat/boolean_problem.cc index d8f91c9f82..950774f263 100644 --- a/src/sat/boolean_problem.cc +++ b/src/sat/boolean_problem.cc @@ -17,8 +17,8 @@ namespace operations_research { namespace sat { -bool LoadBooleanProblem( - const LinearBooleanProblem& problem, SatSolver* solver) { +bool LoadBooleanProblem(const LinearBooleanProblem& problem, + SatSolver* solver) { LOG(INFO) << "Loading problem '" << problem.name() << "', " << problem.num_variables() << " variables, " << problem.constraints_size() << " constraints."; @@ -37,24 +37,23 @@ bool LoadBooleanProblem( cst.push_back(LiteralWithCoeff(literal, constraint.coefficients(i))); } if (!solver->AddLinearConstraint( - constraint.has_lower_bound(), constraint.lower_bound(), - constraint.has_upper_bound(), constraint.upper_bound(), - &cst)) { + constraint.has_lower_bound(), constraint.lower_bound(), + constraint.has_upper_bound(), constraint.upper_bound(), &cst)) { return false; } } LOG(INFO) << "The problem contains " << num_terms << " terms."; // Initialize the heuristic to look for a good solution. - if (problem.type() == LinearBooleanProblem::MINIMIZATION - || problem.type() == LinearBooleanProblem::MAXIMIZATION) { + if (problem.type() == LinearBooleanProblem::MINIMIZATION || + problem.type() == LinearBooleanProblem::MAXIMIZATION) { const int sign = (problem.type() == LinearBooleanProblem::MAXIMIZATION) ? -1 : 1; const LinearObjective& objective = problem.objective(); double max_weight = 0; for (int i = 0; i < objective.literals_size(); ++i) { - max_weight = std::max( - max_weight, fabs(static_cast(objective.coefficients(i)))); + max_weight = + std::max(max_weight, fabs(static_cast(objective.coefficients(i)))); } for (int i = 0; i < objective.literals_size(); ++i) { const double weight = @@ -89,8 +88,7 @@ bool AddObjectiveConstraint(const LinearBooleanProblem& problem, cst.push_back(LiteralWithCoeff(literal, objective.coefficients(i))); } return solver->AddLinearConstraint(use_lower_bound, lower_bound, - use_upper_bound, upper_bound, - &cst); + use_upper_bound, upper_bound, &cst); } Coefficient ComputeObjectiveValue(const LinearBooleanProblem& problem, @@ -183,15 +181,13 @@ std::string LinearBooleanProblemToCnfString(const LinearBooleanProblem& problem) hard_weigth = std::max(hard_weigth, weight + 1); } CHECK_GT(hard_weigth, 0); - output += StringPrintf( - "p wcnf %d %d %lld\n", - problem.num_variables() - objective.literals().size(), - problem.constraints_size(), - hard_weigth); + output += + StringPrintf("p wcnf %d %d %lld\n", + problem.num_variables() - objective.literals().size(), + problem.constraints_size(), hard_weigth); } else { - output += StringPrintf("p cnf %d %d\n", - problem.num_variables(), - problem.constraints_size()); + output += StringPrintf("p cnf %d %d\n", problem.num_variables(), + problem.constraints_size()); } int slack_index = 0; @@ -200,8 +196,8 @@ std::string LinearBooleanProblemToCnfString(const LinearBooleanProblem& problem) for (int i = 0; i < constraint.literals_size(); ++i) { if (constraint.coefficients(i) != 1) return ""; if (i == 0 && is_wcnf) { - if (slack_index < objective.literals_size() - && constraint.literals(0) == objective.literals(slack_index)) { + if (slack_index < objective.literals_size() && + constraint.literals(0) == objective.literals(slack_index)) { output += StringPrintf("%lld ", objective.coefficients(slack_index)); ++slack_index; continue; diff --git a/src/sat/pb_constraint.cc b/src/sat/pb_constraint.cc index 64a1f09389..73e27e2dff 100644 --- a/src/sat/pb_constraint.cc +++ b/src/sat/pb_constraint.cc @@ -19,7 +19,7 @@ namespace { // Returns false if the addition overflow/underflow. Otherwise returns true // and performs the addition *b += a; -bool SafeAdd(Coefficient a, Coefficient *b) { +bool SafeAdd(Coefficient a, Coefficient* b) { if (a > 0) { if (*b > std::numeric_limits::max() - a) return false; } else { @@ -42,8 +42,7 @@ bool CoeffComparator(const LiteralWithCoeff& a, const LiteralWithCoeff& b) { } // namespace -bool PbCannonicalForm(std::vector* cst, - Coefficient* bound_shift, +bool PbCannonicalForm(std::vector* cst, Coefficient* bound_shift, Coefficient* max_value) { *bound_shift = 0; *max_value = 0; @@ -56,15 +55,15 @@ bool PbCannonicalForm(std::vector* cst, for (int i = 0; i < cst->size(); ++i) { const LiteralWithCoeff current = (*cst)[i]; if (current.coefficient == 0) continue; - if (representative != nullptr - && current.literal.Variable() == representative->literal.Variable()) { + if (representative != nullptr && + current.literal.Variable() == representative->literal.Variable()) { if (current.literal == representative->literal) { - if (!SafeAdd(current.coefficient, - &(representative->coefficient))) return false; + if (!SafeAdd(current.coefficient, &(representative->coefficient))) + return false; } else { // Here current_literal is equal to (1 - representative). - if (!SafeAdd(-current.coefficient, - &(representative->coefficient))) return false; + if (!SafeAdd(-current.coefficient, &(representative->coefficient))) + return false; if (!SafeAdd(-current.coefficient, bound_shift)) return false; } } else { @@ -143,8 +142,10 @@ bool UpperBoundedLinearConstraint::HasIdenticalTerms( } bool UpperBoundedLinearConstraint::InitializeRhs(Coefficient rhs, - int trail_index, Coefficient* slack, Trail* trail, - std::vector* conflict) { + int trail_index, + Coefficient* slack, + Trail* trail, + std::vector* conflict) { rhs_ = rhs; // Compute the current_rhs from the assigned variables with a trail index @@ -159,7 +160,7 @@ bool UpperBoundedLinearConstraint::InitializeRhs(Coefficient rhs, } ++literal_index; if (literal_index == starts_[coeff_index + 1]) { - ++coeff_index; + ++coeff_index; } } @@ -171,7 +172,8 @@ bool UpperBoundedLinearConstraint::InitializeRhs(Coefficient rhs, } bool UpperBoundedLinearConstraint::Propagate(int trail_index, - Coefficient* slack, Trail* trail, std::vector* conflict) { + Coefficient* slack, Trail* trail, + std::vector* conflict) { DCHECK_LT(*slack, 0); const Coefficient current_rhs = GetCurrentRhsFromSlack(*slack); while (index_ >= 0 && coeffs_[index_] > current_rhs) --index_; @@ -199,6 +201,13 @@ bool UpperBoundedLinearConstraint::Propagate(int trail_index, void UpperBoundedLinearConstraint::FillReason(const Trail& trail, int source_trail_index, std::vector* reason) { + // Optimization for an "at most one" constraint. + if (rhs_ == 1) { + reason->clear(); + reason->push_back(trail[source_trail_index].Negated()); + return; + } + // Compute the initial reason which is formed by all the literals of the // constraint that were assigned to true at the time of the propagation. // We remove literals with a level of 0 since they are not needed. @@ -228,8 +237,8 @@ void UpperBoundedLinearConstraint::FillReason(const Trail& trail, for (int i = literals_.size() - 1; i >= 0; --i) { if (coeffs_[coeff_index] <= current_rhs) break; const Literal literal = literals_[i]; - if (!trail.Assignment().IsVariableAssigned(literal.Variable()) - || trail.Info(literal.Variable()).trail_index > source_trail_index) { + if (!trail.Assignment().IsVariableAssigned(literal.Variable()) || + trail.Info(literal.Variable()).trail_index > source_trail_index) { coeff = coeffs_[coeff_index]; } if (i == starts_[coeff_index]) --coeff_index; @@ -258,15 +267,15 @@ void UpperBoundedLinearConstraint::FillReason(const Trail& trail, void UpperBoundedLinearConstraint::Untrail(Coefficient* slack) { const Coefficient current_rhs = GetCurrentRhsFromSlack(*slack); - while (index_ + 1 < coeffs_.size() - && coeffs_[index_ + 1] <= current_rhs) ++index_; + while (index_ + 1 < coeffs_.size() && coeffs_[index_ + 1] <= current_rhs) + ++index_; Update(current_rhs, slack); } // TODO(user): This is relatively slow. Take the "transpose" all at once, and // maybe put small constraints first on the to_update_ lists. -bool PbConstraints::AddConstraint( - const std::vector& cst, Coefficient rhs) { +bool PbConstraints::AddConstraint(const std::vector& cst, + Coefficient rhs) { SCOPED_TIME_STAT(&stats_); DCHECK(!cst.empty()); DCHECK(std::is_sorted(cst.begin(), cst.end(), CoeffComparator)); @@ -276,7 +285,8 @@ bool PbConstraints::AddConstraint( if (!constraints_.empty() && constraints_.back().HasIdenticalTerms(cst)) { if (rhs < constraints_.back().Rhs()) { return constraints_.back().InitializeRhs(rhs, propagation_trail_index_, - &slacks_.back(), trail_, &reason_scratchpad_); + &slacks_.back(), trail_, + &reason_scratchpad_); } else { // The constraint is redundant, so there is nothing to do. return true; @@ -287,12 +297,13 @@ bool PbConstraints::AddConstraint( constraints_.emplace_back(UpperBoundedLinearConstraint(cst)); slacks_.push_back(0); if (!constraints_.back().InitializeRhs(rhs, propagation_trail_index_, - &slacks_.back(), trail_, &reason_scratchpad_)) { + &slacks_.back(), trail_, + &reason_scratchpad_)) { return false; } for (LiteralWithCoeff term : cst) { - to_update_[term.literal.Index()].push_back( - ConstraintIndexWithCoeff(cst_index, term.coefficient)); + to_update_[term.literal.Index()] + .push_back(ConstraintIndexWithCoeff(cst_index, term.coefficient)); } return true; } @@ -318,7 +329,7 @@ bool PbConstraints::PropagateNext() { update.need_untrail_inspection = true; ++num_constraint_lookups_; if (!constraints_[update.index.value()].Propagate( - order, &slacks_[update.index], trail_, &reason_scratchpad_)) { + order, &slacks_[update.index], trail_, &reason_scratchpad_)) { trail_->SetFailingClause(ClauseRef(reason_scratchpad_)); conflict = true; } diff --git a/src/sat/pb_constraint.h b/src/sat/pb_constraint.h index 05289a1956..960f8f8ba6 100644 --- a/src/sat/pb_constraint.h +++ b/src/sat/pb_constraint.h @@ -32,11 +32,11 @@ struct LiteralWithCoeff { Literal literal; Coefficient coefficient; bool operator==(const LiteralWithCoeff& other) const { - return literal.Index() == other.literal.Index() - && coefficient == other.coefficient; + return literal.Index() == other.literal.Index() && + coefficient == other.coefficient; } }; -inline std::ostream &operator<<(std::ostream &os, LiteralWithCoeff term) { +inline std::ostream& operator<<(std::ostream& os, LiteralWithCoeff term) { os << term.coefficient << "[" << term.literal.DebugString() << "]"; return os; } @@ -57,8 +57,7 @@ inline std::ostream &operator<<(std::ostream &os, LiteralWithCoeff term) { // // Finaly, this will return false, if some integer overflow or underflow occured // during the reduction to the cannonical form. -bool PbCannonicalForm(std::vector* cst, - Coefficient* bound_shift, +bool PbCannonicalForm(std::vector* cst, Coefficient* bound_shift, Coefficient* max_value); // Returns true iff the linear constraint is in cannonical form. @@ -104,8 +103,8 @@ class UpperBoundedLinearConstraint { // trail index are not yet "processed". // // The slack is updated to its new value. - bool Propagate(int trail_index, Coefficient* slack, - Trail* trail, std::vector* conflict); + bool Propagate(int trail_index, Coefficient* slack, Trail* trail, + std::vector* conflict); // Updates the given slack and the internal state. // This is the opposite of Propagate(). Each time a literal in unassigned, @@ -131,8 +130,7 @@ class UpperBoundedLinearConstraint { // information. For instance one could use the mask of literals that are // better to use during conflict minimization (namely the one already in the // 1-UIP conflict). - void FillReason(const Trail& trail, - int source_trail_index, + void FillReason(const Trail& trail, int source_trail_index, std::vector* reason); private: @@ -164,11 +162,12 @@ class UpperBoundedLinearConstraint { // propagation. class PbConstraints { public: - explicit PbConstraints(Trail* trail) : trail_(trail), - propagation_trail_index_(0), - stats_("PbConstraints"), - num_constraint_lookups_(0), - num_slack_updates_(0) {} + explicit PbConstraints(Trail* trail) + : trail_(trail), + propagation_trail_index_(0), + stats_("PbConstraints"), + num_constraint_lookups_(0), + num_slack_updates_(0) {} ~PbConstraints() { IF_STATS_ENABLED(LOG(INFO) << stats_.StatString()); LOG(INFO) << "num_constraint_lookups_: " << num_constraint_lookups_; @@ -204,8 +203,8 @@ class PbConstraints { SCOPED_TIME_STAT(&stats_); const AssignmentInfo& info = trail_->Info(var); DCHECK_EQ(info.type, AssignmentInfo::PB_PROPAGATION); - info.pb_constraint->FillReason( - *trail_, info.source_trail_index, &reason_scratchpad_); + info.pb_constraint->FillReason(*trail_, info.source_trail_index, + &reason_scratchpad_); return reason_scratchpad_; } @@ -215,7 +214,7 @@ class PbConstraints { DEFINE_INT_TYPE(ConstraintIndex, int32); struct ConstraintIndexWithCoeff { ConstraintIndexWithCoeff(ConstraintIndex i, Coefficient c) - : need_untrail_inspection(false), index(i), coefficient(c) {} + : need_untrail_inspection(false), index(i), coefficient(c) {} bool need_untrail_inspection; ConstraintIndex index; Coefficient coefficient; diff --git a/src/sat/sat_base.h b/src/sat/sat_base.h index 5c7f16fda0..47296e11f2 100644 --- a/src/sat/sat_base.h +++ b/src/sat/sat_base.h @@ -24,7 +24,6 @@ #include "base/int_type.h" #include "util/bitset.h" - namespace operations_research { namespace sat { @@ -65,7 +64,7 @@ class Literal { VariableIndex Variable() const { return VariableIndex(index_ >> 1); } bool IsPositive() const { return !(index_ & 1); } - bool IsNegative() const { return (index_ & 1); } + bool IsNegative() const { return (index_ & 1); } LiteralIndex Index() const { return LiteralIndex(index_); } LiteralIndex NegatedIndex() const { return LiteralIndex(index_ ^ 1); } @@ -84,7 +83,7 @@ class Literal { int index_; }; -inline std::ostream &operator<<(std::ostream &os, Literal literal) { +inline std::ostream& operator<<(std::ostream& os, Literal literal) { os << literal.DebugString(); return os; } @@ -179,15 +178,15 @@ class ClauseRef { public: ClauseRef() : begin_(nullptr), end_(nullptr) {} ClauseRef(Literal const* b, Literal const* e) : begin_(b), end_(e) {} - explicit ClauseRef(const std::vector& literals) : - begin_(&literals[0]), end_(&literals[0] + literals.size()) {} + explicit ClauseRef(const std::vector& literals) + : begin_(&literals[0]), end_(&literals[0] + literals.size()) {} // Allows for range based iteration: for (Literal literal : clause_ref) {}. Literal const* begin() const { return begin_; } - Literal const* end() const {return end_; } + Literal const* end() const { return end_; } // Returns true if this clause contains no literal. - bool IsEmpty() const {return begin_ == end_;} + bool IsEmpty() const { return begin_ == end_; } private: Literal const* begin_; @@ -227,9 +226,9 @@ struct AssignmentInfo { // The index of this assignment in the trail. int trail_index; - // Some data about this assignment used to compute the reason clause when it - // becomes needed. Note that depending on the type, these fields will not be - // used and be left uninitialized. +// Some data about this assignment used to compute the reason clause when it +// becomes needed. Note that depending on the type, these fields will not be +// used and be left uninitialized. #if defined(_MSC_VER) struct { #else @@ -249,9 +248,7 @@ struct AssignmentInfo { // and the information of each assignment. class Trail { public: - Trail() : num_enqueues_(0), trail_index_(0) { - current_info_.level = 0; - } + Trail() : num_enqueues_(0), trail_index_(0) { current_info_.level = 0; } void Resize(int num_variables) { assignment_.Resize(num_variables); @@ -282,8 +279,7 @@ class Trail { current_info_.sat_clause = clause; Enqueue(true_literal, AssignmentInfo::CLAUSE_PROPAGATION); } - void EnqueueWithPbReason(Literal true_literal, - int source_trail_index, + void EnqueueWithPbReason(Literal true_literal, int source_trail_index, UpperBoundedLinearConstraint* cst) { current_info_.source_trail_index = source_trail_index; current_info_.pb_constraint = cst; @@ -299,9 +295,7 @@ class Trail { } // Changes the decision level used by the next Enqueue(). - void SetDecisionLevel(int level) { - current_info_.level = level; - } + void SetDecisionLevel(int level) { current_info_.level = level; } // Wrapper to the same function of the underlying assignment. void SetLastAssignmentValue(Literal literal) { diff --git a/src/sat/sat_conflict.cc b/src/sat/sat_conflict.cc index 5e1d8cea8b..18f2c707eb 100644 --- a/src/sat/sat_conflict.cc +++ b/src/sat/sat_conflict.cc @@ -28,8 +28,7 @@ namespace sat { // http://www.cs.tau.ac.il/~msagiv/courses/ATP/iccad2001_final.pdf // http://gauss.ececs.uc.edu/SAT/articles/FAIA185-0131.pdf void SatSolver::ComputeFirstUIPConflict( - ClauseRef failing_clause, - std::vector* conflict, + ClauseRef failing_clause, std::vector* conflict, std::vector* discarded_last_level_literals) { SCOPED_TIME_STAT(&stats_); @@ -39,7 +38,7 @@ void SatSolver::ComputeFirstUIPConflict( conflict->clear(); discarded_last_level_literals->clear(); - const int current_level = choice_points_.size(); + const int current_level = CurrentDecisionLevel(); int num_literal_at_current_level_that_needs_to_be_processed = 0; DCHECK_GT(current_level, 0); @@ -83,8 +82,7 @@ void SatSolver::ComputeFirstUIPConflict( while (!is_marked_[trail_[trail_index].Variable()]) { --trail_index; DCHECK_GE(trail_index, 0); - DCHECK_EQ(DecisionLevel(trail_[trail_index].Variable()), - current_level); + DCHECK_EQ(DecisionLevel(trail_[trail_index].Variable()), current_level); } if (num_literal_at_current_level_that_needs_to_be_processed == 1) { @@ -100,8 +98,8 @@ void SatSolver::ComputeFirstUIPConflict( // If we already encountered the same reason, we can just skip this literal // which is what setting clause_to_expand to the empty clause do. - if (reason_cache_.FirstVariableWithSameReason(literal.Variable()) - != literal.Variable()) { + if (reason_cache_.FirstVariableWithSameReason(literal.Variable()) != + literal.Variable()) { clause_to_expand = ClauseRef(); } else { clause_to_expand = Reason(literal.Variable()); @@ -117,7 +115,8 @@ void SatSolver::MinimizeConflict(std::vector* conflict) { SCOPED_TIME_STAT(&stats_); const int old_size = conflict->size(); switch (parameters_.minimization_algorithm()) { - case SatParameters::NONE: return; + case SatParameters::NONE: + return; case SatParameters::SIMPLE: { MinimizeConflictSimple(conflict); break; @@ -151,7 +150,7 @@ void SatSolver::MinimizeConflictSimple(std::vector* conflict) { is_marked_.Set(literal.Variable()); } int index = 0; - const int current_level = choice_points_.size(); + const int current_level = CurrentDecisionLevel(); for (int i = 0; i < conflict->size(); ++i) { const VariableIndex var = (*conflict)[i].Variable(); bool can_be_removed = false; @@ -202,8 +201,8 @@ void SatSolver::MinimizeConflictRecursively(std::vector* conflict) { // std::numeric_limits::max() at the end. This is used to prune the // search because any literal at a given level with an index smaller or equal // to min_trail_index_per_level_[level] can't be redundant. - if (choice_points_.size() >= min_trail_index_per_level_.size()) { - min_trail_index_per_level_.resize(choice_points_.size() + 1, + if (CurrentDecisionLevel() >= min_trail_index_per_level_.size()) { + min_trail_index_per_level_.resize(CurrentDecisionLevel() + 1, std::numeric_limits::max()); } @@ -215,8 +214,8 @@ void SatSolver::MinimizeConflictRecursively(std::vector* conflict) { for (Literal literal : *conflict) { const VariableIndex var = literal.Variable(); const int level = DecisionLevel(var); - min_trail_index_per_level_[level] = std::min( - min_trail_index_per_level_[level], trail_.Info(var).trail_index); + min_trail_index_per_level_[level] = + std::min(min_trail_index_per_level_[level], trail_.Info(var).trail_index); } // Remove the redundant variable from the conflict. That is the ones that can @@ -225,8 +224,8 @@ void SatSolver::MinimizeConflictRecursively(std::vector* conflict) { for (int i = 0; i < conflict->size(); ++i) { const VariableIndex var = (*conflict)[i].Variable(); if (trail_.Info(var).trail_index <= - min_trail_index_per_level_[DecisionLevel(var)] - || !CanBeInferedFromConflictVariables(var)) { + min_trail_index_per_level_[DecisionLevel(var)] || + !CanBeInferedFromConflictVariables(var)) { // Mark the conflict variable as independent. Note that is_marked_[var] // will still be true. is_independent_.Set(var); @@ -239,8 +238,8 @@ void SatSolver::MinimizeConflictRecursively(std::vector* conflict) { // all the literals from the same level. conflict->resize(index); for (Literal literal : *conflict) { - min_trail_index_per_level_[DecisionLevel(literal.Variable())] - = std::numeric_limits::max(); + min_trail_index_per_level_[DecisionLevel(literal.Variable())] = + std::numeric_limits::max(); } } @@ -267,8 +266,9 @@ bool SatSolver::CanBeInferedFromConflictVariables(VariableIndex variable) { if (var == variable) continue; const int level = DecisionLevel(var); if (level == 0 || is_marked_[var]) continue; - if (trail_.Info(var).trail_index <= min_trail_index_per_level_[level] - || is_independent_[var]) return false; + if (trail_.Info(var).trail_index <= min_trail_index_per_level_[level] || + is_independent_[var]) + return false; variable_to_process_.push_back(var); } @@ -318,8 +318,8 @@ bool SatSolver::CanBeInferedFromConflictVariables(VariableIndex variable) { if (var == current_var) continue; const int level = DecisionLevel(var); if (level == 0 || is_marked_[var]) continue; - if (trail_.Info(var).trail_index <= min_trail_index_per_level_[level] - || is_independent_[var]) { + if (trail_.Info(var).trail_index <= min_trail_index_per_level_[level] || + is_independent_[var]) { abort_early = true; break; } @@ -348,7 +348,7 @@ struct WeightedVariable { // to break ties struct VariableWithLargerWeightFirst { bool operator()(const WeightedVariable& wv1, - const WeightedVariable& wv2) const { + const WeightedVariable& wv2) const { return (wv1.weight > wv2.weight || (wv1.weight == wv2.weight && wv1.var < wv2.var)); } @@ -372,7 +372,7 @@ void SatSolver::MinimizeConflictExperimental(std::vector* conflict) { // First, sort the variables in the conflict by decreasing decision levels. // Also initialize is_marked_ to true for all conflict variables. is_marked_.ClearAndResize(num_variables_); - const int current_level = choice_points_.size(); + const int current_level = CurrentDecisionLevel(); std::vector variables_sorted_by_level; for (Literal literal : *conflict) { const VariableIndex var = literal.Variable(); @@ -382,8 +382,7 @@ void SatSolver::MinimizeConflictExperimental(std::vector* conflict) { variables_sorted_by_level.push_back(WeightedVariable(var, level)); } } - std::sort(variables_sorted_by_level.begin(), - variables_sorted_by_level.end(), + std::sort(variables_sorted_by_level.begin(), variables_sorted_by_level.end(), VariableWithLargerWeightFirst()); // Then process the reason of the variable with highest level first. @@ -461,8 +460,8 @@ void SatSolver::InitLearnedClauseLimit() { target_number_of_learned_clauses_ = num_learned_clauses + parameters_.clause_cleanup_increment(); num_learned_clause_before_cleanup_ = - target_number_of_learned_clauses_ / parameters_.clause_cleanup_ratio() - - num_learned_clauses; + target_number_of_learned_clauses_ / parameters_.clause_cleanup_ratio() - + num_learned_clauses; VLOG(1) << "reduced learned database to " << num_learned_clauses << " clauses. Next cleanup in " << num_learned_clause_before_cleanup_ << " conflicts."; @@ -475,16 +474,15 @@ void SatSolver::CompressLearnedClausesIfNeeded() { // Move the clause that should be kept at the beginning and sort the other // using the ClauseOrdering order. std::vector::iterator clause_to_keep_end = std::partition( - learned_clauses_.begin(), - learned_clauses_.end(), + learned_clauses_.begin(), learned_clauses_.end(), std::bind1st(std::mem_fun(&SatSolver::ClauseShouldBeKept), this)); std::sort(clause_to_keep_end, learned_clauses_.end(), ClauseOrdering); // Compute the index of the first clause to delete. const int num_learned_clauses = learned_clauses_.size(); - const int first_clause_to_delete = std::max( - static_cast(clause_to_keep_end - learned_clauses_.begin()), - std::min(num_learned_clauses, target_number_of_learned_clauses_)); + const int first_clause_to_delete = + std::max(static_cast(clause_to_keep_end - learned_clauses_.begin()), + std::min(num_learned_clauses, target_number_of_learned_clauses_)); // Delete all the learned clause after 'first_clause_to_delete'. for (int i = first_clause_to_delete; i < num_learned_clauses; ++i) { diff --git a/src/sat/sat_parameters.proto b/src/sat/sat_parameters.proto index 54defb258e..77f757d616 100644 --- a/src/sat/sat_parameters.proto +++ b/src/sat/sat_parameters.proto @@ -151,4 +151,12 @@ message SatParameters { // try to follow the hint. It will revert to the variable_branching default // otherwise. optional bool use_optimization_hints = 35 [default = true]; + + // Maximum time allowed in seconds to solve a problem. + // The counter will starts as soon as Solve() is called. + optional double max_time_in_seconds = 36 [default = inf]; + + // Maximum number of conflicts allowed to solve a problem. + optional int64 max_number_of_conflicts = 37 + [default = 0x7FFFFFFFFFFFFFFF]; // kint64max } diff --git a/src/sat/sat_solver.cc b/src/sat/sat_solver.cc index b7bddb597c..e11ac4fe90 100644 --- a/src/sat/sat_solver.cc +++ b/src/sat/sat_solver.cc @@ -20,6 +20,7 @@ #include "base/integral_types.h" #include "base/logging.h" #include "base/join.h" +#include "util/time_limit.h" #include "base/stl_util.h" namespace operations_research { @@ -28,7 +29,7 @@ namespace sat { namespace { // Returns true if the given watcher list contains the given clause. -template +template bool WatcherListContains(const std::vector& list, const SatClause& candidate) { for (const Watcher& watcher : list) { @@ -38,30 +39,25 @@ bool WatcherListContains(const std::vector& list, } // A simple wrapper to simplify the erase(std::remove_if()) pattern. -template +template void RemoveIf(Container c, Predicate p) { c->erase(std::remove_if(c->begin(), c->end(), p), c->end()); } // Removes dettached clauses from a watcher list. -template +template bool CleanUpPredicate(const Watcher& watcher) { return !watcher.clause->IsAttached(); } // Compares literals by variable first, then sign. -bool CompareLiteral(Literal l1, Literal l2) { - return l1.Index() < l2.Index(); -} +bool CompareLiteral(Literal l1, Literal l2) { return l1.Index() < l2.Index(); } } // namespace // ----- LiteralWatchers ----- LiteralWatchers::LiteralWatchers() - : is_clean_(true), - num_inspected_clauses_(0), - stats_("LiteralWatchers") -{} + : is_clean_(true), num_inspected_clauses_(0), stats_("LiteralWatchers") {} LiteralWatchers::~LiteralWatchers() { IF_STATS_ENABLED(LOG(INFO) << stats_.StatString()); @@ -112,8 +108,7 @@ bool LiteralWatchers::PropagateOnFalse(Literal false_literal, Trail* trail) { SatClause* clause = watchers[i].clause; if (!clause->PropagateOnFalse(false_literal, trail)) { // Conflict: All literals of this clause are false. - memmove(&watchers[new_index], - &watchers[i], + memmove(&watchers[new_index], &watchers[i], (initial_size - i) * sizeof(Watcher)); watchers.resize(new_index + initial_size - i); return false; @@ -134,14 +129,14 @@ bool LiteralWatchers::PropagateOnFalse(Literal false_literal, Trail* trail) { bool LiteralWatchers::AttachAndPropagate(SatClause* clause, Trail* trail) { ++num_watched_clauses_; - UpdateStatistics(*clause, /*added=*/ true); + UpdateStatistics(*clause, /*added=*/true); clause->SortLiterals(statistics_, parameters_); return clause->AttachAndEnqueuePotentialUnitPropagation(trail, this); } void LiteralWatchers::LazyDetach(SatClause* clause) { --num_watched_clauses_; - UpdateStatistics(*clause, /*added=*/ false); + UpdateStatistics(*clause, /*added=*/false); clause->LazyDetach(); is_clean_ = false; needs_cleaning_[clause->FirstLiteral().Index()] = true; @@ -190,8 +185,8 @@ void BinaryImplicationGraph::AddBinaryClause(Literal a, Literal b) { implications_[b.Negated().Index()].push_back(a); } -void BinaryImplicationGraph::AddBinaryConflict( - Literal a, Literal b, Trail* trail) { +void BinaryImplicationGraph::AddBinaryConflict(Literal a, Literal b, + Trail* trail) { SCOPED_TIME_STAT(&stats_); AddBinaryClause(a, b); if (trail->Assignment().IsLiteralFalse(a)) { @@ -201,8 +196,8 @@ void BinaryImplicationGraph::AddBinaryConflict( } } -bool BinaryImplicationGraph::PropagateOnTrue( - Literal true_literal, Trail* trail) { +bool BinaryImplicationGraph::PropagateOnTrue(Literal true_literal, + Trail* trail) { SCOPED_TIME_STAT(&stats_); const VariablesAssignment& assignment = trail->Assignment(); for (Literal literal : implications_[true_literal.Index()]) { @@ -220,8 +215,8 @@ bool BinaryImplicationGraph::PropagateOnTrue( // Conflict. temporary_clause_[0] = true_literal.Negated(); temporary_clause_[1] = literal; - trail->SetFailingClause(ClauseRef(&temporary_clause_[0], - &temporary_clause_[0] + 2)); + trail->SetFailingClause( + ClauseRef(&temporary_clause_[0], &temporary_clause_[0] + 2)); return false; } else { // Propagation. @@ -231,8 +226,8 @@ bool BinaryImplicationGraph::PropagateOnTrue( return true; } -void BinaryImplicationGraph::MinimizeClause( - const Trail& trail, std::vector* conflict) { +void BinaryImplicationGraph::MinimizeClause(const Trail& trail, + std::vector* conflict) { SCOPED_TIME_STAT(&stats_); is_marked_.ClearAndResize(LiteralIndex(implications_.size())); is_removed_.ClearAndResize(LiteralIndex(implications_.size())); @@ -259,8 +254,9 @@ void BinaryImplicationGraph::MinimizeClause( for (Literal implied : implications_[lit.Index()]) { if (is_marked_[implied.Index()]) { DCHECK_LE(lit_level, trail.Info(implied.Variable()).level); - if (lit_level == trail.Info(implied.Variable()).level - && is_removed_[implied.Index()]) continue; + if (lit_level == trail.Info(implied.Variable()).level && + is_removed_[implied.Index()]) + continue; keep_literal = false; break; } @@ -309,7 +305,7 @@ void BinaryImplicationGraph::RemoveFixedVariables( SatClause* SatClause::Create(const std::vector& literals, ClauseType type) { CHECK_GE(literals.size(), 2); SatClause* clause = reinterpret_cast( - ::operator new (sizeof(SatClause) + literals.size() * sizeof(Literal))); + ::operator new(sizeof(SatClause) + literals.size() * sizeof(Literal))); clause->size_ = literals.size(); for (int i = 0; i < literals.size(); ++i) { clause->literals_[i] = literals[i]; @@ -336,8 +332,8 @@ SatClause::SimplifyStatus SatClause::Simplify() { bool SatClause::RemoveFixedLiteralsAndTestIfTrue( const VariablesAssignment& assignment) { DCHECK(is_attached_); - if (assignment.IsVariableAssigned(literals_[0].Variable()) - || assignment.IsVariableAssigned(literals_[1].Variable())) { + if (assignment.IsVariableAssigned(literals_[0].Variable()) || + assignment.IsVariableAssigned(literals_[1].Variable())) { DCHECK(IsSatisfied(assignment)); return true; } @@ -368,7 +364,7 @@ struct WeightedLiteral { bool LiteralWithSmallerWeightFirst(const WeightedLiteral& wv1, const WeightedLiteral& wv2) { return (wv1.weight < wv2.weight) || - (wv1.weight == wv2.weight && + (wv1.weight == wv2.weight && wv1.literal.SignedValue() < wv2.literal.SignedValue()); } @@ -376,7 +372,7 @@ bool LiteralWithSmallerWeightFirst(const WeightedLiteral& wv1, bool LiteralWithLargerWeightFirst(const WeightedLiteral& wv1, const WeightedLiteral& wv2) { return (wv1.weight > wv2.weight) || - (wv1.weight == wv2.weight && + (wv1.weight == wv2.weight && wv1.literal.SignedValue() < wv2.literal.SignedValue()); } @@ -392,8 +388,8 @@ void SatClause::SortLiterals( std::vector order; for (Literal literal : *this) { int weight = literal.IsPositive() - ? statistics[literal.Variable()].num_positive_clauses - : statistics[literal.Variable()].num_negative_clauses; + ? statistics[literal.Variable()].num_positive_clauses + : statistics[literal.Variable()].num_negative_clauses; order.push_back(WeightedLiteral(literal, weight)); } switch (literal_order) { @@ -405,9 +401,7 @@ void SatClause::SortLiterals( std::sort(order.begin(), order.end(), LiteralWithLargerWeightFirst); break; } - default: { - break; - } + default: { break; } } for (int i = 0; i < order.size(); ++i) { literals_[i] = order[i].literal; @@ -554,15 +548,12 @@ void SatSolver::SetNumVariables(int num_variables) { clause_activity_increment_ = 1.0; activities_.resize(num_variables, 0.0); objective_weights_.resize(num_variables << 1, 0.0); + decisions_.resize(num_variables); } -int64 SatSolver::num_branches() const { - return counters_.num_branches; -} +int64 SatSolver::num_branches() const { return counters_.num_branches; } -int64 SatSolver::num_failures() const { - return counters_.num_failures; -} +int64 SatSolver::num_failures() const { return counters_.num_failures; } int64 SatSolver::num_propagations() const { return trail_.NumberOfEnqueues() - counters_.num_branches; @@ -581,7 +572,7 @@ void SatSolver::SetParameters(const SatParameters& parameters) { std::string SatSolver::Indent() const { SCOPED_TIME_STAT(&stats_); - const int level = choice_points_.size(); + const int level = CurrentDecisionLevel(); std::string result; for (int i = 0; i < level; ++i) { result.append("| "); @@ -596,7 +587,7 @@ bool SatSolver::ModelUnsat() { bool SatSolver::AddProblemClause(const std::vector& literals) { SCOPED_TIME_STAT(&stats_); - CHECK(choice_points_.empty()); + CHECK_EQ(CurrentDecisionLevel(), 0); // Deals with clause of size 0 (always false) and 1 (set a literal) right away // so we guarantee that a SatClause is always of size greater than one. This @@ -607,14 +598,17 @@ bool SatSolver::AddProblemClause(const std::vector& literals) { std::unique_ptr clause( SatClause::Create(literals, SatClause::PROBLEM_CLAUSE)); switch (clause->Simplify()) { - case SatClause::CLAUSE_ALWAYS_FALSE: return ModelUnsat(); - case SatClause::CLAUSE_ALWAYS_TRUE: FALLTHROUGH_INTENDED; - case SatClause::CLAUSE_SUBSUMED: return true; + case SatClause::CLAUSE_ALWAYS_FALSE: + return ModelUnsat(); + case SatClause::CLAUSE_ALWAYS_TRUE: + FALLTHROUGH_INTENDED; + case SatClause::CLAUSE_SUBSUMED: + return true; case SatClause::CLAUSE_ACTIVE: { - if (parameters_.treat_binary_clauses_separately() - && clause->Size() == 2) { - binary_implication_graph_.AddBinaryClause( - clause->FirstLiteral(), clause->SecondLiteral()); + if (parameters_.treat_binary_clauses_separately() && + clause->Size() == 2) { + binary_implication_graph_.AddBinaryClause(clause->FirstLiteral(), + clause->SecondLiteral()); } else { if (!watched_clauses_.AttachAndPropagate(clause.get(), &trail_)) { return ModelUnsat(); @@ -631,7 +625,7 @@ bool SatSolver::AddLinearConstraintInternal(const std::vector& Coefficient max_value) { SCOPED_TIME_STAT(&stats_); DCHECK(LinearConstraintIsCannonical(cst)); - if (rhs < 0) return ModelUnsat(); // Unsatisfiable constraint. + if (rhs < 0) return ModelUnsat(); // Unsatisfiable constraint. if (rhs >= max_value) return true; // Always satisfied constraint. // A linear upper bounded constraint is a clause if the only problematic @@ -651,18 +645,18 @@ bool SatSolver::AddLinearConstraintInternal(const std::vector& return pb_constraints_.AddConstraint(cst, rhs); } -bool SatSolver::AddLinearConstraint( - bool use_lower_bound, Coefficient lower_bound, - bool use_upper_bound, Coefficient upper_bound, - std::vector* cst) { +bool SatSolver::AddLinearConstraint(bool use_lower_bound, + Coefficient lower_bound, + bool use_upper_bound, + Coefficient upper_bound, + std::vector* cst) { SCOPED_TIME_STAT(&stats_); - CHECK(choice_points_.empty()); + CHECK_EQ(CurrentDecisionLevel(), 0); Coefficient bound_shift; Coefficient max_value; CHECK(PbCannonicalForm(cst, &bound_shift, &max_value)); if (use_upper_bound) { - if (!AddLinearConstraintInternal(*cst, - upper_bound + bound_shift, + if (!AddLinearConstraintInternal(*cst, upper_bound + bound_shift, max_value)) { return ModelUnsat(); } @@ -671,9 +665,8 @@ bool SatSolver::AddLinearConstraint( for (int i = 0; i < cst->size(); ++i) { (*cst)[i].literal = (*cst)[i].literal.Negated(); } - if (!AddLinearConstraintInternal(*cst, - max_value - (lower_bound + bound_shift), - max_value)) { + if (!AddLinearConstraintInternal( + *cst, max_value - (lower_bound + bound_shift), max_value)) { return ModelUnsat(); } } @@ -686,15 +679,15 @@ void SatSolver::AddLearnedClauseAndEnqueueUnitPropagation( if (literals.size() == 1) { // A length 1 clause fix a literal for all the search. // ComputeBacktrackLevel() should have returned 0. - CHECK(choice_points_.empty()); + CHECK_EQ(CurrentDecisionLevel(), 0); trail_.Enqueue(literals[0], AssignmentInfo::UNIT_REASON); } else { if (parameters_.treat_binary_clauses_separately() && literals.size() == 2) { - binary_implication_graph_.AddBinaryConflict( - literals[0], literals[1], &trail_); + binary_implication_graph_.AddBinaryConflict(literals[0], literals[1], + &trail_); } else { - SatClause* clause = SatClause::Create( - literals, SatClause::LEARNED_CLAUSE); + SatClause* clause = + SatClause::Create(literals, SatClause::LEARNED_CLAUSE); CompressLearnedClausesIfNeeded(); --num_learned_clause_before_cleanup_; learned_clauses_.emplace_back(clause); @@ -711,6 +704,7 @@ void SatSolver::AddLearnedClauseAndEnqueueUnitPropagation( // TODO(user): Clear the solver state and all the constraints. void SatSolver::Reset(int num_variables) { SCOPED_TIME_STAT(&stats_); + current_decision_level_ = 0; SetNumVariables(num_variables); is_model_unsat_ = false; leave_initial_activities_unchanged_ = false; @@ -724,14 +718,14 @@ void SatSolver::Reset(int num_variables) { bool SatSolver::InitialPropagation() { SCOPED_TIME_STAT(&stats_); - CHECK_EQ(choice_points_.size(), 0); + CHECK_EQ(CurrentDecisionLevel(), 0); if (!Propagate()) { return ModelUnsat(); } return true; } -bool SatSolver::EnqueueDecision(Literal true_literal) { +int SatSolver::EnqueueDecisionAndBackjumpOnConflict(Literal true_literal) { SCOPED_TIME_STAT(&stats_); // We are back at level 0. This can happen because of a restart, or because // we proved that some variables must take a given value in any satisfiable @@ -740,23 +734,27 @@ bool SatSolver::EnqueueDecision(Literal true_literal) { // // TODO(user): Do not trigger it all the time if it takes too much time. // TODO(user): Do more advanced preprocessing? - if (choice_points_.empty()) { + if (CurrentDecisionLevel() == 0) { if (num_processed_fixed_variables_ < trail_.Index()) { ProcessNewlyFixedVariables(); } } - NewChoicePoint(true_literal); + int first_propagation_index = trail_.Index(); + NewDecision(true_literal); while (!Propagate()) { // If Propagate() fail at level 0, then the problem is UNSAT. - if (choice_points_.size() == 0) return ModelUnsat(); + if (CurrentDecisionLevel() == 0) { + is_model_unsat_ = true; + return kUnsatTrailIndex; + } reason_cache_.Clear(); // A conflict occured, compute a nice reason for this failure. std::vector reason; std::vector discarded_last_level_literals; - ComputeFirstUIPConflict(trail_.FailingClause(), - &reason, &discarded_last_level_literals); + ComputeFirstUIPConflict(trail_.FailingClause(), &reason, + &discarded_last_level_literals); DCHECK(IsConflictValid(reason)); // Update the activity of all the variables in the first UIP clause. @@ -764,8 +762,10 @@ bool SatSolver::EnqueueDecision(Literal true_literal) { // thus discarded) during the first UIP computation. Note that both // sets are disjoint. const int initial_lbd = ComputeLbd(reason); - const int lbd_limit = parameters_.use_lbd() && - parameters_.use_glucose_bump_again_strategy() ? initial_lbd : 0; + const int lbd_limit = + parameters_.use_lbd() && parameters_.use_glucose_bump_again_strategy() + ? initial_lbd + : 0; BumpVariableActivities(reason, lbd_limit); BumpVariableActivities(discarded_last_level_literals, lbd_limit); @@ -793,6 +793,7 @@ bool SatSolver::EnqueueDecision(Literal true_literal) { // Backtrack and add the reason to the set of learned clause. counters_.num_literals_learned += reason.size(); Backtrack(ComputeBacktrackLevel(reason)); + first_propagation_index = trail_.Index(); AddLearnedClauseAndEnqueueUnitPropagation(reason); // Decay the activities. @@ -810,22 +811,51 @@ bool SatSolver::EnqueueDecision(Literal true_literal) { if (counters_.num_failures % period == 0 && parameters_.variable_activity_decay() < max_decay) { parameters_.set_variable_activity_decay( - parameters_.variable_activity_decay() - + parameters_.glucose_decay_increment()); + parameters_.variable_activity_decay() + + parameters_.glucose_decay_increment()); } } - return true; + return first_propagation_index; +} + +int SatSolver::EnqueueDecisionAndBacktrackOnConflict(Literal true_literal) { + SCOPED_TIME_STAT(&stats_); + int max_level = current_decision_level_; + int first_propagation_index = + EnqueueDecisionAndBackjumpOnConflict(true_literal); + if (first_propagation_index == kUnsatTrailIndex) return kUnsatTrailIndex; + int i = current_decision_level_; + while (i < max_level) { + Literal previous_decision = decisions_[i].literal; + ++i; + if (Assignment().IsLiteralTrue(previous_decision)) continue; + if (Assignment().IsLiteralFalse(previous_decision)) { + return first_propagation_index; + } + + // Not assigned, we try to take it. + first_propagation_index = + std::min(first_propagation_index, + EnqueueDecisionAndBackjumpOnConflict(previous_decision)); + if (first_propagation_index == kUnsatTrailIndex) return kUnsatTrailIndex; + if (current_decision_level_ <= i) { + // Conflict. We know that decision #i can't be applied. + max_level = i - 1; + i = current_decision_level_; + } + } + return first_propagation_index; } void SatSolver::Backtrack(int target_level) { SCOPED_TIME_STAT(&stats_); - DCHECK(!choice_points_.empty()); + DCHECK_GT(CurrentDecisionLevel(), 0); + DCHECK_GE(target_level, 0); ++counters_.num_failures; int target_trail_index = 0; - while (choice_points_.size() > target_level) { - VLOG(2) << Indent() << "Compress " << choice_points_.back().decision; - target_trail_index = choice_points_.back().literal_trail_index; - choice_points_.pop_back(); + while (current_decision_level_ > target_level) { + --current_decision_level_; + target_trail_index = decisions_[current_decision_level_].trail_index; } Untrail(target_trail_index); trail_.SetDecisionLevel(target_level); @@ -833,8 +863,9 @@ void SatSolver::Backtrack(int target_level) { SatSolver::Status SatSolver::Solve() { SCOPED_TIME_STAT(&stats_); + TimeLimit time_limit(parameters_.max_time_in_seconds()); if (is_model_unsat_) return MODEL_UNSAT; - if (!choice_points_.empty()) { + if (CurrentDecisionLevel() > 0) { LOG(ERROR) << "Wrong state when calling SatSolver::Solve()"; return INTERNAL_ERROR; } @@ -842,8 +873,7 @@ SatSolver::Status SatSolver::Solve() { // Display initial statistics. LOG(INFO) << "Initial memory usage: " << MemoryUsage(); - LOG(INFO) << "Number of clauses (size > 2): " - << problem_clauses_.size(); + LOG(INFO) << "Number of clauses (size > 2): " << problem_clauses_.size(); LOG(INFO) << "Number of binary clauses: " << binary_implication_graph_.NumberOfImplications(); LOG(INFO) << "Number of linear constraints: " @@ -871,12 +901,24 @@ SatSolver::Status SatSolver::Solve() { // Starts search. LOG(INFO) << "Start Search: " << parameters_.ShortDebugString(); for (;;) { + // Test if a limit is reached. + if (time_limit.LimitReached()) { + LOG(INFO) << "The time limit has been reached. Aborting."; + LOG(INFO) << RunningStatisticsString(); + return LIMIT_REACHED; + } + if (counters_.num_failures >= parameters_.max_number_of_conflicts()) { + LOG(INFO) << "The conflict limit has been reached. Aborting."; + LOG(INFO) << RunningStatisticsString(); + return LIMIT_REACHED; + } + // This is done this way because counters_.num_failures may augment by // more than one at each iterations. if (counters_.num_failures >= next_progression_display) { LOG(INFO) << RunningStatisticsString(); - next_progression_display = kDisplayFrequency * - (1 + counters_.num_failures / kDisplayFrequency); + next_progression_display = + kDisplayFrequency * (1 + counters_.num_failures / kDisplayFrequency); } if (trail_.Index() == num_variables_.value()) { // At a leaf. @@ -890,8 +932,8 @@ SatSolver::Status SatSolver::Solve() { } // Note that ShouldRestart() comes first because it had side effects and - // should be executed even if choice_points_ is empty. - if (ShouldRestart() && !choice_points_.empty()) { + // should be executed even if CurrentDecisionLevel() is zero. + if (ShouldRestart() && CurrentDecisionLevel() > 0) { Backtrack(0); } @@ -903,7 +945,7 @@ SatSolver::Status SatSolver::Solve() { if (objective_weights_[next_branch.Index()] != 0.0) { next_branch = next_branch.Negated(); } - if (!EnqueueDecision(next_branch)) { + if (EnqueueDecisionAndBackjumpOnConflict(next_branch) == -1) { LOG(INFO) << "UNSAT \n" << StatusString(); return MODEL_UNSAT; } @@ -916,7 +958,7 @@ void SatSolver::BumpVariableActivities(const std::vector& literals, const double max_activity_value = parameters_.max_variable_activity_value(); for (const Literal literal : literals) { const VariableIndex var = literal.Variable(); - if (DecisionLevel(var) == choice_points_.size() && + if (DecisionLevel(var) == CurrentDecisionLevel() && trail_.Info(var).type == AssignmentInfo::CLAUSE_PROPAGATION && trail_.Info(var).sat_clause->IsLearned() && trail_.Info(var).sat_clause->Lbd() < bump_again_lbd_limit) { @@ -993,7 +1035,7 @@ void SatSolver::UpdateClauseActivityIncrement() { bool SatSolver::IsConflictValid(const std::vector& literals) { SCOPED_TIME_STAT(&stats_); if (literals.empty()) return false; - const int current_level = choice_points_.size(); + const int current_level = CurrentDecisionLevel(); int num_literal_at_current_level = 0; for (const Literal literal : literals) { const int level = DecisionLevel(literal.Variable()); @@ -1009,7 +1051,7 @@ bool SatSolver::IsConflictValid(const std::vector& literals) { int SatSolver::ComputeBacktrackLevel(const std::vector& literals) { SCOPED_TIME_STAT(&stats_); - DCHECK(!choice_points_.empty()); + DCHECK_GT(CurrentDecisionLevel(), 0); // Note(user): if the learned clause is of size 1, we backtack all the way to // the beginning. It may be possible to follow another behavior, but then the @@ -1023,7 +1065,7 @@ int SatSolver::ComputeBacktrackLevel(const std::vector& literals) { // We want the highest level which is not the current one. int backtrack_level = 0; - const int current_level = choice_points_.size(); + const int current_level = CurrentDecisionLevel(); for (const Literal literal : literals) { const int level = DecisionLevel(literal.Variable()); if (level != current_level) { @@ -1035,10 +1077,10 @@ int SatSolver::ComputeBacktrackLevel(const std::vector& literals) { return backtrack_level; } -template +template int SatSolver::ComputeLbd(const LiteralList& literals) { SCOPED_TIME_STAT(&stats_); - is_level_marked_.ClearAndResize(SatDecisionLevel(choice_points_.size() + 1)); + is_level_marked_.ClearAndResize(SatDecisionLevel(CurrentDecisionLevel() + 1)); for (const Literal literal : literals) { const SatDecisionLevel level(DecisionLevel(literal.Variable())); DCHECK_GE(level, 0); @@ -1051,70 +1093,72 @@ int SatSolver::ComputeLbd(const LiteralList& literals) { std::string SatSolver::StatusString() const { const double time_in_s = timer_.Get(); - return - StringPrintf(" time: %fs\n", time_in_s) - + StringPrintf(" memory: %s\n", MemoryUsage().c_str()) - + StringPrintf( - " num failures: %" GG_LL_FORMAT "d (%.0f /sec)\n", - counters_.num_failures, - static_cast(counters_.num_failures) / time_in_s) - + StringPrintf(" num branches: %" GG_LL_FORMAT "d" - " (%.2f%% random) (%.0f /sec)\n", - counters_.num_branches, - 100.0 * static_cast(counters_.num_random_branches) - / counters_.num_branches, - static_cast(counters_.num_branches) / time_in_s) - + StringPrintf(" num propagations: %" GG_LL_FORMAT "d (%.0f /sec)\n", - num_propagations(), - static_cast(num_propagations()) / time_in_s) - + StringPrintf(" num binary propagations: %" GG_LL_FORMAT "d\n", - binary_implication_graph_.num_propagations()) - + StringPrintf(" num classic minimizations: %" GG_LL_FORMAT "d" - " (literals removed: %" GG_LL_FORMAT "d)\n", - counters_.num_minimizations, - counters_.num_literals_removed) - + StringPrintf(" num binary minimizations: %" GG_LL_FORMAT "d" - " (literals removed: %" GG_LL_FORMAT "d)\n", - binary_implication_graph_.num_minimization(), - binary_implication_graph_.num_literals_removed()) - + StringPrintf(" num inspected clauses: %" GG_LL_FORMAT "d\n", - watched_clauses_.num_inspected_clauses()) - + StringPrintf(" num learned literals: %lld (%.2f%% forgotten)\n", - counters_.num_literals_learned, 100.0 * - static_cast(counters_.num_literals_forgotten) - / static_cast(counters_.num_literals_learned)) - + StringPrintf(" num restarts: %d\n", restart_count_); + return StringPrintf(" time: %fs\n", time_in_s) + + StringPrintf(" memory: %s\n", MemoryUsage().c_str()) + + StringPrintf(" num failures: %" GG_LL_FORMAT "d (%.0f /sec)\n", + counters_.num_failures, + static_cast(counters_.num_failures) / time_in_s) + + StringPrintf(" num branches: %" GG_LL_FORMAT + "d" + " (%.2f%% random) (%.0f /sec)\n", + counters_.num_branches, + 100.0 * + static_cast(counters_.num_random_branches) / + counters_.num_branches, + static_cast(counters_.num_branches) / time_in_s) + + StringPrintf(" num propagations: %" GG_LL_FORMAT "d (%.0f /sec)\n", + num_propagations(), + static_cast(num_propagations()) / time_in_s) + + StringPrintf(" num binary propagations: %" GG_LL_FORMAT "d\n", + binary_implication_graph_.num_propagations()) + + StringPrintf(" num classic minimizations: %" GG_LL_FORMAT + "d" + " (literals removed: %" GG_LL_FORMAT "d)\n", + counters_.num_minimizations, + counters_.num_literals_removed) + + StringPrintf(" num binary minimizations: %" GG_LL_FORMAT + "d" + " (literals removed: %" GG_LL_FORMAT "d)\n", + binary_implication_graph_.num_minimization(), + binary_implication_graph_.num_literals_removed()) + + StringPrintf(" num inspected clauses: %" GG_LL_FORMAT "d\n", + watched_clauses_.num_inspected_clauses()) + + StringPrintf( + " num learned literals: %lld (%.2f%% forgotten)\n", + counters_.num_literals_learned, + 100.0 * static_cast(counters_.num_literals_forgotten) / + static_cast(counters_.num_literals_learned)) + + StringPrintf(" num restarts: %d\n", restart_count_); } std::string SatSolver::RunningStatisticsString() const { const double time_in_s = timer_.Get(); const int learned = learned_clauses_.size(); - return StringPrintf("%6.2lfs, mem:%s, fails:%" GG_LL_FORMAT "d, " + return StringPrintf("%6.2lfs, mem:%s, fails:%" GG_LL_FORMAT + "d, " "depth:%d, learned:%d, restarts:%d, vars:%d", - time_in_s, - MemoryUsage().c_str(), - counters_.num_failures, - static_cast(choice_points_.size()), - learned, - restart_count_, + time_in_s, MemoryUsage().c_str(), counters_.num_failures, + CurrentDecisionLevel(), learned, restart_count_, num_variables_.value() - num_processed_fixed_variables_); } double SatSolver::ComputeInitialVariableWeight(VariableIndex var) const { if (leave_initial_activities_unchanged_) return activities_[var]; switch (parameters_.initial_activity()) { - case SatParameters::ALL_ZERO_ACTIVITY: return 0; - case SatParameters::RANDOM_ACTIVITY: return random_.RandDouble(); + case SatParameters::ALL_ZERO_ACTIVITY: + return 0; + case SatParameters::RANDOM_ACTIVITY: + return random_.RandDouble(); case SatParameters::SCALED_USAGE_ACTIVITY: { - return watched_clauses_.VariableStatistic(var).weighted_num_appearances - / static_cast(watched_clauses_.num_watched_clauses()); + return watched_clauses_.VariableStatistic(var).weighted_num_appearances / + static_cast(watched_clauses_.num_watched_clauses()); } } } void SatSolver::ProcessNewlyFixedVariables() { SCOPED_TIME_STAT(&stats_); - DCHECK(choice_points_.empty()); + DCHECK_EQ(CurrentDecisionLevel(), 0); int num_detached_clauses = 0; int num_binary = 0; @@ -1131,8 +1175,8 @@ void SatSolver::ProcessNewlyFixedVariables() { // The clause is always true, detach it. watched_clauses_.LazyDetach(clause); ++num_detached_clauses; - } else if (clause->Size() == 2 - && parameters_.treat_binary_clauses_separately()) { + } else if (clause->Size() == 2 && + parameters_.treat_binary_clauses_separately()) { // The clause is now a binary clause, treat it separately. binary_implication_graph_.AddBinaryClause(clause->FirstLiteral(), clause->SecondLiteral()); @@ -1145,14 +1189,13 @@ void SatSolver::ProcessNewlyFixedVariables() { watched_clauses_.CleanUpWatchers(); if (num_detached_clauses > 0) { VLOG(1) << trail_.Index() << " fixed variables at level 0. " - << "Detached " << num_detached_clauses - << " clauses. " << num_binary << " converted to binary."; + << "Detached " << num_detached_clauses << " clauses. " << num_binary + << " converted to binary."; // Free-up learned clause memory. Note that this also postpone a bit the // next clause cleaning phase since we removed some clauses. std::vector::iterator iter = std::partition( - learned_clauses_.begin(), - learned_clauses_.end(), + learned_clauses_.begin(), learned_clauses_.end(), std::bind1st(std::mem_fun(&SatSolver::IsClauseAttachedOrUsedAsReason), this)); STLDeleteContainerPointers(iter, learned_clauses_.end()); @@ -1190,7 +1233,7 @@ bool SatSolver::Propagate() { if (propagation_trail_index_ < trail_.Index()) { const Literal literal = trail_[propagation_trail_index_]; ++propagation_trail_index_; - DCHECK_EQ(DecisionLevel(literal.Variable()), choice_points_.size()); + DCHECK_EQ(DecisionLevel(literal.Variable()), CurrentDecisionLevel()); if (!watched_clauses_.PropagateOnFalse(literal.Negated(), &trail_)) { return false; } @@ -1233,11 +1276,12 @@ ClauseRef SatSolver::Reason(VariableIndex var) const { } } -void SatSolver::NewChoicePoint(Literal literal) { +void SatSolver::NewDecision(Literal literal) { SCOPED_TIME_STAT(&stats_); counters_.num_branches++; - choice_points_.push_back(ChoicePoint(trail_.Index(), literal)); - trail_.SetDecisionLevel(choice_points_.size()); + decisions_[current_decision_level_] = Decision(trail_.Index(), literal); + ++current_decision_level_; + trail_.SetDecisionLevel(current_decision_level_); trail_.Enqueue(literal, AssignmentInfo::SEARCH_DECISION); } @@ -1251,8 +1295,8 @@ Literal SatSolver::NextBranch() { do { // TODO(user): This may not be super efficient if almost all the // variables are assigned. - var = (*var_ordering_.Raw())[ - random_.Uniform(var_ordering_.Raw()->size())]->variable(); + var = (*var_ordering_.Raw())[random_.Uniform(var_ordering_.Raw()->size())] + ->variable(); var_ordering_.Remove(&queue_elements_[var]); } while (trail_.Assignment().IsVariableAssigned(var)); } else { @@ -1266,17 +1310,25 @@ Literal SatSolver::NextBranch() { } // Choose its assignment (i.e. True of False). - const bool sign = watched_clauses_.VariableStatistic(var).num_positive_clauses - > watched_clauses_.VariableStatistic(var).num_negative_clauses; - const bool polarity = trail_.Assignment() - .GetLastVariableValueIfEverAssignedOrDefault(var, sign); + const bool sign = + watched_clauses_.VariableStatistic(var).num_positive_clauses > + watched_clauses_.VariableStatistic(var).num_negative_clauses; + const bool polarity = + trail_.Assignment().GetLastVariableValueIfEverAssignedOrDefault(var, + sign); switch (parameters_.variable_branching()) { - case SatParameters::FIXED_POSITIVE: return Literal(var, true); - case SatParameters::FIXED_NEGATIVE: return Literal(var, false); - case SatParameters::SIGN: return Literal(var, sign); - case SatParameters::REVERSE_SIGN: return Literal(var, !sign); - case SatParameters::POLARITY: return Literal(var, polarity); - case SatParameters::REVERSE_POLARITY: return Literal(var, !polarity); + case SatParameters::FIXED_POSITIVE: + return Literal(var, true); + case SatParameters::FIXED_NEGATIVE: + return Literal(var, false); + case SatParameters::SIGN: + return Literal(var, sign); + case SatParameters::REVERSE_SIGN: + return Literal(var, !sign); + case SatParameters::POLARITY: + return Literal(var, polarity); + case SatParameters::REVERSE_POLARITY: + return Literal(var, !polarity); } } @@ -1337,7 +1389,8 @@ bool SatSolver::IsAssignmentValid(const VariablesAssignment& assignment) const { std::string result; for (VariableIndex var(0); var < num_variables_; ++var) { result.append(trail_.Assignment() - .GetTrueLiteralForAssignedVariable(var).DebugString()); + .GetTrueLiteralForAssignedVariable(var) + .DebugString()); result.append(" "); } return true; @@ -1349,9 +1402,10 @@ std::string SatSolver::DebugString(const SatClause& clause) const { if (!result.empty()) { result.append(" || "); } - const std::string value = trail_.Assignment().IsLiteralTrue(literal) - ? "true" : (trail_.Assignment().IsLiteralFalse(literal) ? "false" - : "undef"); + const std::string value = + trail_.Assignment().IsLiteralTrue(literal) + ? "true" + : (trail_.Assignment().IsLiteralFalse(literal) ? "false" : "undef"); result.append( StringPrintf("%s(%s)", literal.DebugString().c_str(), value.c_str())); } diff --git a/src/sat/sat_solver.h b/src/sat/sat_solver.h index e16f0bf717..e3375b23b4 100644 --- a/src/sat/sat_solver.h +++ b/src/sat/sat_solver.h @@ -38,7 +38,6 @@ #include "util/stats.h" #include "base/adjustable_priority_queue.h" - namespace operations_research { namespace sat { @@ -71,10 +70,10 @@ inline int SUniv(int i) { // Variable information. This is updated each time we attach/detach a clause. struct VariableInfo { VariableInfo() - : num_positive_clauses(0), - num_negative_clauses(0), - num_appearances(0), - weighted_num_appearances(0.0) {} + : num_positive_clauses(0), + num_negative_clauses(0), + num_appearances(0), + weighted_num_appearances(0.0) {} int num_positive_clauses; int num_negative_clauses; @@ -85,11 +84,10 @@ struct VariableInfo { // Priority queue element to support var ordering by lowest weight first. class WeightedVarQueueElement { public: - WeightedVarQueueElement() - : heap_index_(-1), weight_(0.0), var_(-1) {} - bool operator <(const WeightedVarQueueElement& other) const { + WeightedVarQueueElement() : heap_index_(-1), weight_(0.0), var_(-1) {} + bool operator<(const WeightedVarQueueElement& other) const { return weight_ < other.weight_ || - (weight_ == other.weight_ && var_ < other.var_); + (weight_ == other.weight_ && var_ < other.var_); } void SetHeapIndex(int h) { heap_index_ = h; } int GetHeapIndex() const { return heap_index_; } @@ -197,9 +195,9 @@ class SatClause { // Note that the max lbd is the maximum depth of the search tree (decision // levels), so it should fit easily in 29 bits. Note that we can also upper // bound it without hurting too much the clause cleaning heuristic. - bool is_learned_: 1; - bool is_attached_: 1; - int lbd_ : 30; + bool is_learned_ : 1; + bool is_attached_ : 1; + int lbd_ : 30; int size_ : 32; double activity_; @@ -233,8 +231,7 @@ class LiteralWatchers { // Attaches the given clause to the event: the given literal becomes false. // The blocking_literal can be any literal from the clause, it is used to // speed up PropagateOnFalse() by skipping the clause if it is true. - void AttachOnFalse(Literal literal, - Literal blocking_literal, + void AttachOnFalse(Literal literal, Literal blocking_literal, SatClause* clause); // Lazily detach the given clause. The deletion will actually occur when @@ -251,7 +248,7 @@ class LiteralWatchers { int64 num_inspected_clauses() const { return num_inspected_clauses_; } // Number of clauses currently watched. - int64 num_watched_clauses() const {return num_watched_clauses_; } + int64 num_watched_clauses() const { return num_watched_clauses_; } // Returns some statistics on the number of appearance of this variable in // all the attached clauses. @@ -327,7 +324,9 @@ class LiteralWatchers { class BinaryImplicationGraph { public: BinaryImplicationGraph() - : num_propagations_(0), num_minimization_(0), num_literals_removed_(0), + : num_propagations_(0), + num_minimization_(0), + num_literals_removed_(0), stats_("BinaryImplicationGraph") {} ~BinaryImplicationGraph() { IF_STATS_ENABLED(LOG(INFO) << stats_.StatString()); @@ -397,6 +396,9 @@ class BinaryImplicationGraph { DISALLOW_COPY_AND_ASSIGN(BinaryImplicationGraph); }; +// A constant used by the EnqueueDecision*() API. +const int kUnsatTrailIndex = -1; + // The main SAT solver. // It currently implements the CDCL algorithm. See // http://en.wikipedia.org/wiki/Conflict_Driven_Clause_Learning @@ -431,10 +433,9 @@ class SatSolver { // efficient. // // TODO(user): Add error handling for overflow/underflow. - bool AddLinearConstraint( - bool use_lower_bound, Coefficient lower_bound, - bool use_upper_bound, Coefficient upper_bound, - std::vector* cst); + bool AddLinearConstraint(bool use_lower_bound, Coefficient lower_bound, + bool use_upper_bound, Coefficient upper_bound, + std::vector* cst); // Gives a hint so the solver tries to find a solution with the given literal // sets to true. The weight is a number in [0,1] reflecting the relative @@ -457,6 +458,7 @@ class SatSolver { enum Status { MODEL_UNSAT, MODEL_SAT, + LIMIT_REACHED, INTERNAL_ERROR, }; Status Solve(); @@ -474,10 +476,32 @@ class SatSolver { bool InitialPropagation(); // Takes a new decision (the given true_literal must be unassigned) and - // propagates it. If it leads to conflict, the conflict is learned, and the - // trail is automatically backtracked to a valid state. Returns false if the - // problem is UNSAT. - bool EnqueueDecision(Literal true_literal); + // propagates it. Returns the trail index of the first newly propagated + // literal. If there is a conflict and the problem is detected to be UNSAT, + // returns kUnsatTrailIndex. + // + // A client can determine if there is a conflict by checking if the + // CurrentDecisionLevel() was increased by 1 or not. + // + // If there is a conflict, the given decision is not applied and: + // - The conflict is learned. + // - The decisions are potentially backtracked to the first decision that + // propagates more variables because of the newly learned conflict. + // - The returned value is equal to trail_.Index() after this backtracking and + // just before the new propagation (due to the conflict) which is also + // performed by this function. + int EnqueueDecisionAndBackjumpOnConflict(Literal true_literal); + + // This function starts by calling EnqueueDecisionAndBackjumpOnConflict(). If + // there is no conflict, it stops there. Otherwise, it tries to reapply all + // the decisions that where backjumped over until the first one that can't be + // taken because it is incompatible. Note that during this process, more + // conflicts may happen and the trail may be backtracked even further. + // + // In any case, the new decisions stack will be the largest valid prefix + // of the old stack. Hence, the first deleted decision will corresponds to a + // literal that was already propagated to its opposite value. + int EnqueueDecisionAndBacktrackOnConflict(Literal true_literal); // Restores the state to the given target decision level. The decision at that // level and all its propagation will not be undone. But all the trail after @@ -485,13 +509,15 @@ class SatSolver { // sate after InitialPropagation() was called. void Backtrack(int target_level); - // Returns the current choices, trail and variable assignement. - struct ChoicePoint { - ChoicePoint(int i, Literal d) : literal_trail_index(i), decision(d) {} - int literal_trail_index; - Literal decision; + // Returns the current decisions, trail and variable assignment. + struct Decision { + Decision() : trail_index(-1) {} + Decision(int i, Literal l) : trail_index(i), literal(l) {} + int trail_index; + Literal literal; }; - const std::vector& ChoicePoints() const { return choice_points_; } + int CurrentDecisionLevel() const { return current_decision_level_; } + const std::vector& Decisions() const { return decisions_; } const Trail& LiteralTrail() const { return trail_; } const VariablesAssignment& Assignment() const { return trail_.Assignment(); } @@ -510,9 +536,7 @@ class SatSolver { std::string Indent() const; // Returns the decision level of a given variable. - int DecisionLevel(VariableIndex var) const { - return trail_.Info(var).level; - } + int DecisionLevel(VariableIndex var) const { return trail_.Info(var).level; } // Returns the reason for a given variable assignment. The variable must be // assigned (this is DCHECKed). Note that the reason clause may or may not @@ -536,8 +560,8 @@ class SatSolver { // SatClause::AttachAndEnqueuePotentialUnitPropagation(). bool IsClauseUsedAsReason(SatClause* clause) const { const VariableIndex var = clause->SecondLiteral().Variable(); - return trail_.Info(var).type == AssignmentInfo::CLAUSE_PROPAGATION - && trail_.Info(var).sat_clause == clause; + return trail_.Info(var).type == AssignmentInfo::CLAUSE_PROPAGATION && + trail_.Info(var).sat_clause == clause; } // Predicate used by ProcessNewlyFixedVariables(). @@ -547,9 +571,8 @@ class SatSolver { // Predicate used by CompressLearnedClausesIfNeeded(). bool ClauseShouldBeKept(SatClause* clause) const { - return clause->Lbd() <= 2 - || clause->Size() <= 2 - || IsClauseUsedAsReason(clause); + return clause->Lbd() <= 2 || clause->Size() <= 2 || + IsClauseUsedAsReason(clause); } // Returns false if the literal is already assigned to false. @@ -560,8 +583,7 @@ class SatSolver { // infeasible/trivial constraints or clause constraints and takes the proper // action. bool AddLinearConstraintInternal(const std::vector& cst, - Coefficient rhs, - Coefficient max_value); + Coefficient rhs, Coefficient max_value); // Adds a learned clause to the problem. This should be called after // Backtrack(). The backtrack is such that after it is applied, all the @@ -570,9 +592,9 @@ class SatSolver { void AddLearnedClauseAndEnqueueUnitPropagation( const std::vector& literals); - // Creates a new choice point which corresponds to setting the given literal - // to True and Enqueue() this change. - void NewChoicePoint(Literal literal); + // Creates a new decision which corresponds to setting the given literal to + // True and Enqueue() this change. + void NewDecision(Literal literal); // Performs propagation of the recently enqueued elements. bool Propagate(); @@ -636,7 +658,7 @@ class SatSolver { // Solver" in Twenty-first International Joint Conference on Artificial // Intelligence (IJCAI'09), july 2009. // http://www.ijcai.org/papers09/Papers/IJCAI09-074.pdf - template + template int ComputeLbd(const LiteralList& literals); // Checks if we need to reduce the number of learned clauses and do @@ -704,8 +726,12 @@ class SatSolver { // The solver trail. Trail trail_; - // The stack of choice points. - std::vector choice_points_; + // The stack of decisions taken by the solver. They are stored in [0, + // current_decision_level_). The vector is of size num_variables_ so it can + // store all the decisions. This is done this way because in some situation we + // need to remember the previously taken decisions after a backtrack. + int current_decision_level_; + std::vector decisions_; // The index of the first non-propagated literal on the trail. The first index // is for non-binary clauses propagation and the second index is for binary @@ -733,9 +759,13 @@ class SatSolver { int64 num_literals_forgotten; Counters() - : num_branches(0), num_random_branches(0), num_failures(0), - num_minimizations(0), num_literals_removed(0), - num_literals_learned(0), num_literals_forgotten(0) { } + : num_branches(0), + num_random_branches(0), + num_failures(0), + num_minimizations(0), + num_literals_removed(0), + num_literals_learned(0), + num_literals_forgotten(0) {} }; Counters counters_; diff --git a/src/util/bitset.cc b/src/util/bitset.cc index 66f5237c00..318d053c2f 100644 --- a/src/util/bitset.cc +++ b/src/util/bitset.cc @@ -23,37 +23,35 @@ namespace operations_research { // ---------- Bit Operations ---------- -#define BIT_COUNT_RANGE(size, zero) \ - uint##size BitCountRange##size( \ - const uint##size* const bits, uint##size start, uint##size end) { \ - if (end - start > FLAGS_bitset_small_bitset_count) { \ - const int offset_start = BitOffset##size(start); \ - const int pos_start = BitPos##size(start); \ - const int offset_end = BitOffset##size(end); \ - const int pos_end = BitPos##size(end); \ - if (offset_end == offset_start) { \ - return BitCount##size(bits[offset_start] \ - & OneRange##size(pos_start, pos_end)); \ - } else { \ - uint##size bit_count = zero; \ - bit_count += BitCount##size(bits[offset_start] \ - & IntervalUp##size(pos_start)); \ - for (int offset = offset_start + 1; \ - offset < offset_end; \ - ++offset) { \ - bit_count += BitCount##size(bits[offset]); \ - } \ - bit_count += BitCount##size(bits[offset_end] \ - & IntervalDown##size(pos_end)); \ - return bit_count; \ - } \ - } else { \ - uint##size bit_count = zero; \ - for (uint##size i = start; i <= end; ++i) { \ - bit_count += IsBitSet##size(bits, i); \ - } \ - return bit_count; \ - } \ +#define BIT_COUNT_RANGE(size, zero) \ + uint##size BitCountRange##size(const uint##size* const bits, \ + uint##size start, uint##size end) { \ + if (end - start > FLAGS_bitset_small_bitset_count) { \ + const int offset_start = BitOffset##size(start); \ + const int pos_start = BitPos##size(start); \ + const int offset_end = BitOffset##size(end); \ + const int pos_end = BitPos##size(end); \ + if (offset_end == offset_start) { \ + return BitCount##size(bits[offset_start] & \ + OneRange##size(pos_start, pos_end)); \ + } else { \ + uint##size bit_count = zero; \ + bit_count += \ + BitCount##size(bits[offset_start] & IntervalUp##size(pos_start)); \ + for (int offset = offset_start + 1; offset < offset_end; ++offset) { \ + bit_count += BitCount##size(bits[offset]); \ + } \ + bit_count += \ + BitCount##size(bits[offset_end] & IntervalDown##size(pos_end)); \ + return bit_count; \ + } \ + } else { \ + uint##size bit_count = zero; \ + for (uint##size i = start; i <= end; ++i) { \ + bit_count += IsBitSet##size(bits, i); \ + } \ + return bit_count; \ + } \ } BIT_COUNT_RANGE(64, GG_ULONGLONG(0)) @@ -61,33 +59,31 @@ BIT_COUNT_RANGE(32, 0U) #undef BIT_COUNT_RANGE -#define IS_EMPTY_RANGE(size) \ - bool IsEmptyRange##size(const uint##size* const bits, \ - uint##size start, uint##size end) { \ - const int offset_start = BitOffset##size(start); \ - const int pos_start = BitPos##size(start); \ - const int offset_end = BitOffset##size(end); \ - const int pos_end = BitPos##size(end); \ - if (offset_end == offset_start) { \ - if (bits[offset_start] & OneRange##size(pos_start, pos_end)) { \ - return false; \ - } \ - } else { \ - if (bits[offset_start] & IntervalUp##size(pos_start)) { \ - return false; \ - } \ - for (int offset = offset_start + 1; \ - offset < offset_end; \ - ++offset) { \ - if (bits[offset]) { \ - return false; \ - } \ - } \ - if (bits[offset_end] & IntervalDown##size(pos_end)) { \ - return false; \ - } \ - } \ - return true; \ +#define IS_EMPTY_RANGE(size) \ + bool IsEmptyRange##size(const uint##size* const bits, uint##size start, \ + uint##size end) { \ + const int offset_start = BitOffset##size(start); \ + const int pos_start = BitPos##size(start); \ + const int offset_end = BitOffset##size(end); \ + const int pos_end = BitPos##size(end); \ + if (offset_end == offset_start) { \ + if (bits[offset_start] & OneRange##size(pos_start, pos_end)) { \ + return false; \ + } \ + } else { \ + if (bits[offset_start] & IntervalUp##size(pos_start)) { \ + return false; \ + } \ + for (int offset = offset_start + 1; offset < offset_end; ++offset) { \ + if (bits[offset]) { \ + return false; \ + } \ + } \ + if (bits[offset_end] & IntervalDown##size(pos_end)) { \ + return false; \ + } \ + } \ + return true; \ } IS_EMPTY_RANGE(64) @@ -95,51 +91,49 @@ IS_EMPTY_RANGE(32) #undef IS_EMPTY_RANGE -#define LEAST_SIGNIFCANT_BIT_POSITION(size) \ - int##size LeastSignificantBitPosition##size( \ - const uint##size* const bits, uint##size start, uint##size end) { \ - DCHECK_LE(start, end); \ - if (IsBitSet##size(bits, start)) { \ - return start; \ - } \ - const int offset_start = BitOffset##size(start); \ - const int offset_end = BitOffset##size(end); \ - const int pos_start = BitPos##size(start); \ - if (offset_start == offset_end) { \ - const int pos_end = BitPos##size(end); \ - const uint##size active_range = \ - bits[offset_start] & OneRange##size(pos_start, pos_end); \ - if (active_range) { \ - return BitShift##size(offset_start) \ - + LeastSignificantBitPosition##size(active_range); \ - } \ - return -1; \ - } else { \ - const uint##size start_mask = bits[offset_start] \ - & IntervalUp##size(pos_start); \ - if (start_mask) { \ - return BitShift##size(offset_start) \ - + LeastSignificantBitPosition##size(start_mask); \ - } else { \ - for (int offset = offset_start + 1; \ - offset < offset_end; \ - ++offset) { \ - if (bits[offset]) { \ - return BitShift##size(offset) \ - + LeastSignificantBitPosition##size(bits[offset]); \ - } \ - } \ - const int pos_end = BitPos##size(end); \ - const uint##size active_range = bits[offset_end] \ - & IntervalDown##size(pos_end); \ - if (active_range) { \ - return BitShift##size(offset_end) \ - + LeastSignificantBitPosition##size(active_range); \ - } else { \ - return -1; \ - } \ - } \ - } \ +#define LEAST_SIGNIFCANT_BIT_POSITION(size) \ + int##size LeastSignificantBitPosition##size( \ + const uint##size* const bits, uint##size start, uint##size end) { \ + DCHECK_LE(start, end); \ + if (IsBitSet##size(bits, start)) { \ + return start; \ + } \ + const int offset_start = BitOffset##size(start); \ + const int offset_end = BitOffset##size(end); \ + const int pos_start = BitPos##size(start); \ + if (offset_start == offset_end) { \ + const int pos_end = BitPos##size(end); \ + const uint##size active_range = \ + bits[offset_start] & OneRange##size(pos_start, pos_end); \ + if (active_range) { \ + return BitShift##size(offset_start) + \ + LeastSignificantBitPosition##size(active_range); \ + } \ + return -1; \ + } else { \ + const uint##size start_mask = \ + bits[offset_start] & IntervalUp##size(pos_start); \ + if (start_mask) { \ + return BitShift##size(offset_start) + \ + LeastSignificantBitPosition##size(start_mask); \ + } else { \ + for (int offset = offset_start + 1; offset < offset_end; ++offset) { \ + if (bits[offset]) { \ + return BitShift##size(offset) + \ + LeastSignificantBitPosition##size(bits[offset]); \ + } \ + } \ + const int pos_end = BitPos##size(end); \ + const uint##size active_range = \ + bits[offset_end] & IntervalDown##size(pos_end); \ + if (active_range) { \ + return BitShift##size(offset_end) + \ + LeastSignificantBitPosition##size(active_range); \ + } else { \ + return -1; \ + } \ + } \ + } \ } LEAST_SIGNIFCANT_BIT_POSITION(64) @@ -147,53 +141,50 @@ LEAST_SIGNIFCANT_BIT_POSITION(32) #undef LEAST_SIGNIFCANT_BIT_POSITION -#define MOST_SIGNIFICANT_BIT_POSITION(size) \ - int##size MostSignificantBitPosition##size( \ - const uint##size* const bits, \ - uint##size start, uint##size end) { \ - DCHECK_GE(end, start); \ - if (IsBitSet##size(bits, end)) { \ - return end; \ - } \ - const int offset_start = BitOffset##size(start); \ - const int offset_end = BitOffset##size(end); \ - const int pos_end = BitPos##size(end); \ - if (offset_start == offset_end) { \ - const int pos_start = BitPos##size(start); \ - const uint##size active_range = \ - bits[offset_start] & OneRange##size(pos_start, pos_end); \ - if (active_range) { \ - return BitShift##size(offset_end) \ - + MostSignificantBitPosition##size(active_range); \ - } else { \ - return -1; \ - } \ - } else { \ - const uint##size end_mask = \ - bits[offset_end] & IntervalDown##size(pos_end); \ - if (end_mask) { \ - return BitShift##size(offset_end) \ - + MostSignificantBitPosition##size(end_mask); \ - } else { \ - for (int offset = offset_end - 1; \ - offset > offset_start; \ - --offset) { \ - if (bits[offset]) { \ - return BitShift##size(offset) \ - + MostSignificantBitPosition##size(bits[offset]); \ - } \ - } \ - const int pos_start = BitPos##size(start); \ - const uint##size active_range = \ - bits[offset_start] & IntervalUp##size(pos_start); \ - if (active_range) { \ - return BitShift##size(offset_start) \ - + MostSignificantBitPosition##size(active_range); \ - } else { \ - return -1; \ - } \ - } \ - } \ +#define MOST_SIGNIFICANT_BIT_POSITION(size) \ + int##size MostSignificantBitPosition##size( \ + const uint##size* const bits, uint##size start, uint##size end) { \ + DCHECK_GE(end, start); \ + if (IsBitSet##size(bits, end)) { \ + return end; \ + } \ + const int offset_start = BitOffset##size(start); \ + const int offset_end = BitOffset##size(end); \ + const int pos_end = BitPos##size(end); \ + if (offset_start == offset_end) { \ + const int pos_start = BitPos##size(start); \ + const uint##size active_range = \ + bits[offset_start] & OneRange##size(pos_start, pos_end); \ + if (active_range) { \ + return BitShift##size(offset_end) + \ + MostSignificantBitPosition##size(active_range); \ + } else { \ + return -1; \ + } \ + } else { \ + const uint##size end_mask = \ + bits[offset_end] & IntervalDown##size(pos_end); \ + if (end_mask) { \ + return BitShift##size(offset_end) + \ + MostSignificantBitPosition##size(end_mask); \ + } else { \ + for (int offset = offset_end - 1; offset > offset_start; --offset) { \ + if (bits[offset]) { \ + return BitShift##size(offset) + \ + MostSignificantBitPosition##size(bits[offset]); \ + } \ + } \ + const int pos_start = BitPos##size(start); \ + const uint##size active_range = \ + bits[offset_start] & IntervalUp##size(pos_start); \ + if (active_range) { \ + return BitShift##size(offset_start) + \ + MostSignificantBitPosition##size(active_range); \ + } else { \ + return -1; \ + } \ + } \ + } \ } MOST_SIGNIFICANT_BIT_POSITION(64) @@ -201,32 +192,30 @@ MOST_SIGNIFICANT_BIT_POSITION(32) #undef MOST_SIGNIFICANT_BIT_POSITION -#define UNSAFE_LEAST_SIGNIFICANT_BIT_POSITION(size) \ - int##size UnsafeLeastSignificantBitPosition##size( \ - const uint##size* const bits, uint##size start, uint##size end) { \ - DCHECK_LE(start, end); \ - DCHECK(IsBitSet##size(bits, end)); \ - if (IsBitSet##size(bits, start)) { \ - return start; \ - } \ - const int offset_start = BitOffset##size(start); \ - const int offset_end = BitOffset##size(end); \ - const int pos_start = BitPos##size(start); \ - const uint##size start_mask = \ - bits[offset_start] & IntervalUp##size(pos_start); \ - if (start_mask) { \ - return BitShift##size(offset_start) \ - + LeastSignificantBitPosition##size(start_mask); \ - } \ - for (int offset = offset_start + 1; \ - offset <= offset_end; \ - ++offset) { \ - if (bits[offset]) { \ - return BitShift##size(offset) \ - + LeastSignificantBitPosition##size(bits[offset]); \ - } \ - } \ - return -1; \ +#define UNSAFE_LEAST_SIGNIFICANT_BIT_POSITION(size) \ + int##size UnsafeLeastSignificantBitPosition##size( \ + const uint##size* const bits, uint##size start, uint##size end) { \ + DCHECK_LE(start, end); \ + DCHECK(IsBitSet##size(bits, end)); \ + if (IsBitSet##size(bits, start)) { \ + return start; \ + } \ + const int offset_start = BitOffset##size(start); \ + const int offset_end = BitOffset##size(end); \ + const int pos_start = BitPos##size(start); \ + const uint##size start_mask = \ + bits[offset_start] & IntervalUp##size(pos_start); \ + if (start_mask) { \ + return BitShift##size(offset_start) + \ + LeastSignificantBitPosition##size(start_mask); \ + } \ + for (int offset = offset_start + 1; offset <= offset_end; ++offset) { \ + if (bits[offset]) { \ + return BitShift##size(offset) + \ + LeastSignificantBitPosition##size(bits[offset]); \ + } \ + } \ + return -1; \ } UNSAFE_LEAST_SIGNIFICANT_BIT_POSITION(64) @@ -234,32 +223,30 @@ UNSAFE_LEAST_SIGNIFICANT_BIT_POSITION(32) #undef UNSAFE_LEAST_SIGNIFICANT_BIT_POSITION -#define UNSAFE_MOST_SIGNIFICANT_BIT_POSITION(size) \ - int##size UnsafeMostSignificantBitPosition##size( \ - const uint##size* const bits, uint##size start, uint##size end) { \ - DCHECK_GE(end, start); \ - DCHECK(IsBitSet##size(bits, start)); \ - if (IsBitSet##size(bits, end)) { \ - return end; \ - } \ - const int offset_start = BitOffset##size(start); \ - const int offset_end = BitOffset##size(end); \ - const int pos_end = BitPos##size(end); \ - const uint##size end_mask = \ - bits[offset_end] & IntervalDown##size(pos_end); \ - if (end_mask) { \ - return BitShift##size(offset_end) \ - + MostSignificantBitPosition##size(end_mask); \ - } \ - for (int offset = offset_end - 1; \ - offset >= offset_start; \ - --offset) { \ - if (bits[offset]) { \ - return BitShift##size(offset) \ - + MostSignificantBitPosition##size(bits[offset]); \ - } \ - } \ - return -1; \ +#define UNSAFE_MOST_SIGNIFICANT_BIT_POSITION(size) \ + int##size UnsafeMostSignificantBitPosition##size( \ + const uint##size* const bits, uint##size start, uint##size end) { \ + DCHECK_GE(end, start); \ + DCHECK(IsBitSet##size(bits, start)); \ + if (IsBitSet##size(bits, end)) { \ + return end; \ + } \ + const int offset_start = BitOffset##size(start); \ + const int offset_end = BitOffset##size(end); \ + const int pos_end = BitPos##size(end); \ + const uint##size end_mask = \ + bits[offset_end] & IntervalDown##size(pos_end); \ + if (end_mask) { \ + return BitShift##size(offset_end) + \ + MostSignificantBitPosition##size(end_mask); \ + } \ + for (int offset = offset_end - 1; offset >= offset_start; --offset) { \ + if (bits[offset]) { \ + return BitShift##size(offset) + \ + MostSignificantBitPosition##size(bits[offset]); \ + } \ + } \ + return -1; \ } UNSAFE_MOST_SIGNIFICANT_BIT_POSITION(64) diff --git a/src/util/bitset.h b/src/util/bitset.h index 7c859e2e20..245a816a0b 100644 --- a/src/util/bitset.h +++ b/src/util/bitset.h @@ -38,9 +38,9 @@ inline uint32 OneBit32(int pos) { return 1U << pos; } // Returns the number of bits set in n. inline uint64 BitCount64(uint64 n) { - const uint64 m1 = GG_ULONGLONG(0x5555555555555555); - const uint64 m2 = GG_ULONGLONG(0x3333333333333333); - const uint64 m4 = GG_ULONGLONG(0x0F0F0F0F0F0F0F0F); + const uint64 m1 = GG_ULONGLONG(0x5555555555555555); + const uint64 m2 = GG_ULONGLONG(0x3333333333333333); + const uint64 m4 = GG_ULONGLONG(0x0F0F0F0F0F0F0F0F); const uint64 h01 = GG_ULONGLONG(0x0101010101010101); n -= (n >> 1) & m1; n = (n & m2) + ((n >> 2) & m2); @@ -58,12 +58,8 @@ inline uint32 BitCount32(uint32 n) { } // Returns a word with only the least significant bit of n set. -inline uint64 LeastSignificantBitWord64(uint64 n) { - return n & ~(n-1); -} -inline uint32 LeastSignificantBitWord32(uint32 n) { - return n & ~(n-1); -} +inline uint64 LeastSignificantBitWord64(uint64 n) { return n & ~(n - 1); } +inline uint32 LeastSignificantBitWord32(uint32 n) { return n & ~(n - 1); } // Returns the least significant bit position in n. // Discussions around lsb computation. @@ -71,7 +67,7 @@ inline uint32 LeastSignificantBitWord32(uint32 n) { // win on PIII. On k8, bsf is much slower than the C-equivalent! // Using inline assembly code yields a 10% performance gain. // Use de Bruijn hashing instead of bsf is always a win, on both P3 and K8. -#define USE_DEBRUIJN true // if true, use de Bruijn bit forward scanner +#define USE_DEBRUIJN true // if true, use de Bruijn bit forward scanner #if defined(ARCH_K8) || defined(ARCH_PIII) #define USE_ASM_LEAST_SIGNIFICANT_BIT true // if true, use assembly lsb #endif @@ -96,12 +92,11 @@ inline int LeastSignificantBitPosition64(uint64 n) { // de Bruijn sequence static const uint64 kSeq = GG_ULONGLONG(0x0218a392dd5fb34f); static const int kTab[64] = { - // initialized by 'kTab[(kSeq << i) >> 58] = i - 0, 1, 2, 7, 3, 13, 8, 19, 4, 25, 14, 28, 9, 52, 20, 58, - 5, 17, 26, 56, 15, 38, 29, 40, 10, 49, 53, 31, 21, 34, 59, 42, - 63, 6, 12, 18, 24, 27, 51, 57, 16, 55, 37, 39, 48, 30, 33, 41, - 62, 11, 23, 50, 54, 36, 47, 32, 61, 22, 35, 46, 60, 45, 44, 43, - }; + // initialized by 'kTab[(kSeq << i) >> 58] = i + 0, 1, 2, 7, 3, 13, 8, 19, 4, 25, 14, 28, 9, 52, 20, 58, + 5, 17, 26, 56, 15, 38, 29, 40, 10, 49, 53, 31, 21, 34, 59, 42, + 63, 6, 12, 18, 24, 27, 51, 57, 16, 55, 37, 39, 48, 30, 33, 41, + 62, 11, 23, 50, 54, 36, 47, 32, 61, 22, 35, 46, 60, 45, 44, 43, }; return kTab[((n & -n) * kSeq) >> 58]; #else if (n == 0) { @@ -119,22 +114,22 @@ inline int LeastSignificantBitPosition64(uint64 n) { n >>= 16; } if (n & 0x00000000000000FFLL) { - pos -= 8; + pos -= 8; } else { - n >>= 8; + n >>= 8; } if (n & 0x000000000000000FLL) { - pos -= 4; + pos -= 4; } else { - n >>= 4; + n >>= 4; } if (n & 0x0000000000000003LL) { - pos -= 2; + pos -= 2; } else { - n >>= 2; + n >>= 2; } if (n & 0x0000000000000001LL) { - pos -= 1; + pos -= 1; } return pos; #endif @@ -148,10 +143,9 @@ inline int LeastSignificantBitPosition32(uint32 n) { #elif defined(USE_DEBRUIJN) static const uint32 kSeq = 0x077CB531U; // de Bruijn sequence static const int kTab[32] = { - // initialized by 'kTab[(kSeq << i) >> 27] = i - 0, 1, 3, 7, 14, 29, 27, 23, 15, 31, 30, 28, 25, 18, 5, 11, - 22, 13, 26, 21, 10, 20, 9, 19, 6, 12, 24, 17, 2, 4, 8, 16 - }; + // initialized by 'kTab[(kSeq << i) >> 27] = i + 0, 1, 3, 7, 14, 29, 27, 23, 15, 31, 30, 28, 25, 18, 5, 11, + 22, 13, 26, 21, 10, 20, 9, 19, 6, 12, 24, 17, 2, 4, 8, 16}; return kTab[((n & -n) * kSeq) >> 27]; #else if (n == 0) { @@ -164,22 +158,22 @@ inline int LeastSignificantBitPosition32(uint32 n) { n >>= 16; } if (n & 0x000000FFL) { - pos -= 8; + pos -= 8; } else { - n >>= 8; + n >>= 8; } if (n & 0x0000000FL) { - pos -= 4; + pos -= 4; } else { - n >>= 4; + n >>= 4; } if (n & 0x00000003L) { - pos -= 2; + pos -= 2; } else { - n >>= 2; + n >>= 2; } if (n & 0x00000001L) { - pos -= 1; + pos -= 1; } return pos; #endif @@ -359,16 +353,16 @@ bool IsEmptyRange64(const uint64* const bitset, uint64 start, uint64 end); bool IsEmptyRange32(const uint32* const bitset, uint32 start, uint32 end); // Returns the first bit set in bitset between start and max_bit. -int64 LeastSignificantBitPosition64(const uint64* const bitset, - uint64 start, uint64 end); -int LeastSignificantBitPosition32(const uint32* const bitset, - uint32 start, uint32 end); +int64 LeastSignificantBitPosition64(const uint64* const bitset, uint64 start, + uint64 end); +int LeastSignificantBitPosition32(const uint32* const bitset, uint32 start, + uint32 end); // Returns the last bit set in bitset between min_bit and start. -int64 MostSignificantBitPosition64(const uint64* const bitset, - uint64 start, uint64 end); -int MostSignificantBitPosition32(const uint32* const bitset, - uint32 start, uint32 end); +int64 MostSignificantBitPosition64(const uint64* const bitset, uint64 start, + uint64 end); +int MostSignificantBitPosition32(const uint32* const bitset, uint32 start, + uint32 end); // Unsafe versions of the functions above where respectively end and start // are supposed to be set. @@ -395,8 +389,7 @@ inline uint64 TwoBitsFromPos64(uint64 pos) { template class Bitset64 { public: - Bitset64() : size_(), data_(), - end_(*this, /*at_end=*/true) {} + Bitset64() : size_(), data_(), end_(*this, /*at_end=*/true) {} explicit Bitset64(IndexType size) : size_(size > 0 ? size : IndexType(0)), data_(BitLength64(size_.value())), @@ -482,7 +475,7 @@ class Bitset64 { // Class to iterate over the bit positions at 1 of a Bitset64. class Iterator { public: - explicit Iterator(const Bitset64 &data_) + explicit Iterator(const Bitset64& data_) : bitset_(data_), index_(0), base_index_(0), current_(0) { if (bitset_.data_.empty()) { index_ = -1; @@ -526,7 +519,7 @@ class Bitset64 { // STL version of the functions above to support range-based "for" loop. // These functions are only meant to be used with GetNonZeroPositions(), see // below. - Iterator(const Bitset64 &data_, bool at_end) + Iterator(const Bitset64& data_, bool at_end) : bitset_(data_), index_(0), base_index_(0), current_(0) { if (at_end || bitset_.data_.empty()) { index_ = -1; @@ -538,12 +531,8 @@ class Bitset64 { bool operator!=(const Iterator& other) const { return index_ != other.index_; } - IndexType operator*() const { - return IndexType(index_); - } - void operator++() { - Next(); - } + IndexType operator*() const { return IndexType(index_); } + void operator++() { Next(); } private: const Bitset64& bitset_; @@ -564,18 +553,18 @@ class Bitset64 { // This is just an optimized version of a given piece of code and has probably // little general use. Sets the bit at position i to the result of // (other1[i] && use1) XOR (other2[i] && use2). - void SetBitFromOtherBitSets(IndexType i, - const Bitset64& other1, uint64 use1, - const Bitset64& other2, uint64 use2) { + void SetBitFromOtherBitSets(IndexType i, const Bitset64& other1, + uint64 use1, const Bitset64& other2, + uint64 use2) { DCHECK_EQ(data_.size(), other1.data_.size()); DCHECK_EQ(data_.size(), other2.data_.size()); DCHECK(use1 == 0 || use1 == 1); DCHECK(use2 == 0 || use2 == 1); const int bucket = BitOffset64(i.value()); const int pos = BitPos64(i.value()); - data_[bucket] ^= ((1ull << pos) & data_[bucket]) - ^ ((use1 << pos) & other1.data_[bucket]) - ^ ((use2 << pos) & other2.data_[bucket]); + data_[bucket] ^= ((1ull << pos) & data_[bucket]) ^ + ((use1 << pos) & other1.data_[bucket]) ^ + ((use2 << pos) & other2.data_[bucket]); } private: @@ -604,18 +593,14 @@ class SparseBitset { } to_clear_.clear(); } - bool operator[](IntegerType index) const { - return is_set_[index.value()]; - } + bool operator[](IntegerType index) const { return is_set_[index.value()]; } void Set(IntegerType index) { if (!is_set_[index.value()]) { is_set_[index.value()] = true; to_clear_.push_back(index); } } - void Clear(IntegerType index) { - is_set_[index.value()] = false; - } + void Clear(IntegerType index) { is_set_[index.value()] = false; } int NumberOfSetCallsWithDifferentArguments() const { return to_clear_.size(); } diff --git a/src/util/cached_log.h b/src/util/cached_log.h index 419e1f28a3..f356cd7941 100644 --- a/src/util/cached_log.h +++ b/src/util/cached_log.h @@ -39,6 +39,7 @@ class CachedLog { // Returns the log2 of 'input'. double Log2(int64 input) const; + private: std::vector cache_; DISALLOW_COPY_AND_ASSIGN(CachedLog); diff --git a/src/util/data.swig b/src/util/data.swig index 59b0954e6c..a67300ee77 100644 --- a/src/util/data.swig +++ b/src/util/data.swig @@ -17,14 +17,15 @@ #include #include "base/callback.h" #include "base/integral_types.h" +using std::string; %} #if defined(SWIGPYTHON) namespace operations_research { // ----- Callback Wrapping ----- %{ -static std::string PyCallbackString(PyObject* pyfunc) { - std::string result; +static string PyCallbackString(PyObject* pyfunc) { + string result; PyObject* arglist = Py_BuildValue("()"); PyObject* pyresult = PyEval_CallObject(pyfunc, arglist); Py_DECREF(arglist); @@ -36,7 +37,7 @@ static std::string PyCallbackString(PyObject* pyfunc) { } %} -%typemap(in) ResultCallback* { +%typemap(in) ResultCallback* { if (!PyCallable_Check($input)) { PyErr_SetString(PyExc_TypeError, "Need a callable object!"); SWIG_fail; diff --git a/src/util/fp_utils.h b/src/util/fp_utils.h index 943b1521b5..fdf3918827 100644 --- a/src/util/fp_utils.h +++ b/src/util/fp_utils.h @@ -51,7 +51,7 @@ namespace operations_research { // being modified. This can be used to avoid wrong over-optimizations by gcc. // See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47617 for an explanation. #ifdef NDEBUG -#define TOUCH(var) asm("":"+X"(var)) +#define TOUCH(var) asm("" : "+X"(var)) #else #define TOUCH(var) #endif @@ -78,10 +78,10 @@ inline void SetFPPrecision(fpu_control_t precision) { #undef TOUCH -template +template inline bool IsPositiveOrNegativeInfinity(FloatType x) { - return x == std::numeric_limits::infinity() - || x == -std::numeric_limits::infinity(); + return x == std::numeric_limits::infinity() || + x == -std::numeric_limits::infinity(); } // Tests whether x and y are close to one another using absolute and relative @@ -91,10 +91,10 @@ inline bool IsPositiveOrNegativeInfinity(FloatType x) { // Returns true if |x - y| <= std::max(|x|, |y|) * r. (with r being the relative // tolerance.) // The cases for infinities are treated separately to avoid generating NaNs. -template bool AreWithinAbsoluteOrRelativeTolerances( - FloatType x, FloatType y, - FloatType relative_tolerance, - FloatType absolute_tolerance) { +template +bool AreWithinAbsoluteOrRelativeTolerances(FloatType x, FloatType y, + FloatType relative_tolerance, + FloatType absolute_tolerance) { DCHECK_LE(0.0, relative_tolerance); DCHECK_LE(0.0, absolute_tolerance); DCHECK_GT(1.0, relative_tolerance); @@ -112,9 +112,9 @@ template bool AreWithinAbsoluteOrRelativeTolerances( // Tests whether x and y are close to one another using an absolute tolerance. // Returns true if |x - y| <= a (with a being the absolute_tolerance). // The cases for infinities are treated separately to avoid generating NaNs. -template bool AreWithinAbsoluteTolerance( - FloatType x, FloatType y, - FloatType absolute_tolerance) { +template +bool AreWithinAbsoluteTolerance(FloatType x, FloatType y, + FloatType absolute_tolerance) { DCHECK_LE(0.0, absolute_tolerance); if (IsPositiveOrNegativeInfinity(x) || IsPositiveOrNegativeInfinity(y)) { return x == y; @@ -125,19 +125,18 @@ template bool AreWithinAbsoluteTolerance( // Handy alternatives to EXPECT_NEAR(), using relative and absolute tolerance // instead of relative tolerance only, and with a proper support for infinity. // TODO(user): investigate moving this to base/ or some other place. -#define EXPECT_COMPARABLE(expected, obtained, epsilon) \ - EXPECT_TRUE(operations_research::AreWithinAbsoluteOrRelativeTolerances( \ - expected, obtained, epsilon, epsilon)) \ - << obtained << " != expected value " << expected \ +#define EXPECT_COMPARABLE(expected, obtained, epsilon) \ + EXPECT_TRUE(operations_research::AreWithinAbsoluteOrRelativeTolerances( \ + expected, obtained, epsilon, epsilon)) \ + << obtained << " != expected value " << expected \ << " within epsilon = " << epsilon; -#define EXPECT_NOTCOMPARABLE(expected, obtained, epsilon) \ - EXPECT_FALSE(operations_research::AreWithinAbsoluteOrRelativeTolerances( \ - expected, obtained, epsilon, epsilon)) \ - << obtained << " == expected value " << expected \ +#define EXPECT_NOTCOMPARABLE(expected, obtained, epsilon) \ + EXPECT_FALSE(operations_research::AreWithinAbsoluteOrRelativeTolerances( \ + expected, obtained, epsilon, epsilon)) \ + << obtained << " == expected value " << expected \ << " within epsilon = " << epsilon; - } // namespace operations_research #endif // OR_TOOLS_UTIL_FP_UTILS_H_ diff --git a/src/util/graph_export.cc b/src/util/graph_export.cc index 8a3d7ba300..dc47cadbf5 100644 --- a/src/util/graph_export.cc +++ b/src/util/graph_export.cc @@ -30,13 +30,10 @@ class GraphSyntax { virtual ~GraphSyntax() {} // Node in the right syntax. - virtual std::string Node(const std::string& name, - const std::string& label, - const std::string& shape, - const std::string& color) = 0; + virtual std::string Node(const std::string& name, const std::string& label, + const std::string& shape, const std::string& color) = 0; // Adds one link in the generated graph. - virtual std::string Link(const std::string& source, - const std::string& destination, + virtual std::string Link(const std::string& source, const std::string& destination, const std::string& label) = 0; // File header. virtual std::string Header(const std::string& name) = 0; @@ -49,25 +46,17 @@ class DotSyntax : public GraphSyntax { public: virtual ~DotSyntax() {} - virtual std::string Node(const std::string& name, - const std::string& label, - const std::string& shape, - const std::string& color) { - return StringPrintf("%s [shape=%s label=\"%s\" color=%s]\n", - name.c_str(), - shape.c_str(), - label.c_str(), - color.c_str()); + virtual std::string Node(const std::string& name, const std::string& label, + const std::string& shape, const std::string& color) { + return StringPrintf("%s [shape=%s label=\"%s\" color=%s]\n", name.c_str(), + shape.c_str(), label.c_str(), color.c_str()); } // Adds one link in the generated graph. - virtual std::string Link(const std::string& source, - const std::string& destination, + virtual std::string Link(const std::string& source, const std::string& destination, const std::string& label) { - return StringPrintf("%s -> %s [label=%s]\n", - source.c_str(), - destination.c_str(), - label.c_str()); + return StringPrintf("%s -> %s [label=%s]\n", source.c_str(), + destination.c_str(), label.c_str()); } // File header. @@ -76,58 +65,49 @@ class DotSyntax : public GraphSyntax { } // File footer. - virtual std::string Footer() { - return "}\n"; - } + virtual std::string Footer() { return "}\n"; } }; class GmlSyntax : public GraphSyntax { public: virtual ~GmlSyntax() {} - virtual std::string Node(const std::string& name, - const std::string& label, - const std::string& shape, - const std::string& color) { - return StringPrintf(" node [\n" - " name \"%s\"\n" - " label \"%s\"\n" - " graphics [\n" - " type \"%s\"\n" - " fill \"%s\"\n" - " ]\n" - " ]\n", - name.c_str(), - label.c_str(), - shape.c_str(), - color.c_str()); + virtual std::string Node(const std::string& name, const std::string& label, + const std::string& shape, const std::string& color) { + return StringPrintf( + " node [\n" + " name \"%s\"\n" + " label \"%s\"\n" + " graphics [\n" + " type \"%s\"\n" + " fill \"%s\"\n" + " ]\n" + " ]\n", + name.c_str(), label.c_str(), shape.c_str(), color.c_str()); } // Adds one link in the generated graph. - virtual std::string Link(const std::string& source, - const std::string& destination, + virtual std::string Link(const std::string& source, const std::string& destination, const std::string& label) { - return StringPrintf(" edge [\n" - " label \"%s\"\n" - " source \"%s\"\n" - " target \"%s\"\n" - " ]\n", - label.c_str(), - source.c_str(), - destination.c_str()); + return StringPrintf( + " edge [\n" + " label \"%s\"\n" + " source \"%s\"\n" + " target \"%s\"\n" + " ]\n", + label.c_str(), source.c_str(), destination.c_str()); } // File header. virtual std::string Header(const std::string& name) { - return StringPrintf("graph [\n" - " name \"%s\"\n" - , name.c_str()); + return StringPrintf( + "graph [\n" + " name \"%s\"\n", + name.c_str()); } // File footer. - virtual std::string Footer() { - return "]\n"; - } + virtual std::string Footer() { return "]\n"; } }; // Graph exporter that will write to a file with a given format. @@ -140,16 +120,13 @@ class FileGraphExporter : public GraphExporter { virtual ~FileGraphExporter() {} // Write node in GML or DOT format. - virtual void WriteNode(const std::string& name, - const std::string& label, - const std::string& shape, - const std::string& color) { + virtual void WriteNode(const std::string& name, const std::string& label, + const std::string& shape, const std::string& color) { Append(syntax_->Node(name, label, shape, color)); } // Adds one link in the generated graph. - virtual void WriteLink(const std::string& source, - const std::string& destination, + virtual void WriteLink(const std::string& source, const std::string& destination, const std::string& label) { Append(syntax_->Link(source, destination, label)); } @@ -158,14 +135,10 @@ class FileGraphExporter : public GraphExporter { Append(syntax_->Header(name)); } - virtual void WriteFooter() { - Append(syntax_->Footer()); - } + virtual void WriteFooter() { Append(syntax_->Footer()); } private: - void Append(const std::string& str) { - file_->Write(str.c_str(), str.size()); - } + void Append(const std::string& str) { file_->Write(str.c_str(), str.size()); } File* const file_; std::unique_ptr syntax_; @@ -173,8 +146,7 @@ class FileGraphExporter : public GraphExporter { } // namespace GraphExporter* GraphExporter::MakeFileExporter( - File* const file, - GraphExporter::GraphFormat format) { + File* const file, GraphExporter::GraphFormat format) { GraphSyntax* syntax = NULL; switch (format) { case GraphExporter::DOT_FORMAT: { diff --git a/src/util/graph_export.h b/src/util/graph_export.h index 0017b21376..26d371b166 100644 --- a/src/util/graph_export.h +++ b/src/util/graph_export.h @@ -20,7 +20,6 @@ #include "base/macros.h" #include "base/file.h" - namespace operations_research { // ----- Export to graph file ----- @@ -43,14 +42,11 @@ class GraphExporter { virtual void WriteFooter() = 0; // Write node in GML or DOT format. - virtual void WriteNode(const std::string& name, - const std::string& label, - const std::string& shape, - const std::string& color) = 0; + virtual void WriteNode(const std::string& name, const std::string& label, + const std::string& shape, const std::string& color) = 0; // Adds one link in the generated graph. - virtual void WriteLink(const std::string& source, - const std::string& destination, + virtual void WriteLink(const std::string& source, const std::string& destination, const std::string& label) = 0; // Creates a graph exporter that will write to file with a given format. diff --git a/src/util/iterators.h b/src/util/iterators.h index bd10e3a274..77373e9e31 100644 --- a/src/util/iterators.h +++ b/src/util/iterators.h @@ -29,12 +29,13 @@ namespace operations_research { // // And a client will use it like this: // for (const ArcIndex arc : graph.OutgoingArcs(node)) { ... } -template +template class BeginEndWrapper { public: BeginEndWrapper(Iterator begin, Iterator end) : begin_(begin), end_(end) {} Iterator begin() const { return begin_; } Iterator end() const { return end_; } + private: const Iterator begin_; const Iterator end_; @@ -44,26 +45,25 @@ class BeginEndWrapper { // for loop over a container that support STL reverse iterators. // The syntax is: // for (const type& t : Reverse(container_of_t)) { ... } -template +template class BeginEndReverseIteratorWrapper { public: explicit BeginEndReverseIteratorWrapper(const Container& c) : c_(c) {} typename Container::const_reverse_iterator begin() const { - return c_.rbegin(); - } - typename Container::const_reverse_iterator end() const { - return c_.rend(); + return c_.rbegin(); } + typename Container::const_reverse_iterator end() const { return c_.rend(); } + private: const Container& c_; }; -template +template BeginEndReverseIteratorWrapper Reverse(const Container& c) { return BeginEndReverseIteratorWrapper(c); } // Simple iterator on an integer range, see IntegerRange below. -template +template class IntegerRangeIterator { public: explicit IntegerRangeIterator(IntegerType value) : index_(value) {} @@ -72,12 +72,9 @@ class IntegerRangeIterator { // loop if one use IntegerRange(1, 0) below for instance. return index_ < other.index_; } - IntegerType operator*() const { - return index_; - } - void operator++() { - ++index_; - } + IntegerType operator*() const { return index_; } + void operator++() { ++index_; } + private: IntegerType index_; }; @@ -92,13 +89,13 @@ class IntegerRangeIterator { // for (const ArcIndex arc : graph.AllOutgoingArcs()); // for (const NodeIndex node : graph.AllNodes()); // for (const EntryIndex i : sparse_column.AllEntryIndex()); -template +template class IntegerRange : public BeginEndWrapper> { public: IntegerRange(IntegerType begin, IntegerType end) - : BeginEndWrapper> ( - IntegerRangeIterator(begin), - IntegerRangeIterator(end)) {} + : BeginEndWrapper>( + IntegerRangeIterator(begin), + IntegerRangeIterator(end)) {} }; } // namespace operations_research diff --git a/src/util/monoid_operation_tree.h b/src/util/monoid_operation_tree.h index a955bb9ac3..d6b010eb62 100644 --- a/src/util/monoid_operation_tree.h +++ b/src/util/monoid_operation_tree.h @@ -53,7 +53,7 @@ namespace operations_research { // result is independent of the order of past numerical issues // * Maintain a product of identically sized square matrices, which is an // example of use with non-commutative operations. -template +template class MonoidOperationTree { public: // Constructs a MonoidOperationTree able to store 'size' operands. @@ -132,7 +132,7 @@ class MonoidOperationTree { std::vector nodes_; // A pointer to the root node - T const * result_; + T const* result_; DISALLOW_COPY_AND_ASSIGN(MonoidOperationTree); }; @@ -141,7 +141,7 @@ class MonoidOperationTree { // Implementation // --------------------------------------------------------------------- // -template +template int MonoidOperationTree::ComputeLeafOffset(int size) { int smallest_pow_two_not_less_than_size = 1; while (smallest_pow_two_not_less_than_size < size) { @@ -150,37 +150,36 @@ int MonoidOperationTree::ComputeLeafOffset(int size) { return std::max(1, smallest_pow_two_not_less_than_size - 1); } -template +template int MonoidOperationTree::ComputeNumberOfNodes(int leaf_offset) { // leaf_offset should be a power of 2 minus 1. - DCHECK_EQ(0, (leaf_offset) & (leaf_offset+1)); + DCHECK_EQ(0, (leaf_offset) & (leaf_offset + 1)); const int num_leaves = leaf_offset + 1; const int num_nodes = leaf_offset + num_leaves; DCHECK_GE(num_nodes, 3); // We need at least the root and its 2 children return num_nodes; } -template +template MonoidOperationTree::MonoidOperationTree(int size) - : size_(size), - leaf_offset_(ComputeLeafOffset(size)), - num_nodes_(ComputeNumberOfNodes(leaf_offset_)), - nodes_(num_nodes_, T()), - result_(&(nodes_[0])) { -} + : size_(size), + leaf_offset_(ComputeLeafOffset(size)), + num_nodes_(ComputeNumberOfNodes(leaf_offset_)), + nodes_(num_nodes_, T()), + result_(&(nodes_[0])) {} -template +template void MonoidOperationTree::Clear() { const int size = nodes_.size(); nodes_.assign(size, T()); } -template +template void MonoidOperationTree::Reset(int argument_index) { Set(argument_index, T()); } -template +template void MonoidOperationTree::Set(int argument_index, const T& argument) { CHECK_LT(argument_index, size_); const int position = leaf_offset_ + argument_index; @@ -188,7 +187,7 @@ void MonoidOperationTree::Set(int argument_index, const T& argument) { ComputeAbove(position); } -template +template void MonoidOperationTree::ComputeAbove(int position) { int pos = father(position); while (pos > 0) { @@ -198,19 +197,19 @@ void MonoidOperationTree::ComputeAbove(int position) { Compute(0); } -template +template void MonoidOperationTree::Compute(int position) { const T& left_child = nodes_[left(position)]; const T& right_child = nodes_[right(position)]; nodes_[position].Compute(left_child, right_child); } -template +template std::string MonoidOperationTree::DebugString() const { std::string out; int layer = 0; for (int i = 0; i < num_nodes_; ++i) { - if (((i+1) & i) == 0) { + if (((i + 1) & i) == 0) { // New layer StringAppendF(&out, "-------------- Layer %d ---------------\n", layer); ++layer; diff --git a/src/util/permutation.h b/src/util/permutation.h index 9fa9dfb890..a7c366f4a4 100644 --- a/src/util/permutation.h +++ b/src/util/permutation.h @@ -89,7 +89,8 @@ namespace operations_research { // Abstract base class template defining the interface needed by // PermutationApplier to handle a single cycle of a permutation. -template class PermutationCycleHandler { +template +class PermutationCycleHandler { public: // Sets the internal temporary storage from the given index in the // underlying container(s). @@ -127,10 +128,10 @@ template class PermutationCycleHandler { return false; } - virtual ~PermutationCycleHandler() { } + virtual ~PermutationCycleHandler() {} protected: - PermutationCycleHandler() { } + PermutationCycleHandler() {} private: DISALLOW_COPY_AND_ASSIGN(PermutationCycleHandler); @@ -141,14 +142,12 @@ template class PermutationCycleHandler { // permutation is represented by a mutable array of nonnegative // int-typed index values. To mark a permutation element as seen, we // replace it by its ones-complement value. -template class ArrayIndexCycleHandler - : public PermutationCycleHandler { +template +class ArrayIndexCycleHandler : public PermutationCycleHandler { public: - explicit ArrayIndexCycleHandler(DataType* data) : data_(data) { } + explicit ArrayIndexCycleHandler(DataType* data) : data_(data) {} - virtual void SetTempFromIndex(IndexType source) { - temp_ = data_[source]; - } + virtual void SetTempFromIndex(IndexType source) { temp_ = data_[source]; } virtual void SetIndexFromIndex(IndexType source, IndexType destination) const { data_[destination] = data_[source]; @@ -156,7 +155,7 @@ template class ArrayIndexCycleHandler virtual void SetIndexFromTemp(IndexType destination) const { data_[destination] = temp_; } - virtual void SetSeen(IndexType *permutation_element) const { + virtual void SetSeen(IndexType* permutation_element) const { *permutation_element = -*permutation_element - 1; } virtual bool Unseen(IndexType permutation_element) const { @@ -176,17 +175,15 @@ template class ArrayIndexCycleHandler // Note that this template is not implemented in an especially // performance-sensitive way. In particular, it makes multiple virtual // method calls for each element of the permutation. -template class PermutationApplier { +template +class PermutationApplier { public: - explicit PermutationApplier( - PermutationCycleHandler* cycle_handler) - : cycle_handler_(cycle_handler) { } + explicit PermutationApplier(PermutationCycleHandler* cycle_handler) + : cycle_handler_(cycle_handler) {} - void Apply(IndexType permutation[], - int permutation_start, + void Apply(IndexType permutation[], int permutation_start, int permutation_end) { - for (IndexType current = permutation_start; - current < permutation_end; + for (IndexType current = permutation_start; current < permutation_end; ++current) { IndexType next = permutation[current]; // cycle_start is only for debugging. diff --git a/src/util/piecewise_linear_function.cc b/src/util/piecewise_linear_function.cc index 9fb14e018c..2ae1850382 100644 --- a/src/util/piecewise_linear_function.cc +++ b/src/util/piecewise_linear_function.cc @@ -35,13 +35,12 @@ int FindSegmentIndex(const std::vector& segments, int64 x) { // Returns an iterator pointing to the first segment whose the x coordinate // of its start point which compares greater than the x value. - std::vector::const_iterator position = - std::upper_bound(segments.begin(), segments.end(), x, - PiecewiseSegment::FindComparator); + std::vector::const_iterator position = std::upper_bound( + segments.begin(), segments.end(), x, PiecewiseSegment::FindComparator); position -= position->start_x() > x ? 1 : 0; - return position == segments.end() ? segments.size() - 1 : - position - segments.begin(); + return position == segments.end() ? segments.size() - 1 + : position - segments.begin(); } inline bool IsAtBounds(int64 value) { @@ -56,8 +55,7 @@ inline bool PointInsideRange(int64 point, int64 range_start, int64 range_end) { // the slope of the right is bigger than the slope of the left. inline bool FormConvexPair(const PiecewiseSegment& left, const PiecewiseSegment& right) { - return right.slope() >= left.slope() && - right.start_x() == left.end_x() && + return right.slope() >= left.slope() && right.start_x() == left.end_x() && right.start_y() == left.end_y(); } @@ -72,13 +70,13 @@ uint64 UnsignedCapProd(uint64 left, uint64 right) { } } // namespace -PiecewiseSegment::PiecewiseSegment(int64 point_x, int64 point_y, int64 slope, +PiecewiseSegment::PiecewiseSegment(int64 point_x, int64 point_y, int64 slope, int64 other_point_x) - : slope_(slope), reference_x_(point_x), reference_y_(point_y) { + : slope_(slope), reference_x_(point_x), reference_y_(point_y) { start_x_ = std::min(point_x, other_point_x); end_x_ = std::max(point_x, other_point_x); - intersection_y_ = reference_x_ < 0 ? SafeValuePostReference(0) - : SafeValuePreReference(0); + intersection_y_ = + reference_x_ < 0 ? SafeValuePostReference(0) : SafeValuePreReference(0); } int64 PiecewiseSegment::Value(int64 x) const { @@ -136,32 +134,35 @@ int64 PiecewiseSegment::SafeValuePostReference(int64 x) const { } else { const uint64 opp_reference_y = static_cast(-reference_y_); if (span_y >= opp_reference_y) { - return span_y - opp_reference_y > kint64max ? - kint64max : static_cast(span_y - opp_reference_y); + return span_y - opp_reference_y > kint64max + ? kint64max + : static_cast(span_y - opp_reference_y); } else { - return opp_reference_y - span_y > static_cast(kint64max) + 1 ? - kint64min : -static_cast(opp_reference_y - span_y); + return opp_reference_y - span_y > static_cast(kint64max) + 1 + ? kint64min + : -static_cast(opp_reference_y - span_y); } } } else { // Negative slope segment. const uint64 span_y = UnsignedCapProd(span_x, -slope_); if (reference_y_ == 0) { - return span_y > kint64max ? kint64min - : -static_cast(span_y); + return span_y > kint64max ? kint64min : -static_cast(span_y); } else if (reference_y_ < 0) { const uint64 opp_reference_y = static_cast(-reference_y_); - const uint64 opp_unsigned_sum = UnsignedCapAdd(opp_reference_y, - span_y); + const uint64 opp_unsigned_sum = UnsignedCapAdd(opp_reference_y, span_y); return opp_unsigned_sum > kint64max - ? kint64min : -static_cast(opp_unsigned_sum); + ? kint64min + : -static_cast(opp_unsigned_sum); } else { if (reference_y_ >= span_y) { - return reference_y_ - span_y > kint64max ? - kint64max : static_cast(reference_y_ - span_y); + return reference_y_ - span_y > kint64max + ? kint64max + : static_cast(reference_y_ - span_y); } else { - return span_y - reference_y_ > static_cast(kint64max) + 1 ? - kint64min : -static_cast(span_y - reference_y_); + return span_y - reference_y_ > static_cast(kint64max) + 1 + ? kint64min + : -static_cast(span_y - reference_y_); } } } @@ -177,23 +178,23 @@ int64 PiecewiseSegment::SafeValuePreReference(int64 x) const { // Positive slope segment. const uint64 span_y = UnsignedCapProd(span_x, slope_); if (reference_y_ == 0) { - return span_y > kint64max ? kint64min - : -static_cast(span_y); + return span_y > kint64max ? kint64min : -static_cast(span_y); } else if (reference_y_ > 0) { if (reference_y_ >= span_y) { - return reference_y_ - span_y > kint64max ? - kint64max : - static_cast(reference_y_ - span_y); + return reference_y_ - span_y > kint64max + ? kint64max + : static_cast(reference_y_ - span_y); } else { - return span_y - reference_y_ > static_cast(kint64max) + 1 ? - kint64min : -static_cast(span_y - reference_y_); + return span_y - reference_y_ > static_cast(kint64max) + 1 + ? kint64min + : -static_cast(span_y - reference_y_); } } else { const uint64 opp_reference_y = static_cast(-reference_y_); - const uint64 opp_unsigned_sum = UnsignedCapAdd(opp_reference_y, - span_y); + const uint64 opp_unsigned_sum = UnsignedCapAdd(opp_reference_y, span_y); return opp_unsigned_sum > kint64max - ? kint64min : -static_cast(opp_unsigned_sum); + ? kint64min + : -static_cast(opp_unsigned_sum); } } else { // Negative slope segment. @@ -203,14 +204,14 @@ int64 PiecewiseSegment::SafeValuePreReference(int64 x) const { } else if (reference_y_ < 0) { const uint64 opp_reference_y = static_cast(-reference_y_); if (span_y >= opp_reference_y) { - return span_y - opp_reference_y > kint64max ? - kint64max : - static_cast(span_y - opp_reference_y); - } else { - return opp_reference_y - span_y > static_cast(kint64max) + 1 ? - kint64min : - -static_cast(opp_reference_y - span_y); - } + return span_y - opp_reference_y > kint64max + ? kint64max + : static_cast(span_y - opp_reference_y); + } else { + return opp_reference_y - span_y > static_cast(kint64max) + 1 + ? kint64min + : -static_cast(opp_reference_y - span_y); + } } else { const uint64 unsigned_sum = UnsignedCapAdd(reference_y_, span_y); return unsigned_sum > kint64max ? kint64max @@ -220,7 +221,7 @@ int64 PiecewiseSegment::SafeValuePreReference(int64 x) const { } bool PiecewiseSegment::SortComparator(const PiecewiseSegment& segment1, - const PiecewiseSegment& segment2) { + const PiecewiseSegment& segment2) { return segment1.start_x_ < segment2.start_x_; } @@ -229,9 +230,7 @@ bool PiecewiseSegment::FindComparator(int64 point, return point == kint64min || point < segment.start_x(); } -void PiecewiseSegment::ExpandEnd(int64 end_x) { - end_x_ = std::max(end_x_, end_x); -} +void PiecewiseSegment::ExpandEnd(int64 end_x) { end_x_ = std::max(end_x_, end_x); } void PiecewiseSegment::AddConstantToX(int64 constant) { if (IsAtBounds(CapAdd(reference_x_, constant))) { @@ -252,30 +251,32 @@ void PiecewiseSegment::AddConstantToY(int64 constant) { } std::string PiecewiseSegment::DebugString() const { - std::string result = StringPrintf( - "PiecewiseSegment()", - start_x_, Value(start_x_), end_x_, Value(end_x_), - reference_x_, reference_y_, slope_); + std::string result = StringPrintf("PiecewiseSegment()", + start_x_, Value(start_x_), end_x_, Value(end_x_), + reference_x_, reference_y_, slope_); return result; } const int PiecewiseLinearFunction::kNotFound = -1; PiecewiseLinearFunction::PiecewiseLinearFunction( - std::vector* segments) { + std::vector* segments) { CHECK_NOTNULL(segments); // Sort the segments in ascending order of start. std::sort(segments->begin(), segments->end(), PiecewiseSegment::SortComparator); // Check for overlapping segments. for (int i = 0; i < segments->size() - 1; ++i) { - if (segments->at(i).end_x() > segments->at(i+1).start_x()) { - LOG(FATAL) << "Overlapping segments: " - << segments->at(i).DebugString() << " & " - << segments->at(i+1).DebugString(); + if (segments->at(i).end_x() > segments->at(i + 1).start_x()) { + LOG(FATAL) << "Overlapping segments: " << segments->at(i).DebugString() + << " & " << segments->at(i + 1).DebugString(); } } // Construct the piecewise linear function. @@ -285,8 +286,8 @@ PiecewiseLinearFunction::PiecewiseLinearFunction( } PiecewiseLinearFunction* PiecewiseLinearFunction::CreatePiecewiseLinearFunction( - std::vector points_x, std::vector points_y, - std::vector slopes, std::vector other_points_x) { + std::vector points_x, std::vector points_y, std::vector slopes, + std::vector other_points_x) { CHECK_EQ(points_x.size(), points_y.size()); CHECK_EQ(points_x.size(), other_points_x.size()); CHECK_EQ(points_x.size(), slopes.size()); @@ -294,8 +295,8 @@ PiecewiseLinearFunction* PiecewiseLinearFunction::CreatePiecewiseLinearFunction( std::vector segments; for (int i = 0; i < points_x.size(); ++i) { - segments.push_back(PiecewiseSegment(points_x[i], points_y[i], - slopes[i], other_points_x[i])); + segments.push_back(PiecewiseSegment(points_x[i], points_y[i], slopes[i], + other_points_x[i])); } return new PiecewiseLinearFunction(&segments); @@ -310,8 +311,8 @@ PiecewiseLinearFunction* PiecewiseLinearFunction::CreateStepFunction( std::vector segments; for (int i = 0; i < points_x.size(); ++i) { - segments.push_back(PiecewiseSegment(points_x[i], points_y[i], - 0, other_points_x[i])); + segments.push_back( + PiecewiseSegment(points_x[i], points_y[i], 0, other_points_x[i])); } return new PiecewiseLinearFunction(&segments); @@ -324,18 +325,18 @@ PiecewiseLinearFunction* PiecewiseLinearFunction::CreateFullDomainFunction( int64 level = initial_level; std::vector segments; - PiecewiseSegment segment = PiecewiseSegment(points_x[0], level, - slopes[0], kint64min); + PiecewiseSegment segment = + PiecewiseSegment(points_x[0], level, slopes[0], kint64min); segments.push_back(segment); level = segment.Value(points_x[0]); for (int i = 1; i < points_x.size(); ++i) { - PiecewiseSegment segment = PiecewiseSegment(points_x[i-1], level, - slopes[i], points_x[i]); + PiecewiseSegment segment = + PiecewiseSegment(points_x[i - 1], level, slopes[i], points_x[i]); segments.push_back(segment); level = segment.Value(points_x[i]); } - segments.push_back(PiecewiseSegment(points_x.back(), level, - slopes.back(), kint64max)); + segments.push_back( + PiecewiseSegment(points_x.back(), level, slopes.back(), kint64max)); return new PiecewiseLinearFunction(&segments); } @@ -380,27 +381,26 @@ PiecewiseLinearFunction* PiecewiseLinearFunction::CreateEarlyTardyFunction( std::vector segments; CHECK_GE(earliness_slope, 0); CHECK_GE(tardiness_slope, 0); - segments.push_back(PiecewiseSegment(reference, 0, -earliness_slope, - kint64min)); - segments.push_back(PiecewiseSegment(reference, 0, tardiness_slope, - kint64max)); + segments.push_back( + PiecewiseSegment(reference, 0, -earliness_slope, kint64min)); + segments.push_back( + PiecewiseSegment(reference, 0, tardiness_slope, kint64max)); return new PiecewiseLinearFunction(&segments); } PiecewiseLinearFunction* - PiecewiseLinearFunction::CreateEarlyTardyFunctionWithSlack( - int64 early_slack, int64 late_slack, - int64 earliness_slope, int64 tardiness_slope) { +PiecewiseLinearFunction::CreateEarlyTardyFunctionWithSlack( + int64 early_slack, int64 late_slack, int64 earliness_slope, + int64 tardiness_slope) { std::vector segments; CHECK_GE(earliness_slope, 0); CHECK_GE(tardiness_slope, 0); - segments.push_back(PiecewiseSegment(early_slack, 0, - -earliness_slope, kint64min)); - segments.push_back(PiecewiseSegment(early_slack, 0, - 0, late_slack)); - segments.push_back(PiecewiseSegment(late_slack, 0, - tardiness_slope, kint64max)); + segments.push_back( + PiecewiseSegment(early_slack, 0, -earliness_slope, kint64min)); + segments.push_back(PiecewiseSegment(early_slack, 0, 0, late_slack)); + segments.push_back( + PiecewiseSegment(late_slack, 0, tardiness_slope, kint64max)); return new PiecewiseLinearFunction(&segments); } @@ -418,7 +418,7 @@ bool PiecewiseLinearFunction::InDomain(int64 x) const { bool PiecewiseLinearFunction::IsConvex() const { for (int i = 1; i < segments_.size(); ++i) { - if (!FormConvexPair(segments_[i-1], segments_[i])) { + if (!FormConvexPair(segments_[i - 1], segments_[i])) { return false; } } @@ -454,10 +454,10 @@ int64 PiecewiseLinearFunction::GetMaximum(int64 range_start, int64 range_maximum = kint64min; if (InDomain(range_start)) { - range_maximum = std::max(Value(range_start), range_maximum); + range_maximum = std::max(Value(range_start), range_maximum); } if (InDomain(range_end)) { - range_maximum = std::max(Value(range_end), range_maximum); + range_maximum = std::max(Value(range_end), range_maximum); } for (int i = std::max(0, start_segment); i <= end_segment; ++i) { @@ -490,10 +490,10 @@ int64 PiecewiseLinearFunction::GetMinimum(int64 range_start, int64 range_minimum = kint64max; if (InDomain(range_start)) { - range_minimum = std::min(Value(range_start), range_minimum); + range_minimum = std::min(Value(range_start), range_minimum); } if (InDomain(range_end)) { - range_minimum = std::min(Value(range_end), range_minimum); + range_minimum = std::min(Value(range_end), range_minimum); } for (int i = std::max(0, start_segment); i <= end_segment; ++i) { @@ -508,13 +508,11 @@ int64 PiecewiseLinearFunction::GetMinimum(int64 range_start, } int64 PiecewiseLinearFunction::GetMaximum() const { - return GetMaximum(segments_.front().start_x(), - segments_.back().end_x()); + return GetMaximum(segments_.front().start_x(), segments_.back().end_x()); } int64 PiecewiseLinearFunction::GetMinimum() const { - return GetMinimum(segments_.front().start_x(), - segments_.back().end_x()); + return GetMinimum(segments_.front().start_x(), segments_.back().end_x()); } void PiecewiseLinearFunction::AddConstantToX(int64 constant) { @@ -531,25 +529,24 @@ void PiecewiseLinearFunction::AddConstantToY(int64 constant) { void PiecewiseLinearFunction::Add(const PiecewiseLinearFunction& other) { std::unique_ptr > add( - NewPermanentCallback(&CapAdd)); + NewPermanentCallback(&CapAdd)); Operation(other, add.get()); } void PiecewiseLinearFunction::Subtract(const PiecewiseLinearFunction& other) { std::unique_ptr > subtract( - NewPermanentCallback(&CapSub)); + NewPermanentCallback(&CapSub)); Operation(other, subtract.get()); } void PiecewiseLinearFunction::DecomposeToConvexFunctions( - std::vector* convex_functions) { + std::vector* convex_functions) { CHECK_NOTNULL(convex_functions); CHECK_GE(segments_.size(), 1); if (IsConvex()) { std::vector convex_segments(segments_); - convex_functions->push_back( - new PiecewiseLinearFunction(&convex_segments)); + convex_functions->push_back(new PiecewiseLinearFunction(&convex_segments)); return; } @@ -570,7 +567,7 @@ void PiecewiseLinearFunction::DecomposeToConvexFunctions( convex_segments.push_back(segment); } else { PiecewiseLinearFunction* function( - new PiecewiseLinearFunction(&convex_segments)); + new PiecewiseLinearFunction(&convex_segments)); convex_functions->push_back(function); convex_segments.clear(); convex_segments.push_back(segment); @@ -603,7 +600,7 @@ void PiecewiseLinearFunction::InsertSegment(const PiecewiseSegment& segment) { // Common endpoint. if (segments_.back().end_x() == segment.start_x()) { if (segments_.back().end_y() == segment.start_y() && - segments_.back().slope() == segment.slope()) { + segments_.back().slope() == segment.slope()) { segments_.back().ExpandEnd(segment.end_x()); return; } @@ -636,10 +633,10 @@ void PiecewiseLinearFunction::Operation( const int64 end_x = std::min(own_segment.end_x(), other_segment.end_x()); const int64 start_y = operation->Run(own_segment.Value(start_x), other_segment.Value(start_x)); - const int64 end_y = operation->Run(own_segment.Value(end_x), - other_segment.Value(end_x)); - const int64 slope = operation->Run(own_segment.slope(), - other_segment.slope()); + const int64 end_y = + operation->Run(own_segment.Value(end_x), other_segment.Value(end_x)); + const int64 slope = + operation->Run(own_segment.slope(), other_segment.slope()); int64 point_x, point_y, other_point_x; if (IsAtBounds(start_y)) { diff --git a/src/util/piecewise_linear_function.h b/src/util/piecewise_linear_function.h index 7db5101cf5..032a1be7e7 100644 --- a/src/util/piecewise_linear_function.h +++ b/src/util/piecewise_linear_function.h @@ -30,7 +30,6 @@ #include "util/saturated_arithmetic.h" - namespace operations_research { // This structure stores one straight line. It contains the start point, the // end point and the slope. @@ -118,15 +117,15 @@ class PiecewiseLinearFunction { // The segments represented by these vectors should not be overlapping. // Common endpoints are allowed. static PiecewiseLinearFunction* CreatePiecewiseLinearFunction( - std::vector points_x, std::vector points_y, - std::vector slopes, std::vector other_points_x); + std::vector points_x, std::vector points_y, std::vector slopes, + std::vector other_points_x); // Builds a multiple-segment step function with continuous or non continuous // domain. The arguments have the same semantics with the generic builder of // the piecewise linear function. In the step function all the slopes are 0. static PiecewiseLinearFunction* CreateStepFunction( - std::vector points_x, std::vector points_y, - std::vector other_points_x); + std::vector points_x, std::vector points_y, + std::vector other_points_x); // Builds a multiple-segment piecewise linear function with domain from // from kint64min to kint64max with n points and n+1 slopes. Each slope @@ -134,28 +133,32 @@ class PiecewiseLinearFunction { // which stops at kint64max. The first slope stops at the first point at // the level specified. static PiecewiseLinearFunction* CreateFullDomainFunction( - int64 initial_level, std::vector points_x, std::vector slopes); + int64 initial_level, std::vector points_x, std::vector slopes); // Builds a function consisting of one segment. - static PiecewiseLinearFunction* CreateOneSegmentFunction( - int64 point_x, int64 point_y, int64 slope, int64 other_point_x); + static PiecewiseLinearFunction* CreateOneSegmentFunction(int64 point_x, + int64 point_y, + int64 slope, + int64 other_point_x); // Builds a function consisting of one ray starting at the specified // x and y coordinates with the specified slope. - static PiecewiseLinearFunction* CreateRightRayFunction( - int64 point_x, int64 point_y, int64 slope); + static PiecewiseLinearFunction* CreateRightRayFunction(int64 point_x, + int64 point_y, + int64 slope); // Builds a function consisting of one ray starting at the specified // x and y coordinates with the specified slope. - static PiecewiseLinearFunction* CreateLeftRayFunction( - int64 point_x, int64 point_y, int64 slope); + static PiecewiseLinearFunction* CreateLeftRayFunction(int64 point_x, + int64 point_y, + int64 slope); // Builds a two-segment fixed charge piecewise linear cost function. For // values less than zero, the cost is zero. For values greater than zero, // cost follows the line specified by the slope and the value given as // arguments. The slope and value are positive. - static PiecewiseLinearFunction* CreateFixedChargeFunction( - int64 slope, int64 value); + static PiecewiseLinearFunction* CreateFixedChargeFunction(int64 slope, + int64 value); // Builds an earliness-tardiness two-segment piecewise linear cost function. // The reference specifies the point where the cost is zero. Before the @@ -163,7 +166,7 @@ class PiecewiseLinearFunction { // referece, it increases with the tardiness slope. The absolute values of // the slopes are given. static PiecewiseLinearFunction* CreateEarlyTardyFunction( - int64 reference, int64 earliness_slope, int64 tardiness_slope); + int64 reference, int64 earliness_slope, int64 tardiness_slope); // Builds an earliness-tardiness three-segment piecewise linear cost function // with a slack period around the due date. The early slack is the point @@ -172,8 +175,8 @@ class PiecewiseLinearFunction { // specified. Between the early and the late slack point, the cost is zero. // The absolute values of the slopes are given. static PiecewiseLinearFunction* CreateEarlyTardyFunctionWithSlack( - int64 early_slack, int64 late_slack, - int64 earliness_slope, int64 tardiness_slope); + int64 early_slack, int64 late_slack, int64 earliness_slope, + int64 tardiness_slope); // Returns if x is in the domain of the function. bool InDomain(int64 x) const; @@ -213,8 +216,7 @@ class PiecewiseLinearFunction { void Subtract(const PiecewiseLinearFunction& function); // Decomposes the piecewise linear function in a set of convex piecewise // linear functions. The objects in the vector are owned by the client code. - void DecomposeToConvexFunctions( - std::vector* convex_set); + void DecomposeToConvexFunctions(std::vector* convex_set); const std::vector& segments() const { return segments_; } diff --git a/src/util/stats.cc b/src/util/stats.cc index ead62b46c6..14a33ae060 100644 --- a/src/util/stats.cc +++ b/src/util/stats.cc @@ -21,26 +21,26 @@ namespace operations_research { std::string MemoryUsage() { -static const int64 kDisplayThreshold = 2; - static const int64 kKiloByte = 1024; - static const int64 kMegaByte = kKiloByte * kKiloByte; - static const int64 kGigaByte = kMegaByte * kKiloByte; - const int64 memory_usage = GetProcessMemoryUsage(); - if (memory_usage > kDisplayThreshold * kGigaByte) { - return StringPrintf("memory used = %.2lf GB", - memory_usage * 1.0 / kGigaByte); - } else if (memory_usage > kDisplayThreshold * kMegaByte) { - return StringPrintf("memory used = %.2lf MB", - memory_usage * 1.0 / kMegaByte); - } else if (memory_usage > kDisplayThreshold * kKiloByte) { - return StringPrintf("memory used = %2lf KB", - memory_usage * 1.0 / kKiloByte); - } else { - return StringPrintf("memory used = %" GG_LL_FORMAT "d", memory_usage); - } + static const int64 kDisplayThreshold = 2; + static const int64 kKiloByte = 1024; + static const int64 kMegaByte = kKiloByte * kKiloByte; + static const int64 kGigaByte = kMegaByte * kKiloByte; + const int64 memory_usage = GetProcessMemoryUsage(); + if (memory_usage > kDisplayThreshold * kGigaByte) { + return StringPrintf("memory used = %.2lf GB", + memory_usage * 1.0 / kGigaByte); + } else if (memory_usage > kDisplayThreshold * kMegaByte) { + return StringPrintf("memory used = %.2lf MB", + memory_usage * 1.0 / kMegaByte); + } else if (memory_usage > kDisplayThreshold * kKiloByte) { + return StringPrintf("memory used = %2lf KB", + memory_usage * 1.0 / kKiloByte); + } else { + return StringPrintf("memory used = %" GG_LL_FORMAT "d", memory_usage); + } } -Stat::Stat(const std::string& name, StatsGroup *group) : name_(name) { +Stat::Stat(const std::string& name, StatsGroup* group) : name_(name) { group->Register(this); } @@ -48,13 +48,9 @@ std::string Stat::StatString() const { return std::string(name_ + ": " + ValueAsString()); } -StatsGroup::~StatsGroup() { - STLDeleteValues(&time_distributions_); -} +StatsGroup::~StatsGroup() { STLDeleteValues(&time_distributions_); } -void StatsGroup::Register(Stat* stat) { - stats_.push_back(stat); -} +void StatsGroup::Register(Stat* stat) { stats_.push_back(stat); } void StatsGroup::Reset() { for (int i = 0; i < stats_.size(); ++i) { @@ -63,7 +59,7 @@ void StatsGroup::Reset() { } namespace { -bool CompareStatPointerByName(Stat* s1, Stat *s2) { +bool CompareStatPointerByName(Stat* s1, Stat* s2) { return s1->Name() < s2->Name(); } } // namespace @@ -89,15 +85,15 @@ std::string StatsGroup::StatString() const { for (int i = 0; i < sorted_stats.size(); ++i) { result += " "; result += sorted_stats[i]->Name(); - result.append(longest_name_size - sorted_stats[i]->Name().size() , ' '); + result.append(longest_name_size - sorted_stats[i]->Name().size(), ' '); result += " : " + sorted_stats[i]->ValueAsString(); } result += "}\n"; return result; } -TimeDistribution *StatsGroup::LookupOrCreateTimeDistribution(std::string name) { - TimeDistribution* &ref = time_distributions_[name]; +TimeDistribution* StatsGroup::LookupOrCreateTimeDistribution(std::string name) { + TimeDistribution*& ref = time_distributions_[name]; if (ref == NULL) { ref = new TimeDistribution(name); Register(ref); @@ -107,13 +103,21 @@ TimeDistribution *StatsGroup::LookupOrCreateTimeDistribution(std::string name) { DistributionStat::DistributionStat(const std::string& name) : Stat(name), - sum_(0.0), average_(0.0), sum_squares_from_average_(0.0), - min_(0.0), max_(0.0), num_(0) {} + sum_(0.0), + average_(0.0), + sum_squares_from_average_(0.0), + min_(0.0), + max_(0.0), + num_(0) {} DistributionStat::DistributionStat(const std::string& name, StatsGroup* group) : Stat(name, group), - sum_(0.0), average_(0.0), sum_squares_from_average_(0.0), - min_(0.0), max_(0.0), num_(0) {} + sum_(0.0), + average_(0.0), + sum_squares_from_average_(0.0), + min_(0.0), + max_(0.0), + num_(0) {} void DistributionStat::Reset() { sum_ = 0.0; @@ -142,9 +146,7 @@ void DistributionStat::AddToDistribution(double value) { sum_squares_from_average_ += delta * (value - average_); } -double DistributionStat::Average() const { - return average_; -} +double DistributionStat::Average() const { return average_; } double DistributionStat::StdDeviation() const { if (num_ == 0) return 0.0; @@ -181,11 +183,9 @@ void TimeDistribution::AddTimeInCycles(double cycles) { } std::string TimeDistribution::ValueAsString() const { - return StringPrintf("%8llu [%8s, %8s] %8s %8s %8s\n", - num_, - PrintCyclesAsTime(min_).c_str(), - PrintCyclesAsTime(max_).c_str(), - PrintCyclesAsTime(Average()).c_str(), + return StringPrintf( + "%8llu [%8s, %8s] %8s %8s %8s\n", num_, PrintCyclesAsTime(min_).c_str(), + PrintCyclesAsTime(max_).c_str(), PrintCyclesAsTime(Average()).c_str(), PrintCyclesAsTime(StdDeviation()).c_str(), PrintCyclesAsTime(sum_).c_str()); } @@ -196,25 +196,16 @@ void RatioDistribution::Add(double value) { } std::string RatioDistribution::ValueAsString() const { - return StringPrintf("%8llu [%7.2lf%%, %7.2lf%%] %7.2lf%% %7.2lf%%\n", - num_, - 100.0 * min_, - 100.0 * max_, - 100.0 * Average(), - 100.0 * StdDeviation()); + return StringPrintf("%8llu [%7.2lf%%, %7.2lf%%] %7.2lf%% %7.2lf%%\n", num_, + 100.0 * min_, 100.0 * max_, 100.0 * Average(), + 100.0 * StdDeviation()); } -void DoubleDistribution::Add(double value) { - AddToDistribution(value); -} +void DoubleDistribution::Add(double value) { AddToDistribution(value); } std::string DoubleDistribution::ValueAsString() const { - return StringPrintf("%8llu [%8.1e, %8.1e] %8.1e %8.1e\n", - num_, - min_, - max_ , - Average(), - StdDeviation()); + return StringPrintf("%8llu [%8.1e, %8.1e] %8.1e %8.1e\n", num_, min_, max_, + Average(), StdDeviation()); } void IntegerDistribution::Add(int64 value) { @@ -222,13 +213,8 @@ void IntegerDistribution::Add(int64 value) { } std::string IntegerDistribution::ValueAsString() const { - return StringPrintf("%8llu [%8.lf, %8.lf] %8.2lf %8.2lf %8.lf\n", - num_, - min_, - max_ , - Average(), - StdDeviation(), - sum_); + return StringPrintf("%8llu [%8.lf, %8.lf] %8.2lf %8.2lf %8.lf\n", num_, min_, + max_, Average(), StdDeviation(), sum_); } } // namespace operations_research diff --git a/src/util/stats.h b/src/util/stats.h index 46353b2b0e..bc7533b08b 100644 --- a/src/util/stats.h +++ b/src/util/stats.h @@ -73,7 +73,6 @@ #include "base/scoped_ptr.h" #include "base/timer.h" - namespace operations_research { // Returns the current thread's total memory usage in an human-readable std::string. @@ -89,7 +88,7 @@ class Stat { explicit Stat(const std::string& name) : name_(name) {} // Also add this stat to the given group. - Stat(const std::string& name, StatsGroup * group); + Stat(const std::string& name, StatsGroup* group); virtual ~Stat() {} // Only used for display purpose. @@ -130,7 +129,7 @@ class StatsGroup { // Returns and if needed creates and registers a TimeDistribution with the // given name. Note that this involve a map lookup and his thus slower than // directly accessing a TimeDistribution variable. - TimeDistribution *LookupOrCreateTimeDistribution(std::string name); + TimeDistribution* LookupOrCreateTimeDistribution(std::string name); // Calls Reset() on all the statistics registered with this group. void Reset(); @@ -138,7 +137,7 @@ class StatsGroup { private: std::string name_; std::vector stats_; - std::map time_distributions_; + std::map time_distributions_; DISALLOW_COPY_AND_ASSIGN(StatsGroup); }; @@ -211,9 +210,7 @@ class TimeDistribution : public DistributionStat { void AddTimeInCycles(double value); // Starts the timer in preparation of a StopTimerAndAddElapsedTime(). - inline void StartTimer() { - timer_.Restart(); - } + inline void StartTimer() { timer_.Restart(); } // Adds the elapsed time since the last StartTimer() to the distribution and // returns this time in cpu cycles. @@ -286,13 +283,11 @@ class ScopedTimeDistributionUpdater { // case TypeA : timer.AlsoUpdate(&typeA_timer); break; // case TypeB : timer.AlsoUpdate(&typeB_timer); break; // } - void AlsoUpdate(TimeDistribution* also_update) { - also_update_ = also_update; - } + void AlsoUpdate(TimeDistribution* also_update) { also_update_ = also_update; } private: - TimeDistribution *stat_; - TimeDistribution *also_update_; + TimeDistribution* stat_; + TimeDistribution* also_update_; DISALLOW_COPY_AND_ASSIGN(ScopedTimeDistributionUpdater); }; @@ -316,9 +311,9 @@ class ScopedTimeDistributionUpdater { // Note(user): This adds more extra overhead around the measured code compared // to defining your own TimeDistribution stat in your StatsGroup. About 80ns // per measurement compared to about 20ns (as of 2012-06, on my workstation). -#define SCOPED_TIME_STAT(stats) \ - operations_research::ScopedTimeDistributionUpdater \ - scoped_time_stat((stats)->LookupOrCreateTimeDistribution(__FUNCTION__)) +#define SCOPED_TIME_STAT(stats) \ + operations_research::ScopedTimeDistributionUpdater scoped_time_stat( \ + (stats)->LookupOrCreateTimeDistribution(__FUNCTION__)) #endif // OR_STATS diff --git a/src/util/string_array.h b/src/util/string_array.h index 60c5c1335e..47f27aea84 100644 --- a/src/util/string_array.h +++ b/src/util/string_array.h @@ -19,17 +19,16 @@ #include "base/integral_types.h" #include "base/stringprintf.h" - namespace operations_research { // ---------- Pretty Print Helpers ---------- // See the straightforward (and unique) usage of this macro below. -#define RETURN_STRINGIFIED_VECTOR(vector, separator, method)\ - std::string out;\ - for (int i = 0; i < vector.size(); ++i) {\ - if (i > 0) out += separator;\ - out += vector[i] method;\ - }\ +#define RETURN_STRINGIFIED_VECTOR(vector, separator, method) \ + std::string out; \ + for (int i = 0; i < vector.size(); ++i) { \ + if (i > 0) out += separator; \ + out += vector[i] method; \ + } \ return out // Converts a vector into a std::string by calling the given method (or simply diff --git a/src/util/time_limit.cc b/src/util/time_limit.cc index 51f055e464..68cda3f9f5 100644 --- a/src/util/time_limit.cc +++ b/src/util/time_limit.cc @@ -66,10 +66,7 @@ double RunningMax::GetCurrentMax() { } TimeLimit::TimeLimit(double limit_in_seconds) - : timer_(), - last_(0.0), - limit_(0.0), - running_max_(kValues) { + : timer_(), last_(0.0), limit_(0.0), running_max_(kValues) { timer_.Start(); last_ = timer_.Get(); limit_ = last_ + limit_in_seconds; diff --git a/src/util/tuple_set.h b/src/util/tuple_set.h index 5349e44114..7c2042b867 100644 --- a/src/util/tuple_set.h +++ b/src/util/tuple_set.h @@ -103,9 +103,12 @@ class IntTupleSet { void AddSharedOwner(); bool RemovedSharedOwner(); Data* CopyIfShared(); - template int Insert(const std::vector& tuple); - template bool Contains(const std::vector& candidate) const; - template int64 Fingerprint(const std::vector& tuple) const; + template + int Insert(const std::vector& tuple); + template + bool Contains(const std::vector& candidate) const; + template + int64 Fingerprint(const std::vector& tuple) const; int NumTuples() const; int64 Value(int index, int pos) const; int Arity() const; @@ -152,9 +155,7 @@ inline IntTupleSet::Data::Data(const Data& data) inline IntTupleSet::Data::~Data() {} -inline void IntTupleSet::Data::AddSharedOwner() { - num_owners_++; -} +inline void IntTupleSet::Data::AddSharedOwner() { num_owners_++; } inline bool IntTupleSet::Data::RemovedSharedOwner() { return (--num_owners_ == 0); @@ -170,7 +171,8 @@ inline IntTupleSet::Data* IntTupleSet::Data::CopyIfShared() { return this; } -template int IntTupleSet::Data::Insert(const std::vector& tuple) { +template +int IntTupleSet::Data::Insert(const std::vector& tuple) { DCHECK(arity_ == 0 || flat_tuples_.size() % arity_ == 0); CHECK_EQ(arity_, tuple.size()); DCHECK_EQ(1, num_owners_); @@ -190,8 +192,8 @@ template int IntTupleSet::Data::Insert(const std::vector& tuple) { } } -template bool IntTupleSet::Data::Contains( - const std::vector& candidate) const { +template +bool IntTupleSet::Data::Contains(const std::vector& candidate) const { if (candidate.size() != arity_) { return false; } @@ -211,8 +213,8 @@ template bool IntTupleSet::Data::Contains( return false; } -template int64 IntTupleSet::Data::Fingerprint( - const std::vector& tuple) const { +template +int64 IntTupleSet::Data::Fingerprint(const std::vector& tuple) const { switch (arity_) { case 0: return 0; @@ -338,21 +340,15 @@ inline void IntTupleSet::InsertAll(const std::vector >& tuple } } -inline int IntTupleSet::NumTuples() const { - return data_->NumTuples(); -} +inline int IntTupleSet::NumTuples() const { return data_->NumTuples(); } inline int64 IntTupleSet::Value(int index, int pos) const { return data_->Value(index, pos); } -inline int IntTupleSet::Arity() const { - return data_->Arity(); -} +inline int IntTupleSet::Arity() const { return data_->Arity(); } -inline const int64* IntTupleSet::RawData() const { - return data_->RawData(); -} +inline const int64* IntTupleSet::RawData() const { return data_->RawData(); } inline int IntTupleSet::NumDifferentValuesInColumn(int col) const { if (col < 0 || col >= data_->Arity()) { diff --git a/src/util/vector_map.h b/src/util/vector_map.h index cec027648a..a27625590f 100644 --- a/src/util/vector_map.h +++ b/src/util/vector_map.h @@ -25,7 +25,8 @@ namespace operations_research { // This class stores a vector of distinct elements, as well as a map // from elements to index to find the index in the vector. // This is useful to store mapping between objects and indices. -template class VectorMap { +template +class VectorMap { public: // Adds an element if not already present, and returns its index in // the vector-map. @@ -57,9 +58,7 @@ template class VectorMap { // TODO(user): explore a int-type version. // Returns wether the element has already been added to the vector-map. - bool Contains(const T& element) const { - return ContainsKey(map_, element); - } + bool Contains(const T& element) const { return ContainsKey(map_, element); } // Returns the element at position index. const T& Element(int index) const { @@ -68,9 +67,7 @@ template class VectorMap { return list_[index]; } - const T& operator[](int index) const { - return Element(index); - } + const T& operator[](int index) const { return Element(index); } // Returns the number of distinct elements added to the vector-map. int size() const { return list_.size(); } diff --git a/src/util/xml_helper.h b/src/util/xml_helper.h index b0f146f528..51b57350f7 100644 --- a/src/util/xml_helper.h +++ b/src/util/xml_helper.h @@ -19,7 +19,6 @@ #include #include "base/macros.h" - namespace operations_research { // Lightweight XML writer that is optimized for CPViz output. As it only diff --git a/src/util/zvector.h b/src/util/zvector.h index 424dc6a7a5..6f309d1aba 100644 --- a/src/util/zvector.h +++ b/src/util/zvector.h @@ -40,20 +40,14 @@ namespace operations_research { -template class ZVector { +template +class ZVector { public: - ZVector() : base_(NULL), - min_index_(0), - max_index_(-1), - size_(0), - storage_() {} + ZVector() + : base_(NULL), min_index_(0), max_index_(-1), size_(0), storage_() {} ZVector(int64 min_index, int64 max_index) - : base_(NULL), - min_index_(0), - max_index_(-1), - size_(0), - storage_() { + : base_(NULL), min_index_(0), max_index_(-1), size_(0), storage_() { if (!Reserve(min_index, max_index)) { LOG(DFATAL) << "Could not reserve memory for indices ranging from " << min_index << " to " << max_index; @@ -161,11 +155,11 @@ template class ZVector { }; // Shorthands for all the types of ZVector's. -typedef ZVector Int8ZVector; +typedef ZVector Int8ZVector; typedef ZVector Int16ZVector; typedef ZVector Int32ZVector; typedef ZVector Int64ZVector; -typedef ZVector UInt8ZVector; +typedef ZVector UInt8ZVector; typedef ZVector UInt16ZVector; typedef ZVector UInt32ZVector; typedef ZVector UInt64ZVector;