12 Aralık 2016 Pazartesi

locale translate

Şöyle yaparız.
boost::locale::translate ("Hello world!");

10 Aralık 2016 Cumartesi

log linkleme

BOOST_LOG_DYN_LINK
Açıklaması şöyle. Windows'ta bu macro'yu tanımlamak gereksiz. Gcc'de .so ile linklemek istiyorsak tanımlamak gerekir.
If defined in user code, the library will assume the binary is built as a dynamically loaded library ("dll" or "so"). Otherwise it is assumed that the library is built in static mode. This macro must be either defined or not defined for all translation units of user application that uses logging. This macro can help with auto-linking on platforms that support it.
Gcc
Derlerken şöyle yaparız.
g++ ... -DBOOST_LOG_DYN_LINK ...
 -lpthread -lboost_filesystem -lboost_log_setup -lboost_log
Eğer derlerken değil de linklerken yapmaya kalkarsak doğal olarak hata alırız. Yani şu adım yanlış.
g++ -DBOOST_LOG_DYN_LINK boosttest.o -o boosttest -lboost_log -lpthread
Bir diğer seçenek ise kodda bu macroyu tanımlamak şöyle yaparız.
#define BOOST_LOG_DYN_LINK 1
CMake
Şöyle yaparız.
...
add_definitions( -DBOOST_LOG_DYN_LINK )

target_link_libraries(testapp
    ...
    pthread
    boost_system
    boost_log
)

8 Aralık 2016 Perşembe

qvm

mat Sınıfı
Giriş
Şu satırı dahil ederiz.
#include <boost/qvm/mat.hpp>
Constructor
Şöyle yaparız.
boost::qvm::mat<double, 4, 4> matrix;
rot_mat Sınıfı
Constructor
Şöyle yaparız
boost::qvm::rotx_mat<4>(3.14159f); // rotation on x axis by PI radians
vector Sınıfı
Giriş
Şu satırı dahil ederiz.
#include <boost/qvm/vec.hpp>
Constructor
3 tane nokta içeren nesne için şöyle yaparız
const auto axis = boost::qvm::vec<double, 3>{{ 0.0, 1.0, 0.0}};
quat Sınıfı
Tanımlama
Şöyle yaparız
boost::qvm::vec<double, 3> axis = ...;
auto rotationAngle = (3.14159/2.0);

const boost::qvm::quat<double> q = boost::qvm::rot_quat (axis, rotationAngle);
operator * metodu
Örnek ver

Free Style Metodlar
conjugate metodu
Şöyle yaparız.
boost::qvm::vec<double, 3> v = ...;
boost::qvm::quat<double> q = ...;

boost::qvm::vec<double, 3> v2 = q * (boost::qvm::conjugate(q) * v);
roty_mat metodu
Şu satırı dahil ederiz.
#include <boost/qvm/mat_operations.hpp>
Şöyle yaparız.
auto heading = 90.0;
boost::qvm::mat<double, 4, 4> rot = boost::qvm::roty_mat<4>(deg2rad(heading));
set_identity metodu
Şu satırı dahil ederiz.
#include <boost/qvm/mat_operations.hpp>
Şöyle yaparız.
boost::qvm::mat<double, 4, 4> matrix;
boost::qvm::set_identity(matrix);
translation_mat metodu
Şu satırı dahil ederiz.
#include <boost/qvm/mat_operations.hpp>
Şöyle yaparız.
auto speed = 10.0;;boost::qvm::vec<double, 3> v {{0.0, -speed, 0.0}};
boost::qvm::mat<double, 4, 4> translation = boost::qvm::translation_mat(v);
Şöyle yaparız.
vec<float,3> v={0,0,7};
mat<float,4,4> tr=translation_mat(v); // translation by 7 units on z axis


7 Aralık 2016 Çarşamba

log sinks text_multifile_backend Sınıfı

Constructor
Şöyle yaparız.
boost::shared_ptr<sinks::text_multifile_backend> backend =
  boost::make_shared< sinks::text_multifile_backend >();
set_file_name_composer metodu
Şöyle yaparız.
backend->set_file_name_composer
(
  sinks::file::as_file_name_composer(
    boost::log::expressions::stream <<
      boost::log::expressions::attr< std::string >("level") << ".log")
);

mpl

vector Sınıfı
Şu satırı dahil ederiz.
#include <boost/mpl/vector.hpp>
Tanımlama
Şöyle yaparız.
using namespace boost::mpl;

using test_type = vector<int, double>;

6 Aralık 2016 Salı

iostreams mapped_file_sink Sınıfı

Giriş
Şu satırı dahil ederiz.
#include <boost/iostreams/device/mapped_file.hpp>
Sınıf sadece yazma amaçlı (writeonly) metod sunar. Okuma işlemi için kullanılamaz. Bu sınıfı kardeşi mapped_file_source sınıfıdır.

Sınıf msync() veya FlushViewOfFile() benzeri veriyi diske yollayan - yani flush() eden - bir metod sunmaz.

Constructor
Şöyle yaparız.
std::string fpath = ...;
bios::mapped_file_sink file (fpath);
data metodu
Şöyle yaparız.
char * const begin  = file.data();
is_open metodu
Şöyle yaparız.
if (!file.is_open()) {...}
size metodu
Şöyle yaparız.
char * const begin  = file.data();
char * const end    = file.data() + file.size();

3 Aralık 2016 Cumartesi

iostreams code_converter Sınıfı

Giriş
Şu satırı dahil ederiz.
#include <boost/iostreams/code_converter.hpp>
constructor
Elimizde iki farklı locale kullanan stream olsun.
boost::locale::generator gen;

bio::filtering_stream<bio::input> in;
...
std::locale lru2 = gen("ru_RU.UTF-8");
in.imbue (lru2);

// output
std::ofstream outFile = ...
std::locale lru = gen("ru_RU.CP1251");
outFile.imbue(lru);
Şöyle yaparız.
bio::code_converter<bio::filtering_stream<bio::input> > win (in);
bio::code_converter<decltype(outFile)> wout (outFile);

win.imbue (lru2);
wout.imbue (lru);
const int buffSize = 500000;
/*auto totalWritten =*/ boost::iostreams::copy (win, wout, buffSize);