Exemple #1
0
void widget::visible(bool visible)
{
    if (impl_->visible_ == visible)
        return;

    if (visible)
    {
        if (!onShowing())
            return;
        if (impl_->father_ && !impl_->father_->onChildShowing(this))
            return;

        impl_->visible_ = true;

        onShown();
        if (father())
            father()->onChildShown(this);
    }
    else
    {
        if (!onHiding())
            return;
        if (impl_->father_ && !impl_->father_->onChildHiding(this))
            return;

        impl_->visible_ = false;

        onHidden();
        if (father())
            father()->onChildHidden(this);
    }

    window().visible(visible);
    repaint();
}
Exemple #2
0
node * brother(node *nd)
{
	if(!father(nd))
		return NULL;
	if(isleft(nd))
		return right(father(nd));
	return left(father(nd));
}
int main(){
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; ++i)
		fa[i] = i;
	while(m--){
		scanf("%d%d", &a, &b);
	if(father(a) == father(b))
			ans <<= 1;
		fa[father(a)] = father(b);
		printf("%lld\n", ans - 1);
	}
	return 0;
}
Exemple #4
0
	void slide_up(const vertex &v, const T &value)
	{
		/* Jesteśmy w korzeniu, nie ma gdzie wyżej jechać. */
		if (v == 1) {
			array[v] = value;
			return;
		}

		/* Jeżeli podstawienie wartości może zaburzyć porządek - rekurencja. */
		if (value < array[father(v)]) {
			array[v] = array[father(v)];
			slide_up(father(v), value);
		} else {
			array[v] = value;
		}
	}
Exemple #5
0
bool widget::as_window(cross_platform_window::Handle handle)
{
    if (father())
        return false;

    if (is_window())
        return true;

    if (handle)
    {
        if (takisy::all_windows__.find(handle) == takisy::all_windows__.end())
        {
            cross_platform_window window(handle);

            window.xy(xy() - window.client_offset());
            window.client_size(size());
            window.visible(visible());
            window.repaint();

            takisy::all_windows__[handle] = this;
        }
    }
    else
    {
        handle = takisy::handleFromLPWIDGET(this);
        if (handle)
        {
            takisy::all_windows__.erase(handle);

            cross_platform_window(handle).repaint();
        }
    }

    return true;
}
Exemple #6
0
bool widget::as_window(bool enable_alpha_channel)
{
    if (father())
        return false;

    if (is_window())
        return true;

    cross_platform_window::Handle handle = nullptr;
#ifdef __os_win__
    DWORD style = WS_POPUP;
    if (visible())
        style |= WS_VISIBLE;

    DWORD exstyle = WS_EX_TOOLWINDOW;
    if (enable_alpha_channel)
        exstyle |= WS_EX_LAYERED;

    handle = CreateWindowEx(exstyle, takisy::class_name__,
                            "takisy::gui::cross_platform_window::winnt::widget",
                            style, x(), y(), width(), height(),
                            GetDesktopWindow(), nullptr,
                            GetModuleHandle(nullptr), nullptr);
#endif

    if (!handle)
        return false;
    else
        return as_window(handle);
}
bool VValueBag::ReplaceElementByPath( const VValueBag::StKeyPath& inPath, VValueBag *inBag)
{
	if (!testAssert( !inPath.empty()))
		return false;
	
	bool ok;
	if (inPath.size() > 1)
	{
		VValueBag::StKeyPath father( inPath);
		father.pop_back();
		if (inBag == NULL)
		{
			// removing
			VValueBag *fatherBag = GetUniqueElementByPath( father);
			if (fatherBag != NULL)
				fatherBag->RemoveElements( inPath.back());
			ok = true;
		}
		else
		{
			VValueBag *fatherBag = GetElementByPathAndCreateIfDontExists( father);
			if (fatherBag != NULL)
				ok = fatherBag->ReplaceElement( inPath.back(), inBag);
			else
				ok = false;
		}
	}
	else
	{
		ok = ReplaceElement( inPath.back(), inBag);
	}
	
	return ok;
}
Exemple #8
0
/**
 * @brief BTRecordFile::readRecordFromDiskTest
 * @param pDisk
 * @param pRecordID
 * Hace la lectura de un registro en la RAM
 */
void BTRecordFile::readRecordFromDiskTest(Disk pDisk, unsigned short pRecordID)
{
    const char *padre = pDisk.read(this->_metadataPtr->getFirstRecordPos(), 7);
    const char *hizq = pDisk.read(this->_metadataPtr->getFirstRecordPos() + 8, 7);
    const char *hder = pDisk.read(this->_metadataPtr->getFirstRecordPos() + 16, 7);
    std::string father(padre);          // obtiene el padre
    std::string HI(hizq);               // obtiene el hijo izq
    std::string HD(hder);               // obtiene el hijo der
    unsigned short _sizeCounter = this->_metadataPtr->getFirstRecordPos() + 24;       // inicio de la data
    DLL<IRecordDataType*> *tmp1 = _metadataPtr->getRecordStruct();
    DLLNode<IRecordDataType*> *tmp = tmp1->getHeadPtr();
    const char *data;

    cout << "Binario " << father << " " << HI << " " << HD << endl;
    std::string P = _conversion->binaryToDecimal(father);
    std::string PHI = _conversion->binaryToDecimal(HI);
    std::string PHD = _conversion->binaryToDecimal(HD);
    cout << P << " " << PHI << " " << PHD << " ";
    while (tmp != nullptr) {
        data = (dynamic_cast<RecordDataType<char>*>(tmp->getData()))->getDataPtr();
        const char *DATO = pDisk.read(_sizeCounter, 7);
        std::string DATOSTR(DATO);       // obtiene el padre
        _sizeCounter += 8;
        cout << sortUserDataFromDisk(DATOSTR, *data) << endl;
        tmp = tmp->getNextPtr();
    }
}
/**
    \fn analyzeTracks
    \brief Read Tracks Info.
*/
uint8_t mkvHeader::analyzeTracks(void *head,uint32_t headlen)
{
  uint64_t id,len;
  ADM_MKV_TYPE type;
  const char *ss;
 ADM_ebml_file father( (ADM_ebml_file *)head,headlen);
 while(!father.finished())
 {
      father.readElemId(&id,&len);
      if(!ADM_searchMkvTag( (MKV_ELEM_ID)id,&ss,&type))
      {
        printf("[MKV] Tag 0x%x not found (len %llu)\n",id,len);
        father.skip(len);
        continue;
      }
      ADM_assert(ss);
      if(id!=MKV_TRACK_ENTRY)
      {
        printf("[MKV] skipping %s\n",ss);
        father.skip(len);
        continue;
      }
      if(!analyzeOneTrack(&father,len)) return 0;
 }
 return 1;
}
Exemple #10
0
void test() {
    parent_ptr father(new parent());
    children_ptr son(new children());

    father->children = son;
    son->parent = father;
}
Exemple #11
0
void father(char *svname, int loop)
{
  pid_t p_id;
  int killed = 0;

  p_id = fork();
  if (p_id < 0)
  {
    printf("Fork failed in svwatch.\n");
    exit (-1);
  }
  if (p_id > 0)
  {
    printf("Luke, I'm your father.\n");
    while (loop && !killed)
    {
      if (waitpid(p_id, NULL, WNOHANG) > 0)
      {
	killed = 1;
	logvalue(p_id, svname);
	father(svname, loop);
      }
    }
  }
  if (p_id == 0)
    child(svname);
}
Exemple #12
0
void Node::decisions(DecisionList& result) const {
  if (!isRoot()) {
    result.push_front(_decision);
    father()->decisions(result);
  }

}
Exemple #13
0
int	exec_pipe(int i, char **command)
{
  int	pid;
  int	fd[2];

  if (command[i + 1])
    {
      if (pipe(fd) == -1 || (pid = fork()) == -1)
	return (0);
      if (pid != 0)
	{
	  close(fd[1]);
	  if (dup2(fd[0], 0) == -1)
	    return (0);
	  waitpid(pid, 0, 0);
	  if (my_pipe(i + 1, command) == 0)
	    return (0);
	  close(fd[0]);
	}
      else if (father(fd, command, i) == 0)
	return (0);
    }
  if (execlp(command[i], command[i], NULL) == -1)
    return (0);
  return (1);
}
Exemple #14
0
// -------------------------------------------------------------------
// insert element at end of heap and fixup heap by walk towards root
// 
void insertHeap( Heap h, void* value )
{
  // expand if necessary to accommodate a new node
  if ( end(h) == h->maxsize ) {	// no more available slots
    h->maxsize *= 2;
    h->node = safe_realloc( h->node, h->maxsize * sizeof(void*) );
  }

  // create a hole at end of heap
  int hole = end(h);
  h->cursize++;

  // move hole upwards to place where new value goes
  while (hole != root) {
    // test if value belongs in hole
    int scan = father(hole);    
    if (h->comp( h->node[ scan ], value ) <= 0) // yes
      break;
    // no, move hole up one level
    h->node[ hole ] = h->node[ scan ];
    hole = scan;
  }

  // fill hole with new element
  h->node[ hole ] = value;   
}
Exemple #15
0
void Node::decisions(DecisionSet&result) const {
  if (!isRoot()) {
    result.insert(_decision);
    father()->decisions(result);
  }

}
Exemple #16
0
/* 建堆 */
static void build_heap(int *heap, int size, fun compare)
{
    int index = father(size - 1);

    for (; index >= 0; --index)
        heapify(heap, index, size, compare);
}
Exemple #17
0
widget::~widget(void)
{
    for (widget* child : children())
        child->father(nullptr);
    father(nullptr);
    as_window(nullptr);
    delete impl_;
}
Exemple #18
0
		/** reorganize the heap
		 *
		 * @param i - index from which the reorganization start
		*/
		inline void reorganize_heap( uint64_t i )
		{
			uint64_t select;

			// checks if some node must be put to the top
			while(i > 0 && (heap_t[i].value > heap_t[father( i )].value)){
				swap( &heap_t[i], &heap_t[father( i )] );
				i = father( i );
			}

			// checks if some node must be put on the bottom
			while(left_node( i ) < heap_size && i != max_father_children( i )){
				select = max_father_children( i );
				swap( &heap_t[i], &heap_t[select] );
				i = select;
			}
		}
Exemple #19
0
bool widget::is_senior(widget* widget) const
{
    class widget* w = father();

    while (w && w != widget)
        w = w->father();

    return w;
}
/**
    \fn checkHeader
    \brief Check that we are compatible with that version of matroska. At the moment, just dump some infos.
*/
uint8_t mkvHeader::checkHeader(void *head,uint32_t headlen)
{
  printf("[MKV] *** Header dump ***\n");
 ADM_ebml_file father( (ADM_ebml_file *)head,headlen);
 walk(&father);
 printf("[MKV] *** End of Header dump ***\n");
 return 1;

}
Exemple #21
0
void run() {
  pid = fork();
  if (pid < 0) {
    die("fork: %m");
  } else if (pid == 0) {
    child();
  } else {
    father();
  }
}
Exemple #22
0
int main (int  argc,
	  char **argv)
{
  int loop = 1;
  char *svname;

  svname = set_svname(argc, argv, &loop);
  init_act(svname);
  father(svname, loop);
}
Exemple #23
0
 int countComponents(int n, vector<pair<int, int>>& edges) {
     
     vector<int> father(n);
     vector<int> size(n,1);
     
     for(int i = 0 ; i < n; ++i) father[i] = i;
     
     for(auto &edge: edges) {
         Union(edge.first, edge.second, father, size);
     }
     int cnt = 0;
     for(int i = 0; i < n; ++i) if(father[i] == i) ++cnt;
     return cnt;
 }
Exemple #24
0
int main(int argc, char** argv) {

   	 familyNode 
   	 
	 mather("valentina","hotchenkova",59,true,0),
	 father("alexandr","hotchenkov",58,false,0),
	 first_son("maxim","hotchenkov",34,false,&mather),
	 junior_son("alexey","hotchenkov",24,false,&mather),
	 junior_son_girl_friend("irina","kilchevskaya",20,true,0),
	 wife_first_son("nataly","hotchenkova",30,true,0),
	 first_niece("anna","hotchenkova",5,true,&first_son),
	 junior_nience("olga","hotchenkova",2,true,&first_son);
			

	return 0;
}
Exemple #25
0
    __INLINE ElementRef
    ElementRef::getFather ()
    {
        if (getElementPtr() == getDocument().rootElementPtr)
        {
            return ElementRef(getDocument());
        }
        ElementRef father( document, getMe<Read>()->fatherPtr);
#ifdef __XEM_DOM_NODEREF_CHROOT_USING_XEMINT_ROOT
        if ( 0 && father && father.getKeyId() == getKeyCache().getBuiltinKeys().xemint.root())
        {
            return ElementRef(getDocument(), 0);
        }
#endif // __XEM_DOM_NODEREF_CHROOT_USING_XEMINT_ROOT
        return father;
    }
Exemple #26
0
int main(void) {

    short int i;

    srand(time(NULL));

    initialize();

    puts("To πρόγραμμα εξυπηρετεί Χ αιτήσεις όπου Χ ένας τυχαίος αριθμός");
    puts("αιτήσεων ο οποίος δημιουργήθηκε σε n δευτερόλεπτα.");
    puts("\nΣημείωση:");
    puts("Ο χρόνος που θα δημιουργεί αιτήσεις δεν εχει σχέση με τον χρόνο");
    puts("που θα εκτελείται το πρόγραμμα");
    puts("\nΕισήγαγε τα n δευτερόλεπτα που το πρόγραμμα θα δημιουργεί");
    puts("αιτήσεις:");

    /* Εισήγαγε μη μηδενική τιμή */
    do {
	scanf("%d", &EndTime);
    } while (EndTime < 0);

    for (i = 0; i < 10; i++) {
	pid_c[i] = fork();
	switch (pid_c[i]) {
	    case 0:
		childs(i);
		flag_c = TRUE;
		break; //case break
	    case -1:
		perror("Fork SSTF");
		return Error;
	}
	//Αν είσαι παιδί κάνε break απ'το for
	if (flag_c == TRUE) {
	    break;
	}
    }

    if (flag_c == FALSE) {
	father();
    }

    return (EXIT_SUCCESS);
}
    /**
     * @param n an integer
     * @param m an integer
     * @param operators an array of point
     * @return an integer array
     */
    vector<int> numIslands2(int n, int m, vector<Point> &operators) {
        // Write your code here
        vector<int> res;
        if(n == 0 || m == 0) return res;
        vector<vector<int>> grid(n, vector<int>(m, 0));
        vector<int> father(n * m, -1);
        int sz = operators.size();
        for(int i = 0; i < sz; i++) {
            int x = operators[i].x;
            int y = operators[i].y;
            grid[x][y] = 1;
            int t = x * m + y;
            int ft = find(father, t);
            if(i == 0) {
                res.push_back(1);
                continue;
            }
            unordered_set<int> s;
            for(int k = 0; k < 4; k++) {
                int nx = x + dx[k];
                int ny = y + dy[k];
                int nt = nx * m + ny;
                if(!inBound(nx, ny, n, m)) continue;
                if(grid[nx][ny] == 0) continue;
                s.insert(find(father, nt));
            }
            res.push_back(res.back() + 1 - s.size());

            for(int k = 0; k < 4; k++) {
                int nx = x + dx[k];
                int ny = y + dy[k];
                int nt = nx * m + ny;
                if(!inBound(nx, ny, n, m)) continue;
                if(grid[nx][ny] == 0) continue;
                ft = find(father, t);
                int fnt = find(father, nt);
                father[ft] = min(ft, fnt);
                father[fnt] = min(ft, fnt);
            }
        }

        return res;
    }
Exemple #28
0
    vector<int> numIslands2(int m, int n, vector<pair<int, int>>& positions) {
        vector<int> res;
        if(n == 0 || m == 0) return res;
        vector<int> father(n * m, -1);
        vector<int> rank(n * m, 0);
        int sz = positions.size();
        for(int i = 0; i < sz; i++) {
            int x = positions[i].first;
            int y = positions[i].second;
            int t = x * n + y;
            int ft = find(father, t);
            if(i == 0) {
                res.push_back(1);
                continue;
            }

            int cnt = res.back() + 1;
            for(int k = 0; k < 4; k++) {
                int nx = x + dx[k];
                int ny = y + dy[k];
                int nt = nx * n + ny;
                if(!inBound(nx, ny, m, n)) continue;
                if(father[nt] == -1) continue;
                ft = find(father, t);
                int fnt = find(father, nt);
                if(ft != fnt) {
                    cnt--;
                    if(rank[ft] < rank[fnt]) {
                        father[ft] = fnt;
                    } else if(rank[fnt] < rank[ft]) {
                        father[fnt] = ft;
                    } else {
                        father[ft] = fnt;
                        rank[fnt]++;
                    }
                }
            }
            res.push_back(cnt);
        }

        return res;
    }
Exemple #29
0
int main(int argc, char *argv[]) {
  char *cmd;

  if (argc < 2) {
    cmd = "/bin/sh";
  }
  else {
    cmd = argv[1];
  }

  int master_fd = create_master();
  if (master_fd < 0) {
    return -1;
  }

  char *pts = ptsname(master_fd);

  printf("master = %d\n", master_fd);
  printf("cpath = %s\n", pts);

  int slave_fd = open(pts, O_RDWR);
  pid_t pid = fork();

  if (pid > 0) {
    // Father
    close(slave_fd);
    father(master_fd);
  }
  else if (pid == 0) {
    // Child
    close(master_fd);
    child(slave_fd, pts, cmd);
  }
  else {
    perror("fork");
    return -1;
  }

  return 0;
}
Exemple #30
0
	void GTPopulation::reproduction()
	{
		vector<GTOrganism*> newOrganisms;

		for(unsigned int i{0}; i < organisms.size(); ++i)
		{
			int m{getRnd(0, matingPool.size() - 1)};
			int d{getRnd(0, matingPool.size() - 1)};

			GTOrganism& mother(*matingPool[m]);
			GTOrganism& father(*matingPool[d]);

			GTDna childDna{mother.dna.crossover(father.dna)};
			childDna.mutate(mutationRate);

			newOrganisms.push_back(new GTOrganism{childDna});
		}

		for(const auto& o : organisms) delete o;
		organisms = newOrganisms;
		++generation;
	}