merge the formfield patch from ooo-build
[ooovba.git] / autodoc / source / ary / loc / loca_le.cxx
blobdf7768a5ccba1d2ada59e8e6930b9626619ba8b5
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: loca_le.cxx,v $
10 * $Revision: 1.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include <precomp.h>
32 #include "loca_le.hxx"
35 // NOT FULLY DEFINED SERVICES
36 #include <ary/loc/loc_dir.hxx>
37 #include <ary/loc/loc_file.hxx>
38 #include <ary/loc/loc_root.hxx>
39 #include <loc_internalgate.hxx>
40 #include "locs_le.hxx"
45 namespace ary
47 namespace loc
50 DYN LocationPilot &
51 InternalGate::Create_Locations_()
53 return *new LocationAdmin;
59 inline Le_Storage &
60 LocationAdmin::Storage() const
62 csv_assert(pStorage);
63 return *pStorage.MutablePtr();
67 LocationAdmin::LocationAdmin()
68 : pStorage(new Le_Storage)
72 LocationAdmin::~LocationAdmin()
76 Root &
77 LocationAdmin::CheckIn_Root(const csv::ploc::Path & i_path)
79 Dyn<Root>
80 p_new( new Root(i_path) );
82 Le_id
83 id = Storage().RootIndex().Search(p_new->LocalName());
84 if ( id.IsValid() )
86 return ary_cast<Root>(Storage()[id]);
89 Root *
90 ret = p_new.Ptr();
91 Storage().Store_Entity(*p_new.Release());
92 Storage().RootIndex().Add(ret->LeId());
94 Directory *
95 p_rootdir = new Directory(ret->LeId());
96 Storage().Store_Entity(*p_rootdir);
97 ret->Assign_Directory(p_rootdir->LeId());
99 return *ret;
102 File &
103 LocationAdmin::CheckIn_File( const String & i_name,
104 const csv::ploc::DirectoryChain & i_subPath,
105 Le_id i_root )
107 Root &
108 root = Find_Root(i_root);
109 Directory &
110 parent_dir = CheckIn_Directories(
111 Find_Directory(root.MyDir()),
112 i_subPath.Begin(),
113 i_subPath.End() );
114 Le_id
115 fid = parent_dir.Search_File(i_name);
116 if (NOT fid.IsValid())
118 File *
119 ret = new File(i_name, parent_dir.LeId());
120 Storage().Store_Entity(*ret);
121 parent_dir.Add_File(*ret);
122 return *ret;
124 else
126 return Find_File(fid);
130 Root &
131 LocationAdmin::Find_Root(Le_id i_id) const
133 return ary_cast<Root>(Storage()[i_id]);
136 Directory &
137 LocationAdmin::Find_Directory(Le_id i_id) const
139 return ary_cast<Directory>(Storage()[i_id]);
142 File &
143 LocationAdmin::Find_File(Le_id i_id) const
145 return ary_cast<File>(Storage()[i_id]);
148 Directory &
149 LocationAdmin::CheckIn_Directory( Directory & io_parent,
150 const String & i_name )
152 Le_id
153 did = io_parent.Search_Dir(i_name);
154 if (NOT did.IsValid())
156 Directory *
157 ret = new Directory(i_name, io_parent.LeId());
158 Storage().Store_Entity(*ret);
159 io_parent.Add_Dir(*ret);
160 return *ret;
162 else
164 return Find_Directory(did);
168 Directory &
169 LocationAdmin::CheckIn_Directories(
170 Directory & io_root,
171 StringVector::const_iterator i_beginSubPath,
172 StringVector::const_iterator i_endSubPath )
174 if (i_beginSubPath == i_endSubPath)
175 return io_root;
177 Directory &
178 next = CheckIn_Directory(io_root, *i_beginSubPath);
179 return CheckIn_Directories(next, i_beginSubPath+1, i_endSubPath);
183 } // namespace loc
184 } // namespace ary