Helix Core is now P4. Product user interfaces will be updated soon. Learn more >>

P4 Server Administration Documentation | 2025.1

# Class P4.Map

## Description

The `P4.Map` class allows users to create and work with P4 Server mappings without requiring a connection to a P4 Server.

## Class Methods

### Map.join ( map1, map2 ) -> Map

Join two `P4.Map` objects and create a third.

The new map is composed of the left-hand side of the first mapping, as joined to the right-hand side of the second mapping. For example:

Copy

    # Map depot syntax to client syntax
    client_map = P4.Map:new()
    client_map:insert( "//depot/main/...", "//client/..." )

    # Map client syntax to local syntax
    client_root = P4.Map:new()
    client_root:insert( "//client/...", "/home/bruno/workspace/..." )

    # Join the previous mappings to map depot syntax to local syntax
    local_map = P4::Map:new()
    local_map = local_map:join( client_map, client_root )
    local_path = local_map:translate( "//depot/main/www/index.html" )

    # local_path is now /home/bruno/workspace/www/index.html

## Instance Methods

### map:clear() -> boolean

Empty a map.

### map:count () -> number

Return the number of entries in a map.

### map:includes ( string) -> boolean

Tests whether a path is mapped or not.

### map:insert( string, [ string ] ) -> Map

Inserts an entry into the map.

Can be called with one or two arguments. If called with one argument, the string is assumed to be a string containing either a half-map, or a string containing both halves of the mapping. In this form, mappings with embedded spaces must be quoted. If called with two arguments, each argument is assumed to be half of the mapping, and quotes are optional.

Copy

    # called with two arguments:
    map:insert( "//depot/main/...", "//client/..." )

    # called with one argument containing both halves of the mapping:
    map:insert( "//depot/live/... //client/live/..." )

    # called with one argument containing a half-map:
    # This call produces the mapping "depot/... depot/..."
    map:insert( "depot/..." )

### map:isempty() -> boolean

Test whether a map object is empty.

### map:lhs() -> table

Returns the left side of a mapping as a table.

### map:reverse()

Reverses the `P4.Map` object with the left and right sides of the mapping swapped.

### map:rhs() -> table

Returns the right side of a mapping as a table.

### map:to_a() -> table

Returns the map as a table.

### map:translate( string, [ boolean] ) -> string

Translates a file path from one side of a mapping to the other. If the optional second argument is true, translate forward, and if it is false, translate in the reverse direction. By default, translation is in the forward direction.

Your search for returned results