/*
Copyright 2011-2016 Google Inc. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package com.google.security.zynamics.binnavi.API.debug;

import java.util.ArrayList;
import java.util.List;


// / Describes the layout of the target process memory.
/**
 * Gives information about the layout of the target process memory. The memory is made up from
 * several allocated memory sections with gaps in between. Using the memory map it is possible to
 * find out what parts of the target process memory contain data.
 */
public final class MemoryMap {
  /**
   * Wrapped internal memory map object.
   */
  private final com.google.security.zynamics.binnavi.debug.models.processmanager.MemoryMap
      memoryMap;

  // / @cond INTERNAL
  /**
   * Creates a new memory map object.
   *
   * @param memoryMap The wrapped internal memory object.
   */
  // / @endcond
  public MemoryMap(
      final com.google.security.zynamics.binnavi.debug.models.processmanager.MemoryMap memoryMap) {
    this.memoryMap = memoryMap;
  }

  // ! Returns the memory sections.
  /**
   * Returns a list of memory sections that describe the allocated memory data in the target memory
   * process.
   *
   * @return A list of memory sections.
   */
  public List<MemorySection> getSections() {
    final List<MemorySection> sections = new ArrayList<>();
    for (final com.google.security.zynamics.binnavi.debug.models.processmanager.MemorySection
        section : memoryMap) {
      sections.add(new MemorySection(section));
    }
    return sections;
  }

  // ! Printable representation of the memory map.
  /**
   * Returns a string representation of the memory map.
   *
   * @return A string representation of the memory map.
   */
  @Override
  public String toString() {
    return String.format("Memory Map (%d sections)", memoryMap.getNumberOfSections());
  }
}
