예제 #1
0
파일: midi_In.cpp 프로젝트: lubyk/midi
/** int midi::In::port() const
 * include/midi/In.h:78
 */
static int In_port(lua_State *L) {
  try {
    In *self = *((In **)dub_checksdata(L, 1, "midi.In"));
    lua_pushnumber(L, self->port());
    return 1;
  } catch (std::exception &e) {
    lua_pushfstring(L, "port: %s", e.what());
  } catch (...) {
    lua_pushfstring(L, "port: Unknown exception");
  }
  return dub_error(L);
}
예제 #2
0
파일: midi_In.cpp 프로젝트: lubyk/midi
/** bool lk::FifoMethods::hasMessage()
 * bind/Fifo.h:12
 */
static int In_hasMessage(lua_State *L) {
  try {
    In *self = *((In **)dub_checksdata(L, 1, "midi.In"));
    lua_pushboolean(L, self->hasMessage());
    return 1;
  } catch (std::exception &e) {
    lua_pushfstring(L, "hasMessage: %s", e.what());
  } catch (...) {
    lua_pushfstring(L, "hasMessage: Unknown exception");
  }
  return dub_error(L);
}
예제 #3
0
파일: copy.hpp 프로젝트: psiha/nt2
  inline void copy( In const& a, Out& b , HDI const& , HDO const&
                  , cudaStream_t stream = 0)
  {
    using T = typename Out::value_type;
//TODO

    CUDA_ERROR(cudaMemcpyAsync( (T*)b.data()
                              , a.data()
                              , a.size()* sizeof(T)
                              , copy_<HDI,HDO>::mode()
                              , stream
                              ));
  }
예제 #4
0
파일: midi_In.cpp 프로젝트: lubyk/midi
/** void midi::In::virtualPort(const char *port_name)
 * include/midi/In.h:127
 */
static int In_virtualPort(lua_State *L) {
  try {
    In *self = *((In **)dub_checksdata(L, 1, "midi.In"));
    const char *port_name = dub_checkstring(L, 2);
    self->virtualPort(port_name);
    return 0;
  } catch (std::exception &e) {
    lua_pushfstring(L, "virtualPort: %s", e.what());
  } catch (...) {
    lua_pushfstring(L, "virtualPort: Unknown exception");
  }
  return dub_error(L);
}
예제 #5
0
파일: rshd.cpp 프로젝트: arthur-samarin/os
 void transfer(In& in, cyclic_buffer<capacity>& buf) {
     if (!buf.isFull()) {
         size_t availSpace = std::min(buf.availableSpace(), TRANSFER_CHUNK_SIZE);
         char buffer[TRANSFER_CHUNK_SIZE];
         size_t numRead = in.read(buffer, availSpace);
         buf.write(buffer, numRead);
     }
 }
예제 #6
0
파일: Iconv.hpp 프로젝트: Sophrinix/gosu
    Out iconvert(const In& in)
    {
        if (in.empty())
            return Out();
    
        const size_t bufferLen = 128;
        typedef typename In::value_type InElem;
        typedef typename Out::value_type OutElem;

        static iconv_t cd = iconv_open(to, from);
        
        Out result;
        OutElem buffer[bufferLen];
        
        char* inbuf = const_cast<char*>(reinterpret_cast<const char*>(&in[0]));
        size_t inbytesleft = in.size() * sizeof(InElem);
        char* outbuf = reinterpret_cast<char*>(buffer);
        size_t outbytesleft = sizeof buffer;
        
        for (;;)
        {
            size_t ret = ::iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
            if (ret == static_cast<size_t>(-1) && errno == EILSEQ)
            {
                // Skip illegal sequence part, repeat loop.
                // TODO: Or retry w/ different encoding?
                ++inbuf;
                --inbytesleft;
            }
            else if (ret == static_cast<size_t>(-1) && errno == E2BIG)
            {
                // Append new characters, reset out buffer, then repeat loop.
                result.insert(result.end(), buffer, buffer + bufferLen);
                outbuf = reinterpret_cast<char*>(buffer);
                outbytesleft = sizeof buffer;
            }
            else
            {
                // Append what's new in the buffer, then LEAVE loop.
                result.insert(result.end(), buffer, buffer + bufferLen - outbytesleft / sizeof(OutElem));
                return result;
            }
        }        
    }
예제 #7
0
bool Input::poll(In &in)
{
  in.zero();
  if(SDL_PollEvent(&event))
  {
    if(event.type == SDL_QUIT) in.type = In::QUIT;
    #ifdef FG_PC
    else if(event.type == SDL_MOUSEBUTTONDOWN && event.button.button == SDL_BUTTON_LEFT)
    {
      in.x = event.button.x;
      in.y = event.button.y;
      in = mapIn(in);
      in.type = In::DOWN;
    }
    else if(event.type == SDL_MOUSEBUTTONUP && event.button.button == SDL_BUTTON_LEFT)
    {
      in.x = event.button.x;
      in.y = event.button.y;
      in = mapIn(in);
      in.type = In::UP;
    }
    else if(event.type == SDL_MOUSEMOTION && (event.motion.state & SDL_BUTTON_LMASK))
    {
      in.x = event.motion.x;
      in.y = event.motion.y;
      in = mapIn(in);
      in.type = In::MOVE;
    }
    #elif defined FG_ANDROID
    else if(event.type == SDL_FINGERDOWN)
    {
      in.x = event.tfinger.x*graphics->trueWinWidth();
      in.y = event.tfinger.y*graphics->trueWinHeight();
      in = mapIn(in);
      in.type = In::DOWN;
    }
    else if(event.type == SDL_FINGERUP)
    {
      in.x = event.tfinger.x*graphics->trueWinWidth();
      in.y = event.tfinger.y*graphics->trueWinHeight();
      in = mapIn(in);
      in.type = In::UP;
    }
    else if(event.type == SDL_FINGERMOTION)
    {
      in.x = event.tfinger.x*graphics->trueWinWidth();
      in.y = event.tfinger.y*graphics->trueWinHeight();
      in = mapIn(in);
      in.type = In::MOVE;
    }
    #endif

    return true;
  }
  return false;
}
예제 #8
0
파일: PJson.cpp 프로젝트: deepinit-arek/Srl
pair<Lib::MemBlock, Value> PJson::read(In& source)
{
    State state;
    while(!state.complete) {

        /* literals can be 'un-quoted', values in 'square-brackets' don't have a name */
        if(!state.reading_value && this->scope_type != Type::Array) {

            source.move_until(error, '\"', ':', '{', '[', '}', ']', '/');

        } else {
            source.move_while(error, ' ', ',', '\n', '\t', '\r');
        }

        bool move = true;
        char c = *source.pointer();
        switch(c) {
            case '\"': this->process_quote(source, state);
                       break;

            case ':' : if(state.reading_value) {
                           this->throw_exception(state, "Redundant semicolon.");
                        }
                        state.reading_value = true;
                        break;
            case '{' :
            case '}' :
            case '[' :
            case ']' : this->process_bracket(c, state);
                       break;
            case '/' : skip_comment(source);
                       break;

            default  : this->process_char(source, state, move);
        }

        if(move) {
            source.move(1, error);
        }
    }

    return { state.name, state.value };
}
예제 #9
0
파일: PJson.cpp 프로젝트: deepinit-arek/Srl
/* values not in quotes are literals */
void PJson::process_char(In& source, State& state, bool& out_move)
{
    bool is_literal = this->lookup.table[*source.pointer()];

    if(is_literal) {

        bool likely_fp = false;
        In::Notify dec ('.', likely_fp);

        auto block = source.read_block_until(error, ',', ' ', '}', ']', dec);

        this->process_literal(block, state, likely_fp ? Type::FP64 : Type::Null);

        if(*source.pointer() == '}' || *source.pointer() == ']') {
            /* The bracket has a double meaning here, first it delimits the literal,
             * and second it closes the scope. So make sure it will be processed. */
            out_move = false;
        }
    }
}
예제 #10
0
파일: midi_In.cpp 프로젝트: lubyk/midi
/** void midi::In::openPort(int port)
 * include/midi/In.h:86
 */
static int In_openPort(lua_State *L) {
  try {
    In *self = *((In **)dub_checksdata(L, 1, "midi.In"));
    int type__ = lua_type(L, 2);
    if (type__ == LUA_TNUMBER) {
      int port = dub_checkint(L, 2);
      self->openPort(port);
      return 0;
    } else {
      const char *port_name = dub_checkstring(L, 2);
      self->openPort(port_name);
      return 0;
    }
  } catch (std::exception &e) {
    lua_pushfstring(L, "openPort: %s", e.what());
  } catch (...) {
    lua_pushfstring(L, "openPort: Unknown exception");
  }
  return dub_error(L);
}
예제 #11
0
void TestVector(const Hasher &h, const In &in, const Out &out) {
    Out hash;
    BOOST_CHECK(out.size() == h.OUTPUT_SIZE);
    hash.resize(out.size());
    {
        // Test that writing the whole input string at once works.
        Hasher(h).Write((unsigned char*)&in[0], in.size()).Finalize(&hash[0]);
        BOOST_CHECK(hash == out);
    }
    for (int i=0; i<32; i++) {
        // Test that writing the string broken up in random pieces works.
        Hasher hasher(h);
        size_t pos = 0;
        while (pos < in.size()) {
            size_t len = insecure_rand() % ((in.size() - pos + 1) / 2 + 1);
            hasher.Write((unsigned char*)&in[pos], len);
            pos += len;
            if (pos > 0 && pos + 2 * out.size() > in.size() && pos < in.size()) {
                // Test that writing the rest at once to a copy of a hasher works.
                Hasher(hasher).Write((unsigned char*)&in[pos], in.size() - pos).Finalize(&hash[0]);
                BOOST_CHECK(hash == out);
            }
        }
        hasher.Finalize(&hash[0]);
        BOOST_CHECK(hash == out);
    }
}
예제 #12
0
void MessageQueue::append(In& stream)
{
  unsigned usedSize,
           numberOfMessages;
  stream >> usedSize >> numberOfMessages;
  // Trying a direct copy. This is hacked, but fast.
  char* dest = numberOfMessages == (unsigned) -1 ? 0 : queue.reserve(usedSize - MessageQueueBase::headerSize);
  if(dest)
  {
    stream.read(dest - MessageQueueBase::headerSize, usedSize);
    queue.numberOfMessages += numberOfMessages;
    queue.usedSize += usedSize;
    queue.writePosition = 0;
  }
  else // Not all messages fit in there, so try step by step (some will be missing).
    for(unsigned i = 0; numberOfMessages == (unsigned) -1 ? !stream.eof() : i < numberOfMessages ; ++i)
    {
      unsigned char id = 0;
      unsigned int size = 0;
      stream >> id;

      stream.read(&size, 3);

      if((id >= numOfDataMessageIDs || size == 0) &&  numberOfMessages == (unsigned) -1)
      {
        OUTPUT(idText, text, "MessageQueue: Logfile appears to be broken. Skipping rest of file. Read messages: " << queue.numberOfMessages << " read size:" << queue.usedSize);
        break;
      }

      char* dest = numberOfMessages != (unsigned) -1 || id < numOfDataMessageIDs ? queue.reserve(size) : 0;
      if(dest)
      {
        stream.read(dest, size);
        out.finishMessage(MessageID(id));
      }
      else
        stream.skip(size);
    }
}
예제 #13
0
파일: PJson.cpp 프로젝트: deepinit-arek/Srl
void PJson::process_quote(In& source, State& state)
{
    if(this->scope_type == Type::Null) {
        this->throw_exception(state, "Value not in a scope.");
    }
    /* skip opening quotation-mark */
    source.move(1, error);

    auto& buffer = state.name_processed ? this->value_buffer : this->name_buffer;
    MemBlock block = read_unescape(source, buffer);

    this->process_string(block, state);
}
예제 #14
0
파일: specific_cuda.hpp 프로젝트: psiha/nt2
      inline void transfer_htd( In & in, int blockid, Stream & stream ,std::size_t streamid
                              , std::size_t leftover , nt2::pinned_ & )
      {
        std::size_t sizeb = blocksize;
        if(leftover !=0) sizeb = leftover ;

        if( block_stream_htd[blockid] == false )
        {
        block_stream_htd[blockid] = true;

        CUDA_ERROR(cudaMemcpyAsync( buffers.get_device(streamid)
                                  , in.data()
                                  , sizeb* sizeof(T)
                                  , cudaMemcpyHostToDevice
                                  , stream
                  ));
        cudaStreamSynchronize(stream);
        }

      }
예제 #15
0
파일: make_copy.hpp 프로젝트: rubicks/kapp
        /* todo: concepts...

           In, Out are "container-like" classes that support:

           ::value_type, ::size(void), ::resize(size_t), ::operator[](size_t),
           &::value_type (i.e. addressable ::value_type) */
        Out make_copy( const In&in )
        {
            const size_t
                n_ival( sizeof( typename In::value_type ) ),
                n_oval( sizeof( typename Out::value_type ) );
            const size_t b_total( in.size() * n_ival );
            const size_t size_out
                ( b_total / n_oval +
                  ( ( b_total % n_oval ) ? 1 : 0 ) );

            Out out;
            out.resize( size_out,
                        typename Out::value_type( 0 ) );

            assert
                ( b_total ==
                  out.size() * n_oval +
                  ( b_total % n_oval ? 1 : 0 ) );

            memcpy( &out[0], &in[0], b_total );
            return out;
        }