1%%--------------------------------------------------------------------
2%%
3%% %CopyrightBegin%
4%%
5%% Copyright Ericsson AB 1997-2016. All Rights Reserved.
6%%
7%% Licensed under the Apache License, Version 2.0 (the "License");
8%% you may not use this file except in compliance with the License.
9%% 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, software
14%% distributed under the License is distributed on an "AS IS" BASIS,
15%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16%% See the License for the specific language governing permissions and
17%% limitations under the License.
18%%
19%% %CopyrightEnd%
20%%
21%%
22%%-----------------------------------------------------------------
23%% File: CosNaming_BindingIterator_impl.erl
24%%
25%%-----------------------------------------------------------------
26-module('CosNaming_BindingIterator_impl').
27
28-include_lib("orber/include/corba.hrl").
29-include("CosNaming.hrl").
30-include("orber_cosnaming.hrl").
31
32
33%%-----------------------------------------------------------------
34%% External exports
35%%-----------------------------------------------------------------
36-export([init/1, terminate/2, code_change/3]).
37-export([next_one/1, next_n/2, destroy/1]).
38
39%%-----------------------------------------------------------------
40%% Internal exports
41%%-----------------------------------------------------------------
42-export([]).
43
44%%-----------------------------------------------------------------
45%% External interface functions
46%%-----------------------------------------------------------------
47%%-----------------------------------------------------------------
48%% Func: init/1
49%% Args:
50%% Returns:
51%%-----------------------------------------------------------------
52init(State) ->
53    {ok, State}.
54
55%%-----------------------------------------------------------------
56%% Func: terminate/2
57%% Args:
58%% Returns:
59%%-----------------------------------------------------------------
60terminate(_Reason, _State) ->
61    ok.
62
63code_change(_OldVsn, State, _Extra) ->
64    {ok, State}.
65
66next_one([]) ->
67    NoBinding = #'CosNaming_Binding'{binding_name=[],
68				     binding_type=nobject},
69    {reply, {false, NoBinding}, []};
70next_one([Binding]) ->
71    {reply, {true, Binding}, []};
72next_one([Binding|Rest]) ->
73    {reply, {true, Binding}, Rest}.
74
75next_n([], _) ->
76    {reply, {false, []}, []};
77next_n(List, HowMany) ->
78    {More, Acc, NewList} = split(List, HowMany, []),
79    {reply, {More, Acc}, NewList}.
80
81split([], _, Acc) ->
82    {false, Acc, []};
83split(Rest, 0, Acc) ->
84    {true, Acc, Rest};
85split([H|T], N, Acc) ->
86    split(T, N-1, [H|Acc]).
87
88
89destroy(OE_State) ->
90    {stop, normal, ok, OE_State}.
91
92%%-----------------------------------------------------------------
93%% Internal functions
94%%-----------------------------------------------------------------
95