xref: /trunk/main/autodoc/source/ary/loc/loca_le.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #include <precomp.h>
29 #include "loca_le.hxx"
30 
31 
32 // NOT FULLY DEFINED SERVICES
33 #include <ary/loc/loc_dir.hxx>
34 #include <ary/loc/loc_file.hxx>
35 #include <ary/loc/loc_root.hxx>
36 #include <loc_internalgate.hxx>
37 #include "locs_le.hxx"
38 
39 
40 
41 
42 namespace ary
43 {
44 namespace loc
45 {
46 
47 DYN LocationPilot &
48 InternalGate::Create_Locations_()
49 {
50     return *new LocationAdmin;
51 }
52 
53 
54 
55 
56 inline Le_Storage &
57 LocationAdmin::Storage() const
58 {
59     csv_assert(pStorage);
60     return *pStorage.MutablePtr();
61 }
62 
63 
64 LocationAdmin::LocationAdmin()
65     :   pStorage(new Le_Storage)
66 {
67 }
68 
69 LocationAdmin::~LocationAdmin()
70 {
71 }
72 
73 Root &
74 LocationAdmin::CheckIn_Root(const csv::ploc::Path & i_path)
75 {
76     Dyn<Root>
77         p_new( new Root(i_path) );
78 
79     Le_id
80         id = Storage().RootIndex().Search(p_new->LocalName());
81     if ( id.IsValid() )
82     {
83         return ary_cast<Root>(Storage()[id]);
84     }
85 
86     Root *
87         ret = p_new.Ptr();
88     Storage().Store_Entity(*p_new.Release());
89     Storage().RootIndex().Add(ret->LeId());
90 
91     Directory *
92         p_rootdir = new Directory(ret->LeId());
93     Storage().Store_Entity(*p_rootdir);
94     ret->Assign_Directory(p_rootdir->LeId());
95 
96     return *ret;
97 }
98 
99 File &
100 LocationAdmin::CheckIn_File( const String  &                   i_name,
101                                   const csv::ploc::DirectoryChain & i_subPath,
102                                   Le_id                             i_root )
103 {
104     Root &
105         root = Find_Root(i_root);
106     Directory &
107         parent_dir = CheckIn_Directories(
108                         Find_Directory(root.MyDir()),
109                         i_subPath.Begin(),
110                         i_subPath.End() );
111     Le_id
112         fid = parent_dir.Search_File(i_name);
113     if (NOT fid.IsValid())
114     {
115         File *
116             ret = new File(i_name, parent_dir.LeId());
117         Storage().Store_Entity(*ret);
118         parent_dir.Add_File(*ret);
119         return *ret;
120     }
121     else
122     {
123         return Find_File(fid);
124     }
125 }
126 
127 Root &
128 LocationAdmin::Find_Root(Le_id  i_id) const
129 {
130     return ary_cast<Root>(Storage()[i_id]);
131 }
132 
133 Directory &
134 LocationAdmin::Find_Directory(Le_id i_id) const
135 {
136     return ary_cast<Directory>(Storage()[i_id]);
137 }
138 
139 File &
140 LocationAdmin::Find_File(Le_id i_id) const
141 {
142     return ary_cast<File>(Storage()[i_id]);
143 }
144 
145 Directory &
146 LocationAdmin::CheckIn_Directory( Directory &         io_parent,
147                                        const String &      i_name )
148 {
149     Le_id
150         did = io_parent.Search_Dir(i_name);
151     if (NOT did.IsValid())
152     {
153         Directory *
154             ret = new Directory(i_name, io_parent.LeId());
155         Storage().Store_Entity(*ret);
156         io_parent.Add_Dir(*ret);
157         return *ret;
158     }
159     else
160     {
161         return Find_Directory(did);
162     }
163 }
164 
165 Directory &
166 LocationAdmin::CheckIn_Directories(
167                             Directory &                     io_root,
168                             StringVector::const_iterator    i_beginSubPath,
169                             StringVector::const_iterator    i_endSubPath )
170 {
171     if (i_beginSubPath == i_endSubPath)
172         return io_root;
173 
174     Directory &
175         next = CheckIn_Directory(io_root, *i_beginSubPath);
176     return CheckIn_Directories(next, i_beginSubPath+1, i_endSubPath);
177 }
178 
179 
180 }   // namespace loc
181 }   // namespace ary
182