1*d291ea28SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*d291ea28SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*d291ea28SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*d291ea28SAndrew Rist * distributed with this work for additional information
6*d291ea28SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*d291ea28SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*d291ea28SAndrew Rist * "License"); you may not use this file except in compliance
9*d291ea28SAndrew Rist * with the License. You may obtain a copy of the License at
10*d291ea28SAndrew Rist *
11*d291ea28SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*d291ea28SAndrew Rist *
13*d291ea28SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*d291ea28SAndrew Rist * software distributed under the License is distributed on an
15*d291ea28SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*d291ea28SAndrew Rist * KIND, either express or implied. See the License for the
17*d291ea28SAndrew Rist * specific language governing permissions and limitations
18*d291ea28SAndrew Rist * under the License.
19*d291ea28SAndrew Rist *
20*d291ea28SAndrew Rist *************************************************************/
21cdf0e10cSrcweir
22cdf0e10cSrcweir #include <precomp.h>
23cdf0e10cSrcweir #include "loca_le.hxx"
24cdf0e10cSrcweir
25cdf0e10cSrcweir
26cdf0e10cSrcweir // NOT FULLY DEFINED SERVICES
27cdf0e10cSrcweir #include <ary/loc/loc_dir.hxx>
28cdf0e10cSrcweir #include <ary/loc/loc_file.hxx>
29cdf0e10cSrcweir #include <ary/loc/loc_root.hxx>
30cdf0e10cSrcweir #include <loc_internalgate.hxx>
31cdf0e10cSrcweir #include "locs_le.hxx"
32cdf0e10cSrcweir
33cdf0e10cSrcweir
34cdf0e10cSrcweir
35cdf0e10cSrcweir
36cdf0e10cSrcweir namespace ary
37cdf0e10cSrcweir {
38cdf0e10cSrcweir namespace loc
39cdf0e10cSrcweir {
40cdf0e10cSrcweir
41cdf0e10cSrcweir DYN LocationPilot &
Create_Locations_()42cdf0e10cSrcweir InternalGate::Create_Locations_()
43cdf0e10cSrcweir {
44cdf0e10cSrcweir return *new LocationAdmin;
45cdf0e10cSrcweir }
46cdf0e10cSrcweir
47cdf0e10cSrcweir
48cdf0e10cSrcweir
49cdf0e10cSrcweir
50cdf0e10cSrcweir inline Le_Storage &
Storage() const51cdf0e10cSrcweir LocationAdmin::Storage() const
52cdf0e10cSrcweir {
53cdf0e10cSrcweir csv_assert(pStorage);
54cdf0e10cSrcweir return *pStorage.MutablePtr();
55cdf0e10cSrcweir }
56cdf0e10cSrcweir
57cdf0e10cSrcweir
LocationAdmin()58cdf0e10cSrcweir LocationAdmin::LocationAdmin()
59cdf0e10cSrcweir : pStorage(new Le_Storage)
60cdf0e10cSrcweir {
61cdf0e10cSrcweir }
62cdf0e10cSrcweir
~LocationAdmin()63cdf0e10cSrcweir LocationAdmin::~LocationAdmin()
64cdf0e10cSrcweir {
65cdf0e10cSrcweir }
66cdf0e10cSrcweir
67cdf0e10cSrcweir Root &
CheckIn_Root(const csv::ploc::Path & i_path)68cdf0e10cSrcweir LocationAdmin::CheckIn_Root(const csv::ploc::Path & i_path)
69cdf0e10cSrcweir {
70cdf0e10cSrcweir Dyn<Root>
71cdf0e10cSrcweir p_new( new Root(i_path) );
72cdf0e10cSrcweir
73cdf0e10cSrcweir Le_id
74cdf0e10cSrcweir id = Storage().RootIndex().Search(p_new->LocalName());
75cdf0e10cSrcweir if ( id.IsValid() )
76cdf0e10cSrcweir {
77cdf0e10cSrcweir return ary_cast<Root>(Storage()[id]);
78cdf0e10cSrcweir }
79cdf0e10cSrcweir
80cdf0e10cSrcweir Root *
81cdf0e10cSrcweir ret = p_new.Ptr();
82cdf0e10cSrcweir Storage().Store_Entity(*p_new.Release());
83cdf0e10cSrcweir Storage().RootIndex().Add(ret->LeId());
84cdf0e10cSrcweir
85cdf0e10cSrcweir Directory *
86cdf0e10cSrcweir p_rootdir = new Directory(ret->LeId());
87cdf0e10cSrcweir Storage().Store_Entity(*p_rootdir);
88cdf0e10cSrcweir ret->Assign_Directory(p_rootdir->LeId());
89cdf0e10cSrcweir
90cdf0e10cSrcweir return *ret;
91cdf0e10cSrcweir }
92cdf0e10cSrcweir
93cdf0e10cSrcweir File &
CheckIn_File(const String & i_name,const csv::ploc::DirectoryChain & i_subPath,Le_id i_root)94cdf0e10cSrcweir LocationAdmin::CheckIn_File( const String & i_name,
95cdf0e10cSrcweir const csv::ploc::DirectoryChain & i_subPath,
96cdf0e10cSrcweir Le_id i_root )
97cdf0e10cSrcweir {
98cdf0e10cSrcweir Root &
99cdf0e10cSrcweir root = Find_Root(i_root);
100cdf0e10cSrcweir Directory &
101cdf0e10cSrcweir parent_dir = CheckIn_Directories(
102cdf0e10cSrcweir Find_Directory(root.MyDir()),
103cdf0e10cSrcweir i_subPath.Begin(),
104cdf0e10cSrcweir i_subPath.End() );
105cdf0e10cSrcweir Le_id
106cdf0e10cSrcweir fid = parent_dir.Search_File(i_name);
107cdf0e10cSrcweir if (NOT fid.IsValid())
108cdf0e10cSrcweir {
109cdf0e10cSrcweir File *
110cdf0e10cSrcweir ret = new File(i_name, parent_dir.LeId());
111cdf0e10cSrcweir Storage().Store_Entity(*ret);
112cdf0e10cSrcweir parent_dir.Add_File(*ret);
113cdf0e10cSrcweir return *ret;
114cdf0e10cSrcweir }
115cdf0e10cSrcweir else
116cdf0e10cSrcweir {
117cdf0e10cSrcweir return Find_File(fid);
118cdf0e10cSrcweir }
119cdf0e10cSrcweir }
120cdf0e10cSrcweir
121cdf0e10cSrcweir Root &
Find_Root(Le_id i_id) const122cdf0e10cSrcweir LocationAdmin::Find_Root(Le_id i_id) const
123cdf0e10cSrcweir {
124cdf0e10cSrcweir return ary_cast<Root>(Storage()[i_id]);
125cdf0e10cSrcweir }
126cdf0e10cSrcweir
127cdf0e10cSrcweir Directory &
Find_Directory(Le_id i_id) const128cdf0e10cSrcweir LocationAdmin::Find_Directory(Le_id i_id) const
129cdf0e10cSrcweir {
130cdf0e10cSrcweir return ary_cast<Directory>(Storage()[i_id]);
131cdf0e10cSrcweir }
132cdf0e10cSrcweir
133cdf0e10cSrcweir File &
Find_File(Le_id i_id) const134cdf0e10cSrcweir LocationAdmin::Find_File(Le_id i_id) const
135cdf0e10cSrcweir {
136cdf0e10cSrcweir return ary_cast<File>(Storage()[i_id]);
137cdf0e10cSrcweir }
138cdf0e10cSrcweir
139cdf0e10cSrcweir Directory &
CheckIn_Directory(Directory & io_parent,const String & i_name)140cdf0e10cSrcweir LocationAdmin::CheckIn_Directory( Directory & io_parent,
141cdf0e10cSrcweir const String & i_name )
142cdf0e10cSrcweir {
143cdf0e10cSrcweir Le_id
144cdf0e10cSrcweir did = io_parent.Search_Dir(i_name);
145cdf0e10cSrcweir if (NOT did.IsValid())
146cdf0e10cSrcweir {
147cdf0e10cSrcweir Directory *
148cdf0e10cSrcweir ret = new Directory(i_name, io_parent.LeId());
149cdf0e10cSrcweir Storage().Store_Entity(*ret);
150cdf0e10cSrcweir io_parent.Add_Dir(*ret);
151cdf0e10cSrcweir return *ret;
152cdf0e10cSrcweir }
153cdf0e10cSrcweir else
154cdf0e10cSrcweir {
155cdf0e10cSrcweir return Find_Directory(did);
156cdf0e10cSrcweir }
157cdf0e10cSrcweir }
158cdf0e10cSrcweir
159cdf0e10cSrcweir Directory &
CheckIn_Directories(Directory & io_root,StringVector::const_iterator i_beginSubPath,StringVector::const_iterator i_endSubPath)160cdf0e10cSrcweir LocationAdmin::CheckIn_Directories(
161cdf0e10cSrcweir Directory & io_root,
162cdf0e10cSrcweir StringVector::const_iterator i_beginSubPath,
163cdf0e10cSrcweir StringVector::const_iterator i_endSubPath )
164cdf0e10cSrcweir {
165cdf0e10cSrcweir if (i_beginSubPath == i_endSubPath)
166cdf0e10cSrcweir return io_root;
167cdf0e10cSrcweir
168cdf0e10cSrcweir Directory &
169cdf0e10cSrcweir next = CheckIn_Directory(io_root, *i_beginSubPath);
170cdf0e10cSrcweir return CheckIn_Directories(next, i_beginSubPath+1, i_endSubPath);
171cdf0e10cSrcweir }
172cdf0e10cSrcweir
173cdf0e10cSrcweir
174cdf0e10cSrcweir } // namespace loc
175cdf0e10cSrcweir } // namespace ary
176