29 Kasım 2016 Salı

graph read_graphml metodu

Giriş
Bu metodu read_graphviz ile kardeş.

Elimizde şöyle bir graph olsun
typedef  boost::labeled_graph<boost::adjacency_list<
        boost::listS, boost::vecS, boost::directedS,
        Vertex, Edge>, int> Graph;
 Graph graph;
Şöyle yaparız.
boost::dynamic_properties dp(boost::ignore_other_properties);

dp.property("IdV", boost::get(&Vertex::ID, graph));
dp.property("LabelV", boost::get(&Vertex::Name, graph));
dp.property("TypeV", boost::get(&Vertex::Type, graph));

dp.property("WeightE", boost::get(&Edge::Weight, graph));
dp.property("TypeE", boost::get(&Edge::Type, graph));
dp.property("LabelE", boost::get(&Edge::Name, graph));

std::ifstream dot ("inputpath");
boost::read_graphml(dot, graph, dp);

25 Kasım 2016 Cuma

polygon polygon_set_data Sınıfı

Tanımlama 
Şöyle yaparız.
typedef boost::polygon::polygon_set_data<long long int> polygon_set;
Constructor
Şöyle yaparız.
polygon_set a;
operator + metodu
Şöyle yaparız.
a += boost::polygon::rectangle_data<long long int>(0, 0, 10, 10);

20 Kasım 2016 Pazar

serialization BOOST_CLASS_EXPORT

Giriş
Kalıtım varsa kullanılır. Şu satırı dahil ederiz.
#include <boost/serialization/export.h>
BOOST_SERIALIZATION_ASSUME_ABSTRACT yazısına da göz atabilirsiniz.

Sınıfları tanımlamak için şöyle yaparız
class Father {

public:

  friend class boost::serialization::access;

  template<class Archive>
  void serialize(Archive& ar, const unsigned version)
  {
    ...
  }
};

class Daughter : public Father {

  friend class boost::serialization::access;
  template<class Archive>

  void serialize(Archive& ar, const unsigned version)
  {  
    ar & boost::serialization::base_object<Father>(*this);
    ...
  }
}; 

BOOST_CLASS_EXPORT(Daughter);
boost::serialization::base_object metodu
Burada dikkat edilmesi gereken nokta kalıtan sınıfı serialize etmek. İstersek şu satırı dahil ederiz.
#include <boost/serialization/base_object.hpp>
Şöyle  yaparız.
ar & boost::serialization::base_object<B>(*this);
Kullanım
Şöyle yaparız. Burada archive nesnesine yapılan register_type çağrısından emin değilim.
Daughter girl;
Daughter *d = &girl;

Father *papa = d; // My father object contains daughter object

//SEND
{
  boost::archive::text_oarchive oa = ...;
  oa.register_type<Daughter>();
  oa << *papa;
}

18 Kasım 2016 Cuma

multiprecision export_bits metodu

export_bits metodu
Açıklaması şöyle. Sayının mutlak değerini yazar.
Exports the absolute value of val to OutputIterator out. The function will write chunk_size bits at a time to the OutputIterator, and if msv_first is true, will write the most-significant block first. Byte and bit order within each chunk_size block is always in the machines native format. Further, each block is stored in a boost::uintmax_t when it's assigned to *out.
Şöyle yaparız.
typedef multiprecision::int512_t balance_value;
vector<uint8_t> byteSet;
export_bits(balance, back_inserter(byteSet), 8);
import_bits metodu
Şöyle yaparız.
balance_value balance;
import_bits(balance, byteSet.begin(), byteSet.end());


15 Kasım 2016 Salı

interprocess interprocess_semaphore Sınıfı

Constructor
Şöyle yaparız.
boost::interprocess::interprocess_semaphore semDone(0);
timed_wait metodu
Şöyle yaparız.
long sec = 10;
boost::posix_time::ptime p = boost::posix_time::second_clock::universal_time() 
 + boost::posix_time::seconds(sec);
bool ret = semDone.timed_wait (p);

geometry multi_polygon Sınıfı

Giriş
Şu satırları dahil ederiz.
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/geometry/geometries/multi_polygon.hpp>
Constructor
Şöyle yaparız.
using PointType = boost::geometry::model::d2::point_xy<double>;
using PolygonType = boost::geometry::model::polygon<PointType>;
using MultiPolygonType = boost::geometry::model::multi_polygon<PolygonType>;
MultiPolygonType polygon;
boost::geometry::read_wkt("MULTIPOLYGON(((...)))", polygon);
push_back metodu
Elimizde iki tane polygon olsun.
PolygonType singlePolygon1;
PolygonType singlePolygon2;

boost::geometry::read_wkt("POLYGON((...))", singlePolygon1);
boost::geometry::read_wkt("POLYGON((...))", singlePolygon2);

boost::geometry::correct(singlePolygon1);
boost::geometry::correct(singlePolygon2);
Şöyle yaparız.
MultiPolygonType polygon;
polygon.push_back (singlePolygon1);
polygon.push_back (singlePolygon2);

12 Kasım 2016 Cumartesi

asio io_service work Sınıfı

Giriş
io_service eğer yapacak iş yoksa sonlanır. io_service.run () metodu sonlanmasın istiyorsak work sınıfını kullanırız.

Constructor
Örnek 1
Şöyle yaparız.
boost::asio::io_service ios;
boost::asio::io_service::work w (ios);
Örnek 2
Heap'te yaratmak istersek şöyle yaparız
boost::asio::io_service ios;
auto w = std::make_shared<boost::asio::io_service::work> (ios);
Örnek 3
Şöyle yaparız.
boost::asio::io_service ios;
boost::asio::io_service::work *w = new boost::asio::io_service::work (ios);
Daha sonra bu nesneyi sileriz.
delete w;
Yardımcı Sınıf
work nesnesi yaşadığı müddetçe is_service nesnesi döngüsünden çıkmaz. Tüm işler bittikten sonra döngüden çıkması için yardım bir sınıf kullanırız. Şöyle yaparız.
#include <boost/asio.hpp>
#include <boost/optional.hpp>

struct workutil {
  using io_service = boost::asio::io_service;
  workutil (io_service& ios) :
    m_work (io_service::work (ios)) 
    { }

  void release() {
    m_work.reset();
  }

  void enlist(io_service& ios) {
    m_work.emplace (io_service::work (ios));
  }

private:
  boost::optional<io_service::work> m_work;
};
Şöyle yaparız
boost::asio::io_service ios;
workutil lock (ios);

...

lock.release();