Home | History | Annotate | Download | only in src
      1 // Copyright (C) 2014 Google Inc.
      2 //
      3 // Licensed under the Apache License, Version 2.0 (the "License");
      4 // you may not use this file except in compliance with the License.
      5 // You may obtain a copy of the License at
      6 //
      7 // http://www.apache.org/licenses/LICENSE-2.0
      8 //
      9 // Unless required by applicable law or agreed to in writing, software
     10 // distributed under the License is distributed on an "AS IS" BASIS,
     11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12 // See the License for the specific language governing permissions and
     13 // limitations under the License.
     14 
     15 #include <libaddressinput/region_data.h>
     16 
     17 #include <cassert>
     18 #include <cstddef>
     19 #include <string>
     20 #include <vector>
     21 
     22 namespace i18n {
     23 namespace addressinput {
     24 
     25 RegionData::RegionData(const std::string& region_code)
     26     : key_(region_code),
     27       name_(region_code),
     28       parent_(NULL),
     29       sub_regions_() {}
     30 
     31 RegionData::~RegionData() {
     32   for (std::vector<const RegionData*>::const_iterator it = sub_regions_.begin();
     33        it != sub_regions_.end(); ++it) {
     34     delete *it;
     35   }
     36 }
     37 
     38 RegionData* RegionData::AddSubRegion(const std::string& key,
     39                                      const std::string& name) {
     40   RegionData* sub_region = new RegionData(key, name, this);
     41   sub_regions_.push_back(sub_region);
     42   return sub_region;
     43 }
     44 
     45 RegionData::RegionData(const std::string& key,
     46                        const std::string& name,
     47                        RegionData* parent)
     48     : key_(key), name_(name), parent_(parent), sub_regions_() {}
     49 
     50 }  // namespace addressinput
     51 }  // namespace i18n
     52