PageRenderTime 87ms CodeModel.GetById 21ms app.highlight 61ms RepoModel.GetById 2ms app.codeStats 0ms

/core/externals/update-engine/externals/gdata-objectivec-client/Source/Clients/Spreadsheets/GDataSpreadsheetCell.m

http://macfuse.googlecode.com/
Objective C | 196 lines | 137 code | 37 blank | 22 comment | 18 complexity | 3a3748de39d79b98e9e2724d07bd8e17 MD5 | raw file
  1/* Copyright (c) 2007 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
 16//
 17//  GDataSpreadsheetCell.m
 18//
 19
 20#if !GDATA_REQUIRE_SERVICE_INCLUDES || GDATA_INCLUDE_SPREADSHEET_SERVICE
 21
 22#import "GDataSpreadsheetCell.h"
 23
 24#import "GDataEntrySpreadsheet.h" // for namespaces
 25
 26@implementation GDataSpreadsheetCell
 27
 28// For spreadsheet cells like:
 29//   <gs:cell row="2" col="4" inputValue="=FLOOR(R[0]C[-1]/(R[0]C[-2]*60),.0001)"
 30//            numericValue="0.0033">0.0033</gs:cell>
 31//
 32// http://code.google.com/apis/spreadsheets/reference.html#gs_reference
 33
 34+ (NSString *)extensionElementURI       { return kGDataNamespaceGSpread; }
 35+ (NSString *)extensionElementPrefix    { return kGDataNamespaceGSpreadPrefix; }
 36+ (NSString *)extensionElementLocalName { return @"cell"; }
 37
 38+ (GDataSpreadsheetCell *)cellWithRow:(NSInteger)row
 39                               column:(NSInteger)column
 40                          inputString:(NSString *)inputStr
 41                         numericValue:(NSNumber *)numericValue
 42                         resultString:(NSString *)resultStr {
 43  
 44  GDataSpreadsheetCell *obj = [self object];
 45  [obj setRow:row];
 46  [obj setColumn:column];
 47  [obj setInputString:inputStr];
 48  [obj setNumericValue:numericValue];
 49  [obj setResultString:resultStr];
 50  return obj;
 51}
 52
 53- (id)init {
 54  self = [super init];
 55  if (self) {
 56    row_ = -1;
 57    column_ = -1;
 58  }
 59  return self;
 60}
 61
 62- (id)initWithXMLElement:(NSXMLElement *)element
 63                  parent:(GDataObject *)parent {
 64  self = [super initWithXMLElement:element
 65                            parent:parent];
 66  if (self) {
 67    NSString *rowStr = [self stringForAttributeName:@"row"
 68                                        fromElement:element];
 69    if (rowStr) {
 70      [self setRow:[rowStr intValue]];
 71    }
 72
 73    NSString *columnStr = [self stringForAttributeName:@"col"
 74                                        fromElement:element];
 75    if (columnStr) {
 76      [self setColumn:[columnStr intValue]];
 77    }
 78
 79    [self setInputString:[self stringForAttributeName:@"inputValue"
 80                                          fromElement:element]];
 81
 82    [self setNumericValue:[self doubleNumberForAttributeName:@"numericValue"
 83                                                 fromElement:element]];
 84      
 85    [self setResultString:[self stringValueFromElement:element]];
 86
 87  }
 88  return self;
 89}
 90
 91- (void)dealloc {
 92  [inputString_ release];
 93  [numericValue_ release];
 94  [resultString_ release];
 95  [super dealloc];
 96}
 97
 98- (id)copyWithZone:(NSZone *)zone {
 99  GDataSpreadsheetCell* newObj = [super copyWithZone:zone];
100  [newObj setRow:[self row]];
101  [newObj setColumn:[self column]];
102  [newObj setInputString:[self inputString]];
103  [newObj setNumericValue:[self numericValue]];
104  [newObj setResultString:[self resultString]];
105  return newObj;
106}
107
108- (BOOL)isEqual:(GDataSpreadsheetCell *)other {
109  if (self == other) return YES;
110  if (![other isKindOfClass:[GDataSpreadsheetCell class]]) return NO;
111  
112  return [super isEqual:other]
113    && ([self row] == [other row])
114    && ([self column] == [other column])
115    && AreEqualOrBothNil([self inputString], [other inputString])
116    && AreEqualOrBothNil([self numericValue], [other numericValue])
117    && AreEqualOrBothNil([self resultString], [other resultString]);
118}
119
120#if !GDATA_SIMPLE_DESCRIPTIONS
121- (NSMutableArray *)itemsForDescription {
122  NSMutableArray *items = [NSMutableArray array];
123  
124  [self addToArray:items objectDescriptionIfNonNil:inputString_ withName:@"inputString"];
125  [self addToArray:items objectDescriptionIfNonNil:numericValue_ withName:@"numericValue"];
126  [self addToArray:items objectDescriptionIfNonNil:resultString_ withName:@"resultString"];
127  
128  return items;
129}
130#endif
131
132- (NSXMLElement *)XMLElement {
133  
134  NSXMLElement *element = [self XMLElementWithExtensionsAndDefaultName:@"gs:cell"];
135
136  if (row_ > 0) {
137    [self addToElement:element attributeValueWithInteger:row_ withName:@"row"];
138  }
139  if (column_ > 0) {
140    [self addToElement:element attributeValueWithInteger:column_ withName:@"col"];
141  }
142  
143  [self addToElement:element attributeValueIfNonNil:inputString_ withName:@"inputValue"];
144
145  [self addToElement:element
146 attributeValueIfNonNil:[numericValue_ stringValue]
147            withName:@"numericValue"];
148
149  if ([resultString_ length] > 0) {
150    [element addStringValue:resultString_]; 
151  }
152    
153  return element;
154}
155
156- (NSInteger)row {
157  return row_; 
158}
159- (void)setRow:(NSInteger)row {
160  row_ = row; 
161}
162
163- (NSInteger)column {
164  return column_; 
165}
166- (void)setColumn:(NSInteger)column {
167  column_ = column; 
168}
169
170- (NSString *)inputString {
171  return inputString_; 
172}
173- (void)setInputString:(NSString *)str {
174  [inputString_ autorelease];
175  inputString_ = [str copy];
176}
177
178- (NSNumber *)numericValue {
179  return numericValue_;
180}
181- (void)setNumericValue:(NSNumber *)num {
182  [numericValue_ autorelease];
183  numericValue_ = [num copy]; 
184}
185
186- (NSString *)resultString {
187  return resultString_; 
188}
189- (void)setResultString:(NSString *)str {
190  [resultString_ autorelease];
191  resultString_ = [str copy];
192}
193
194@end
195
196#endif // !GDATA_REQUIRE_SERVICE_INCLUDES || GDATA_INCLUDE_SPREADSHEET_SERVICE