Source

lqpl / GUI / src / panels / quantum_stack / descriptor / qubit_descriptor_model.rb

class QubitDescriptorModel < AbstractDescriptorModel

  PATTERN=Regexp.new /^<Qubits>((<pair>((<qz\/>)|(<qo\/>))((<qz\/>)|(<qo\/>))<\/pair>){1,4})<\/Qubits>$/

  LIST_PATTERN = Regexp.new /^(<pair>((<qz\/>)|(<qo\/>))((<qz\/>)|(<qo\/>))<\/pair>)/
  # match 2 and 5

  def initialize(in_string)
    @value = check_and_return_value(PATTERN,in_string,
      lambda { |m| QubitDescriptorModel::parse_list m})
  end

  def length
    @value.length
  end

  def substack_labels
    @value.collect {|v| "#{v[0]}#{v[1]}"}
  end


  def self.parse_list(qubit_string)
    raise InvalidInput, "Must have qubit indicators" if !qubit_string or qubit_string.length == 0
    r = values_to_list qubit_string, LIST_PATTERN  do |rval,md|
      elem = [self.translate_qubit(md[2]), self.translate_qubit(md[5])]
      raise InvalidInput, "#{elem} duplicated in qubit" if rval.include? elem
      rval << elem
    end

    raise InvalidInput, qubit_string if r.length > 4

    raise InvalidInput, qubit_string if r.length == 0 and qubit_string and qubit_string.length > 0
    r
  end

  def self.translate_qubit(single_qubit)
   case single_qubit
   when "<qz/>" then 0
   when "<qo/>" then 1
   else raise InvalidInput, "Got #{single_qubit}, expecting one of '<qz/>' or '<qo/>'"
   end
 end
end
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.