Files
libreoffice/configmgr/source/tree/treefragment.cxx
Rüdiger Timm 31a4102e83 INTEGRATION: CWS changefileheader (1.7.16); FILE MERGED
2008/04/01 15:06:53 thb 1.7.16.3: #i85898# Stripping all external header guards
2008/04/01 12:27:33 thb 1.7.16.2: #i85898# Stripping all external header guards
2008/03/31 12:22:53 rt 1.7.16.1: #i87441# Change license header to LPGL v3.
2008-04-11 12:34:57 +00:00

141 lines
4.5 KiB
C++

/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2008 by Sun Microsystems, Inc.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* $RCSfile: treefragment.cxx,v $
* $Revision: 1.8 $
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_configmgr.hxx"
#include "treefragment.hxx"
#include "attributes.hxx"
#include <rtl/ustring.hxx>
// memset
#include <string.h>
namespace configmgr
{
//-----------------------------------------------------------------------------
namespace sharable
{
//-----------------------------------------------------------------------------
rtl::OUString TreeFragment::getName() const
{
return readString(this->header.name);
}
//-----------------------------------------------------------------------------
bool TreeFragment::isNamed(rtl::OUString const & _aName) const
{
// TODO: optimize comparison
return !!(this->getName() == _aName);
}
//-----------------------------------------------------------------------------
bool TreeFragment::hasDefaults() const
{
switch (this->header.state & State::mask_state)
{
default: OSL_ASSERT(false); // not reachable
case State::merged:
case State::defaulted: return true;
case State::replaced:
case State::added: return false;
}
}
//-----------------------------------------------------------------------------
bool TreeFragment::hasDefaultsAvailable() const
{
return (this->header.state & State::flag_default_avail) || isDefault();
}
//-----------------------------------------------------------------------------
bool TreeFragment::isDefault() const
{
return (this->header.state & State::mask_state) == State::defaulted;
}
//-----------------------------------------------------------------------------
bool TreeFragment::isNew() const
{
return (this->header.state & State::mask_state) == State::added;
}
//-----------------------------------------------------------------------------
configmgr::node::Attributes TreeFragment::getAttributes() const
{
configmgr::node::Attributes aResult;
switch (this->header.state & State::mask_state)
{
case State::merged: aResult.setState(configmgr::node::isMerged); break;
case State::defaulted: aResult.setState(configmgr::node::isDefault); break;
case State::replaced: aResult.setState(configmgr::node::isReplaced); break;
case State::added: aResult.setState(configmgr::node::isAdded); break;
default: OSL_ASSERT(false); break; // not reachable
}
aResult.setRemovability(!!(this->header.state & State::flag_removable),
!!(this->header.state & State::flag_mandatory));
OSL_ASSERT( header.count != 0 );
NodeInfo const & aRootNodeInfo = this->nodes[0].node.info;
aResult.setAccess( !!(this->header.state & State::flag_readonly),
!!(aRootNodeInfo.flags & Flags::finalized) );
aResult.setLocalized ( !!(aRootNodeInfo.flags & Flags::localized));
return aResult;
}
TreeFragment *TreeFragment::allocate(sal_uInt32 nFragments)
{
sal_uInt32 nSize = sizeof(TreeFragment) + sizeof(Node) * (nFragments-1);
sal_uInt8 *pMem = new sal_uInt8 [nSize];
memset (pMem, 0, nSize);
return reinterpret_cast<TreeFragment *>(pMem);
}
void TreeFragment::free_shallow(TreeFragment *pFragment )
{
delete[] (sal_uInt8 *) pFragment;
}
//-----------------------------------------------------------------------------
} // namespace sharable
//-----------------------------------------------------------------------------
} // namespace configmgr