Example #1
0
void Tree::ToFileNodeRooted(TextFile &File, unsigned uNodeIndex) const
	{
	assert(IsRooted());

	bool bGroup = !IsLeaf(uNodeIndex) || IsRoot(uNodeIndex);
	if (bGroup)
		File.PutString("(\n");

	if (IsLeaf(uNodeIndex))
		File.PutString(GetName(uNodeIndex));
	else
		{
		ToFileNodeRooted(File, GetLeft(uNodeIndex));
		File.PutString(",\n");
		ToFileNodeRooted(File, GetRight(uNodeIndex));
		}

	if (bGroup)
		File.PutString(")");

	if (!IsRoot(uNodeIndex))
		{
		unsigned uParent = GetParent(uNodeIndex);
		if (HasEdgeLength(uNodeIndex, uParent))
			File.PutFormat(":%g", GetEdgeLength(uNodeIndex, uParent));
		}
	File.PutString("\n");
	}
Example #2
0
// Travel backward in directory structure
BOOL CFileManip::CdDotDot(LPTSTR lpCurDirectory)
{
	// Travel backward one directory level, same as DOS
	// command "cd.." does.
	TCHAR szCurDir[MAX_PATH + 1] = _T("");
	::GetCurrentDirectory(MAX_PATH, szCurDir);
	if (IsRoot(szCurDir) != 0)
		return FALSE; // root reached
	
	int nLen = ::_tcslen(szCurDir);
	for (int i = nLen - 1; i >= 0; i--)
	{
		if (szCurDir[i] == _T('\\'))
		{
			szCurDir[i] = _T('\0');
			if (lpCurDirectory != NULL)
				::_tcscpy(lpCurDirectory, szCurDir);

			if (IsRoot(szCurDir) != 0)
				return FALSE; // root reached

			::SetCurrentDirectory(szCurDir);
			return TRUE; // Moved backward successfully
		}
	}
	
	if (lpCurDirectory != NULL)
		::_tcscpy(lpCurDirectory, szCurDir);
	return FALSE; // Already at root directory
}
Example #3
0
void TreeServer::SQuitChild(TreeServer* server, const std::string& reason)
{
	stdalgo::erase(Children, server);

	if (IsRoot())
	{
		// Server split from us, generate a SQUIT message and broadcast it
		ServerInstance->SNO->WriteGlobalSno('l', "Server \002" + server->GetName() + "\002 split: " + reason);
		CmdBuilder("SQUIT").push(server->GetID()).push_last(reason).Broadcast();
	}
	else
	{
		ServerInstance->SNO->WriteToSnoMask('L', "Server \002" + server->GetName() + "\002 split from server \002" + GetName() + "\002 with reason: " + reason);
	}

	unsigned int num_lost_servers = 0;
	server->SQuitInternal(num_lost_servers);

	const std::string quitreason = GetName() + " " + server->GetName();
	unsigned int num_lost_users = QuitUsers(quitreason);

	ServerInstance->SNO->WriteToSnoMask(IsRoot() ? 'l' : 'L', "Netsplit complete, lost \002%u\002 user%s on \002%u\002 server%s.",
		num_lost_users, num_lost_users != 1 ? "s" : "", num_lost_servers, num_lost_servers != 1 ? "s" : "");

	// No-op if the socket is already closed (i.e. it called us)
	if (server->IsLocal())
		server->GetSocket()->Close();

	// Add the server to the cull list, the servers behind it are handled by cull() and the destructor
	ServerInstance->GlobalCulls.AddItem(server);
}
Example #4
0
static void
RootlessPaintWindowBackground(WindowPtr pWin, RegionPtr pRegion, int what)
{
    int oldBackgroundState = 0;
    PixUnion oldBackground;
    ScreenPtr pScreen = pWin->drawable.pScreen;

    SCREEN_UNWRAP(pScreen, PaintWindowBackground);
    RL_DEBUG_MSG("paintwindowbackground start (win 0x%x) ", pWin);
    if (IsFramedWindow(pWin)) {
        if (IsRoot(pWin)) {
            // set root background to magic transparent color
            oldBackgroundState = pWin->backgroundState;
            oldBackground = pWin->background;
            pWin->backgroundState = BackgroundPixel;
            pWin->background.pixel = 0x00fffffe;
        }
    }

    pScreen->PaintWindowBackground(pWin, pRegion, what);

    if (IsFramedWindow(pWin)) {
        RootlessDamageRegion(pWin, pRegion);
        if (IsRoot(pWin)) {
            pWin->backgroundState = oldBackgroundState;
            pWin->background = oldBackground;
        }
    }
    SCREEN_WRAP(pScreen, PaintWindowBackground);
    RL_DEBUG_MSG("paintwindowbackground end\n");
}
Example #5
0
void DemoCollection::PopulateList( void ) {
	std::string fullPath = std::string( PATH_ROOT ) + ( IsRoot() ? "" : "/" + path );

	// populate the list of directories and demo files
	demoList.clear();

	if( !IsRoot() ) {
		// back dir ".."
		demoList.push_back( PATH_PARENT );
	}

	DirList dirList;
	dirList.clear();

	getFileList( dirList, fullPath, "/", true );
	for( DirList::iterator it = dirList.begin(); it != dirList.end(); ++it ) {
		std::string fullName = *it + "/";
		demoList.push_back( fullName );
	}

	// populate directories
	numDirectories = demoList.size();

	getFileList( demoList, fullPath, demoExtension.c_str(), true );
}
Example #6
0
std::string DemoCollection::GetItemPath( const int index ) const {
	if( !index && !IsRoot() ) {
		// return path to part dir
		return GetPathToParentDir();
	}

	assert( index >= 0 && index < int(demoList.size() ) );
	return ( IsRoot() ? "" : path + "/" ) + demoList[index];
}
Example #7
0
void UnionFind::GetRoots(std::vector<int>& roots) const
{
  roots.resize(0);
  for(size_t i=0;i<parents.size();i++)
    if(IsRoot((int)i))
       roots.push_back((int)i);
}
Example #8
0
size_t UnionFind::CountSets() const
{
  size_t n=0;
  for(size_t i=0;i<parents.size();i++)
    if(IsRoot((int)i)) n++;
  return n;
}
Example #9
0
File: data.cpp Project: darkk/porto
    uint64_t GetDefault() const override {
        auto c = GetContainer();

        if (c->IsRoot()) {
            struct sysinfo si;
            int ret = sysinfo(&si);
            if (ret)
                return -1;

            return si.uptime;
        }

        // we started recording raw start/death time since porto v1.15;
        // in case we updated from old version, return zero
        if (!c->Prop->Get<uint64_t>(P_RAW_START_TIME))
            c->Prop->Set<uint64_t>(P_RAW_START_TIME, GetCurrentTimeMs());

        if (!c->Prop->Get<uint64_t>(P_RAW_DEATH_TIME))
            c->Prop->Set<uint64_t>(P_RAW_DEATH_TIME, GetCurrentTimeMs());

        if (c->GetState() == EContainerState::Dead)
            return (c->Prop->Get<uint64_t>(P_RAW_DEATH_TIME) -
                    c->Prop->Get<uint64_t>(P_RAW_START_TIME)) / 1000;
        else
            return (GetCurrentTimeMs() -
                    c->Prop->Get<uint64_t>(P_RAW_START_TIME)) / 1000;
    }
Example #10
0
void CUITreeViewItem::SendMessage(CUIWindow* pWnd, s16 msg, void* pData)
{
	static CUITreeViewItem *pPrevFocusedItem = NULL;

	if (pWnd == this && BUTTON_CLICKED == msg)
	{
		if (IsRoot())
		{
			IsOpened() ? Close() : Open();
		}
		else
		{
			MarkArticleAsRead(true);
		}
	}
	else if (pWnd == this && STATIC_FOCUS_RECEIVED == msg)
	{
		UIBkg.TextureOn();

		if (pPrevFocusedItem)
		{
			pPrevFocusedItem->UIBkg.TextureOff();
		}
		pPrevFocusedItem = this;
	}
	else if (pWnd == this && STATIC_FOCUS_LOST == msg)
	{
		UIBkg.TextureOff();
		pPrevFocusedItem = NULL;
	}
	else
		inherited::SendMessage(pWnd, msg, pData);
}
Example #11
0
bool
ZXmlParser::_add_before( IXMLDOMNodePtr newNode )
{
   if ( IsRoot( ) )
   {
      m_LastError = "ZXmlParser::_add_before( )   : Can't add node at same level that the root node";
      return( false );
   }

   // Create Reference Node for the Insertion
   IXMLDOMNodePtr pParent;
   m_CurrentNode->get_parentNode( &pParent );
   _variant_t NodeRef = (IUnknown *) m_CurrentNode;


   // Attach the Node to the document
   if ( m_CurrentNode )
          newNode = pParent->insertBefore( newNode, NodeRef );
   else
   if ( m_pDocRoot )
      newNode = m_pDocRoot->insertBefore( newNode, NodeRef );
   else
   {
      m_pDocRoot = newNode;
      m_plDomDocument->documentElement = m_pDocRoot;
   }

   // Update Current Node (cast operation)
   m_CurrentNode = newNode;

   // Update information for this Node
   GrabNodeInformation( m_CurrentNode );

   return( true );
}
 StatementReference::StatementReference()
 {
   root_ = NULL;
   refCount_ = 0;
   statement_ = NULL;
   assert(IsRoot());
 }
Example #13
0
/*
 * RootlessValidateTree
 *  ValidateTree is modified in two ways:
 *   - top-level windows don't clip each other
 *   - windows aren't clipped against root.
 *  These only matter when validating from the root.
 */
static int
RootlessValidateTree(WindowPtr pParent, WindowPtr pChild, VTKind kind)
{
    int result;
    RegionRec saveRoot;
    ScreenPtr pScreen = pParent->drawable.pScreen;

    SCREEN_UNWRAP(pScreen, ValidateTree);
    RL_DEBUG_MSG("VALIDATETREE start ");

    // Use our custom version to validate from root
    if (IsRoot(pParent)) {
        RL_DEBUG_MSG("custom ");
        result = RootlessMiValidateTree(pParent, pChild, kind);
    } else {
        HUGE_ROOT(pParent);
        result = pScreen->ValidateTree(pParent, pChild, kind);
        NORMAL_ROOT(pParent);
    }

    SCREEN_WRAP(pScreen, ValidateTree);
    RL_DEBUG_MSG("VALIDATETREE end\n");

    return result;
}
JString
JVMVarNode::GetFullName
	(
	JBoolean* isPointer
	)
	const
{
	JString str;
	if (IsRoot())
		{
		return str;
		}

	const JVMVarNode* parent = dynamic_cast<const JVMVarNode*>(GetVarParent());
	const JString& name      = GetName();
	if (parent->IsRoot())
		{
		str = "(" + name + ")";
		}
	else if (name.IsEmpty())
		{
		JIndex i;
		const JBoolean found = parent->FindChild(this, &i);
		assert( found );
		str = parent->GetFullName(isPointer);
		if (!str.BeginsWith("(") || !str.EndsWith(")"))
			{
			str.PrependCharacter('(');
			str.AppendCharacter(')');
			}
		str += "[" + JString(i-1, JString::kBase10) + "]";
		}
	else if (name.BeginsWith("<"))
		{
		if (isPointer != NULL)
			{
			*isPointer = parent->IsPointer();
			}
		str = parent->GetFullName(isPointer);
		}
	else if (name.BeginsWith("["))
		{
		str = parent->GetFullName(isPointer) + name;
		}
	else if (name.BeginsWith("*"))
		{
		str = parent->GetPath() + "(" + name + ")";
		}
	else
		{
		str = name;
		if (str.BeginsWith("static "))
			{
			str.RemoveSubstring(1,7);
			}
		str.Prepend(parent->GetPath());
		}

	return str;
}
Example #15
0
void StateNode::ContributeToMenu(QMenu *menu)
{
    menu->addAction("Connect",this, SLOT(Connect()));
    menu->addAction("Remove", this, SLOT(Remove()));
    if(IsRoot() == false)
        menu->addAction("Set As Root",this, SLOT(SetAsRoot()));
}
Example #16
0
QRect CWndControl::GetLayoutRect() const
{
    QRect rect(QPoint(0, 0), m_clientRect.size());
    if (!IsRoot() && !HasFlag(WBS_NOFRAME))
        rect = QRect(QPoint(8, 8), m_clientRect.size() - QSize(16, 16));
    return rect;
}
Example #17
0
void CUITreeViewItem::MarkArticleAsRead(bool value)
{
	// Если элемент рутовый, то мы его маркаем его, и все чилды
	if (IsRoot())
	{
		m_bArticleRead = value;
		if(!m_bManualSetColor)
			SetItemColor();

		for (SubItems_it it = vSubItems.begin(); it != vSubItems.end(); ++it)
		{
			(*it)->m_bArticleRead = value;
			(*it)->SetItemColor();
			if ((*it)->IsRoot())
				(*it)->MarkArticleAsRead(value);
		}
	}
	else
	{
		// Если же нет, то маркаем себя и говорим проверить свой парентовый элемент
		m_bArticleRead	= value;
		if(!m_bManualSetColor)
			SetItemColor();
		CheckParentMark(GetOwner());
	}
}
BOOL CBaseObject::CanFindRoot(void)
{
	ValidateNotEmbedded(__METHOD__);

	CEmbeddedObject*				pcPointedFrom;
	BOOL							bResult;

	if (IsRoot())
	{
		return TRUE;
	}

	SetFlag(OBJECT_FLAGS_TESTED_FOR_ROOT, TRUE);

	pcPointedFrom = GetClosestFromForCanFindRoot();
	if (pcPointedFrom == NULL)
	{
		SetFlag(OBJECT_FLAGS_TESTED_FOR_ROOT, FALSE);
		return FALSE;
	}

	bResult = pcPointedFrom->GetEmbeddingContainer()->CanFindRoot();

	SetFlag(OBJECT_FLAGS_TESTED_FOR_ROOT, FALSE);
	return bResult;
}
Example #19
0
	Path Path::getParent()
	{
		if(m_sPath.length() == 0 || IsRoot())
		{
			// return empty path.
			return Path("");
		}
		
		// reverse find a / ignoring the end / if it exists.
		std::string::size_type nLength(m_sPath.length());
		std::string::size_type nOffset ((m_sPath[nLength - 1] == PATH_SEPARATOR_CHAR && nLength - 2 > 0) ? nLength - 2 : std::string::npos);
		std::string::size_type nPos (m_sPath.rfind(PATH_SEPARATOR_STR, nOffset));
		
		// create new path object given position of find / and return it.
		if(nPos != std::string::npos)
		{
	#if defined(_WINDOWS)
			return Path(m_sDrive + m_sPath.substr(0, nPos + 1), false);
	#else
			return Path(m_sPath.substr(0, nPos + 1), false);
	#endif
		}
		else
		{
			// not parent path avaliable, return an empty path.
			return Path("");
		}    
	}
 StatementReference::~StatementReference()
 {
   if (IsRoot())
   {
     if (refCount_ != 0)
     {
       // There remain references to this object
       throw OrthancException(ErrorCode_InternalError);
     }
     else if (statement_ != NULL)
     {
       sqlite3_finalize(statement_);
     }
   }
   else
   {
     if (root_->refCount_ == 0)
     {
       throw OrthancException(ErrorCode_InternalError);
     }
     else
     {
       root_->refCount_--;
     }
   }
 }
		ScoredNode* GetRootConnection()
		{
			if (IsRoot())
				return nullptr;
			if (prev->IsRoot())
				return this;
			return prev->GetRootConnection();
		}
/*
 * Create and display a new frame.
 */
static Bool
xprCreateFrame(RootlessWindowPtr pFrame, ScreenPtr pScreen,
               int newX, int newY, RegionPtr pShape)
{
    WindowPtr pWin = pFrame->win;
    xp_window_changes wc;
    unsigned int mask = 0;
    xp_error err;

    wc.x = newX;
    wc.y = newY;
    wc.width = pFrame->width;
    wc.height = pFrame->height;
    wc.bit_gravity = XP_GRAVITY_NONE;
    mask |= XP_BOUNDS;

    if (pWin->drawable.depth == 8) {
        wc.depth = XP_DEPTH_INDEX8;
        wc.colormap = xprColormapCallback;
        wc.colormap_data = pScreen;
        mask |= XP_COLORMAP;
    }
    else if (pWin->drawable.depth == 15)
        wc.depth = XP_DEPTH_RGB555;
    else if (pWin->drawable.depth == 24)
        wc.depth = XP_DEPTH_ARGB8888;
    else
        wc.depth = XP_DEPTH_NIL;
    mask |= XP_DEPTH;

    if (pShape != NULL) {
        wc.shape_nrects = RegionNumRects(pShape);
        wc.shape_rects = RegionRects(pShape);
        wc.shape_tx = wc.shape_ty = 0;
        mask |= XP_SHAPE;
    }

    pFrame->level =
        !IsRoot(pWin) ? AppleWMWindowLevelNormal : AppleWMNumWindowLevels;

    if (XQuartzIsRootless)
        wc.window_level = normal_window_levels[pFrame->level];
    else if (XQuartzShieldingWindowLevel)
        wc.window_level = XQuartzShieldingWindowLevel + 1;
    else
        wc.window_level = rooted_window_levels[pFrame->level];
    mask |= XP_WINDOW_LEVEL;

    err = xp_create_window(mask, &wc, (xp_window_id *)&pFrame->wid);

    if (err != Success) {
        return FALSE;
    }

#ifdef HAVE_LIBDISPATCH
    dispatch_async(window_hash_serial_q, ^ {
                       x_hash_table_insert(window_hash, pFrame->wid, pFrame);
                   });
TreeServer::~TreeServer()
{
	/* We'd better tidy up after ourselves, eh? */
	if (!IsRoot())
		delete ServerUser;

	Utils->sidlist.erase(sid);
	Utils->serverlist.erase(GetName());
}
Example #24
0
void
VnodeToInode::Replace(Inode* newInode)
{
	WriteLocker _(fLock);
	if (!IsRoot())
		delete fInode;

	fInode = newInode;
}
void CBaseObject::ValidateCanFindRoot(void)
{
	ValidateNotEmbedded(__METHOD__);

	CChars			sz;
	BOOL			bCanFindRoot;

	if (miDistToRoot > ROOT_DIST_TO_ROOT)
	{
		bCanFindRoot = CanFindRoot();

		if (!bCanFindRoot)
		{
			sz.Init();
			PrintObject(&sz, IsEmbedded());
			gcLogger.Error2(__METHOD__, " Object {", sz.Text(), "} has a positive dist to root and should be able to find the Root object.", NULL);
			sz.Kill();
		}
	}
	else if (miDistToRoot == ROOT_DIST_TO_ROOT)
	{
		if (!IsRoot())
		{
			sz.Init();
			PrintObject(&sz, IsEmbedded());
			gcLogger.Error2(__METHOD__, " Object {", sz.Text(), "} has a dist to root [0] but is not the Root object.", NULL);
			sz.Kill();
		}
	}
	else if (miDistToRoot == UNATTACHED_DIST_TO_ROOT)
	{
		bCanFindRoot = CanFindRoot();

		if (bCanFindRoot)
		{
			sz.Init();
			PrintObject(&sz, IsEmbedded());
			gcLogger.Error2(__METHOD__, " Object {", sz.Text(), "} has an [UNATTACHED_DIST_TO_ROOT] dist to root should not be able to find the Root object.", NULL);
			sz.Kill();
		}
	}
	else if (miDistToRoot == CLEARED_DIST_TO_ROOT)
	{
		sz.Init();
		PrintObject(&sz, IsEmbedded());
		gcLogger.Error2(__METHOD__, " Object {", sz.Text(), "} should not have dist to root [CLEARED_DIST_TO_ROOT].", NULL);
		sz.Kill();
	}
	else
	{
		sz.Init();
		PrintObject(&sz, IsEmbedded());
		gcLogger.Error2(__METHOD__, " Object {", sz.Text(), "} should not have dist to root [", IntToString(miDistToRoot), "].", NULL);
		sz.Kill();
	}
}
Example #26
0
TreeServer::~TreeServer()
{
	// Recursively delete all servers that are under us in the tree first
	for (ChildServers::const_iterator i = Children.begin(); i != Children.end(); ++i)
		delete *i;

	// Delete server user unless it's us
	if (!IsRoot())
		delete ServerUser;
}
Example #27
0
void clRowEntry::SetHidden(bool b)
{
    if(b && !IsRoot()) { return; }
    SetFlag(kNF_Hidden, b);
    if(b) {
        m_indentsCount = -1;
    } else {
        m_indentsCount = 0;
    }
}
CButtonExd::~CButtonExd(void)
{
	for (int i=0;i<m_Childs.size();++i)
	{
		delete m_Childs[i];
	}
	m_Childs.clear();

	if(IsRoot()&& m_all!=NULL)
		delete m_all;
}
Example #29
0
void HierarchicalZipWriter::Index::CloseDirectory()
{
    if (IsRoot())
    {
        // Cannot close the root node
        throw OrthancException(ErrorCode_BadSequenceOfCalls);
    }

    delete stack_.back();
    stack_.pop_back();
}
Example #30
0
	FilePath FilePath::operator/(const WString& relativePath)const
	{
		if (IsRoot())
		{
			return relativePath;
		}
		else
		{
			return _fullPath + L"/" + relativePath;
		}
	}