void selection_column::on_change( const inventory_entry &entry )
{
    inventory_entry my_entry( entry );
    my_entry.category = &selected_cat;

    const auto iter = std::find( entries.begin(), entries.end(), my_entry );
    if( my_entry.chosen_count != 0 ) {
        if( iter == entries.end() ) {
            add_entry( my_entry );
        } else {
            iter->chosen_count = my_entry.chosen_count;
        }
    } else {
        entries.erase( iter );
    }

    prepare_paging();
    // Now let's update selection
    const auto select_iter = std::find( entries.begin(), entries.end(), my_entry );
    if( select_iter != entries.end() ) {
        select( std::distance( entries.begin(), select_iter ) );
    } else {
        select( entries.empty() ? 0 : entries.size() - 1 ); // Just select the last one
    }
}
Esempio n. 2
0
void SymbolTable::AddEntry(std::string id, DataTypes type) {
    std::string type_string;
    std::string default_value;
    switch (type) {
        case TYPE_CHEESE_LIT:
            type_string = "CHEESE_LIT";
            default_value = "";
            break;
        case TYPE_FLOAT_LIT:
            type_string = "FLOAT_LIT";
            default_value = "0.00";
            break;
        case TYPE_INT_LIT:
            type_string = "INT_LIT";
            default_value = "0";
            break;
        case TYPE_BOOL_LIT:
            type_string = "BOOL_LIT";
            default_value = "FALSE";
            break;
        default:
        std::cerr << "Undefined type error" << std::endl;
    }

    // First Check if the entry exists
    if (SymbolTable::EntryExists(id)) {
        // Should update the entry, rather than create a new one
        std::cout << "Already Exists!" << std::endl;
    }
    else {
        // Add to total entries
        total_entries++;

        // Create label entry name
        std::string lbl_name = "LBL" + std::to_string(total_entries);

        // Create a new entry
        std::cout << "Added entry! Type: " << type_string << std::endl;
        DataEntry my_entry(id, type, lbl_name, total_entries);
        table_entries.push_back(my_entry);
        // table_entries[SymbolTable::GetEntry(id)].AssignValue(default_value);
    }
}
Esempio n. 3
0
int
ACE_Token::renew (int requeue_position,
                  ACE_Time_Value *timeout)
{
  ACE_TRACE ("ACE_Token::renew");
  ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1);

#if defined (ACE_TOKEN_DEBUGGING)
  this->dump ();
#endif /* ACE_TOKEN_DEBUGGING */
  // ACE_ASSERT (ACE_OS::thr_equal (ACE_Thread::self (), this->owner_));

  // Check to see if there are any waiters worth giving up the lock
  // for.

  // If no writers and either we are a writer or there are no readers.
  if (this->writers_.head_ == 0 &&
      (this->in_use_ == ACE_Token::WRITE_TOKEN ||
       this->readers_.head_ == 0))
    // Immediate return.
    return 0;

  // We've got to sleep until we get the token again.

  // Determine which queue should this thread go to.
  ACE_Token::ACE_Token_Queue *this_threads_queue =
    this->in_use_ == ACE_Token::READ_TOKEN ?
    &this->readers_ : &this->writers_;

  ACE_Token::ACE_Token_Queue_Entry my_entry (this->lock_,
                                             this->owner_);

  this_threads_queue->insert_entry (my_entry,
                                    // if requeue_position == 0 then we want to go next,
                                    // otherwise use the queueing strategy, which might also
                                    // happen to be 0.
                                    requeue_position == 0 ? 0 : this->queueing_strategy_);
  ++this->waiters_;

  // Remember nesting level...
  int const save_nesting_level_ = this->nesting_level_;

  // Reset state for new owner.
  this->nesting_level_ = 0;

  // Wakeup waiter.
  this->wakeup_next_waiter ();

  bool timed_out = false;
  bool error = false;

  // Sleep until we've got the token (ignore signals).
  do
    {
      int const result = my_entry.wait (timeout, this->lock_);

      if (result == -1)
        {
          // Note, this should obey whatever thread-specific interrupt
          // policy is currently in place...
          if (errno == EINTR)
            continue;

#if defined (ACE_TOKEN_DEBUGGING)
          cerr << '(' << ACE_Thread::self () << ')'
               << " renew: "
               << (errno == ETIME ? "timed out" : "error occurred")
               << endl;
#endif /* ACE_TOKEN_DEBUGGING */

          // We come here if a timeout occurs or some serious
          // ACE_Condition object error.
          if (errno == ETIME)
            timed_out = true;
          else
            error = true;

          // Stop the loop.
          break;
        }
    }
  while (!ACE_OS::thr_equal (my_entry.thread_id_, this->owner_));

  // Do this always and irrespective of the result of wait().
  --this->waiters_;
  this_threads_queue->remove_entry (&my_entry);

#if defined (ACE_TOKEN_DEBUGGING)
  ACELIB_DEBUG ((LM_DEBUG, "(%t) ACE_Token::renew (UNBLOCKED)\n"));
#endif /* ACE_TOKEN_DEBUGGING */

  // If timeout occurred
  if (timed_out)
    {
      // This thread was still selected to own the token.
      if (my_entry.runable_)
        {
          // Wakeup next waiter since this thread timed out.
          this->wakeup_next_waiter ();
        }

      // Return error.
     return -1;
    }
  else if (error)
    {
      // Return error.
      return -1;
    }

  // If this is a normal wakeup, this thread should be runnable.
  ACE_ASSERT (my_entry.runable_);

  // Reinstate nesting level.
  this->nesting_level_ = save_nesting_level_;

  return 0;
}
Esempio n. 4
0
int
ACE_Token::shared_acquire (void (*sleep_hook_func)(void *),
                           void *arg,
                           ACE_Time_Value *timeout,
                           ACE_Token_Op_Type op_type)
{
  ACE_TRACE ("ACE_Token::shared_acquire");
  ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1);

#if defined (ACE_TOKEN_DEBUGGING)
  this->dump ();
#endif /* ACE_TOKEN_DEBUGGING */

  ACE_thread_t const thr_id = ACE_Thread::self ();

  // Nobody holds the token.
  if (!this->in_use_)
    {
      // Its mine!
      this->in_use_ = op_type;
      this->owner_ = thr_id;
      return 0;
    }

  // Someone already holds the token.

  // Check if it is us.
  if (ACE_OS::thr_equal (thr_id, this->owner_))
    {
      ++this->nesting_level_;
      return 0;
    }

  // Do a quick check for "polling" behavior.
  if (timeout != 0 && *timeout == ACE_Time_Value::zero)
    {
      errno = ETIME;
      return -1;
    }

  //
  // We've got to sleep until we get the token.
  //

  // Which queue we should end up in...
  ACE_Token_Queue *queue = (op_type == ACE_Token::READ_TOKEN
                            ? &this->readers_
                            : &this->writers_);

  // Allocate queue entry on stack.  This works since we don't exit
  // this method's activation record until we've got the token.
  ACE_Token::ACE_Token_Queue_Entry my_entry (this->lock_,
                                             thr_id,
                                             this->attributes_);
  queue->insert_entry (my_entry, this->queueing_strategy_);
  ++this->waiters_;

  // Execute appropriate <sleep_hook> callback.  (@@ should these
  // methods return a success/failure status, and if so, what should
  // we do with it?)
  int ret = 0;
  if (sleep_hook_func)
    {
      (*sleep_hook_func) (arg);
      ++ret;
    }
  else
    {
      // Execute virtual method.
      this->sleep_hook ();
      ++ret;
    }

  bool timed_out = false;
  bool error = false;

  // Sleep until we've got the token (ignore signals).
  do
    {
      int const result = my_entry.wait (timeout, this->lock_);

      if (result == -1)
        {
          // Note, this should obey whatever thread-specific interrupt
          // policy is currently in place...
          if (errno == EINTR)
            continue;

#if defined (ACE_TOKEN_DEBUGGING)
          cerr << '(' << ACE_Thread::self () << ')'
               << " acquire: "
               << (errno == ETIME ? "timed out" : "error occurred")
               << endl;
#endif /* ACE_TOKEN_DEBUGGING */

          // We come here if a timeout occurs or some serious
          // ACE_Condition object error.
          if (errno == ETIME)
            timed_out = true;
          else
            error = true;

          // Stop the loop.
          break;
        }
    }
  while (!ACE_OS::thr_equal (thr_id, this->owner_));

  // Do this always and irrespective of the result of wait().
  --this->waiters_;
  queue->remove_entry (&my_entry);

#if defined (ACE_TOKEN_DEBUGGING)
  ACELIB_DEBUG ((LM_DEBUG, "(%t) ACE_Token::shared_acquire (UNBLOCKED)\n"));
#endif /* ACE_TOKEN_DEBUGGING */

  // If timeout occurred
  if (timed_out)
    {
      // This thread was still selected to own the token.
      if (my_entry.runable_)
        {
          // Wakeup next waiter since this thread timed out.
          this->wakeup_next_waiter ();
        }

      // Return error.
     return -1;
    }
  else if (error)
    {
      // Return error.
      return -1;
    }

  // If this is a normal wakeup, this thread should be runnable.
  ACE_ASSERT (my_entry.runable_);

  return ret;
}
Esempio n. 5
0
ConditionalEntry SymbolTable::CreateConditional(ConditionalType type_used) {
    ConditionalEntry my_entry(total_conditonals, type_used);
    cur_cond = &my_entry;
    total_conditonals++;
    return my_entry;
}