mod kind;
mod source_tree;
use super::*;
use crate::pbxproj::PBXHashMap;
use anyhow::Result;
pub use kind::*;
pub use source_tree::*;
#[derive(Debug, Default)]
pub struct PBXFSReference<'a> {
pub id: String,
pub source_tree: PBXSourceTree,
pub path: Option<&'a String>,
pub name: Option<&'a String>,
pub include_in_index: Option<bool>,
pub uses_tabs: Option<bool>,
pub indent_width: Option<&'a isize>,
pub tab_width: Option<&'a isize>,
pub wraps_lines: Option<bool>,
pub kind: PBXFSReferenceKind,
pub file_encoding: Option<&'a isize>,
pub explicit_file_type: Option<&'a String>,
pub last_known_file_type: Option<&'a String>,
pub line_ending: Option<&'a isize>,
pub language_specification_identifier: Option<&'a String>,
pub xc_language_specification_identifier: Option<&'a String>,
pub plist_structure_definition_identifier: Option<&'a String>,
pub current_version_reference: Option<&'a String>,
pub version_group_type: Option<&'a String>,
pub parent: Option<Box<Self>>,
pub children: Vec<Self>,
}
impl<'a> Eq for PBXFSReference<'a> {}
impl<'a> PartialEq for PBXFSReference<'a> {
fn eq(&self, other: &Self) -> bool {
self.kind == other.kind
&& self.source_tree == other.source_tree
&& self.path == other.path
&& self.name == other.name
&& self.current_version_reference == other.current_version_reference
&& self.version_group_type == other.version_group_type
&& self.include_in_index == other.include_in_index
&& self.uses_tabs == other.uses_tabs
&& self.indent_width == other.indent_width
&& self.tab_width == other.tab_width
&& self.wraps_lines == other.wraps_lines
&& self.file_encoding == other.file_encoding
&& self.explicit_file_type == other.explicit_file_type
&& self.last_known_file_type == other.last_known_file_type
&& self.line_ending == other.line_ending
&& self.language_specification_identifier == other.language_specification_identifier
&& self.xc_language_specification_identifier
== other.xc_language_specification_identifier
&& self.plist_structure_definition_identifier
== other.plist_structure_definition_identifier
}
}
impl<'a> AsPBXObject<'a> for PBXFSReference<'a> {
fn as_pbx_object(
id: String,
value: &'a PBXHashMap,
objects: &'a PBXObjectCollection,
) -> Result<Self>
where
Self: Sized + 'a,
{
let kind = value
.try_get_kind("isa")?
.as_pbxfs_reference()
.ok_or_else(|| anyhow::anyhow!("isa isn't defined: trying to get `PBXFSReference`"))?
.clone();
Ok(Self {
id,
name: value.get_string("name"),
path: value.get_string("path"),
kind,
source_tree: value
.get_string("sourceTree")
.map(|s| s.as_str().into())
.unwrap_or_default(),
include_in_index: value.get_number("includeInIndex").map(|v| v == &1),
uses_tabs: value.get_number("usesTabs").map(|v| v == &1),
indent_width: value.get_number("indentWidth"),
tab_width: value.get_number("tabWidth"),
wraps_lines: value.get_number("wrapsLines").map(|v| v == &1),
current_version_reference: value.get_string("currentVersion"),
parent: None,
file_encoding: value.get_number("fileEncoding"),
explicit_file_type: value.get_string("explicitFileType"),
last_known_file_type: value.get_string("lastKnownFileType"),
line_ending: value.get_number("lineEnding"),
language_specification_identifier: value.get_string("languageSpecificationIdentifier"),
xc_language_specification_identifier: value
.get_string("xcLanguageSpecificationIdentifier"),
plist_structure_definition_identifier: value
.get_string("xcLanguageSpecificationIdentifier"),
version_group_type: value.get_string("versioGroupType"),
children: value
.get_vec("children")
.map(|v| objects.get_vec(v.as_vec_strings()))
.unwrap_or_default(),
})
}
}
impl<'a> PBXFSReference<'a> {
pub fn is_group(&self) -> bool {
self.kind.is_group()
}
pub fn is_file_group(&self) -> bool {
self.kind.is_file_group()
}
pub fn is_version_group(&self) -> bool {
self.kind.is_version_group()
}
pub fn is_varient_group(&self) -> bool {
self.kind.is_variant_group()
}
pub fn is_file(&self) -> bool {
self.kind.is_file()
}
}