Esempio n. 1
0
static int
calc_connect_ep(_point_t p1, _point_t p2, _point_t *ep, double m)
{
    _size_t d = _delta(p1, p2);
    int mode = 0;

    double l = sqrt(d.w*d.w + d.h*d.h);
    double ms = MIN(m, l);
    double as = 2*ms;

    if (d.w > fabs(d.h))
	as = MAX(0, as - 2*ms*(M_PI/4-atan(fabs(d.h)/d.w)));

    ep[0] = _move(p1, _size(as, 0));
    ep[3] = _move(p2, _size(-as, 0));

    if (d.w < 0) {
	double xs = ms*0.58;
	double ys = d.h*0.113;
	ep[1] = _move(p1, _size(xs, ys));
	ep[2] = _move(p2, _size(-xs, -ys));

	mode = 1;
    }
    return mode;
}
Esempio n. 2
0
void MemoryDebugger::clean(void)
{
 if (_CleanAllowed && (_size() < _capacity() / 2))
 {
  _reserve(_size() + 16);
 }
}
Esempio n. 3
0
static inline size_t
_item_len(const struct varyad *v, size_t i)
{
    if (i) {
        return _size(v, i) - _size(v, i - 1);
    } else {
        return _size(v, i);
    }
}
Esempio n. 4
0
static void
calc_node_type(cairo_t *cr, designer_node_type_t *nt)
{
    node_type_data_t *ntd = node_type_data(nt);
    _rect_t br, ir, or, sr;

    ntd->is = g_slist_length(nt->input_slot_specs);
    ntd->os = g_slist_length(nt->output_slot_specs);

    set_slot_font(cr);
    sr = text_rect(cr, "Mg");
    /* add sep space */
    sr.s.h += 3;

    ir = _rect(0, 0, 10, 0);
    for (int i=0; i<ntd->is; i++) {
	designer_slot_spec_t *slot =
	    g_slist_nth_data(nt->input_slot_specs, i);
	slot_spec_data_t *ssd = slot_spec_data(slot);
	
	ssd->offset = _size(3, 5 + sr.s.h * i);
	ir = _union(ir, text_rect(cr, slot->name));
    }
    /* offset left */
    ir = _offset(ir, _size(0, 5));
    /* add slot and sep space */
    ir.s.w += 5+5;
    /* height including sep space */
    ir.s.h = ntd->is * sr.s.h - 3;

    or = _rect(0, 0, 10, 0);
    for (int i=0; i<ntd->os; i++) {
	designer_slot_spec_t *slot =
	    g_slist_nth_data(nt->output_slot_specs, i);
	slot_spec_data_t *ssd = slot_spec_data(slot);
	
	ssd->offset = _size(3, 5 + sr.s.h * i);
	or = _union(or, text_rect(cr, slot->name));
    }
    /* move right, including sep space */
    or = _offset(or, _size(ir.s.w + 5, 5));
    /* add slot and sep space */
    or.s.w += 5+5;
    /* height including sep space */
    or.s.h = ntd->os * sr.s.h - 3;

    br = _union(ir, or);
    /* reserve space around area */
    br = _inset(br, _size(-5, -5));

    ntd->br = br;
    ntd->ir = _splith(&ir, 6);
    _splith(&or, or.s.w - 6);
    ntd->or = or;
    ntd->sr = sr;
}
void String::realloc (int newlen)
{
  newlen++;
  if (newlen <= _size (buf))
    return;
  int newsize = (_size (buf) < ALLOC_STEP ? _size (buf) * 2 : _size (buf) + ALLOC_STEP);
  if (newsize < newlen)
    newsize = newlen;
  char* tmp = _new (newsize);
  _len (tmp) = _len (buf);
  _ref (tmp) = _ref (buf);
  memcpy (tmp, buf, _len (buf) + 1);
  _del (buf);
  buf = tmp;
}
Esempio n. 6
0
File: server.c Progetto: Asiron/ucs
int await_server_response(int node_server_id){
    MSG_SERVER2SERVER pong;
    MSG_SERVER2SERVER ping;
    ping.type = SERVER2SERVER;
    ping.server_ipc_num = MSG_RECEIVER;
    msgsnd(node_server_id, &ping, _size(MSG_SERVER2SERVER), 0);
    clock_t start = clock();
    while (1) {
        if (msgrcv(MSG_RECEIVER, &pong, _size(MSG_SERVER2SERVER), SERVER2SERVER, IPC_NOWAIT) != -1) {
            return TRUE; 
        } else if ( ((double)(clock()-start)*1000)/CLOCKS_PER_SEC > 500){
            return FALSE;
        }
    }
}
Esempio n. 7
0
static _size_t
get_visible_size (widget_data_t *data)
{
    GtkAllocation *allocation = &(GTK_WIDGET(data->drawing_area)->allocation);

    return _size(allocation->width, allocation->height);
}
Esempio n. 8
0
void ufs_file_base::set_size(offset_type newsize)
{
    scoped_mutex_lock fd_lock(fd_mutex);
    offset_type cur_size = _size();

    if (!(mode_ & RDONLY))
    {
#ifdef BOOST_MSVC
        HANDLE hfile;
        stxxl_check_ge_0(hfile = (HANDLE) ::_get_osfhandle(file_des), io_error);

        LARGE_INTEGER desired_pos;
        desired_pos.QuadPart = newsize;

        if (!SetFilePointerEx(hfile, desired_pos, NULL, FILE_BEGIN))
            stxxl_win_lasterror_exit("SetFilePointerEx in ufs_file_base::set_size(..) oldsize=" << cur_size <<
                                     " newsize=" << newsize << " ", io_error);

        if (!SetEndOfFile(hfile))
            stxxl_win_lasterror_exit("SetEndOfFile oldsize=" << cur_size <<
                                     " newsize=" << newsize << " ", io_error);
#else
        stxxl_check_ge_0(::ftruncate(file_des, newsize), io_error);
#endif
    }

#ifndef BOOST_MSVC
    if (newsize > cur_size)
        stxxl_check_ge_0(::lseek(file_des, newsize - 1, SEEK_SET), io_error);
#endif
}
Esempio n. 9
0
_point_t place_new_node(widget_data_t *data)
{
    /* calc new place */
    data->place_next = _move(data->place_next, _size(20,20));

    return data->place_next;
}
Esempio n. 10
0
		void putFile(const char* filename,const char* nameInArchive)
		{
			char buff[BUFSIZ];
			std::FILE* in=std::fopen(filename,"rb");
			if(in==NULL)
			{
				std::stringstream err;
				err << "Cannot open " << filename << " "<< std::strerror(errno);
				throw std::runtime_error(err.str());
			}
			std::fseek(in, 0L, SEEK_END);
			long int len= std::ftell(in);
			std::fseek(in,0L,SEEK_SET);

			PosixTarHeader header;
			_init((void*)&header);
			_filename((void*)&header,nameInArchive);
			header.typeflag[0]=0;
			_size((void*)&header,len);
			_checksum((void*)&header);
			out.write((const char*)&header,sizeof(PosixTarHeader));

			std::size_t nRead=0;
			while((nRead=std::fread(buff,sizeof(char),BUFSIZ,in))>0)
			{
				out.write(buff,nRead);
			}
			std::fclose(in);

			_endRecord(len);
		}
Esempio n. 11
0
static _rect_t
recalc_area(cairo_t *cr, widget_data_t *data)
{
    _rect_t area;
    int count = 0;

    /* no valid data */
    if (!data || !data->design || !data->design->nodes)
	return _zeror;

    /* check the nodes */
    for (GSList *list = data->design->nodes;
	list != NULL; list = list->next) {
	designer_node_t *node = list->data;

	if (cr) {
	    calc_node_type(cr, node->type);
	    calc_node(cr, node);
	}

	node_data_t *nd = node_data(node);
	_rect_t nr = _offset(nd->nr, _ptos(nd->origin));

	area = (count++) ? _union(area, nr) : nr;
    }
    return _inset(area, _size(-40, -20));
}
Esempio n. 12
0
bool String::fromClipboard ()
{
  if (!IsClipboardFormatAvailable (CF_UNICODETEXT))
    return false;
  if (!OpenClipboard (NULL))
    return false;
  wchar_t* wide = (wchar_t*) GetClipboardData (CF_UNICODETEXT);
  CloseClipboard ();
  if (wide)
  {
    if (_ref (buf) > 1) splice ();
    int count = WideCharToMultiByte (CP_ACP, WC_COMPOSITECHECK, (LPWSTR) wide, -1, NULL, 0, NULL, NULL);
    realloc (count);
    WideCharToMultiByte (CP_ACP, WC_COMPOSITECHECK, (LPWSTR) wide, -1, buf, _size (buf), NULL, NULL);
    int len = 0;
    for (int i = 0; buf[i]; i++)
      if (buf[i] != '\r')
        buf[len++] = buf[i];
    buf[len] = 0;
    _len (buf) = len;
    return true;
  }
  else
    return false;
}
Esempio n. 13
0
Variant PackedDataContainer::_iter_get_ofs(const Variant &p_iter, uint32_t p_offset) {

	int size = _size(p_offset);
	int pos = p_iter;
	if (pos < 0 || pos >= size)
		return Variant();

	PoolVector<uint8_t>::Read rd = data.read();
	const uint8_t *r = &rd[p_offset];
	uint32_t type = decode_uint32(r);

	bool err = false;
	if (type == TYPE_ARRAY) {

		uint32_t vpos = decode_uint32(rd.ptr() + p_offset + 8 + pos * 4);
		return _get_at_ofs(vpos, rd.ptr(), err);

	} else if (type == TYPE_DICT) {

		uint32_t vpos = decode_uint32(rd.ptr() + p_offset + 8 + pos * 12 + 4);
		return _get_at_ofs(vpos, rd.ptr(), err);
	} else {
		ERR_FAIL_V(Variant());
	}
}
Esempio n. 14
0
void _gadget::setSizeInternal( _length width , _length height )
{
	_size size = this->getSize();
	
	// Respect Fixed width/height of the gadget and size limits
	if( !this->isResizeableX() )
		width = this->getWidth();
	else
		width = max( width , this->getMinWidth() );
	
	if( !this->isResizeableY() )
		height = this->getHeight();
	else
		height = max( height , this->getMinHeight() );
	
	if( width == this->getWidth() && height == this->getHeight() )
		return;
	
	// Compute area to redraw
	_size refreshSize = _size( max<_length>( width , size.first ) , max<_length>( height , size.second ) );
	_pos refreshPos = this->getAbsolutePosition();
	
	// Refresh
	this->bitmap.resize( width , height );
	
	// Notify dependent gadgets
	this->notifyDependentGadgets( onResize );
	
	// Refresh
	this->redraw( _rect( refreshPos , refreshSize ) );
}
Esempio n. 15
0
void UfsFileBase::_set_size(offset_type newsize) {
    offset_type cur_size = _size();

    if (!(mode_ & RDONLY) && !is_device_)
    {
#if THRILL_WINDOWS || defined(__MINGW32__)
        HANDLE hfile = (HANDLE)::_get_osfhandle(file_des_);
        THRILL_THROW_ERRNO_NE_0((hfile == INVALID_HANDLE_VALUE), IoError,
                                "_get_osfhandle() path=" << path_ << " fd=" << file_des_);

        LARGE_INTEGER desired_pos;
        desired_pos.QuadPart = newsize;

        if (!SetFilePointerEx(hfile, desired_pos, nullptr, FILE_BEGIN))
            THRILL_THROW_WIN_LASTERROR(IoError,
                                       "SetFilePointerEx in ufs_file_base::set_size(..) oldsize=" << cur_size <<
                                       " newsize=" << newsize << " ");

        if (!SetEndOfFile(hfile))
            THRILL_THROW_WIN_LASTERROR(IoError,
                                       "SetEndOfFile oldsize=" << cur_size <<
                                       " newsize=" << newsize << " ");
#else
        THRILL_THROW_ERRNO_NE_0(::ftruncate(file_des_, newsize), IoError,
                                "ftruncate() path=" << path_ << " fd=" << file_des_);
#endif
    }

#if !THRILL_WINDOWS
    if (newsize > cur_size)
        THRILL_THROW_ERRNO_LT_0(::lseek(file_des_, newsize - 1, SEEK_SET), IoError,
                                "lseek() path=" << path_ << " fd=" << file_des_ << " pos=" << newsize - 1);
#endif
}
Esempio n. 16
0
static inline void *
_item_buf(const struct varyad *v, size_t i)
{
    if (i) {
        return _head(v) + _size(v, i - 1);
    } else {
        return _head(v);
    }
}
Esempio n. 17
0
File: server.c Progetto: Asiron/ucs
void handle_logout(void* received, int msg_type){
    MSG_LOGIN temp = *(MSG_LOGIN*)(received);
    MSG_RESPONSE response;
    response.type = RESPONSE;
    switch (unregister_user(temp)) {
        case SUCCESS:
            remove_user_from_local_repo(temp.ipc_num);
            response.response_type = LOGOUT_SUCCESS;
            strcpy(response.content, "LOGOUT SUCCESS - 200");
            msgsnd(temp.ipc_num, &response, _size(MSG_RESPONSE), 0);
            break;
        case FAIL:
            response.response_type = LOGOUT_FAILED;
            strcpy(response.content, "LOGOUT FAILED");
            msgsnd(temp.ipc_num, &response, _size(MSG_RESPONSE), 0);
            break;
    }
}
Esempio n. 18
0
void String::splice ()
{
  char* tmp = _new (_size (buf));
  _len (tmp) = _len (buf);
  _ref (tmp) = 1;
  memcpy (tmp, buf, _len (buf) + 1);
  deref ();
  buf = tmp;
}
Esempio n. 19
0
Animation * ParticleEmitter::SizeAnimation(const Vector3 & newSize, float32 time, Interpolation::FuncType interpolationFunc /*= Interpolation::LINEAR*/, int32 track /*= 0*/)
{
    Vector3 _size(0, 0, 0);
    if(size)
        _size = size->GetValue(0);
    LinearAnimation<Vector3> * animation = new LinearAnimation<Vector3>(this, &_size, newSize, time, interpolationFunc);
    animation->Start(track);
    return animation;
}
Esempio n. 20
0
static void
calc_node(cairo_t *cr, designer_node_t *n)
{
    node_data_t *nd = node_data(n);
    node_type_data_t *ntd = node_type_data(n->type);
    _rect_t nr, lr, tr, ir, or, br, xr;

    set_title_font(cr);
    lr = text_rect(cr, n->name);

    tr = _inset(lr, _size(-5, -5));
    tr.s.w += 20; /* button space */

    br = ntd->br;

    /* move into place */
    br.o.y = tr.o.y + tr.s.h;
    nr = _union(tr, br);

    /* break down areas once again */
    br = nr; tr = _splitv(&br, tr.s.h);

    /* split off close button */
    xr = tr; _splith(&xr, tr.s.w - 16);
    xr = _splitv(&xr, 16);
    xr = _inset(xr, _size(4, 4));

    ir = ntd->ir;
    /* align inputs to the left */
    ir.o = _move(br.o, _size(5, 5));

    or = ntd->or;
    /* align outputs to the right */
    or.o = _move(br.o, _size(br.s.w - or.s.w - 5, 5));

    nd->nr = nr;
    nd->lr = lr;
    nd->tr = tr;
    nd->br = br;
    nd->ir = ir;
    nd->or = or;
    nd->xr = xr;
}
Esempio n. 21
0
void Counter::AddSize(const D3DXVECTOR2& size)
{
	Size += size;

	D3DXVECTOR3 _size(Size.x,Size.y,0);
	for (int cnt = 0;cnt < CountPlace;cnt++)
	{
		number[cnt]->SetSize(_size);
	}
}
Esempio n. 22
0
static _point_t
output_slot_origin(designer_node_t *n, int i)
{
    designer_node_type_t *nt = n->type;
    node_type_data_t *ntd = node_type_data(nt);
    node_data_t *nd = node_data(n);

    return _move(_move(nd->or.o,
	_size(nd->or.s.w - 3, 5 + ntd->sr.s.h * i)),
	_ptos(nd->origin));
}
void sim_disk_file::set_size(offset_type newsize)
{
    scoped_mutex_lock fd_lock(fd_mutex);
    if (newsize > _size())
    {
        STXXL_THROW_ERRNO_LT_0(::lseek(file_des, newsize - 1, SEEK_SET), io_error,
                               "lseek() fd=" << file_des << " pos=" << newsize - 1);
        STXXL_THROW_ERRNO_LT_0(::write(file_des, "", 1), io_error,
                               "write() fd=" << file_des << " size=1");
    }
}
Esempio n. 24
0
Variant PackedDataContainer::_iter_init_ofs(const Array &p_iter, uint32_t p_offset) {

	Array ref = p_iter;
	uint32_t size = _size(p_offset);
	if (size == 0 || ref.size() != 1)
		return false;
	else {
		ref[0] = 0;
		return true;
	}
}
Esempio n. 25
0
void MemoryDebugger::_resize(unsigned int new_size)
{
 VtIterator new_first = (VtIterator) NxOgreMalloc(new_size * sizeof(Vt));
 _copy(_First, _Last, new_first);
 _range_destruct(_First, _Last);
 if (_First)
  NxOgreFree(_First);
 _End = new_first + new_size;
 _Last = new_first + _size();
 _First = new_first;
}
Esempio n. 26
0
String String::printf (char const* fmt, ...)
{
  va_list ap;
  va_start (ap, fmt);

  char* buf = _new (_vscprintf (fmt, ap) + 1);
  _len (buf) = _size (buf) - 1;
  _ref (buf) = 1;
  vsprintf (buf, fmt, ap);
  return frombuf (buf);
}
Esempio n. 27
0
static inline size_t
_avail(const struct varyad *v)
{
    size_t size = v->size;
    size -= sizeof(struct varyad);
    if (v->rank) {
        size -= v->rank * sizeof(size_t);
        size -= _size(v, v->rank - 1);
    }
    return size;
}
Esempio n. 28
0
void* MemoryDebugger::addAllocation(void* ptr, size_t size, unsigned int class_id, const char* file, unsigned int line)
{
 if (_End <= _Last)
  _reserve((1 + _size()) * 2);
 _Last->_Ptr = ptr;
 _Last->_Size = size;
 _Last->_Type = class_id;
 _Last->_File = file;
 _Last->_Line = line;
 _Last++;
 return ptr;
}
Esempio n. 29
0
static void
show_axis(cairo_t *cr, _point_t p, float r, float g, float b, float w, float h)
{
    _point_t ap[4];

    ap[0] = _move(p, _size(-w, 0));
    ap[1] = _move(p, _size( w, 0));
    ap[2] = _move(p, _size( 0, h));
    ap[3] = _move(p, _size( 0,-h));

    cairo_set_source_rgba(cr, r, g, b, 0.6);
    cairo_set_line_width(cr, 1.0);

    _move_to(cr, ap[0]);
    _line_to(cr, ap[1]);
    cairo_stroke(cr);

    _move_to(cr, ap[2]);
    _line_to(cr, ap[3]);
    cairo_stroke(cr);
}
Esempio n. 30
0
String& String::operator += (char ch)
{
  if (ch == 0) return *this;
  if (_ref (buf) > 1) splice ();
  if (_len (buf) + 1 >= _size (buf))
    realloc (_len (buf) + 1);

  buf[_len (buf)++] = ch;
  buf[_len (buf)] = 0;

  return *this;
}