예제 #1
0
파일: Monitor.cpp 프로젝트: trapexit/Nebula
void Monitor::drawStartUp() {
    const int MID_X = (sim::MONITOR_CELLS_PER_SCREEN_WIDTH / 2) - 1;
    const int MID_Y = (sim::MONITOR_CELLS_PER_SCREEN_HEIGHT / 2) - 1;
    const int NUM_LINES = 4;

    fill( BackgroundColor { 0x9 } );

    auto drawCentered = [&] ( int lineIndex, const std::uint8_t* line, std::size_t length ) {
        for ( std::size_t i = 0; i < length; ++i ) {
            drawCell( MID_X - (length / 2) + i,
                      MID_Y - (NUM_LINES / 2) + lineIndex,
                      Character { line[i] },
                      ForegroundColor { 0xe },
                      BackgroundColor { 0x9 } );
        }
    };

    const std::array<std::uint8_t, 14> LINE1 = { 'N', 'Y', 'A', ' ', 'E', 'L', 'E', 'K', 'T', 'R', 'I', 'S', 'K', 'A'};
    const std::array<std::uint8_t, 7 > LINE2 = { 'L', 'E', 'M', '1', '8', '0', '2' };
    const std::array<std::uint8_t, 18> LINE3 = {'L', 'o', 'w', ' ', 'E', 'n', 'e', 'r', 'g', 'y', ' ', 'M', 'o', 'n', 'i', 't', 'o', 'r' };

    drawCentered( 0, LINE1.data(), LINE1.size() );
    drawCentered( 2, LINE2.data(), LINE2.size() );
    drawCentered( 3, LINE3.data(), LINE3.size() );
}
예제 #2
0
 inline std::string PrettyPrint(const std::array<T, N>& arraytoprint, const bool add_delimiters=false, const std::string& separator=", ")
 {
     std::ostringstream strm;
     if (arraytoprint.size() > 0)
     {
         if (add_delimiters)
         {
             strm << "[" << PrettyPrint(arraytoprint[0], add_delimiters, separator);
             for (size_t idx = 1; idx < arraytoprint.size(); idx++)
             {
                 strm << separator << PrettyPrint(arraytoprint[idx], add_delimiters, separator);
             }
             strm << "]";
         }
         else
         {
             strm << PrettyPrint(arraytoprint[0], add_delimiters, separator);
             for (size_t idx = 1; idx < arraytoprint.size(); idx++)
             {
                 strm << separator << PrettyPrint(arraytoprint[idx], add_delimiters, separator);
             }
         }
     }
     return strm.str();
 }
예제 #3
0
파일: span.cpp 프로젝트: gnzlbg/range-v3
void test_case_from_const_std_array_constructor()
{
    const std::array<int, 4> arr = {1, 2, 3, 4};

    {
        span<const int> s{arr};
        CHECK((s.size() == narrow_cast<std::ptrdiff_t>(arr.size()) && s.data() == arr.data()));
    }

    {
        span<const int, 4> s{arr};
        CHECK((s.size() == narrow_cast<std::ptrdiff_t>(arr.size()) && s.data() == arr.data()));
    }

    CONCEPT_ASSERT(!std::is_constructible<span<const int, 2>, decltype((arr))>::value);
    CONCEPT_ASSERT(!std::is_constructible<span<const int, 0>, decltype((arr))>::value);
    CONCEPT_ASSERT(!std::is_constructible<span<const int, 5>, decltype((arr))>::value);

    {
        auto get_an_array = []() -> const std::array<int, 4> { return {1, 2, 3, 4}; };
        auto take_a_span = [](span<const int>) {};
        take_a_span(get_an_array());
    }

    {
        auto s = make_span(arr);
        CHECK((s.size() == narrow_cast<std::ptrdiff_t>(arr.size()) && s.data() == arr.data()));
    }
}
static void
parseRegisterValue(std::array<latte::SPI_VS_OUT_ID_N, 10> &spi_vs_out_id,
                   uint32_t index,
                   const std::string &member,
                   const std::string &value)
{
   if (index >= spi_vs_out_id.size()) {
      throw gfd_header_parse_exception {
         fmt::format("SQ_VTX_SEMANTIC[{}] invalid index, max: {}",
                     index, spi_vs_out_id.size())
      };
   }

   if (member == "SEMANTIC_0") {
      spi_vs_out_id[index] = spi_vs_out_id[index]
         .SEMANTIC_0(parseValueNumber(value));
   } else if (member == "SEMANTIC_1") {
      spi_vs_out_id[index] = spi_vs_out_id[index]
         .SEMANTIC_1(parseValueNumber(value));
   } else if (member == "SEMANTIC_2") {
      spi_vs_out_id[index] = spi_vs_out_id[index]
         .SEMANTIC_2(parseValueNumber(value));
   } else if (member == "SEMANTIC_3") {
      spi_vs_out_id[index] = spi_vs_out_id[index]
         .SEMANTIC_3(parseValueNumber(value));
   } else {
      throw gfd_header_parse_exception {
         fmt::format("SPI_VS_OUT_ID[{}] does not have member {}",
                     index, member)
      };
   }
}
예제 #5
0
int main(int argc, char** argv)
{
    // ut::setLogLevel(ut::LOGLEVEL_DEBUG);

    size_t selected = 0;

    if (argc == 2) {
        selected = boost::lexical_cast<size_t>(argv[1]);
    }

    while (selected < 1 || EXAMPLES.size() < selected) {
        printf ("Examples:\n\n");
            
        for (size_t i = 0; i < EXAMPLES.size(); i++) {
            printf ("%02d: %s\n", (int) (i + 1), EXAMPLES[i].second.c_str());
        }

        printf ("\nSelect: ");
        try {
            const char* line = readLine();
            selected = boost::lexical_cast<size_t>(line);
        } catch (...) {
        }

        printf ("\n---------\n\n");
    }

    auto& example = EXAMPLES[selected - 1];
    example.first();

    return 0;
}
예제 #6
0
bool fileinformation::validate_lines_information(std::string& line) {
	std::smatch  matches; 
	bool output = false;
	std::size_t index;
	static bool recursivecomment = false;

	for(index = 0; index < regularexpression.size(); ++index) {
		regularexpression[index].second = std::regex_search(line, matches, regularexpression[index].first);
		/*
		{
				output = true;
				if(index != 2){
					break;
				}
		}
		*/
	}

	recursivecomment = (regularexpression.at(2).second) && !(regularexpression.at(3).second);


	for(index = 0; index < regularexpression.size(); ++index) {
		regularexpression[index].second = false;
	}



	return output;
}
예제 #7
0
파일: 2049.cpp 프로젝트: horazont/2048-ai
score_t shift_line(std::array<cell_value_t*, board_size> &line)
{
    score_t result = 0;
    for (size_t i = 0; i < line.size(); /* nothing */) {
        bool merged = false;
        if (    *line[i] != 0 &&
                i > 0 &&
                *line[i-1] == *line[i])
        {
            *line[i-1] += 1;
            *line[i] = 0;
            merged = true;
            // result += round(pow(SCORE_MERGE_BASE, *line[i-1]));
            result += round((*line[i-1]) * SCORE_MERGE_FACTOR);
        }
        if (*line[i] == 0) {
            bool shifted = false;
            for (size_t j = i+1; j < line.size(); j++) {
                if (*line[j] != 0) {
                    *line[i] = *line[j];
                    *line[j] = 0;
                    shifted = true;
                    break;
                }
            }
            if (!shifted || merged) {
                i++;
            }
        } else {
            i++;
        }
    }
    return result;
};
예제 #8
0
std::vector<std::string> getTransformCombinations(std::array<std::string, 3> transformers, int iteration) {
    std::vector<std::string> list;
    std::vector<bool> v(transformers.size());
    std::fill(v.begin() + iteration, v.end(), true);
    
    do {
        std::string tmp = "";
        for (int i = 0; i < transformers.size(); ++i) {
            if (!v[i]) {
                if(tmp != "") {
                    tmp = tmp + "+";
                }
                tmp = tmp + transformers[i];
            }
        }
        list.push_back(tmp);
    } while (std::next_permutation(v.begin(), v.end()));
    
    if(iteration < transformers.size()) {
        std::vector<std::string> nlist;
        nlist = getTransformCombinations(transformers, iteration+1);
        for(std::string s : nlist) {
            list.push_back(s);
        }
    }
    
    return list;
}
예제 #9
0
파일: main.cpp 프로젝트: CCJY/coliru
int main()
{
    const std::array<int, 3> arr { 1, 2, 3 };
    
    std::array<int, arr.size()> arr2;
    
    std::cout << arr.size() << arr2.size() << std::endl;
}
예제 #10
0
int getIndexForConfTarget(int target) {
    for (unsigned int i = 0; i < confTargets.size(); i++) {
        if (confTargets[i] >= target) {
            return i;
        }
    }
    return confTargets.size() - 1;
}
예제 #11
0
	virtual double toNormalizedFromValue(double x) override
	{
		for (int i = 0; i<c_fft_sizes.size() - 1; ++i)
		{
			if (x >= c_fft_sizes[i] && x<c_fft_sizes[i + 1])
				return 1.0 / c_fft_sizes.size() *i;
		}
		return 0.0;
	}
예제 #12
0
const char *Init(JSContext *ctx, unsigned ID){
    assert(ctx);
    assert(function_name_list.size() == function_list.size());
    
    Network::socket_proto.initForContext(ctx, nullptr, socket_methods);
    Network::listening_socket_proto.initForContext(ctx, nullptr, listening_socket_methods);
    
    return PLUGINNAME;
}
예제 #13
0
파일: space.hpp 프로젝트: juronen/Dubuskan
 size_t operator()(const std::array<size_t, dims> &arr) const noexcept
 {
     size_t result = arr.size();
     for (size_t i = 0; i < arr.size(); i++)
     {
         result *= result * 63 + arr[i];
     }
     return result;
 }
예제 #14
0
	blit_saw_oscillator()
		:pitchbend(0.0)
	{
		// sine wave table
		for (size_t ii = 0; ii < sin_table.size(); ii++)
		{
			sin_table[ii] = std::sin(2.0*PI * ii / (sin_table.size() - 1));
		}
	}
예제 #15
0
	shared_byte_allocator& _get_alloc(span_size_t align) {
		assert(_alignment.size() == _aligned_alloc.size());
		for(std::size_t i=0; i<_alignment.size(); ++i) {
			if(_alignment[i] == align) {
				return _aligned_alloc[i];
			}
		}
		return _fallback_alloc;
	}
bool mcal::display::display_console::do_write(const std::uint8_t value_to_write)
{
  static const std::array<std::uint8_t, 16U> character_table =
  {{
    UINT8_C('0'),
    UINT8_C('1'),
    UINT8_C('2'),
    UINT8_C('3'),
    UINT8_C('4'),
    UINT8_C('5'),
    UINT8_C('6'),
    UINT8_C('7'),
    UINT8_C('8'),
    UINT8_C('9'),
    UINT8_C('A'),
    UINT8_C('b'),
    UINT8_C('c'),
    UINT8_C('d'),
    UINT8_C('E'),
    UINT8_C('F')
  }};

  std::uint8_t table_index;
  bool         write_is_ok;

  const bool byte_is_in_range =
    (value_to_write < std::uint8_t(character_table.size()));

  if(byte_is_in_range)
  {
    table_index = value_to_write;

    write_is_ok = true;
  }
  else
  {
    table_index = std::uint8_t(character_table.size() - 1U);

    write_is_ok = false;
  }

  set_data(character_table[table_index]);

  std::cout << "seven_segment display: "
            << char(get_data());

  if(get_dp_is_on())
  {
    std::cout << char('.');
  }

  std::cout << std::endl;

  return write_is_ok;
}
예제 #17
0
TEST(testCountersManager, checkEmpty)
{
    clearBuffers();
    CountersManager cm(AtomicBuffer(&labelsBuffer[0], labelsBuffer.size()),
            AtomicBuffer(&countersBuffer[0], countersBuffer.size()));

    cm.forEach([](int id, const std::string &label)
    {
        FAIL();
    });
}
예제 #18
0
/*!
@brief comparison operator for JSON types

Returns an ordering that is similar to Python:
- order: null < boolean < number < object < array < string
- furthermore, each type is not smaller than itself
- discarded values are not comparable

@since version 1.0.0
*/
inline bool operator<(const value_t lhs, const value_t rhs) noexcept
{
    static constexpr std::array<std::uint8_t, 8> order = {{
            0 /* null */, 3 /* object */, 4 /* array */, 5 /* string */,
            1 /* boolean */, 2 /* integer */, 2 /* unsigned */, 2 /* float */
        }
    };

    const auto l_index = static_cast<std::size_t>(lhs);
    const auto r_index = static_cast<std::size_t>(rhs);
    return l_index < order.size() and r_index < order.size() and order[l_index] < order[r_index];
}
예제 #19
0
size_t c_tuntap_linux_obj::send_to_tun_separated_addresses(const unsigned char *const data, size_t size,
	const std::array<unsigned char, IPV6_LEN> &src_binary_address,
	const std::array<unsigned char, IPV6_LEN> &dst_binary_address) {
	_check_input(size >= 8);
	std::array<boost::asio::const_buffer, 4> buffers;
	buffers.at(0) = boost::asio::buffer(data, 8); // version, traffic, flow label, payload length, next header, hop limit
	buffers.at(1) = boost::asio::buffer(src_binary_address.data(), src_binary_address.size());
	buffers.at(2) = boost::asio::buffer(dst_binary_address.data(), dst_binary_address.size());
	buffers.at(3) = boost::asio::buffer(data + 8, size - 8); // 8 bytes are filled in buffers.at(0)
	boost::system::error_code ec;
	return m_tun_stream.write_some(buffers, ec);
}
예제 #20
0
		void FillBillionairesToPersons()
		{
			Billionaire one;
			auto half = order.size() / 2;
			for (auto i = order.size(); i > 0; --i)
			{
				one.Age = 20;
				one.Total = order[i - 1];
				one.Citizenship = std::string((i <= half ? "upper" : "lower"));
				persons.AddBillionaire(one);
			}
		}
예제 #21
0
int maxSubSum(const std::array<int, B>& a) {
    if (a.size() < 0) { throw std::invalid_argument("can not get a max of empty list"); }
    int maxsum = a[0];
    int sum = maxsum;
    for (int i = 1; i < a.size(); ++i) {
        sum = (maxsum < 0) ? a[i] : sum + a[i];
        if (maxsum < sum) {
            maxsum = sum;
        } else if (sum < 0 && maxsum >= 0) {
            sum = 0;
        }
    }
    return maxsum;
} 
예제 #22
0
TEST(testCountersManager, checkOverflow)
{
    clearBuffers();
    CountersManager cm (AtomicBuffer(&labelsBuffer[0], labelsBuffer.size()),
            AtomicBuffer(&countersBuffer[0], countersBuffer.size()));

    std::vector<std::string> labels = { "lab0", "lab1", "lab2", "lab3", "lab4" };

    ASSERT_THROW({
        for (auto& l: labels)
        {
            cm.allocate(l);
        }
    }, IllegalArgumentException);
예제 #23
0
파일: glExtra.cpp 프로젝트: sprunk/spring
void gleGenBoxMeshBuffer(unsigned int* meshData) {
	if (meshData == nullptr)
		return;

	glGenBuffers(1, &meshData[0]);
	glBindBuffer(GL_ARRAY_BUFFER, meshData[0]);
	glBufferData(GL_ARRAY_BUFFER, BOX_VERTS.size() * sizeof(float3), BOX_VERTS.data(), GL_STATIC_DRAW);
	glBindBuffer(GL_ARRAY_BUFFER, 0);

	glGenBuffers(1, &meshData[1]);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, meshData[1]);
	glBufferData(GL_ELEMENT_ARRAY_BUFFER, BOX_INDCS.size() * sizeof(uint32_t), BOX_INDCS.data(), GL_STATIC_DRAW);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}
예제 #24
0
	/* Fill buffers to fill up the source queue. Returns the number of buffers
	 * queued.
	 */
	ALint fillBufferQueue(std::vector<char> &buffer)
	{
		ALint queued;
		alGetSourcei(mSource, AL_BUFFERS_QUEUED, &queued);
		while (queued < mBuffers.size())
		{
			ALuint bufid = mBuffers[mBufferIdx];
			if (!fillBuffer(bufid, buffer))
				break;
			mBufferIdx = (mBufferIdx + 1) % mBuffers.size();
			alSourceQueueBuffers(mSource, 1, &bufid);
			++queued;
		}
		return queued;
	}
예제 #25
0
파일: main.cpp 프로젝트: michiroooo/cppcv
    std::string select(){

        if (++current_ >= methods_.size()) {
            current_ = 0;
        }
        return methods_.at(current_);
    }
예제 #26
0
TEST(TestJsonreader, ReadingAndParsingMatrix) {
	using namespace nntl_supp;
	using ErrCode = jsonreader::ErrorCode;
	typedef train_data<real_t> train_data_t;
	typedef train_data_t::mtx_t realmtx_t;
	using mtx_size_t = realmtx_t::mtx_size_t;
	using vec_len_t = realmtx_t::vec_len_t;

	realmtx_t m;
	jsonreader reader;

	ErrCode ec = reader.read(NNTL_STRING("./test_data/mtx4-2.json"), m);
	ASSERT_EQ(ErrCode::Success, ec) << "Error code description: " << reader.get_last_error_string();

	const std::array<std::array<real_t, 4>, 2> train_x_data{ 81,91,13,91,63,10,28,55 };

	mtx_size_t train_x_size(static_cast<vec_len_t>(train_x_data[0].size()), static_cast<vec_len_t>(train_x_data.size()));

	ASSERT_EQ(train_x_size, m.size()) << "td.train_x size differs from expected";
	
	for (int i = 0; i < train_x_data.size(); i++) {
		for (int j = 0; j < train_x_data[0].size(); j++)
			EXPECT_EQ(train_x_data[i][j], m.get(j, i));
	}
}
예제 #27
0
void debug_draw_verts(std::vector<debug_line>& lines, const rgba col, const std::array<vec2, I>& arr, const vec2 pos) {
	const auto n = arr.size();

	for (std::size_t i = 0; i < n; ++i) {
		lines.emplace_back(col, pos + arr[i], pos + arr[(i + 1) % n]);
	}
}
예제 #28
0
Shader createShader(GLenum shaderType, const std::string &glslVersion, const std::string &shaderSource) {
    Shader shader(glCreateShader(shaderType));
    if (!shader) {
        throw OpenGLException("Shader creation failed", glGetError());
    }
    
    const std::array<const GLchar *, 5> strings = {
        "#version ", glslVersion.data(), "\n",
        "precision highp float;\n",
        shaderSource.data()
    };
    glShaderSource(shader.get(), strings.size(), strings.data(), nullptr);
    glCompileShader(shader.get());
    
    GLint infoLogLength;
    glGetShaderiv(shader.get(), GL_INFO_LOG_LENGTH, &infoLogLength);
    if (infoLogLength > 0) {
        std::vector<GLchar> infoLog(infoLogLength);
        glGetShaderInfoLog(shader.get(), infoLogLength, nullptr, infoLog.data());
        mwarning(M_DISPLAY_MESSAGE_DOMAIN,
                 "OpenGL: Shader compilation produced the following information log:\n%s",
                 infoLog.data());
    }
    
    GLint compileStatus;
    glGetShaderiv(shader.get(), GL_COMPILE_STATUS, &compileStatus);
    if (compileStatus != GL_TRUE) {
        throw OpenGLException("Shader compilation failed");
    }
    
    return shader;
}
예제 #29
0
void osc_exampleApp::draw()
{
  gl::clear( Color( 0, 0, 0 ) );
  
  float width = getWindowWidth();
  float height = getWindowHeight() / mEMG.size();
  float currY = 0.0f;
  vec3 currColor = vec3(0.0f, 1.0f, 1.0f);
  float hInc = 1.0 / mEMG.size();
  for (auto emg : mEMG) {
    ColorA c = hsvToRgb(currColor);
    drawBuffer(emg, Rectf(0, currY, width, currY + height), true, c, 1.0f / 256.0f);
    currColor.r += hInc;
    currY += height;
  }
}
예제 #30
0
파일: sys_fs.cpp 프로젝트: notoknight/rpcs3
s32 sys_fs_opendir(vm::cptr<char> path, vm::ptr<u32> fd)
{
	sys_fs.Warning("sys_fs_opendir(path=*0x%x, fd=*0x%x)", path, fd);
	sys_fs.Warning("*** path = '%s'", path.get_ptr());

	std::shared_ptr<vfsDirBase> dir(Emu.GetVFS().OpenDir(path.get_ptr()));

	if (!dir || !dir->IsOpened())
	{
		sys_fs.Error("sys_fs_opendir('%s'): failed to open directory", path.get_ptr());
		return CELL_FS_ENOENT;
	}

	for (u32 i = 3; i < g_fds.size(); i++)
	{
		// try to reserve fd
		if (g_fds[i].compare_and_swap_test(0, ~0))
		{
			g_fds[i].store(Emu.GetIdManager().make<lv2_dir_t>(std::move(dir)));

			*fd = i;

			return CELL_OK;
		}
	}

	// out of file descriptors
	return CELL_FS_EMFILE;
}