src/jdk.incubator.jpackage/share/native/libapplauncher/OrderedMap.h
author herrick
Fri, 08 Nov 2019 14:53:03 -0500
branchJDK-8200758-branch
changeset 58994 b09ba68c6a19
parent 57455 src/jdk.jpackage/share/native/libapplauncher/OrderedMap.h@f1290ca0fee6
permissions -rw-r--r--
8233636 : Make jpackage an incubator and remove tool provider implementation Reviewed-by: asemenyuk, almatvee, kcr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
57064
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
     1
/*
57106
ea870b9ce89a 8216492: Update copyright of all new jpackage fils to 2019
kcr
parents: 57064
diff changeset
     2
 * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
57064
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
     4
 *
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    10
 *
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    15
 * accompanied this code).
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    16
 *
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    20
 *
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    23
 * questions.
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    24
 */
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    25
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    26
#ifndef ORDEREDMAP_H
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    27
#define ORDEREDMAP_H
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    28
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    29
#include <map>
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    30
#include <vector>
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    31
#include <assert.h>
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    32
#include <stdexcept>
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    33
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    34
#include <iostream>
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    35
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    36
template <typename _T1, typename _T2>
57194
9d5fccd97421 8212091: Move jpackage native code under platform specific folders and files
herrick
parents: 57106
diff changeset
    37
struct JPPair
57064
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    38
{
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    39
    typedef _T1 first_type;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    40
    typedef _T2 second_type;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    41
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    42
    first_type first;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    43
    second_type second;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    44
57194
9d5fccd97421 8212091: Move jpackage native code under platform specific folders and files
herrick
parents: 57106
diff changeset
    45
    JPPair(first_type Value1, second_type Value2) {
57064
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    46
        first = Value1;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    47
        second = Value2;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    48
    }
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    49
};
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    50
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    51
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    52
template <typename TKey, typename TValue>
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    53
class OrderedMap {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    54
public:
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    55
    typedef TKey key_type;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    56
    typedef TValue mapped_type;
57194
9d5fccd97421 8212091: Move jpackage native code under platform specific folders and files
herrick
parents: 57106
diff changeset
    57
    typedef JPPair<key_type, mapped_type> container_type;
57064
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    58
    typedef typename std::vector<container_type*>::iterator iterator;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    59
    typedef typename std::vector<container_type*>::const_iterator const_iterator;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    60
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    61
private:
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    62
    typedef std::map<key_type, container_type*> map_type;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    63
    typedef std::vector<container_type*> list_type;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    64
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    65
    map_type FMap;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    66
    list_type FList;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    67
    bool FAllowDuplicates;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    68
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    69
    typename list_type::iterator FindListItem(const key_type Key) {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    70
        typename list_type::iterator result = FList.end();
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    71
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    72
        for (typename list_type::iterator iterator =
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    73
                FList.begin(); iterator != FList.end(); iterator++) {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    74
            container_type *item = *iterator;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    75
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    76
            if (item->first == Key) {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    77
                result = iterator;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    78
                break;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    79
            }
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    80
        }
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    81
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    82
        return result;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    83
    }
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    84
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    85
public:
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    86
    OrderedMap() {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    87
        FAllowDuplicates = false;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    88
    }
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    89
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    90
    OrderedMap(const OrderedMap<key_type, mapped_type> &Value) {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    91
        Append(Value);
57455
f1290ca0fee6 8227058: Regressions related to no longer setting user.dir
herrick
parents: 57194
diff changeset
    92
        FAllowDuplicates = Value.GetAllowDuplicates();
57064
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    93
    }
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    94
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    95
    ~OrderedMap() {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    96
        Clear();
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    97
    }
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    98
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    99
    void SetAllowDuplicates(bool Value) {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   100
        FAllowDuplicates = Value;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   101
    }
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   102
57455
f1290ca0fee6 8227058: Regressions related to no longer setting user.dir
herrick
parents: 57194
diff changeset
   103
    bool GetAllowDuplicates() const {
f1290ca0fee6 8227058: Regressions related to no longer setting user.dir
herrick
parents: 57194
diff changeset
   104
        return FAllowDuplicates;
f1290ca0fee6 8227058: Regressions related to no longer setting user.dir
herrick
parents: 57194
diff changeset
   105
    }
f1290ca0fee6 8227058: Regressions related to no longer setting user.dir
herrick
parents: 57194
diff changeset
   106
57064
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   107
    iterator begin() {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   108
        return FList.begin();
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   109
    }
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   110
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   111
    const_iterator begin() const {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   112
        return FList.begin();
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   113
    }
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   114
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   115
    iterator end() {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   116
        return FList.end();
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   117
    }
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   118
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   119
    const_iterator end() const {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   120
        return FList.end();
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   121
    }
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   122
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   123
    void Clear() {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   124
        for (typename list_type::iterator iterator =
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   125
                FList.begin(); iterator != FList.end(); iterator++) {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   126
            container_type *item = *iterator;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   127
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   128
            if (item != NULL) {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   129
                delete item;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   130
                item = NULL;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   131
            }
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   132
        }
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   133
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   134
        FMap.clear();
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   135
        FList.clear();
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   136
    }
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   137
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   138
    bool ContainsKey(key_type Key) {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   139
        bool result = false;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   140
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   141
        if (FMap.find(Key) != FMap.end()) {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   142
            result = true;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   143
        }
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   144
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   145
        return result;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   146
    }
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   147
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   148
    std::vector<key_type> GetKeys() {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   149
        std::vector<key_type> result;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   150
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   151
        for (typename list_type::const_iterator iterator = FList.begin();
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   152
             iterator != FList.end(); iterator++) {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   153
            container_type *item = *iterator;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   154
            result.push_back(item->first);
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   155
        }
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   156
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   157
        return result;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   158
    }
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   159
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   160
    void Assign(const OrderedMap<key_type, mapped_type> &Value) {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   161
        Clear();
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   162
        Append(Value);
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   163
    }
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   164
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   165
    void Append(const OrderedMap<key_type, mapped_type> &Value) {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   166
        for (size_t index = 0; index < Value.FList.size(); index++) {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   167
            container_type *item = Value.FList[index];
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   168
            Append(item->first, item->second);
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   169
        }
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   170
    }
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   171
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   172
    void Append(key_type Key, mapped_type Value) {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   173
        container_type *item = new container_type(Key, Value);
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   174
        FMap.insert(std::pair<key_type, container_type*>(Key, item));
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   175
        FList.push_back(item);
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   176
    }
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   177
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   178
    bool RemoveByKey(key_type Key) {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   179
        bool result = false;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   180
        typename list_type::iterator iterator = FindListItem(Key);
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   181
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   182
        if (iterator != FList.end()) {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   183
            FMap.erase(Key);
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   184
            FList.erase(iterator);
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   185
            result = true;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   186
        }
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   187
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   188
        return result;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   189
    }
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   190
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   191
    bool GetValue(key_type Key, mapped_type &Value) {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   192
        bool result = false;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   193
        container_type* item = FMap[Key];
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   194
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   195
        if (item != NULL) {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   196
            Value = item->second;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   197
            result = true;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   198
        }
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   199
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   200
        return result;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   201
    }
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   202
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   203
    bool SetValue(key_type Key, mapped_type &Value) {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   204
        bool result = false;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   205
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   206
        if ((FAllowDuplicates == false) && (ContainsKey(Key) == true)) {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   207
            container_type *item = FMap[Key];
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   208
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   209
            if (item != NULL) {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   210
                item->second = Value;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   211
                result = true;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   212
            }
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   213
        }
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   214
        else {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   215
            Append(Key, Value);
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   216
            result = true;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   217
        }
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   218
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   219
        return result;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   220
    }
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   221
57455
f1290ca0fee6 8227058: Regressions related to no longer setting user.dir
herrick
parents: 57194
diff changeset
   222
    bool GetKey(int index, key_type &Value) {
f1290ca0fee6 8227058: Regressions related to no longer setting user.dir
herrick
parents: 57194
diff changeset
   223
        if (index < 0 || index >= (int)FList.size()) {
f1290ca0fee6 8227058: Regressions related to no longer setting user.dir
herrick
parents: 57194
diff changeset
   224
            return false;
f1290ca0fee6 8227058: Regressions related to no longer setting user.dir
herrick
parents: 57194
diff changeset
   225
        }
f1290ca0fee6 8227058: Regressions related to no longer setting user.dir
herrick
parents: 57194
diff changeset
   226
        container_type *item = FList.at(index);
f1290ca0fee6 8227058: Regressions related to no longer setting user.dir
herrick
parents: 57194
diff changeset
   227
        if (item != NULL) {
f1290ca0fee6 8227058: Regressions related to no longer setting user.dir
herrick
parents: 57194
diff changeset
   228
            Value = item->first;
f1290ca0fee6 8227058: Regressions related to no longer setting user.dir
herrick
parents: 57194
diff changeset
   229
            return true;
f1290ca0fee6 8227058: Regressions related to no longer setting user.dir
herrick
parents: 57194
diff changeset
   230
        }
f1290ca0fee6 8227058: Regressions related to no longer setting user.dir
herrick
parents: 57194
diff changeset
   231
f1290ca0fee6 8227058: Regressions related to no longer setting user.dir
herrick
parents: 57194
diff changeset
   232
        return false;
f1290ca0fee6 8227058: Regressions related to no longer setting user.dir
herrick
parents: 57194
diff changeset
   233
    }
f1290ca0fee6 8227058: Regressions related to no longer setting user.dir
herrick
parents: 57194
diff changeset
   234
f1290ca0fee6 8227058: Regressions related to no longer setting user.dir
herrick
parents: 57194
diff changeset
   235
    bool GetValue(int index, mapped_type &Value) {
f1290ca0fee6 8227058: Regressions related to no longer setting user.dir
herrick
parents: 57194
diff changeset
   236
        if (index < 0 || index >= (int)FList.size()) {
f1290ca0fee6 8227058: Regressions related to no longer setting user.dir
herrick
parents: 57194
diff changeset
   237
            return false;
f1290ca0fee6 8227058: Regressions related to no longer setting user.dir
herrick
parents: 57194
diff changeset
   238
        }
f1290ca0fee6 8227058: Regressions related to no longer setting user.dir
herrick
parents: 57194
diff changeset
   239
        container_type *item = FList.at(index);
f1290ca0fee6 8227058: Regressions related to no longer setting user.dir
herrick
parents: 57194
diff changeset
   240
        if (item != NULL) {
f1290ca0fee6 8227058: Regressions related to no longer setting user.dir
herrick
parents: 57194
diff changeset
   241
            Value = item->second;
f1290ca0fee6 8227058: Regressions related to no longer setting user.dir
herrick
parents: 57194
diff changeset
   242
            return true;
f1290ca0fee6 8227058: Regressions related to no longer setting user.dir
herrick
parents: 57194
diff changeset
   243
        }
f1290ca0fee6 8227058: Regressions related to no longer setting user.dir
herrick
parents: 57194
diff changeset
   244
f1290ca0fee6 8227058: Regressions related to no longer setting user.dir
herrick
parents: 57194
diff changeset
   245
        return false;
f1290ca0fee6 8227058: Regressions related to no longer setting user.dir
herrick
parents: 57194
diff changeset
   246
    }
f1290ca0fee6 8227058: Regressions related to no longer setting user.dir
herrick
parents: 57194
diff changeset
   247
57064
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   248
    mapped_type &operator[](key_type Key) {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   249
        container_type* item = FMap[Key];
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   250
        assert(item != NULL);
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   251
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   252
        if (item != NULL) {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   253
            return item->second;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   254
        }
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   255
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   256
        throw std::invalid_argument("Key not found");
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   257
    }
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   258
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   259
    OrderedMap& operator= (OrderedMap &Value) {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   260
        Clear();
57455
f1290ca0fee6 8227058: Regressions related to no longer setting user.dir
herrick
parents: 57194
diff changeset
   261
        FAllowDuplicates = Value.GetAllowDuplicates();
57064
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   262
        Append(Value);
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   263
        return *this;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   264
    }
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   265
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   266
    size_t Count() {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   267
        return FList.size();
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   268
    }
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   269
};
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   270
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   271
#endif // ORDEREDMAP_H