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